/*----------------------------------------------------| | dTree 2.05 | www.destroydrop.com/javascript/tree/ | |---------------------------------------------------| | Copyright (c) 2002-2003 Geir Landro | | | | This script can be used freely as long as all | | copyright messages are intact. | | | | Updated: 17.04.2003 | |---------------------------------------------------| | Modified for Dokuwiki by | | Samuele Tognini | | under GPL 2 license | | (http://www.gnu.org/licenses/gpl.html) | | Updated: 29.08.2009 | |---------------------------------------------------| | indexmenu | wiki.splitbrain.org/plugin:indexmenu | |--------------------------------------------------*/ // Node object function Node(dokuid, id, pid, name, hns, isdir, ajax) { this.dokuid = dokuid; this.id = id; this.pid = pid; this.name = name; this.hns = hns; this.isdir = isdir; this.ajax = ajax; this._io = 0; this._is = false; this._ls = false; this._hc = ajax; this._ai = 0; this._p = false; this._lv = 0; this._ok = false; this._cp=false; } // Tree object function dTree(objName,theme) { var objExt = indexmenu_findExt(theme); this.config = { urlbase:DOKU_BASE+'doku.php?id=', plugbase:DOKU_BASE+'lib/plugins/indexmenu', useCookies: true, scroll:true, toc:true, maxjs:1, jsajax:'', sepchar:':', theme:theme }; var objImg=this.config.plugbase+'/images/'+theme+'/'; this.icon = { root: objImg + 'base.'+objExt, folder: objImg + 'folder.'+objExt, folderH: objImg + 'folderh.'+objExt, folderOpen: objImg + 'folderopen.'+objExt, folderHOpen: objImg + 'folderhopen.'+objExt, node: objImg + 'page.'+objExt, empty: objImg + 'empty.'+objExt, line: objImg + 'line.'+objExt, join: objImg + 'join.'+objExt, joinBottom: objImg + 'joinbottom.'+objExt, plus: objImg + 'plus.'+objExt, plusBottom: objImg + 'plusbottom.'+objExt, minus: objImg + 'minus.'+objExt, minusBottom: objImg + 'minusbottom.'+objExt, nlPlus: objImg + 'nolines_plus.'+objExt, nlMinus: objImg + 'nolines_minus.'+objExt }; this.obj = objName; this.aNodes = []; this.aIndent = []; this.root = new Node(false,-1); this.selectedNode = null; this.selectedFound = false; this.completed = false; this.scrllTmr=0; this.pageid=window.indexmenu_ID||''; this.fajax=false; } // Adds a new node to the node array dTree.prototype.add = function(dokuid, id, pid, name, hns, isdir, ajax) { this.aNodes[this.aNodes.length] = new Node(dokuid, id, pid, name, hns, isdir, ajax); }; // Open/close all nodes dTree.prototype.openAll = function() { if (!this.getCookie('co' + this.obj)) { this.oAll(true); } }; // Outputs the tree to the page dTree.prototype.toString = function() { var str=''; if (this.config.scroll) {str += '
';} str += '
'; str += ''; } if (this.config.useCookies) { this.selectedNode = this.getSelected(); } str += this.addNode(this.root)+'
'; if (this.config.scroll) { str += '
'; str += ''; str += ''; } this.completed = true; this.divdisplay('nojs_',0); return str; }; // Creates the tree structure dTree.prototype.addNode = function(pNode) { var str = '',cn,n=pNode._ai,l=pNode._lv+1; for (n; n this.config.maxjs) {h=0;} else {node._ok=true;} str = '
' + this.indent(node, nodeId); node.icon = (this.root.id == node.pid) ? this.icon.root : ((node.hns) ? this.icon.folderH : ((node._hc) ? this.icon.folder : this.icon.node)); node.iconOpen = (node._hc) ? ((node.hns) ? this.icon.folderHOpen : this.icon.folderOpen) : this.icon.node; if (this.root.id == node.pid) { node.icon = this.icon.root; node.iconOpen = this.icon.root; } str += ''; if (!node._hc || node.hns) { str += ''; } else if (node.pid != this.root.id) { str += ''+node.name+''; } else { str += node.name; } str += '
'; if (node._hc) { str += '
'; if (h) {str += this.addNode(node);} str += '
'; } this.aIndent.pop(); return str; }; // Adds the empty and line icons dTree.prototype.indent = function(node, nodeId) { var n,str = ''; if (this.root.id != node.pid) { for (n=0; n'; } if (node._ls) { this.aIndent.push(0); } else { this.aIndent.push(1); } if (node._hc) { str += ''; } else {str += '';} } return str; }; // Checks if a node has any children and if it is the last sibling dTree.prototype.setCS = function(node) { var lastId,n; for (n=0; n0 && match.length >= max) { t = cns.split(this.config.sepchar); n = (this.aNodes[0].dokuid == '') ? 0 :this.aNodes[0].dokuid.split(this.config.sepchar).length; t.splice(max + n,t.length); cnsa=t.join(this.config.sepchar); } for (i=0; i= 0) { addInitEvent(this.scroll("l",4,cn.pid,1)); } break; } if (cnsa == cn.dokuid || cnsa == cn.hns) { cna=cn; this.fajax=true; } } if (cna) {this.openTo(cna.id,false,true);} }; dTree.prototype.fill = function(id) { if (id == -1 || this.aNodes[id]._ok ) {return true;} var n=id,eLoad,node,a,rd,ln,eDiv; if (this.aNodes[n].ajax) { eLoad=DOKUid('l' + this.obj); node=DOKUid('s'+this.obj+n); if (!eLoad) {eLoad=indexmenu_createPicker('l' + this.obj);} eLoad.innerHTML='Loading ...'; DOKUid('s'+this.obj+n).parentNode.appendChild(eLoad); eLoad.style.width='auto'; eLoad.style.display='inline'; this.getAjax(n); return true; } rd = []; while (!this.aNodes[n]._ok) { rd[rd.length]=n; n=this.aNodes[n].pid; } for (ln=rd.length-1; ln>=0; ln--) { id=rd[ln]; a=this.aNodes[id]; eDiv=DOKUid('d' + this.obj + id); if (!eDiv) {return false;} this.aIndent = []; n=a; while (n.pid>=0) { if (n._ls) { this.aIndent.unshift(0); } else { this.aIndent.unshift(1); } n=n._p; } eDiv.innerHTML=this.addNode(a); a._ok=true; } return true; }; dTree.prototype.openCookies = function() { var n,cn,aOpen = this.getCookie('co' + this.obj).split('.'); for (n=0; n= s) { this.divdisplay('left_',0); this.stopscroll(); return; } var self=this; DOKUid('dtree_'+self.obj).style.left = lft + "px"; if (lft>-15) {s=1;} this.scrllTmr=setTimeout(function (){self.scrollRight(lft+s,s+1);},20); }; dTree.prototype.stopscroll = function (){ DOKUid('left_'+this.obj).style.border="none"; clearTimeout(this.scrllTmr); this.scrllTmr=0; }; dTree.prototype.show_feat = function (n){ var w,div,id,dtree,dtreel,self,node=DOKUid('s'+this.obj+n); self=this; if (this.config.toc && node.className != "node") { div=DOKUid('t'+this.obj); id =(this.aNodes[n].hns) ? this.aNodes[n].hns : this.aNodes[n].dokuid; div.onmousedown=function (){indexmenu_createTocMenu('req=toc&id='+decodeURIComponent(id),'picker_'+self.obj,'t'+self.obj);}; node.parentNode.appendChild(div); if (div.style.display=="none") {div.style.display="inline";} } if (this.config.scroll) { div=DOKUid('z'+this.obj); div.onmouseover=function(){div.style.border="none";self.scroll("l",1,n,0);}; div.onmousedown=function(){div.style.border="thin inset";self.scroll("l",4,n,1);}; div.onmouseout=function(){div.style.border="none";self.stopscroll();}; div.onmouseup=div.onmouseover; dtree=DOKUid('dtree_'+this.obj); dtreel=parseInt(dtree.offsetLeft,0); w = parseInt(dtree.parentNode.offsetWidth - node.offsetWidth - node.offsetLeft + 1,0); if (dtreel > w) { div.style.display="none"; div.style.top = node.offsetTop+"px"; div.style.left = parseInt(node.offsetLeft + node.offsetWidth + w - 12,0)+"px"; div.style.display="block"; } } }; dTree.prototype.resizescroll = function (status){ var dtree,w,h,left=DOKUid('left_'+this.obj); if (!left) {return;} if (left.style.display==status) { dtree=DOKUid('dtree_'+this.obj); w=parseInt(dtree.offsetHeight/3,0); h= parseInt(w/50,0)*50; if (h < 50) {h=50;} left.style.height=h+"px"; left.style.top = w+"px"; if (status=="none") {left.style.display="block";} } }; // Toggle Open or close dTree.prototype.getAjax = function(n) { var node,req,curns,selft=this; node=selft.aNodes[n]; // We use SACK to do the AJAX requests var Ajax = new sack(DOKU_BASE+'lib/plugins/indexmenu/ajax.php'); req='req=index&idx='+node.dokuid+decodeURIComponent(this.config.jsajax); curns=this.pageid.substring(0,this.pageid.lastIndexOf(this.config.sepchar)); Ajax.encodeURIString=false; Ajax.onCompletion = function(){ var i,ajxnodes,ajxnode,plus; plus=selft.aNodes.length -1; eval(this.response); if (!isArray(ajxnodes) || ajxnodes.length < 1) { ajxnodes=[['', 1, 0, '', 0, 1, 0]]; } node.ajax=false; for(i=0;i'+node.name+""; for (i=0; i'+html+''; } else { type='span'; rmenu.appendChild(document.createElement('ul')); } li=document.createElement(type); li.innerHTML=html; rmenu.lastChild.appendChild(li); } rmenu.style.display='inline'; return false; }; dTree.prototype.divdisplay = function(obj,v) { var o=DOKUid(obj+this.obj); if (!o) {return false;} (v) ? o.style.display='inline': o.style.display='none' ; }; dTree.prototype.init = function(s,c,n,nav,max) { if (s) {this.loadCss();} if (!c) {this.openCookies();} if (n) {this.getOpenTo(n.split(" "));} if (nav) {this.openCurNS(max);} if (window.indexmenu_contextmenu) { var self = this; indexmenu_createPicker('r'+ this.obj,'indexmenu_rmenu '+this.config.theme); DOKUid('r'+ this.obj).oncontextmenu=indexmenu_stopevt; addEvent(document, 'click', function() {self.divdisplay('r',0);}); } }; // If Push and pop is not implemented by the browser if (!Array.prototype.push) { Array.prototype.push = function array_push() { for(var i=0;i