1/** 2 * Java Script for index view 3 * 4 * @author Andreas Gohr <andi@splitbrain.org> 5 */ 6 7index = { 8 9 /** 10 * Attach event handlers to all "folders" below the given element 11 * 12 * @author Andreas Gohr <andi@splitbrain.org> 13 */ 14 treeattach: function(obj){ 15 if(!obj) return; 16 17 var items = getElementsByClass('idx_dir',obj,'a') 18 for(var i=0; i<items.length; i++){ 19 var elem = items[i]; 20 21 // attach action to make the link clickable by AJAX 22 addEvent(elem,'click',function(event){ return index.toggle(event,this); }); 23 } 24 }, 25 26 /** 27 * Open or close a subtree using AJAX 28 * 29 * @author Andreas Gohr <andi@splitbrain.org> 30 */ 31 toggle: function(event,clicky){ 32 var listitem = clicky.parentNode.parentNode; 33 34 // if already open, close by removing the sublist 35 var sublists = listitem.getElementsByTagName('ul'); 36 if(sublists.length){ 37 listitem.removeChild(sublists[0]); 38 listitem.className='closed'; 39 return false; 40 } 41 42 // prepare an AJAX call to fetch the subtree 43 var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php'); 44 ajax.AjaxFailedAlert = ''; 45 ajax.encodeURIString = false; 46 if(ajax.failed) return true; 47 48 //prepare the new ul 49 var ul = document.createElement('ul'); 50 ul.className = 'idx'; 51 ul.innerHTML = '<li><img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="loading..." title="loading..." /></li>'; 52 listitem.appendChild(ul); 53 ajax.elementObj = ul; 54 ajax.afterCompletion = function(){ index.treeattach(ul); }; 55 ajax.runAJAX(clicky.search.substr(1)+'&call=index'); 56 listitem.className='open'; 57 return false; 58 59 }, 60 61 62} 63 64 65addInitEvent(function(){ 66 index.treeattach($('index__tree')); 67}); 68