dokuwiki-indexmenu-plugin – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /**
2 * Right Context Menu configuration
3 *
4 * Some usefull variables:
5 * node.hns = headpage id;
6 * node.isdir = node is namespace;
7 * node.dokuid = the DW id (namespace parent in case of headpage);
8 * id = the DW id of the selected node (headpage id in case of headpage);
9 * index.config.urlbase = Url Base;
10 * index.config.sepchar = Url separator;
11 *
12 * HOWTO EDIT:
13 *
14 * To override menu entries or add a menu entry:
15 * - PLEASE EDIT ONLY the scripts/contextmenu.local.js file
16 * - DON'T EDIT this file, it is overwritten at plugin update
17 *
18 * Base structure of the context menu is displayed below.
19 * The entries with 'pg' are shown for page noded, these with 'ns' only for namespaces.
20 *
21 * Current available for everybody:
22 * indexmenu_contextmenu['all']['pg']['view'] = [...array with menu description here... ];
23 * indexmenu_contextmenu['all']['pg']['edit'] = [ ... ];
24 * indexmenu_contextmenu['all']['ns']['view'] = [ ... ];
25 *
26 * Current available for admins:
27 * indexmenu_contextmenu['pg']['view'] = [ ... ];
28 * indexmenu_contextmenu['ns']['view'] = [ ... ];
29 *
30 * Current available for authenticated users:
31 * indexmenu_contextmenu['pg']['view'] = [ ... ];
32 * indexmenu_contextmenu['ns']['view'] = [ ... ];
33 *
34 * A menu description may contain four kind of entries:
35 * - section title: array with one entry e.g.:
36 * ['Section title (html allowed)']
37 * - menu action: array with two entries e.g.:
38 * ['Title of action 1 (html allowed)', 'javascript here ... see for examples scripts/contextmenu.js']
39 * - menu action with custom tooltip: array with three entries e.g.:
40 * ['Title of action 1 (html allowed)', 'javascript here ... see for examples scripts/contextmenu.js', 'Customized title']
41 * - submenu: array with two entries where second entry is an array that describes again a menu e.g.:
42 * ['title of submenu (html allowed)', [ ...array with menu actions... ]]
43 *
44 *
45 * Examples:
46 * A menu description array:
47 * ... = [
48 * ['section title'],
49 * ['title of action 1', 'javascript here'],
50 * ['title of submenu', [['title of subaction 1', 'javascript here'], ['title of subaction 1', 'javascript here', 'Click here for action']] ]
51 * ];
52 *
53 * To Override the common menu title:
54 * indexmenu_contextmenu['all']['pg']['view'][0] = ['customtitle'];
55 *
56 * To override a menu entry, for example the menu title:
57 * indexmenu_contextmenu['all']['pg']['view'][0] = ['Custom Title'];
58 *
59 * To add option to page menu:
60 * Array.splice(index, howManyToRemove, description1)
61 * index = position to start (start counting at zero)
62 * howManyToRemove = number of elements that are removed (set to 1 to replace a element)
63 * description1 = array with menu entry description
64 * -> optional: description2 = optional you can add more elements at once by splice(index, howManyToRemove, description1, description2, etc)
65 *
66 * indexmenu_contextmenu['all']['pg']['view'].splice(1, 0, ['Input new page', '"javascript: IndexmenuContextmenu.reqpage(\'"+index.config.urlbase+"\',\'"+index.config.sepchar+"\',\'"+node.dokuid+"\');"']);
67 */
68  
69 // IMPORTANT: DON'T MODIFY THIS FILE, BUT EDIT contextmenu.local.js PLEASE!
70 // THIS FILE IS OVERWRITTEN WHEN PLUGIN IS UPDATED
71  
72 /**
73 * Right Context Menu configuration for all users:
74 */
75 indexmenu_contextmenu['all']['pg'] = {
76 'view': [
77 ['<span class="indexmenu_titlemenu"><b>'+LANG.plugins.indexmenu.page+'</b></span>'],
78 [LANG.plugins.indexmenu.revs, 'IndexmenuContextmenu.getid(index.config.urlbase,id)+"do=revisions"'],
79 [LANG.plugins.indexmenu.tocpreview, '"javascript: IndexmenuContextmenu.createTocMenu(\'call=indexmenu&req=toc&id="+id+"\',\'picker_"+index.obj+"\',\'s"+index.obj+node.id+"\');"']
80 ],
81 //Menu items in edit mode, when previewing
82 'edit': [
83 ['<span class="indexmenu_titlemenu"><b>'+LANG.plugins.indexmenu.editmode+'</b></span>'],
84 [LANG.plugins.indexmenu.insertdwlink, '"javascript: IndexmenuContextmenu.insertTags(\'"+id+"\',\'"+index.config.sepchar+"\');"+index.obj+".divdisplay(\'r\',0);"', LANG.plugins.indexmenu.insertdwlinktooltip]
85 ]
86 };
87  
88 indexmenu_contextmenu['all']['ns'] = {
89 'view': [
90 ['<span class="indexmenu_titlemenu"><b>'+LANG.plugins.indexmenu.ns+'</b></span>'],
91 [LANG.plugins.indexmenu.search, '"javascript: IndexmenuContextmenu.srchpage(\'"+index.config.urlbase+"\',\'"+index.config.sepchar+"\',\'"+node.isdir+"\',\'"+node.dokuid+"\');"', LANG.plugins.indexmenu.searchtooltip]
92 ]
93 };
94  
95  
96 if (JSINFO && JSINFO.isadmin) {
97 /**
98 * Right Context Menu configuration for admin users:
99 */
100 indexmenu_contextmenu['pg'] = {
101 'view': [
102 [LANG.plugins.indexmenu.edit, 'IndexmenuContextmenu.getid(index.config.urlbase,id)+"do=edit"'],
103 ['<em>'+LANG.plugins.indexmenu.create+'--></em>', [
104 [LANG.plugins.indexmenu.headpage, '"javascript: IndexmenuContextmenu.reqpage(\'"+index.config.urlbase+"\',\'"+index.config.sepchar+"\',\'"+node.dokuid+"\',\'"+node.name+"\');"', LANG.plugins.indexmenu.headpagetooltip],
105 [LANG.plugins.indexmenu.startpage, 'IndexmenuContextmenu.getid(index.config.urlbase,id+index.config.sepchar+"start")+"do=edit"', LANG.plugins.indexmenu.startpagetooltip],
106 [LANG.plugins.indexmenu.custompage, '"javascript: IndexmenuContextmenu.reqpage(\'"+index.config.urlbase+"\',\'"+index.config.sepchar+"\',\'"+node.dokuid+"\');"', LANG.plugins.indexmenu.custompagetooltip]
107 ]],
108 ['<em>'+LANG.plugins.indexmenu.more+'--></em>', [
109 [LANG.plugins.indexmenu.acls, 'IndexmenuContextmenu.getid(index.config.urlbase,id)+"do=admin&page=acl"'],
110 [LANG.plugins.indexmenu.purgecache, 'IndexmenuContextmenu.getid(index.config.urlbase,id)+"purge=true"'],
111 [LANG.plugins.indexmenu.exporthtml, 'IndexmenuContextmenu.getid(index.config.urlbase,id)+"do=export_xhtml"'],
112 [LANG.plugins.indexmenu.exporttext, 'IndexmenuContextmenu.getid(index.config.urlbase,id)+"do=export_raw"']
113 ]]
114 ]
115 };
116  
117 indexmenu_contextmenu['ns'] = {
118 'view': [
119 [LANG.plugins.indexmenu.newpage, '"javascript: IndexmenuContextmenu.reqpage(\'"+index.config.urlbase+"\',\'"+index.config.sepchar+"\',\'"+node.dokuid+"\');"', LANG.plugins.indexmenu.newpagetooltip],
120 ['<em>'+LANG.plugins.indexmenu.more+'--></em>', [
121 [LANG.plugins.indexmenu.headpagehere, '"javascript: IndexmenuContextmenu.reqpage(\'"+index.config.urlbase+"\',\'"+index.config.sepchar+"\',\'"+node.dokuid+"\',\'"+node.name+"\');"', LANG.plugins.indexmenu.headpageheretooltip],
122 [LANG.plugins.indexmenu.acls, 'IndexmenuContextmenu.getid(index.config.urlbase,node.dokuid)+"do=admin&page=acl"']
123 ]]
124 ]
125 };
126  
127 } else if (JSINFO && JSINFO.isauth) {
128 /**
129 * Right Context Menu configuration for authenticated users:
130 */
131 indexmenu_contextmenu['pg'] = {
132 'view': [
133 [LANG.plugins.indexmenu.newpagehere, '"javascript: IndexmenuContextmenu.reqpage(\'"+index.config.urlbase+"\',\'"+index.config.sepchar+"\',\'"+node.dokuid+"\');"'],
134 ['Edit', 'IndexmenuContextmenu.getid(index.config.urlbase,id)+"do=edit"', 1, 0 ],
135 ['<em>'+LANG.plugins.indexmenu.more+'--></em>', [
136 [LANG.plugins.indexmenu.headpagehere, '"javascript: IndexmenuContextmenu.reqpage(\'"+index.config.urlbase+"\',\'"+index.config.sepchar+"\',\'"+node.dokuid+"\',\'"+node.name+"\');"'],
137 [LANG.plugins.indexmenu.purgecache, 'IndexmenuContextmenu.getid(index.config.urlbase,id)+"purge=true"'],
138 [LANG.plugins.indexmenu.exporthtml, 'IndexmenuContextmenu.getid(index.config.urlbase,id)+"do=export_xhtml"']
139 ]]
140 ]
141 };
142  
143 }
144  
145 var IndexmenuContextmenu = {
146  
147 /**
148 * Common functions
149 * Insert your custom functions (available for all users) here.
150 */
151  
152 srchpage: function (u, s, isdir, nid) {
153 var r = prompt(LANG.plugins.indexmenu.insertkeywords, "");
154 if (r) {
155 var fnid = nid;
156 if (isdir == "0") {
157 fnid = fnid.substring(0, nid.lastIndexOf(s));
158 }
159 var b = u, re = new RegExp(s, 'g');
160 fnid = fnid.replace(re, ":");
161 b += (u.indexOf("?id=") < 0) ? '?id=' : '';
162 window.location.href = IndexmenuContextmenu.getid(b, r + " @" + fnid) + "do=search";
163 }
164 },
165  
166 getid: function (u, id) {
167 var url = (u || '') + encodeURI(id || '');
168 url += (u.indexOf("?") < 0) ? '?' : '&';
169 return url;
170 },
171  
172 reqpage: function (b, s, id, n) {
173 var r;
174 if (n) {
175 r = id + s + n;
176 } else {
177 r = prompt(LANG.plugins.indexmenu.insertpagename, "");
178 if (!r) {
179 return;
180 }
181 r = id + s + r;
182 }
183 if (r) window.location.href = IndexmenuContextmenu.getid(b, r) + "do=edit";
184 },
185  
186 insertTags: function (lnk, sep) {
187 var r, l = lnk;
188 if (sep) {
189 r = new RegExp(sep, "g");
190 l = lnk.replace(r, ':');
191 }
192 insertTags('wiki__text', '[[', ']]', l);
193 },
194  
195 /**
196 * Create or catch the picker and hide it, next call the ajax content loading to get the ToC
197 *
198 * @param {string} get query string
199 * @param {string} picker id of picker
200 * @param {string} btn id of button
201 */
202 createTocMenu: function (get, picker, btn) {
203 var $toc_picker = jQuery('#' + picker);
204 if (!$toc_picker.length) {
205 $toc_picker = IndexmenuUtils.createPicker(picker, 'indexmenu_toc');
206 $toc_picker
207 .html('<a href="#"><img src="' + DOKU_BASE + 'lib/plugins/indexmenu/images/close.gif" class="indexmenu_close" /></a><div />')
208 .children().first().click(function (event) {
209 event.stopPropagation();
210 return IndexmenuContextmenu.togglePicker($toc_picker, jQuery('#' + btn));
211 });
212 } else {
213 $toc_picker.hide();
214 }
215 IndexmenuContextmenu.ajaxmenu(get, $toc_picker, jQuery('#' + btn), $toc_picker.children().last(), null);
216 },
217  
218 /**
219 * Shows the picker and adds to it or to an internal containter the ajax content
220 *
221 * @param {string} get query string
222 * @param {jQuery} $picker
223 * @param {jQuery} $btn
224 * @param {jQuery} $container if defined ajax result is added to it, otherwise to $picker
225 * @param {function} oncomplete called when defined to handle ajax result
226 */
227 ajaxmenu: function (get, $picker, $btn, $container, oncomplete) {
228 var $indx_list;
229 $indx_list = $container || $picker;
230  
231 if (!IndexmenuContextmenu.togglePicker($picker, $btn)) return;
232  
233 var onComplete = function (data) {
234 $indx_list.html('');
235 if (typeof oncomplete == 'function') {
236 oncomplete(data, $indx_list);
237 } else {
238 $indx_list.html(data);
239 }
240 };
241  
242 //get content for picker/container
243 jQuery.ajax({
244 type: "POST",
245 url: DOKU_BASE + 'lib/exe/ajax.php',
246 data: get,
247 beforeSend: function () {
248 $indx_list.html('<div class="tocheader">'+LANG.plugins.indexmenu.loading+'</div>');
249 },
250 success: onComplete,
251 dataType: 'html'
252 });
253 },
254  
255  
256 /**
257 * Hide/show picker, will be shown beside btn
258 *
259 * @param {string|jQuery} $picker
260 * @param {jQuery} $btn
261 * @return {Boolean} true if open, false closed
262 */
263 togglePicker: function ($picker, $btn) {
264 var x = 8, y = 0;
265  
266 if (!$picker.is(':visible')) {
267 var pos = $btn.offset();
268 //position + width of button
269 x += pos.left + $btn[0].offsetWidth;
270 y += pos.top;
271  
272 $picker
273 .show()
274 .offset({
275 left: x,
276 top: y
277 });
278  
279 return true;
280 } else {
281 $picker.hide();
282 return false;
283 }
284 },
285  
286 /**
287 * Concatenates contextmenu configuration arrays
288 *
289 * @param amenu
290 * @param index
291 * @param n
292 */
293 arrconcat: function (amenu, index, n) {
294 var html, id, item, a, li;
295 if (typeof amenu == 'undefined' || typeof amenu['view'] == 'undefined') {
296 return;
297 }
298 var cmenu = amenu['view'];
299 if (jQuery('#tool__bar')[0] && amenu['edit'] instanceof Array) {
300 cmenu = amenu['edit'].concat(cmenu);
301 }
302 var node = index.aNodes[n];
303 id = node.hns || node.dokuid;
304  
305 var createCMenuEntry = function (entry) {
306 return '<a title="' + ((entry[2]) ? entry[2] : entry[0]) + '" href="' + eval(entry[1]) + '">' + entry[0] + '</a>';
307 };
308  
309 jQuery.each(cmenu, function (i, cmenuentry) {
310 if (cmenuentry == '') {
311 return true;
312 }
313 item = document.createElement('li');
314 var $cmenu = jQuery('#r' + index.obj);
315 if (cmenuentry[1]) {
316 if (cmenuentry[1] instanceof Array) {
317 html = document.createElement('ul');
318 jQuery.each(cmenuentry[1], function (a, subcmenuentry) {
319 li = document.createElement('li');
320 li.innerHTML = createCMenuEntry(subcmenuentry);
321 html.appendChild(li);
322 });
323  
324 //}
325 item.innerHTML = '<span class="indexmenu_submenu">' + cmenuentry[0] + '</span>';
326 html.left = $cmenu[0].width;
327 item.appendChild(html);
328 } else {
329 item.innerHTML = createCMenuEntry(cmenuentry);
330 }
331 } else {
332 item.innerHTML = cmenuentry;
333 }
334 $cmenu.children().last().append(item);
335 });
336 },
337  
338 /**
339 *
340 *
341 * @param obj
342 * @param e
343 */
344 mouseposition: function (obj, e) {
345 //http://www.quirksmode.org/js/events_properties.html
346 var X = 0, Y = 0;
347 if (!e) e = window.event;
348 if (e.pageX || e.pageY) {
349 X = e.pageX;
350 Y = e.pageY;
351 }
352 else if (e.clientX || e.clientY) {
353 X = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
354 Y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
355 }
356 obj.style.left = X - 5 + 'px';
357 obj.style.top = Y - 5 + 'px';
358 },
359  
360 /**
361 *
362 *
363 * @param n
364 * @param obj
365 * @param e
366 */
367 checkcontextm: function (n, obj, e) {
368 e = e || event;
369 if ((e.which == 3 || e.button == 2) || (window.opera && e.which == 1 && e.ctrlKey)) {
370 obj.contextmenu(n, e);
371 IndexmenuContextmenu.stopevt(e);
372 }
373 },
374  
375 /**
376 *
377 *
378 * @param e
379 * @returns {boolean}
380 */
381 stopevt: function (e) {
382 if (!window.indexmenu_contextmenu) {
383 return true;
384 }
385 e = e || event;
386 e.preventDefault ? e.preventDefault() : e.returnValue = false;
387 return false;
388 }
389 };
390