Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with tree Navigation script

Status
Not open for further replies.

isuru

Programmer
Dec 13, 2000
1
AU
I have got the following script for folding menu tree navigation script from http://www.dynamicdrive.com:

Code:
<style>
<!--
#foldheader{cursor:hand ; font-weight:bold ;
list-style-image:url(fold.gif)}
#foldinglist{list-style-image:url(list.gif)}
//-->
</style>
<script language=&quot;JavaScript1.2&quot;>
<!--
/** 
 *  Based on Folding Menu Tree 
 *  Dynamic Drive ([URL unfurl="true"]www.dynamicdrive.com)[/URL]
 *  For full source code, installation instructions,
 *  100's more DHTML scripts, and Terms Of
 *  Use, visit dynamicdrive.com
 *
 *  Updated to support arbitrarily nested lists
 *  by Mark Quinn (mark@robocast.com) November 2nd 1998
 */

var head=&quot;display:''&quot;
img1=new Image()
img1.src=&quot;fold.gif&quot;
img2=new Image()
img2.src=&quot;open.gif&quot;

function change(){
   if(!document.all)
      return
   if (event.srcElement.id==&quot;foldheader&quot;) {
      var srcIndex = event.srcElement.sourceIndex
      var nested = document.all[srcIndex+1]
      if (nested.style.display==&quot;none&quot;) {
         nested.style.display=''
         event.srcElement.style.listStyleImage=&quot;url(open.gif)&quot;
      }
      else {
         nested.style.display=&quot;none&quot;
         event.srcElement.style.listStyleImage=&quot;url(fold.gif)&quot;
      }
   }
}

document.onclick=change

//-->
</script>

<ul>
   <li id=&quot;foldheader&quot;>News</li>
   <ul id=&quot;foldinglist&quot; style=&quot;display:none&quot; style=&{head};>
      <li><a href=&quot;[URL unfurl="true"]http://www.cnn.com&quot;>CNN</a></li>[/URL]
      <li><a href=&quot;[URL unfurl="true"]http://www.abcnews.com&quot;>ABC[/URL] News</a></li>
      <li><a href=&quot;[URL unfurl="true"]http://www.vancouversun.com&quot;>Vancouver[/URL] Sun</a></li>
   </ul>

   <li id=&quot;foldheader&quot;>Games</li>
   <ul id=&quot;foldinglist&quot; style=&quot;display:none&quot; style=&{head};>
      <li><a href=&quot;[URL unfurl="true"]http://www.gamespot.com&quot;>GameSpot</a></li>[/URL]
      <li><a href=&quot;[URL unfurl="true"]http://www.happypuppy.com&quot;>Happy[/URL] Puppy</a></li>
      <li><a href=&quot;[URL unfurl="true"]http://www.gamecenter.com&quot;>Game[/URL] Center</a></li>
   </ul>

   <li id=&quot;foldheader&quot;>Software</li>
   <ul id=&quot;foldinglist&quot; style=&quot;display:none&quot; style=&{head};>
      <li><a href=&quot;[URL unfurl="true"]http://www.download.com&quot;>outer[/URL] 1</a></li>
      <li><a href=&quot;[URL unfurl="true"]http://www.hotfiles.com&quot;>outer[/URL] 2</a></li>
      <li id=&quot;foldheader&quot;>Nested</li>
      <ul id=&quot;foldinglist&quot; style=&quot;display:none&quot; style=&{head};>
         <li><a href=&quot;[URL unfurl="true"]http://www.windows95.com&quot;>nested[/URL] 1</a></li>
         <li><a href=&quot;[URL unfurl="true"]http://www.shareware.com&quot;>nested[/URL] 2</a></li>
      </ul>
      <li><a href=&quot;[URL unfurl="true"]http://www.windows95.com&quot;>outer[/URL] 3</a></li>
      <li><a href=&quot;[URL unfurl="true"]http://www.shareware.com&quot;>outer[/URL] 4</a></li>
   </ul>
</ul>
<script language=&quot;JavaScript1.2&quot;>
<!--
/**
 * Get cookie routine by Shelley Powers 
 * (shelley.powers@ne-dev.com)
 */
function get_cookie(Name) {
  var search = Name + &quot;=&quot;
  var returnvalue = &quot;&quot;;
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(&quot;;&quot;, offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

if (get_cookie(window.location.pathname) != ''){
  var openresults=get_cookie(window.location.pathname).split(&quot; &quot;)
  for (i=0 ; i < openresults.length ; i++){
    foldinglist[openresults[i]].style.display=''
    document.all[foldinglist[openresults[i]].sourceIndex -
1].style.listStyleImage=&quot;url(open.gif)&quot;
  }
}

if (document.all){
  var nodelength=foldinglist.length-1
  var nodes=new Array(nodelength)
  var openones=''
}

function check(){
  for (i=0 ; i <= nodelength ; i++){
    if (foldinglist[i].style.display=='')
       openones=openones + &quot; &quot; + i
  }
  document.cookie=window.location.pathname+&quot;=&quot;+openones
}

if (document.all)
  document.body.onunload=check
//-->
</script>

I was wondering if I placed this in a fram called &quot;left&quot; and I have another frame called &quot;rbottom&quot; and someone clicks a link on the &quot;rbottom&quot; frame, is it possible to make one of the folders expand.

Please one of you Javascript experts - please help

I would really appreciate any help
 
i don't know if this will trick the event handler, but you could (if you were to name all the elements in the script that can be clicked on) say:

parent.left.elementiwantclicked.click() jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top