1function indexmenu_toolbar_additions() {
2    var edbtn,cmenu,indx_btn,toolbar = $('tool__bar');
3    if(!toolbar) return;
4    edbtn = $('edbtn__save');
5    if(!edbtn) return;
6    var indx_list = indexmenu_createPicker('picker_plugin_indexmenu');
7    indx_btn = indexmenu_createToolbar();
8    toolbar.appendChild(indx_btn);
9    indx_btn.onclick = function(){indexmenu_ajaxmenu('req=local',indx_list,this,false,indexmenu_createThemes);return false;};
10    cmenu=window.indexmenu_contextmenu;
11    if(cmenu[1]) {
12	window.indexmenu_contextmenu[0]=cmenu[1].concat(cmenu[0]);
13    }
14}
15
16function indexmenu_createThemes(data,indx_list) {
17    if (data.substring(0,9) != 'indexmenu') {
18	indx_list.innerHTML="Retrieving error";
19	return;
20    }
21    var checkboxes=[['<p><strong><em>Navigation</em></strong></p>',0],
22		    ['navbar','The tree opens at the current namespace'],
23		    ['context','Display the tree of the current wiki namespace context'],
24		    ['nocookie','Don\t remember open/closed nodes during user navigation'],
25		    ['noscroll','Prevent to scrolling the tree when it does not fit its container width'],
26		    ['notoc','Disable the toc preview feature'],
27		    ['<p><strong><em>Sort</em></strong></p>',0],
28		    ['nsort','Sort also namespaces'],
29		    ['tsort','By title'],
30		    ['dsort','By date'],
31		    ['msort','By meta tag'],
32		    ['<p><strong><em>Performance</em></strong></p>',0],
33		    ['max#2','How many levels to render with ajax when a node is opened'],
34		    ['maxjs#2','How many levels to render in the client browser when a node is opened'],
35		    ['<p><strong><em>Filters</em></strong></p>',0],
36		    ['nons','Show only pages'],
37		    ['nopg','Show only namespaces']];
38
39    var btn,key,theme_url,adata,f,f2,l,fo;
40    adata=data.split(',');
41    theme_url = DOKU_BASE + 'lib/plugins/indexmenu/images/';
42    f=indexmenu_toolFrame(indx_list,'Indexmenu');
43    l = document.createElement('div');
44    l.className = 'no indexmenu_nojstoolbar';
45    f.appendChild(l);
46    btn = createToolButton(DOKU_BASE + 'lib/tpl/default/images/open.gif','nojs index');
47    btn.innerHTML += 'Nojs';
48    btn.className = 'pickerbutton';
49    eval('btn.onclick = function(){indexmenu_opts("");}');
50    l.appendChild(btn);
51
52    l = document.createElement('div');
53    l.className = 'no indexmenu_jstoolbar';
54    f.appendChild(l);
55    if (adata[0] != 'indexmenu') {
56	l.innerHTML += 'No themes';
57	adata=[];
58    } else {
59	adata.splice(0,3);
60    }
61    for (key in adata) {
62	btn = createToolButton(theme_url + adata[key]+'/base.'+indexmenu_findExt(adata[key]),adata[key]);
63	btn.className = 'pickerbutton';
64	eval('btn.onclick = function(){indexmenu_opts("js#'+adata[key]+'");}');
65	l.appendChild(btn);
66    }
67    f2=indexmenu_toolFrame(indx_list,'Options');
68    fo=document.createElement('form');
69    fo.id='indexmenu_optfrm';
70    fo.className='indexmenu_opts';
71    f2.appendChild(fo);
72    for (key in checkboxes) {
73	lc = document.createElement('label');
74	lc.innerHTML=checkboxes[key][0]+' ';
75	if (checkboxes[key][1]) {
76	    lc.title= checkboxes[key][1];
77	    btn=document.createElement('input');
78	    btn.type = 'checkbox';
79	    btn.name = 'check';
80	    btn.title = checkboxes[key][1];
81	    btn.value = checkboxes[key][0];
82	    fo.appendChild(btn);
83	}
84	fo.appendChild(lc);
85    }
86
87    l = document.createElement('div');
88    l.className = 'indexmenu_extratoolbar';
89    l.innerHTML='<p><strong><em>Extra</em></strong></p>';
90    f.appendChild(l);
91    btn = createToolButton(theme_url+'/msort.gif','Insert the sort meta-number');
92    btn.className = 'pickerbutton';
93    btn.onclick = function(){insertTags(
94	'wiki__text',
95	'{{indexmenu_n>',
96	'}}',
97	'1'
98	);
99	$('picker_plugin_indexmenu').style.display='none';
100	return false;
101    };
102    l.appendChild(btn);
103}
104
105function indexmenu_createToolbar (){
106    var indx_ico = document.createElement('img');
107    indx_ico.src = DOKU_BASE + 'lib/plugins/indexmenu/images/indexmenu_toolbar.png';
108    var indx_btn = document.createElement('button');
109    indx_btn.id = 'syntax_plugin_indexmenu';
110    indx_btn.className = 'toolbutton';
111    indx_btn.title = 'Insert the Indexmenu tree';
112    indx_btn.appendChild(indx_ico);
113    return indx_btn;
114}
115
116function indexmenu_opts(m) {
117    var i,v = '';
118    var f=$('indexmenu_optfrm');
119    for (i=0; i < f.length; i++) {
120	if (f[i].checked) {
121	    v = v + ' ' + f[i].value;
122	}
123    }
124    insertTags(
125	       'wiki__text',
126	       '{{indexmenu>',
127	       ((m||v)?'|':'')+m.replace(/#default$/,'')+v+'}}',
128	       '#1'
129	       );
130    $('picker_plugin_indexmenu').style.display='none';
131    return false;
132}
133
134function indexmenu_insertTags(lnk,sep) {
135    var r,l=lnk;
136    if (sep) {
137	r=new RegExp (sep,"g");
138	l=lnk.replace(r,':');
139    }
140    insertTags('wiki__text','[[',']]',l);
141}
142
143function indexmenu_toolFrame(parent,txt) {
144    f=document.createElement('fieldset');
145    l=document.createElement('legend');
146    l.innerHTML='<strong>'+txt+'</strong>';
147    f.appendChild(l);
148    parent.appendChild(f);
149    return f;
150}
151
152indexmenu_toolbar_additions();
153