Upperdecker
asked on
Nested plus & minus not changing image.
Hello,
The image now changes from the help of another question, but now if I nest within a link so I have a parent child which become a parent to a child the image for +- doesn't change. Here is the view source for the page.
The image now changes from the help of another question, but now if I nest within a link so I have a parent child which become a parent to a child the image for +- doesn't change. Here is the view source for the page.
islogged = 1
Response.Write(WGUID)
'if ACRUD >14 OR SiteOwner = 1 Then
'if Request.Cookies("editMode")<>0 then
'webpartEditor= ACRUD
'else
'webpartEditor= ACRUD
'end if
'
'Else
'
'if Request.Cookies("LeditMode")<>0 then
'webpartEditor = ACRUD
'else
'webpartEditor = ACRUD
'end if
'end if
Class Collection
Private m_next,m_len
Private m_dic
Public Sub Add(Item)
m_dic.Add "K" & m_next,Item
m_next = m_next+1
m_len = m_len+1
End Sub
Public Sub Clear
m_dic.RemoveAll
End Sub
Public Function Length
Length=m_len
End Function
Public Default Function Item(Index)
Dim tempItem,i
For Each tempItem In m_dic.Items
If i=Index Then
Set Item=tempItem
Exit Function
End If
i=i+1
Next
End Function
Public Sub Remove(ByVal Index)
Dim Item,i
For Each Item In m_dic.Items
If i=Index Then
m_dic.Remove(Item)
m_len=m_len-1
Exit Sub
End If
i=i+1
Next
End Sub
Private Sub Class_Initialize
m_len=0
Set m_dic = Server.CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate
Set m_dic = Nothing
End Sub
End Class
Class Node
Public Parent
Public Text
Public Href
Public Target
Public ToolTipText
Public ChildNodes
Public ImageUrl
Public MenuID
Public ID
Public LinkID
Public RestrictEdit
Public Sub Init(strText,strHref,strToolTipText,strTarget,strMenuID,strLinkID,RestrictEdit)
Text=strText
Href=strHref
ToolTipText=strToolTipText
Target=strTarget
MenuID= strMenuID
LinkID= strLinkID
RestrictEdit = strRestrictEdit
End Sub
Public Sub Add(objNode)
ChildNodes.Add(objNode)
End Sub
Private Sub Class_Initialize
Set ChildNodes = New Collection
End Sub
Private Sub Class_Terminate
Set ChildNodes = Nothing
End Sub
End Class
Class TreeView
Private m_folder
Public Color
Public Nodes
Public DefaultTarget
Public ID
Public LinkID
Public Property Let ImagesFolder(strFolder)
m_folder=strFolder
End Property
Public Property Get ImagesFolder()
ImagesFolder=m_folder
End Property
Private Sub Class_Initialize
Set Nodes = New Collection
Color="660099"
m_folder= commonImages
End Sub
Private Sub Class_Terminate
Set Nodes = Nothing
End Sub
Public Function AddNode(Text)
Dim tn
Set tn = new Node
tn.Text=Text
Nodes.Add(tn)
End Function
Public Function CreateNode(Text,Href,ToolTipText,Target,LinkID)
Dim tn
Set tn = new Node
Call tn.Init(Text,Href,ToolTipText,Target,LinkID)
Set CreateNode=tn
End Function
Public Function CreateSimpleNode(Text)
Dim tn
Set tn = new Node
tn.Text = Text
Set CreateSimpleNode=tn
End Function
Private Sub LoopThru(NodeList,Parent)
Dim i,j,Node,blnHasChild,strStyle
If Parent="0" Then
'If LinkID="" Then
Response.write("<a href=link_editor.asp?WGUID="&WGUID&"&sMode=Links ><img src="&newLink&" alt="&anewLink&"/></a><br>" )
'End If
End If
If Parent<>"0" Then
Out ("<ul class=tree id=""N"&LinkID&Parent & """>")
Else
'Out ("<ul xstyle='margin-left:20px;' id=""N"&LinkID& Parent & """>")
Out ("<ul class=folder id=""P"&LinkID& Parent & """>")
End If
For i=0 To NodeList.Length-1
Set Node = NodeList(i)
If (Node.ChildNodes.Length>0) Then
blnHasChild=True
Else
blnHasChild=False
End If
If Node.ImageUrl="" Then
strStyle=""
Else
strStyle=" style='list-style-image: url("& Node.ImageUrl &");'"
End If
If blnHasChild Then
Out("<li class=folder id=""N" &Node.LinkID & Parent & """><a class=treeview href=""javascript:toggle('N"&Node.LinkID & Parent & "_" & i & "','N"&Node.LinkID & Parent & "')"">" & Node.Text & "</a>")
if isLogged = 1 then
Out(" ")
if ACRUD >14 OR SiteOwner = 1 OR webpartEditor > 6 then
Out("<a href='link_editor.asp?LinkID="&Node.MenuID&"&sMode=Links&WGUID="&WGUID&"' style=""cursor:pointer"" onclick=""if(document.getElementById('addPrimary').style.display=='none') { this.innerHTML='<img src="&smallRedx&" alt="&asmallRedx&" />';document.getElementById('addLink').style.display='block';} else { this.innerHTML='<img src="&smallRedx&" alt="&asmallRedx&" />';document.getElementById('addLink').style.display='none';}""><img src="&smallGreenplus&" alt="&asmallGreenplus&" /></a>")
end if
if ACRUD >14 OR SiteOwner = 1 OR webpartEditor > 14 then
Out("/<form name=""formDelete"" method=""post""><input name=""nodeValue"" id=""nodeValue"" type=""hidden"" value="&Node.MenuID&" /><input type=""image"" name=""delete"" alt="&asmallRedx&" src="&smallRedx&" value='" &Node.MenuID&"'><input name=""WGUID"" id=""WGUID"" type=""hidden"" value="&WGUID&" /></form>")
end if
End if
Else
If Node.Target="" Then
Node.Target=DefaultTarget
End If
Out("<li class=file><a class=treeview href=""javascript:popup('" & Node.Href & """ target=""_new"" title=""" & Node.ToolTipText & "')"">"& Node.Text & "</a>")
if isLogged = 1 then
Out(" ")
if ACRUD >14 OR SiteOwner = 1 OR webpartEditor > 6 then
Out("<a href='link_editor.asp?WGUID="&WGUID&"&LinkID="&Node.MenuID&"&sMode=Links' style=""cursor:pointer"" onclick=""if(document.getElementById('addPrimary').style.display=='none') { this.innerHTML='<img src="&smallRedx&" alt="&asmallRedx&" />';document.getElementById('addLink').style.display='block';} else { this.innerHTML='<img src="&smallRedx&" alt="&asmallRedx&" />';document.getElementById('addLink').style.display='none';}""><img src="&smallGreenplus&" alt="&asmallGreenplus&" /></a>")
end if
if ACRUD >14 OR SiteOwner = 1 OR webpartEditor > 14 then
Out("/<form name=""formDelete"" method=""post""><input name=""nodeValue"" id=""nodeValue"" type=""hidden"" value="&Node.MenuID&" /><input type=""image"" name=""delete"" alt="&asmallRedx&" src="&smallRedx&" value='" &Node.MenuID&"'><input name=""WGUID"" id=""WGUID"" type=""hidden"" value="&WGUID&" /></form>")
end if
end if
end if
If blnHasChild Then
Call LoopThru(Node.ChildNodes,Parent & "_" & i )
End If
If blnHasChild Then
Call LoopThru(Node.ChildNodes,Parent & "_" & i )
End If
'EO !!!!!!!!!! Editor Controls
Out ("</li>")
Next
Out ("</ul>")
End Sub
Private Sub Out(s)
Response.Write(s)
End Sub
Public Sub Display
Out("<script>function toggle(id,p){var myChild = document.getElementById(id);if(myChild.style.display!='block'){myChild.style.display='block';document.getElementById(p).className='folderMinus';}else{myChild.style.display='none';document.getElementById(p).className='folder';}}</script>")
Out("<style>ul.tree{display:none;margin-left:17px;}li.folder{list-style-image: url("&menu_plus&");}li.folderMinus{list-style-image: url("&menu_minus&");}li.file{list-style-image: url("&menu_dot&");}a.treeview{color:"& Color &";font-family:verdana;font-size:8pt;}a.treeview:link {text-decoration:none;}a.treeview:visited{text-decoration:none;}a.treeview:hover {text-decoration:underline;}</style>")
Call LoopThru(Nodes,0)
End Sub
Public Sub LoadFromDB(dataConn,strMenuTable,strSiteID, strPositionID,WGUID)
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open dataConn
strOrder="LinkText"
Response.write(webpartEditor)
If (Cstr(Request("delete")) <> "") then 'name of button
nodeValue = Request.form("nodeValue")
WGUID = Request.form("WGUID")
set dlconx=Server.CreateObject("ADODB.Connection")
dlconx.Open = dataConn
SQL="DELETE FROM "&LinkList&" WHERE MenuID="&nodeValue
dlconx.Execute SQL
set dlconn=Server.CreateObject("ADODB.Connection")
dlconn.Open = dataConn
SQL="DELETE FROM "&LinkList&" WHERE MenuID="&nodeValue
dlconn.Execute SQL
dlconx.Close
dlconn.Close
response.redirect(selfLink &"?WGUID="&WGUID&"&sMode=Links&deleted=true&message=The link has been deleted")
Set dlconn = nothing
end if
Dim RS,node,parentid,parentNode
Set RS = Conn.Execute("SELECT "&strMenuTable&".LinkText,LinkURL, "&strMenuTable&".ToolTip, "&strMenuTable&".LinkTarget,MenuID,LinkID,adminLock,ParentID FROM " & strMenuTable & " LEFT JOIN "&LinkPool&" ON "& strMenuTable &".LinkPoolID = "&LinkPool&".LinkPoolID WHERE cast("&strMenuTable&".LinkID as varchar(50))='"& strSiteID &"' AND Show ='on' ORDER BY ParentID ASC ,"& strMenuTable &".LinkText ASC ,"& strMenuTable &".LinkOrder ASC")
If Not RS.EOF Then
Do While Not RS.EOF
LinkID= RS("LinkID")
parentid=RS("ParentID")
RestrictEdit = RS("adminLock")
Dim child
Set child = new Node
Call child.Init(RS("LinkText"),RS("LinkURL"),RS("ToolTip"),RS("LinkTarget"),RS("MenuID"),RS("LinkID"),RS("adminLock"))
child.ID =Cstr(RS("MenuID"))
If parentid=0 then
Nodes.Add(child)
Else
Set parentNode = FindNode(Nodes,ParentID)
If Not (parentNode is Nothing) Then
parentNode.Add(child)
End If
End If
RS.MoveNext
Loop
RS.Close
End If
Set RS = Nothing
Conn.Close
Set Conn = Nothing
End Sub
Private Function FindNode (nodes,ID)
dim i,tempNode
For i=0 To nodes.Length-1
Set tempNode = nodes(i)
if tempNode.Id=ID then
Set FindNode=tempNode
Exit Function
Else
If tempNode.ChildNodes.length>0 Then
Set tempNode = FindNode(tempNode.ChildNodes,ID)
If Not (tempNode is Nothing) Then
Set FindNode=tempNode
Exit Function
End If
end if
End If
Next
Set FindNode = Nothing
End Function
End Class
%>
View-Source.doc
ASKER
Ok, tried what you're suggesting and it fails to work at all. The list no longer expands. Here is the file with changes, and the source, thanks.
islogged =1
isEditor =1
Class Collection
Private m_next,m_len
Private m_dic
Public Sub Add(Item)
m_dic.Add "K" & m_next,Item
m_next = m_next+1
m_len = m_len+1
End Sub
Public Sub Clear
m_dic.RemoveAll
End Sub
Public Function Length
Length=m_len
End Function
Public Default Function Item(Index)
Dim tempItem,i
For Each tempItem In m_dic.Items
If i=Index Then
Set Item=tempItem
Exit Function
End If
i=i+1
Next
End Function
Public Sub Remove(ByVal Index)
Dim Item,i
For Each Item In m_dic.Items
If i=Index Then
m_dic.Remove(Item)
m_len=m_len-1
Exit Sub
End If
i=i+1
Next
End Sub
Private Sub Class_Initialize
m_len=0
Set m_dic = Server.CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate
Set m_dic = Nothing
End Sub
End Class
Class Node
Public Parent
Public Text
Public Href
Public Target
Public ToolTipText
Public ChildNodes
Public ImageUrl
Public MenuID
Public ID
Public LinkID
Public adminLock
Public Sub Init(strText,strHref,strToolTipText,strTarget,strMenuID,strLinkID,adminLock)
Text=strText
Href=strHref
ToolTipText=strToolTipText
Target=strTarget
MenuID= strMenuID
LinkID= strLinkID
adminLock = stradminLock
End Sub
Public Sub Add(objNode)
ChildNodes.Add(objNode)
End Sub
Private Sub Class_Initialize
Set ChildNodes = New Collection
End Sub
Private Sub Class_Terminate
Set ChildNodes = Nothing
End Sub
End Class
Class TreeView
Private m_folder
Public Color
Public Nodes
Public DefaultTarget
Public ID
Public LinkID
Public Property Let ImagesFolder(strFolder)
m_folder=strFolder
End Property
Public Property Get ImagesFolder()
ImagesFolder=m_folder
End Property
Private Sub Class_Initialize
Set Nodes = New Collection
Color="660099"
m_folder= commonImages
End Sub
Private Sub Class_Terminate
Set Nodes = Nothing
End Sub
Public Function AddNode(Text)
Dim tn
Set tn = new Node
tn.Text=Text
Nodes.Add(tn)
End Function
Public Function CreateNode(Text,Href,ToolTipText,Target,LinkID)
Dim tn
Set tn = new Node
Call tn.Init(Text,Href,ToolTipText,Target,LinkID)
Set CreateNode=tn
End Function
Public Function CreateSimpleNode(Text)
Dim tn
Set tn = new Node
tn.Text = Text
Set CreateSimpleNode=tn
End Function
Private Sub LoopThru(NodeList,Parent)
Dim i,j,Node,blnHasChild,strStyle
If Parent<>"0" Then
Out ("<ul class=tree id=""P"&LinkID&Parent & """>")
Else
'Out ("<ul xstyle='margin-left:20px;' id=""N"&LinkID& Parent & """>")
Out ("<ul class=folder id=""P"&LinkID& Parent & """>")
End If
For i=0 To NodeList.Length-1
Set Node = NodeList(i)
If (Node.ChildNodes.Length>0) Then
blnHasChild=True
Else
blnHasChild=False
End If
If Node.ImageUrl="" Then
strStyle=""
Else
strStyle=" style='list-style-image: url("& Node.ImageUrl &");'"
End If
if adminLock = "on" then
adminLock = (" <input src="&smallLock&" alt="&asmallLock&" type=""image"" />")
else
adminLock= ("<a href=""javascript:popup('"& wsso &"/links/code/link_editor.asp?LinkID=" &Node.MenuID&"')"" ><img src="&smallEdit&" alt="&smallEdit&" /></a>")
end if
If blnHasChild Then
Out("<li class=folder id=""P" &Node.LinkID & Parent & """><a class=treeview href=""javascript:toggle('N"&Node.LinkID & Parent & "_" & i & "','N"&Node.LinkID & Parent & "')"">" & Node.Text & "</a>")
if isLogged = 1 AND isEditor = 1 then
End if
Else
If Node.Target="" Then
Node.Target=DefaultTarget
End If
Out("<li class=file><a class=treeview href=""" & Node.Href & """ target=""" & Node.Target & """ title=""" & Node.ToolTipText & """>"& Node.Text & "</a>")
end if
If blnHasChild Then
Call LoopThru(Node.ChildNodes,Parent & "_" & i )
End If
If blnHasChild Then
Call LoopThru(Node.ChildNodes,Parent & "_" & i )
End If
'EO !!!!!!!!!! Editor Controls
Out ("</li>")
Next
Out ("</ul>")
End Sub
Private Sub Out(s)
Response.Write(s)
End Sub
Public Sub Display
Out("<script>function toggle(id,p){var myChild = document.getElementById(id);if(myChild.style.display!='block'){myChild.style.display='block';document.getElementById(p).className='folderMinus';}else{myChild.style.display='none';document.getElementById(p).className='folder';}}</script>")
Out("<ul><li><style>ul.tree{display:none;margin-left:17px;}li.folder{list-style-image: url("&menu_plus&");}li.folderMinus{list-style-image: url("&menu_minus&");}li.file{list-style-image: url("&menu_dot&");}a.treeview{color:"& Color &";font-family:verdana;font-size:8pt;}a.treeview:link {text-decoration:none;}a.treeview:visited{text-decoration:none;}a.treeview:hover {text-decoration:underline;}</style></li></ul>")
Call LoopThru(Nodes,0)
End Sub
Public Sub LoadFromDB(dataConn,strMenuTable,strSiteID, strPositionID)
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open dataConn
strOrder="LinkText"
Dim RS,node,parentid,parentNode
Set RS = Conn.Execute("SELECT "&strMenuTable&".LinkText,LinkURL , "&strMenuTable&".ToolTip, "&strMenuTable&".LinkTarget,MenuID,LinkID,adminLock,ParentID FROM " & strMenuTable & " LEFT JOIN "&LinkPool&" ON "& strMenuTable &".LinkPoolID = "&LinkPool&".LinkPoolID WHERE cast("&strMenuTable&".LinkID as varchar(50))='"& strSiteID &"' AND LinkActive ='on' ORDER BY ParentID ASC ,"& strMenuTable &".LinkText ASC ,"& strMenuTable &".LinkOrder ASC")
If Not RS.EOF Then
Do While Not RS.EOF
LinkID= RS("LinkID")
parentid=RS("ParentID")
adminLock = RS("adminLock")
Dim child
Set child = new Node
Call child.Init(RS("LinkText"),RS("LinkURL"),RS("ToolTip"),RS("LinkTarget"),RS("MenuID"),RS("LinkID"),RS("adminLock"))
child.ID =Cstr(RS("MenuID"))
If parentid=0 then
Nodes.Add(child)
Else
Set parentNode = FindNode(Nodes,ParentID)
If Not (parentNode is Nothing) Then
parentNode.Add(child)
End If
End If
RS.MoveNext
Loop
RS.Close
End If
Set RS = Nothing
Conn.Close
Set Conn = Nothing
End Sub
Private Function FindNode (nodes,ID)
dim i,tempNode
For i=0 To nodes.Length-1
Set tempNode = nodes(i)
if tempNode.Id=ID then
Set FindNode=tempNode
Exit Function
Else
If tempNode.ChildNodes.length>0 Then
Set tempNode = FindNode(tempNode.ChildNodes,ID)
If Not (tempNode is Nothing) Then
Set FindNode=tempNode
Exit Function
End If
end if
End If
Next
Set FindNode = Nothing
End Function
End Class
View-Source.doc
Appologise, the code was right but the explanation was wrong:
Line 179 should be:
Out("<li class=folder id=""N" &Node.LinkID & Parent & """><a class=treeview href=""javascript:toggle(' P"&Node.Li nkID & Parent & "_" & i & "','N"&Node.LinkID & Parent & "')"">" & Node.Text & "</a>")
Line 179 should be:
Out("<li class=folder id=""N" &Node.LinkID & Parent & """><a class=treeview href=""javascript:toggle('
ASKER
Ok, that almost works. If one link has a nested link it works, but if a link list had two links each a nested it change the first image +\- when it should do the second+\-. Since you answered the question do you want me to open a new one for this question?
It's ok to continue on this, would you please post the html tell me the label/text of the link that it's not working properly.
ASKER
Thanks. The "Link List 2" has two first level links Home Depot and News. Both have children, but News' child is CNN, and when expaned it changes the Home Depot +/- not the News +/-. I captured the view source with this example. This also happends any time there is two links with children on the same level as I found when testing two second level links with children.
View-Source.doc
View-Source.doc
ASKER
I added another new question if you want to work on it as well. https://www.experts-exchange.com/questions/26462226/Display-link-list-fully-expanded.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your help. Can you please give me an explaination on why the changes you made fixed the issue. I'd like to understand instead of just plug it in and move on.
You have to look in html at the ids of the 'ul' & 'li' elements that are forming the menu.
The probelm was actually one and only, there were elements having the same id and when toggling javascript was executing it was working on the same first element.
So to the "ul"s were given ids starting with "P" and "N" to "li"s. Also to differenciate elements at the same level we had to add "i" value to each element id.
That is all.
The probelm was actually one and only, there were elements having the same id and when toggling javascript was executing it was working on the same first element.
So to the "ul"s were given ids starting with "P" and "N" to "li"s. Also to differenciate elements at the same level we had to add "i" value to each element id.
That is all.
Here are the changes:
Line 168 (replace N with P):
Out ("<ul class=tree id=""P"&LinkID&Parent & """>")
Line 197(replace first N with P):
Out("<li class=folder id=""N" &Node.LinkID & Parent & """><a class=treeview href=""javascript:toggle('