diff options
author | michael <michael@content-space.de> | 2008-10-12 16:10:18 +0200 |
---|---|---|
committer | michael <michael@content-space.de> | 2008-10-12 16:10:18 +0200 |
commit | c00de5466db3d6104eec84be1c2bd55afa6b86fa (patch) | |
tree | cba4e42f3f7a0039de7fb7078e5e441fcc3348d4 /lib/scripts/index.js | |
parent | 83434a91e271b6e9784cc3b1270ea29a9e00faa4 (diff) | |
download | dokuwiki-c00de5466db3d6104eec84be1c2bd55afa6b86fa.tar.gz dokuwiki-c00de5466db3d6104eec84be1c2bd55afa6b86fa.zip |
Fixed doubleclick-behaviour of links, fixes FS#1389
There is a new open-attribute of listitems that represents the state that should be achieved or the current state. This makes it possible that clicks that occur when the opening of the listitem has already been triggered close it again and the listitem won't be reopened when the ajax-call is finished.
darcs-hash:20081012141018-074e0-f9be8bbe89083df761d71f665b409bc95e450bf3.gz
Diffstat (limited to 'lib/scripts/index.js')
-rw-r--r-- | lib/scripts/index.js | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/lib/scripts/index.js b/lib/scripts/index.js index 4d082898a..c33eb9597 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'); |