diff --git a/lib/scripts/index.js b/lib/scripts/index.js index 4d082898a3e458df7286eae8675644e8fbbe2c6f..c33eb959719f9cd85d012d290ecad21775bdf24b 100644 --- a/lib/scripts/index.js +++ b/lib/scripts/index.js @@ -26,6 +26,16 @@ index = { // attach action to make the link clickable by AJAX addEvent(elem,'click',function(e){ return index.toggle(e,this); }); + + // get the listitem the elem belongs to + var listitem = elem.parentNode; + while (listitem.tagName != 'LI') { + listitem = listitem.parentNode; + } + //when there are uls under this listitem mark this listitem as opened + if (listitem.getElementsByTagName('ul').length) { + listitem.open = true; + } } }, @@ -40,17 +50,22 @@ index = { toggle: function(e,clicky){ var listitem = clicky.parentNode.parentNode; + listitem.open = !listitem.open; + // listitem.open represents now the action to be done + // if already open, close by removing the sublist var sublists = listitem.getElementsByTagName('ul'); - if(sublists.length && listitem.className=='open'){ - sublists[0].style.display='none'; + if(!listitem.open){ + if (sublists.length) { + sublists[0].style.display='none'; + } listitem.className='closed'; e.preventDefault(); return false; } // just show if already loaded - if(sublists.length && listitem.className=='closed'){ + if(sublists.length && listitem.open){ sublists[0].style.display=''; listitem.className='open'; e.preventDefault(); @@ -68,17 +83,24 @@ index = { ul.className = 'idx'; timeout = window.setTimeout(function(){ // show the throbber as needed - ul.innerHTML = '<li><img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="loading..." title="loading..." /></li>'; - listitem.appendChild(ul); - listitem.className='open'; + if (listitem.open) { + ul.innerHTML = '<li><img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="loading..." title="loading..." /></li>'; + listitem.appendChild(ul); + listitem.className='open'; + } }, this.throbber_delay); ajax.elementObj = ul; ajax.afterCompletion = function(){ window.clearTimeout(timeout); index.treeattach(ul); if (listitem.className!='open') { - listitem.appendChild(ul); + if (!listitem.open) { + ul.style.display='none'; + } + listitem.appendChild(ul); + if (listitem.open) { listitem.className='open'; + } } }; ajax.runAJAX(clicky.search.substr(1)+'&call=index');