aboutsummaryrefslogtreecommitdiff
path: root/mod/dokuwiki/vendors/dokuwiki/lib/plugins/indexmenu/indexmenu-full.js
blob: 7c60ceffe2a57510f4a19a38dd83388933d18c45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/*----------------------------------------------------|
  | 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 <samuele@netsons.org>             |
  | 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 += '<div id="cdtree_'+this.obj+'" class="dtree" style="position:relative;overflow:hidden;width:100%;">';}
    str += '<div id="dtree_'+this.obj+'" class="dtree '+this.config.theme+'" style="overflow:';
    if (this.config.scroll) { str += 'visible;position:relative;width:100%"';} else {str += 'hidden;"';}
    str += '>';
    if (DOKUid('dtree_'+this.obj)) {str += '<div class="error">Indexmenu id conflict</div>';}
    if (this.config.toc) {
	str += '<div id="t' + this.obj + '" class="indexmenu_tocbullet '+this.config.theme+'" style="display:none;" title="Table of contents"></div>';
	str += '<div id="toc_' + this.obj + '" style="display:none;"></div>';
    }
    if (this.config.useCookies) { this.selectedNode = this.getSelected(); }
    str += this.addNode(this.root)+'</div>';
    if (this.config.scroll) {
	str += '<div id="z' + this.obj + '" class="indexmenu_rarrow"></div>';
	str += '<div id="left_'+this.obj+'" class="indexmenu_larrow" style="display:none;" title="Click to scroll back" onmousedown="javascript:'+this.obj+'.scroll(\'r\',1);" onmouseup="javascript:'+this.obj+'.stopscroll();"></div>';
	str += '</div>';
    }
    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.aNodes.length; n++) {
	if (this.aNodes[n].pid == pNode.id) {
	    cn = this.aNodes[n];
	    cn._p = pNode;
	    cn._ai = n;
	    cn._lv=l;
	    this.setCS(cn);
	    if (cn._hc && !cn._io && this.config.useCookies) {cn._io = this.isOpen(cn.id);}
	    if (this.pageid == (!cn.hns && cn.dokuid || cn.hns)) {
		cn._cp=true;
	    } else if (cn.id == this.selectedNode && !this.selectedFound) {
		cn._is = true;
		this.selectedNode = n;
		this.selectedFound = true;
	    }
	    if (!cn._hc && cn.isdir && !cn.ajax && !cn.hns) {
		if (cn._ls) {str += this.noderr(cn, n);}
	    } else {
		str += this.node(cn, n);
	    }
	    if (cn._ls) {break;}
	}
    }
    return str;
};

dTree.prototype.noderr = function(node, nodeId) {
    var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
    str += '<div class="emptynode" title="Empty"></div></div>';
    return str;
};

// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
    var h=1,jsfnc,str;
    jsfnc='onmouseover="'+this.obj+'.show_feat(\''+nodeId+'\');" onmousedown="return indexmenu_checkcontextm(\''+nodeId+'\','+this.obj+',event);" oncontextmenu="return indexmenu_stopevt(event)"';
    if (node._lv > this.config.maxjs) {h=0;} else {node._ok=true;}
    str = '<div class="dTreeNode">' + 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 += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
    if (!node._hc || node.hns) {
	str += '<a id="s' + this.obj + nodeId + '" class="' + ((node._cp) ? 'navSel' : ((node._is) ? 'nodeSel' : (node._hc) ? 'nodeFdUrl' : 'nodeUrl')) ;
	str += '" href="' + this.config.urlbase;
	(node.hns) ? str +=node.hns : str += node.dokuid;
	str += '"' + ' title="' + node.name + '"' +jsfnc;
	str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
	str += '>'+node.name+'</a>';
    }
    else if (node.pid != this.root.id) {
	str += '<a id="s' + this.obj + nodeId + '" href="javascript: ' + this.obj + '.o(' + nodeId + '); " class="node"' + jsfnc + '>'+node.name+'</a>';
    } else {
	str += node.name;
    }
    str += '</div>';
    if (node._hc) {
	str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
	if (h) {str += this.addNode(node);}
	str += '</div>';
    }
    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<this.aIndent.length; n++) {
	    str += '<img src="' + ( (this.aIndent[n] == 1) ? this.icon.line : this.icon.empty ) + '" alt="" />';
        }
	if (node._ls) {
	    this.aIndent.push(0);
	} else {
	    this.aIndent.push(1);
	}
	if (node._hc) {
	    str += '<a href="javascript: ' + this.obj + '.o(' + nodeId+');"><img id="j' + this.obj + nodeId + '" src="';
	    str += ( (node._io) ? ((node._ls) ? this.icon.minusBottom : this.icon.minus) : ((node._ls) ? this.icon.plusBottom : this.icon.plus ) );
	    str += '" alt="" /></a>';
	} else {str += '<img src="' + ((node._ls) ? this.icon.joinBottom : this.icon.join) + '" alt="" />';}
    }
    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; n<this.aNodes.length; n++) {
	if (this.aNodes[n].pid == node.id) {node._hc = true;}
	if (this.aNodes[n].pid == node.pid) {lastId = this.aNodes[n].id;}
    }
    if (lastId==node.id) {node._ls = true;}
};

// Returns the selected node
dTree.prototype.getSelected = function() {
    var sn = this.getCookie('cs' + this.obj);
    return (sn) ? sn : null;
};

// Highlights the selected node
dTree.prototype.s = function(id) {
    var eOld,eNew,cn = this.aNodes[id];
    if (this.selectedNode != id) {
	eNew = DOKUid("s" + this.obj + id);
	if (!eNew ) {return;}
	if (this.selectedNode || this.selectedNode===0) {
	    eOld = DOKUid("s" + this.obj + this.selectedNode);
	    eOld.className = "node";
	}
	eNew.className = "nodeSel";
	this.selectedNode = id;
	if (this.config.useCookies) {this.setCookie('cs' + this.obj, cn.id);}
    }
};

// Toggle Open or close
dTree.prototype.o = function(id) {
    var cn = this.aNodes[id];
    this.nodeStatus(!cn._io, id, cn._ls);
    cn._io = !cn._io;
    if (this.config.useCookies) {this.updateCookie();}
    this.divdisplay('z',0);
    this.resizescroll("block");
};

// Open or close all nodes
dTree.prototype.oAll = function(status) {
    for (var n=0; n<this.aNodes.length; n++) {
	if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
	    this.nodeStatus(status, n, this.aNodes[n]._ls);
	    this.aNodes[n]._io = status;
	}
    }
    if (this.config.useCookies) {this.updateCookie();}
};

// Opens the tree to a specific node
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
    var n,cn;
    if (!bFirst) {
	for (n=0; n<this.aNodes.length; n++) {
	    if (this.aNodes[n].id == nId) {
		nId=n;
		break;
	    }
	}
    }
    this.fill(this.aNodes[nId].pid);
    cn=this.aNodes[nId];
    if (cn.pid==this.root.id || !cn._p) {return;}
    cn._io = 1;
    if (this.completed && cn._hc) {this.nodeStatus(true, cn._ai, cn._ls);}
    if (cn._is) {
	(this.completed) ? this.s(cn._ai) : this._sn=cn._ai;
    }
    this.openTo(cn._p._ai, false, true);
};

dTree.prototype.getOpenTo = function(nodes) {
    if (nodes === '') {
	this.openAll();
    } else if (!this.config.useCookies ||!this.getCookie('co' + this.obj)) {
	for (var n=0; n<nodes.length; n++) {
	    this.openTo(nodes[n],false,true);
	}
    }
};

// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {
    if (status && !this.fill(id)) {return;}
    var eJoin,eIcon;
    eJoin= DOKUid('j' + this.obj + id);
    eIcon= DOKUid('i' + this.obj + id);
    eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
    eJoin.src = ((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus));
     DOKUid('d' + this.obj + id).style.display = (status) ? 'block': 'none';
};

// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {
    var now,yday;
    now = new Date();
    yday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
    this.setCookie('co'+this.obj, 'cookieValue', yday);
    this.setCookie('cs'+this.obj, 'cookieValue', yday);
};

// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
    document.cookie =
    escape(cookieName) + '=' + escape(cookieValue) +
    (expires ? '; expires=' + expires.toGMTString() : '') +
    ';path=/' +
    (domain ? '; domain=' + domain : '') +
    (secure ? '; secure' : '');
};

// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {
    var cookieValue = '',pN,posValue,endPos;
    pN = document.cookie.indexOf(escape(cookieName) + '=');
    if (pN != -1) {
	posValue = pN + (escape(cookieName) + '=').length;
	endPos = document.cookie.indexOf(';', posValue);
	if (endPos != -1) {cookieValue = unescape(document.cookie.substring(posValue, endPos));}
	else {cookieValue = unescape(document.cookie.substring(posValue));}
    }
    return (cookieValue);
};

// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
    var str = '',n;
    for (n=0; n<this.aNodes.length; n++) {
	if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
	    if (str) {str += '.';}
	    str += this.aNodes[n].id;
	}
    }
    this.setCookie('co' + this.obj, str);
};

// [Cookie] Checks if a node id is in a cookie
dTree.prototype.isOpen = function(id) {
    var n,aOpen = this.getCookie('co' + this.obj).split('.');
    for (n=0; n<aOpen.length; n++){
	if (aOpen[n] == id) {return true;}
    }
    return false;
};

dTree.prototype.openCurNS = function (max){
    var r,cn,match,t,i,n,cnsa,cna,cns=this.pageid;
    r=new RegExp ("\\b"+this.config.sepchar+"\\b","g");
    match=cns.match(r)||-1;
    if (max>0 && 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<this.aNodes.length; i++){
	cn=this.aNodes[i];
	if (cns == cn.dokuid || cns == cn.hns) {
	    this.openTo(cn.id,false,true);
	    this.fajax=false;
	    if (cn.pid >= 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<aOpen.length; n++){
	if (aOpen[n] === "") {break;}
	cn = this.aNodes[aOpen[n]];
	if (!cn._ok) {this.nodeStatus(true, aOpen[n], cn._ls);cn._io = 1;}
    }
};

dTree.prototype.scroll = function (where,s,n,i){
    if (!this.config.scroll) {return false;}
    var w,dtree,dtreel,nodeId;
    dtree=DOKUid('dtree_'+this.obj);
    dtreel=parseInt(dtree.offsetLeft,0);
    if (where=="r") {
	DOKUid('left_'+this.obj).style.border="thin inset";
	this.scrollRight(dtreel,s);
    } else {
	nodeId=DOKUid('s'+this.obj+n);
	w = parseInt(dtree.parentNode.offsetWidth - nodeId.offsetWidth - nodeId.offsetLeft,0);
	if (this.config.toc) {w=w-11;}
	if (dtreel <= w) {return;}
	this.resizescroll("none");
	this.stopscroll();
	this.scrollLeft(dtreel,s,w-3,i);
    }
};

dTree.prototype.scrollLeft = function (lft,s,w,i){
    if(lft < w - i -10) {
	this.divdisplay('z',0);
	this.scrllTmr=0;
        return;
    }
    var self=this;
    DOKUid('dtree_'+self.obj).style.left = lft + "px";
    this.scrllTmr=setTimeout(function (){self.scrollLeft(lft - s,s+i,w,i);},20);
};

//Scroll Back
dTree.prototype.scrollRight = function (lft,s){
    if(lft >= 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<ajxnodes.length;i++){
	    ajxnode=ajxnodes[i];
	    ajxnode[2]=(ajxnode[2]==0) ? node.id : ajxnode[2] + plus;
	    ajxnode[1] += plus;
	    selft.add(ajxnode[0],ajxnode[1],ajxnode[2],ajxnode[3],ajxnode[4],ajxnode[5],ajxnode[6]);
	}
	if (selft.fajax) {
	    selft.fajax=false;
	    selft.openCurNS(0);
	} else {
	    selft.openTo(node.id,false,true);
	}
	DOKUid('l'+selft.obj).style.display='none';
    };
    if (this.fajax) {
	req +='&nss='+curns+'&max=1';
    }
    Ajax.encodeURIString = false;
    Ajax.runAJAX(encodeURI(req));
};

//Load custom css
dTree.prototype.loadCss = function() {
    var oLink = document.createElement("link");
    oLink.href = this.config.plugbase+'/images/'+this.config.theme+'/style.css';
    oLink.rel = "stylesheet";
    oLink.type = "text/css";
    document.getElementsByTagName('head')[0].appendChild(oLink);
};

//Right click
dTree.prototype.contextmenu = function(n,e) {
    var li,id,html,type,node,self,cmenu,cdtree,rmenu,X=0,Y=0,i;
    cdtree= DOKUid("cdtree_" + this.obj);
    rmenu=DOKUid('r' + this.obj);
    if(!rmenu) { return true; }
    indexmenu_mouseposition(rmenu,e);
    cmenu=window.indexmenu_contextmenu[0];
    node =this.aNodes[n];
    self=this;
    rmenu.innerHTML='<div class="indexmenu_rmenuhead" title="'+node.name+'">'+node.name+"</div>";
    for (i=0; i<cmenu.length; i++,i++,i++,i++) {
      if (((!node._hc || node.hns) && !cmenu[i+2])||(node._hc && !node.hns && !cmenu[i+3])) {continue;}
	html=cmenu[i];
	if (cmenu[i+1]) {
	    type='li';
	    id =(node.hns) ? node.hns : node.dokuid;
	    html='<a title="'+cmenu[i]+'" href="'+eval(cmenu[i+1])+'">'+html+'</a>';
	} 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<arguments.length;i++){
	    this[this.length]=arguments[i];
	}
	return this.length;
    };
}
if (!Array.prototype.pop) {
    Array.prototype.pop = function array_pop() {
	var lstEl = this[this.length-1];
	this.length = Math.max(this.length-1,0);
	return lstEl;
    };
}