1/* Right Context Menu configuration for admin users:
2   Menu is built from four array items: title, link, show if page or headpage, show if namespace.
3   Link is not created if it's 0, otherwise it's evaluated.
4   Second array is displayed only in edit mode.
5
6   Some usefull variables:
7   node.hns = headpage id;
8   node.isdir = node is namespace;
9   node.dokuid = the DW id (namespace parent in case of headpage);
10   id = the DW id of the selected node (headpage id in case of headpage);
11   this.config.urlbase = Url Base;
12   this.config.sepchar = Url separator;
13*/
14
15var indexmenu_contextmenu=new Array(
16				    //Standard right menu
17				    new Array(
18					      '<b><em>Page action:</em></b>',0,1,0,
19					      '<b><em>Namespace action:</em></b>',0,0,1,
20					      'New page here','"javascript: indexmenu_reqpage(\'"+this.config.urlbase+"\',\'"+this.config.sepchar+"\',\'"+node.dokuid+"\');"',1,1,
21					      'Headpage here','"javascript: indexmenu_reqpage(\'"+this.config.urlbase+"\',\'"+this.config.sepchar+"\',\'"+node.dokuid+"\',\'"+node.name+"\');"',0,1,
22					      'Edit','indexmenu_getid(this.config.urlbase,id)+"do=edit"',1,0,
23					      'Search','"javascript: indexmenu_srchpage(\'"+this.config.urlbase+"\',\'"+this.config.sepchar+"\',\'"+node.isdir+"\',\'"+node.dokuid+"\');"',1,1,
24					      'Toc preview','"javascript: indexmenu_createTocMenu(\'req=toc&id="+id+"\',\'picker_"+this.obj+"\',\'s"+this.obj+node.id+"\');"',1,0,
25					      'Revisions','indexmenu_getid(this.config.urlbase,id)+"do=revisions"',1,0,
26					      'Purge cache','indexmenu_getid(this.config.urlbase,id)+"purge=true"',1,0,
27					      'Acls','indexmenu_getid(this.config.urlbase,id)+"do=admin&page=acl"',1,1
28					      ),
29
30				    //Right menu in edit mode.
31				    new Array(
32					      '<b><em>Edit action:</em></b>',0,1,0,
33					      'Insert as DWlink','"javascript: indexmenu_insertTags(\'"+id+"\',\'"+this.config.sepchar+"\');"+this.obj+".divdisplay(\'r\',0);"',1,0
34					      )
35				    );
36
37/*Custom User Functions
38Insert your custom functions here.
39*/
40function indexmenu_reqpage(b,s,id,n) {
41    var r,u=b;
42    if (n) {
43	r = id + s + n;
44    } else {
45	r = prompt("Insert the pagename to create","");
46	if (!r) {return;}
47	r = id + s + r;
48    }
49    if (r) window.location.href = indexmenu_getid(u,r)+"do=edit";
50}
51
52function indexmenu_srchpage(u,s,isdir,nid) {
53    var r = prompt("Insert keyword(s) to search for within this namespace","");
54    if (r)
55        {
56	    var fnid = nid;
57	    if (isdir == "0") {
58		fnid = fnid.substring(0,nid.lastIndexOf(s));
59	    }
60	    var b=u,re = new RegExp(s, 'g');
61	    fnid = fnid.replace(re, ":");
62	    b += (u.indexOf("?id=") < 0) ? '?id=': '';
63	    window.location.href = indexmenu_getid(b,r+" @"+fnid)+"do=search";
64	}
65}
66
67function indexmenu_getid(u,id) {
68    var url=(u||'')+encodeURI(id||'');
69    url += (u.indexOf("?") < 0) ? '?': '&';
70    return url;
71}
72