index | search | no replies | posting guidelines | help | login | register |
Index » General » Site & Forum Feedback |
| |||||||
Sep 8 2004, 7:33 PM |
| ||||||
naslund![]() ![]() ![]() from: Toronto | I couldn't find the correct forum for this topic so hope it's ok to post here. Is it possible to set the treeView to display Opened when loaded, rather than having to click on the item to open up the next branch? Thanks for the help | ||||||
Sep 9 2004, 6:58 AM |
| ||||||
whichman![]() ![]() ![]() from: Laurel, MD | If you mouse-over the node you want opened on page load, you will see the javascript function call that opens the node. All you have to do is to call that same function on page load for example - I call mine using the function call below at the end of my page <script> ------------------------- Master of the Game | ||||||
Sep 15 2004, 1:59 PM |
| ||||||
ikk3![]() ![]() from: São Paulo | (sorry for my poor english) Just for information about the second message, if you need to open the tree at a sub-folder, you need to put the entire path of nodes. Example: <script> //note: if your treeview is using an ID //your function will be toggleYOURID toggle('N0_0','P00'); toggle('N0_0_0','P0_00'); toggle('N0_0_0_8','P0_0_08'); </script> I have a doubt about this: 0- I´ve a page with treeView without frames; 1- I´ve some link pages in the folders, sub-folders, sub-sub-folders; 2- I click on the link to view the content of a page; 3- When I entered in the page I have a back button to return to the treeview´s page; 4- When I return to the treeview´s page, the treeView returns closed and I have to click on the folder and sub-folders again and again. Question: How can I find a dynamic way to return at the exactly position that was the tree when I´ve clicked on the link ?? | ||||||
Sep 16 2004, 5:51 AM |
| ||||||
whichman![]() ![]() ![]() from: Laurel, MD | You will have to use javascript cookies to remember your last click. So when you return to the page, you can toggle with your cookie values. When I have time I will upgrade the treeview thanx! ------------------------- Master of the Game | ||||||
Mar 2 2006, 11:40 AM |
| ||||||
cosmic![]() ![]() since: Mar 2, 2006 from: somewhere | Just wanted to contribute with some modifications that allows this. <% 'Option Explicit ' ====================================================================================== ' Desc: This code show how to create a simple treeview class using ASP and Cascading Stylesheets. ' Greate for programmers who want to learn how to create simple ASP controls. ' ' Author: Tanwani Anyangwe (tanwani@aspwebsolution.com) ' ' Requires: ASP 2.1 + ' ' Copyright © 2001 Tanwani Anyangwe for AspWebSolution.com ' -------------------------------------------------------------------------------------- ' Visit AspWebSolution - free source code for ASP & AS.NET programmers ' http://aspwebsolution.com ' -------------------------------------------------------------------------------------- ' ' Please ensure you visit the site and read their free source licensing ' information and requirements before using their code in your own ' application. ' ' ====================================================================================== 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 ID Public LEVEL Public Sub Init(strText,strHref,strToolTipText, strLevel) Text=strText Href=strHref ToolTipText=strToolTipText LEVEL = strLevel 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 ColorAlternative Public ColorAlternativeLevel Public ColorAlternativeSecond Public Nodes Public DefaultTarget Public ID 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="Navy" ColorAlternative="LightGrey" ColorAlternativeLevel = "LightSteelBlue" ColorAlternativeSecond="Gray" m_folder="images" 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, strLevel) Dim tn Set tn = new Node Call tn.Init(Text,Href,ToolTipText, LEVEL) 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=""N" & Parent & """>") Else Out ("<ul xstyle='margin-left:20px;' id=""N" & Parent & """>") End If For i=0 To NodeList.Length-1 Set Node = NodeList(i) If (Node.ChildNodes.Length>0 or Node.LEVEL = 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 "& strStyle &" class=folder id=""P" & Parent & i & """><a class=treeview href=""javascript:toggle"& id &"('N" & Parent & "_" & i & "','P" & Parent & i & "')"">" & Node.Text & " (" & Node.ChildNodes.Length & ")</a>" & vbNewline) Out("<li class=insertlink><a class=insertlink href=""http://director/vbsdb/admin/leveladmin/rightframe.asp?VBSdbClickClass_0=VBSdbEditAdd&IdParent=" & Node.Level & """ target=""controlframe"">Insertar nivel aquí</a></li>" & vbNewline) Else If Node.Target="" Then Node.Target=DefaultTarget End If Out("<li "& strStyle &" class=file><a class=treeview href=""" & "#" & Node.Href & """ title=""" & Node.ToolTipText & """>" & Node.Text & "</a> <a href =""http://director/vbsdb/admin/leveladmin/rightframe.asp?VBSdbClickClass_0=VBSdbEditDelete&VBSdbEditWhere_0=%28IDNIVEL%3D" & Node.Id &"%29"" TARGET=""controlframe""><img src="""& ImagesFolder &"/delete_record.gif"" width=""12"" height=""12"" border=""0""></a><a class=insertlinksub href=""http://director/vbsdb/admin/leveladmin/rightframe.asp?VBSdbClickClass_0=VBSdbEditAdd&IdParent=" & Node.Id & """ target=""controlframe""><img src=" & ImagesFolder &"/newrecord_insertsub.gif border=""0"">Insertar sub nivel</a>" & vbNewline) Out("<li class=insertlink><a class=insertlinksublevel href=""http://director/vbsdb/admin/leveladmin/rightframe.asp?VBSdbClickClass_0=VBSdbEditAdd&IdParent=" & Node.Level & """ target=""controlframe"">Insertar nivel aquí</a></li>" & vbNewline) End If If blnHasChild Then Call LoopThru(Node.ChildNodes,Parent & "_" & i) End If Out ("</li>") Next Out ("</ul>") End Sub Private Sub Out(s) Response.Write(s) End Sub Public Sub Display Out("<script> " & vbNewline & _ "function toggle"& id &"(id,p){" & vbNewline & _ " var myChild = document.getElementById(id);" & vbNewline & _ " if(myChild.style.display!='block'){" & vbNewline & _ " myChild.style.display='block';document.getElementById(p).className='folderOpen';" & vbNewline & _ " SetCookie('userclsTreeOpened'+id,p,15);" & vbNewline & _ " //SetCookie('userclsTreeOpened'+p,p,15);" & vbNewline & _ " }else{" & vbNewline & _ " //alert(id+' -'+p);" & vbNewline & _ " myChild.style.display='none';document.getElementById(p).className='folder';" & vbNewline & _ " Delete_Cookie('userclsTreeOpened'+id )" & vbNewline & _ " Delete_Cookie('userclsTreeOpened'+p)" & vbNewline & _ " }" & vbNewline & _ "}" & vbNewline & _ "</script>" & vbNewline) Out("<script> " & vbNewline & _ " function toggleload(){" & vbNewline & _ " //note: if your treeview is using an ID " & vbNewline & _ " //your function will be toggleYOURID " & vbNewline & _ " //toggle"& id &"('N0_0','P00'); " & vbNewline & _ " readCookie('N0_0_0'); " & vbNewline & _ " //toggle"& id &"('N0_0_0_1','P0_0_01'); " & vbNewline & _ " //alert('aqui'); " & vbNewline & _ " }" & vbNewline & _ "</script> " & vbNewline) Out("<script> " & vbNewline & _ " function SetCookie(cookieName,cookieValue,nDays) {" & vbNewline & _ " var today = new Date();" & vbNewline & _ " var expire = new Date();" & vbNewline & _ " if (nDays==null || nDays==0) nDays=1;" & vbNewline & _ " expire.setTime(today.getTime() + 3600000*24*nDays);" & vbNewline & _ " document.cookie = cookieName+'='+escape(cookieValue)" & vbNewline & _ " + ';expires='+expire.toGMTString();" & vbNewline & _ " }" & vbNewline & _ "</script> " & vbNewline) Out("<script> " & vbNewline & _ "// this deletes the cookie when called " & vbNewline & _ " function Delete_Cookie( name, path, domain ) { " & vbNewline & _ " //alert(name) " & vbNewline & _ " if ( Get_Cookie( name ) ) document.cookie = name + '=' + " & vbNewline & _ " ( ( path ) ? ';path=' + path : '') + " & vbNewline & _ " ( ( domain ) ? ';domain=' + domain : '' ) + " & vbNewline & _ " ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; " & vbNewline & _ " }" & vbNewline & _ "</script> " & vbNewline) Out("<script> " & vbNewline & _ " // this function gets the cookie, if it exists " & vbNewline & _ " function Get_Cookie( name ) { " & vbNewline & _ " var start = document.cookie.indexOf( name + '=' ); " & vbNewline & _ " var len = start + name.length + 1; " & vbNewline & _ " if ( ( !start ) && " & vbNewline & _ " ( name != document.cookie.substring( 0, name.length ) ) ) " & vbNewline & _ " { " & vbNewline & _ " return null; " & vbNewline & _ " } " & vbNewline & _ " if ( start == -1 ) return null; " & vbNewline & _ " var end = document.cookie.indexOf( ';', len ); " & vbNewline & _ " if ( end == -1 ) end = document.cookie.length; " & vbNewline & _ " return unescape( document.cookie.substring( len, end ) ); " & vbNewline & _ " }" & vbNewline & _ "</script> " & vbNewline) Out("<script> " & vbNewline & _ " function readCookie(name)" & vbNewline & _ " {" & vbNewline & _ " var nameEQ = name + '=';" & vbNewline & _ " var ca = document.cookie.split(';');" & vbNewline & _ " for(var i=0;i < ca.length;i++)" & vbNewline & _ " {" & vbNewline & _ " var c = ca[i];" & vbNewline & _ " var vl = c.split('=')" & vbNewline & _ " //alert(vl[0]);" & vbNewline & _ " //alert(vl[1]);" & vbNewline & _ " var ckName = leftTrim(vl[0]);" & vbNewline & _ " var ckValue = vl[1];" & vbNewline & _ " var ckBase = 'userclsTreeOpened';" & vbNewline & _ " if(document.getElementById(vl[1])){" & vbNewline & _ " //alert('('+ckName+')' + ' ckLength= ' + ckBase.length +' Id= ' +ckName.substring(ckBase.length)+' VAL= '+ckValue);" & vbNewline & _ " toggle"& id &"(ckName.substr(ckBase.length,ckName.length),ckValue); " & vbNewline & _ " }" & vbNewline & _ " while (c.charAt(0)==' '){" & vbNewline & _ " c = c.substring(1,c.length);" & vbNewline & _ " } "& vbNewline & _ " if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);" & vbNewline & _ " }" & vbNewline & _ " return null;" & vbNewline & _ " }" & vbNewline & _ "</script> " & vbNewline) Out("<script> " & vbNewline & _ " function leftTrim(sString) " & vbNewline & _ " {" & vbNewline & _ " while (sString.substring(0,1) == ' ')" & vbNewline & _ " {" & vbNewline & _ " sString = sString.substring(1, sString.length);" & vbNewline & _ " }" & vbNewline & _ " return sString;" & vbNewline & _ "}" & vbNewline & _ "</script> " & vbNewline) Out("<style>" & vbNewline & _ "ul.tree{" & vbNewline & _ "display:none;margin-left:17px;" & vbNewline & _ "}" & vbNewline & _ "li.folder{" & vbNewline & _ "list-style-image: url("& ImagesFolder &"/plus.gif);" & vbNewline & _ "}" & vbNewline & _ "li.folderOpen{" & vbNewline & _ "list-style-image: url("& ImagesFolder &"/minus.gif);" & vbNewline & _ "}" & vbNewline & _ "li.file{" & vbNewline & _ "list-style-image: url(" & ImagesFolder & "/dot.gif);" & vbNewline & _ "}" & vbNewline & _ "a.treeview{" & vbNewline & _ "color:"& Color &";" & vbNewline & _ "font-family:verdana;" & vbNewline & _ "font-size:8pt;" & vbNewline & _ "}" & vbNewline & _ "a.treeview:link {text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.treeview:visited{text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.treeview:hover {text-decoration:underline;" & vbNewline & _ "}" & vbNewline & _ "a.linktext:link {text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.linktext:link {text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.insertlink{" & vbNewline & _ "color:"& ColorAlternative &";" & vbNewline & _ "font-family:verdana;" & vbNewline & _ "font-size:7pt;" & vbNewline & _ "}" & vbNewline & _ "a.insertlink:link {text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.insertlink:visited{text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.insertlink:hover {text-decoration:underline;" & vbNewline & _ "}" & vbNewline & _ "li.insertlink{" & vbNewline & _ "list-style-image: url("& ImagesFolder &"/newrecord_insert.gif);" & vbNewline & _ "}" & vbNewline & _ "a.insertlinksub{" & vbNewline & _ "color:"& ColorAlternativeSecond &";" & vbNewline & _ "font-family:verdana;" & vbNewline & _ "font-size:7pt;" & vbNewline & _ "}" & vbNewline & _ "a.insertlinksub:link {text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.insertlinksub:visited{text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.insertlinksub:hover {text-decoration:underline;" & vbNewline & _ "}" & vbNewline & _ "a.insertlinksublevel{" & vbNewline & _ "color:"& ColorAlternativeLevel &";" & vbNewline & _ "font-family:verdana;" & vbNewline & _ "font-size:7pt;" & vbNewline & _ "}" & vbNewline & _ "a.insertlinksublevel:link {text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.insertlinksublevel:visited{text-decoration:none;" & vbNewline & _ "}" & vbNewline & _ "a.insertlinksublevel:hover {text-decoration:underline;" & vbNewline & _ "}" & vbNewline & _ "</style>") Call LoopThru(Nodes,0) End Sub Public Sub LoadFromDB(strConn,rstInput) Dim RS,node,parentid,parentNode Set RS = rstInput If Not RS.EOF Then Do While Not RS.EOF parentid=RS("ParentID") Dim child 'Dim childadmin Set child = new Node 'Set childadmin = new Node Call child.Init(RS("Text"),RS("URL"),RS("ToolTip"), RS("ParentID")) 'Call childadmin.Init("<--Insertar","URL","TOOL", RS("ParentID")) child.ID =RS("MenuID") 'childadmin.ID =RS("MenuID") If parentid=0 then Nodes.Add(child) 'Nodes.Add(childadmin) Else Set parentNode = FindNode(Nodes,ParentID) If Not (parentNode is Nothing) Then 'parentNode.Add(childadmin) parentNode.Add(child) 'parentNode.Add(childadmin) End If End If RS.MoveNext Loop RS.Close Else Response.write " No hay información disponible" End If Set RS = 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 Public Sub DisplayFolderContents(ByVal strFolderPath) Out("<script>function toggle"& id &"(id,p){var myChild = document.getElementById(id);if(myChild.style.display!='block'){myChild.style.display='block';document.getElementById(p).className='folderOpen';}else{myChild.style.display='none';document.getElementById(p).className='folder';}}</script>" & vbNewline) Out("<style>ul.tree{display:none;margin-left:17px;}li.folder{list-style-image: url("& ImagesFolder &"/plus.gif);}li.folderOpen{list-style-image: url("& ImagesFolder &"/minus.gif);}li.file{list-style-image: url("& ImagesFolder &"/dot.gif);}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>" & vbNewline) Dim fso Set fso = Server.CreateObject("Scripting.FileSystemObject") If fso.FolderExists(strFolderPath) Then Call ListFolderContents(fso.GetFolder(strFolderPath),0) Else Out "<font color=red>Folder <b>'" & strFolder & "'</b> does not exist</font>" End If Set fso = Nothing End Sub Private Sub ListFolderContents(objFolder,Parent) Dim objSubFolder, objFile If Parent<>"0" Then Out ("<ul class=tree id=""N" & Parent & """>") Else Out ("<ul xstyle='margin-left:20px;' id=""N" & Parent & """>") End If dim i For Each objSubFolder In objFolder.SubFolders Out("<li class=folder id=""P" & Parent & i & """><a class=treeview href=""javascript:toggle"& id &"('N" & Parent & "_" & i & "','P" & Parent & i & "')"">") Out objSubFolder.Name & "</a>" Call ListFolderContents(objSubFolder,Parent & "_" & i) Out "</li>" i=i+1 Next For Each objFile In objFolder.Files Out "<li class=file>" & objFile.Name & "</li>" Next Out "</ul>" Set objFile = Nothing Set objSubFolder = Nothing End Sub End Class %> | ||||||
Pages: (1) [1] |