diff options
author | Adrian Lang <mail@adrianlang.de> | 2011-11-10 15:43:15 +0100 |
---|---|---|
committer | Adrian Lang <mail@adrianlang.de> | 2011-11-10 15:43:15 +0100 |
commit | 16a774a8a61756df2d8fb813bfbaed98b42e3e65 (patch) | |
tree | 3a48d311e74ccbf4017330cef8af00003b0ddb34 /lib/scripts/index.js | |
parent | 662a7b3fcc22d8327026bc1ef161a096683f1580 (diff) | |
parent | a5a71ecfcc1ed6bfca1995b39cd0abe4b8dd9eeb (diff) | |
download | rpg-16a774a8a61756df2d8fb813bfbaed98b42e3e65.tar.gz rpg-16a774a8a61756df2d8fb813bfbaed98b42e3e65.tar.bz2 |
Merge branch 'master' into stable
Conflicts:
doku.php
Diffstat (limited to 'lib/scripts/index.js')
-rw-r--r-- | lib/scripts/index.js | 123 |
1 files changed, 12 insertions, 111 deletions
diff --git a/lib/scripts/index.js b/lib/scripts/index.js index 9c7943d0c..4b67a0b12 100644 --- a/lib/scripts/index.js +++ b/lib/scripts/index.js @@ -1,115 +1,16 @@ -/** - * Javascript for index view - * - * @author Andreas Gohr <andi@splitbrain.org> - */ - -var index = { - - /** - * Delay in ms before showing the throbber. - * Used to skip the throbber for fast AJAX calls. - */ - throbber_delay: 500, - - /** - * Attach event handlers to all "folders" below the given element - * - * @author Andreas Gohr <andi@splitbrain.org> - */ - treeattach: function(obj){ - if(!obj) return; - - var items = getElementsByClass('idx_dir',obj,'a'); - for(var i=0; i<items.length; i++){ - var elem = items[i]; - - // 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; - } - } - }, - - /** - * Open or close a subtree using AJAX - * The contents of subtrees are "cached" untill the page is reloaded. - * A "loading" indicator is shown only when the AJAX call is slow. - * - * @author Andreas Gohr <andi@splitbrain.org> - * @author Ben Coburn <btcoburn@silicodon.net> - */ - 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(!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.open){ - sublists[0].style.display=''; - listitem.className='open'; - e.preventDefault(); - return false; - } - - // prepare an AJAX call to fetch the subtree - var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php'); - ajax.AjaxFailedAlert = ''; - ajax.encodeURIString = false; - if(ajax.failed) return true; - - //prepare the new ul - var ul = document.createElement('ul'); - ul.className = 'idx'; - timeout = window.setTimeout(function(){ - // show the throbber as needed - 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') { - if (!listitem.open) { - ul.style.display='none'; - } - listitem.appendChild(ul); - if (listitem.open) { - listitem.className='open'; - } - } - }; - ajax.runAJAX(clicky.search.substr(1)+'&call=index'); - e.preventDefault(); - return false; +var dw_index = jQuery('#index__tree').dw_tree({deferInit: true, + load_data: function (show_sublist, $clicky) { + jQuery.post( + DOKU_BASE + 'lib/exe/ajax.php', + $clicky[0].search.substr(1) + '&call=index', + show_sublist, 'html' + ); } -}; +}); +jQuery(function () { + var $tree = jQuery('#index__tree'); + dw_index.$obj = $tree; -addInitEvent(function(){ - index.treeattach($('index__tree')); + dw_index.init(); }); |