From c00de5466db3d6104eec84be1c2bd55afa6b86fa Mon Sep 17 00:00:00 2001
From: michael <michael@content-space.de>
Date: Sun, 12 Oct 2008 16:10:18 +0200
Subject: [PATCH] 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
---
 lib/scripts/index.js | 36 +++++++++++++++++++++++++++++-------
 1 file 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');
-- 
GitLab