corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 /**
2 * ### Contextmenu plugin
3 *
4 * Shows a context menu when a node is right-clicked.
5 */
6 /*globals jQuery, define, exports, require, document */
7 (function (factory) {
8 "use strict";
9 if (typeof define === 'function' && define.amd) {
10 define('jstree.contextmenu', ['jquery','jstree'], factory);
11 }
12 else if(typeof exports === 'object') {
13 factory(require('jquery'), require('jstree'));
14 }
15 else {
16 factory(jQuery, jQuery.jstree);
17 }
18 }(function ($, jstree, undefined) {
19 "use strict";
20  
21 if($.jstree.plugins.contextmenu) { return; }
22  
23 /**
24 * stores all defaults for the contextmenu plugin
25 * @name $.jstree.defaults.contextmenu
26 * @plugin contextmenu
27 */
28 $.jstree.defaults.contextmenu = {
29 /**
30 * a boolean indicating if the node should be selected when the context menu is invoked on it. Defaults to `true`.
31 * @name $.jstree.defaults.contextmenu.select_node
32 * @plugin contextmenu
33 */
34 select_node : true,
35 /**
36 * a boolean indicating if the menu should be shown aligned with the node. Defaults to `true`, otherwise the mouse coordinates are used.
37 * @name $.jstree.defaults.contextmenu.show_at_node
38 * @plugin contextmenu
39 */
40 show_at_node : true,
41 /**
42 * an object of actions, or a function that accepts a node and a callback function and calls the callback function with an object of actions available for that node (you can also return the items too).
43 *
44 * Each action consists of a key (a unique name) and a value which is an object with the following properties (only label and action are required). Once a menu item is activated the `action` function will be invoked with an object containing the following keys: item - the contextmenu item definition as seen below, reference - the DOM node that was used (the tree node), element - the contextmenu DOM element, position - an object with x/y properties indicating the position of the menu.
45 *
46 * * `separator_before` - a boolean indicating if there should be a separator before this item
47 * * `separator_after` - a boolean indicating if there should be a separator after this item
48 * * `_disabled` - a boolean indicating if this action should be disabled
49 * * `label` - a string - the name of the action (could be a function returning a string)
50 * * `title` - a string - an optional tooltip for the item
51 * * `action` - a function to be executed if this item is chosen, the function will receive
52 * * `icon` - a string, can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
53 * * `shortcut` - keyCode which will trigger the action if the menu is open (for example `113` for rename, which equals F2)
54 * * `shortcut_label` - shortcut label (like for example `F2` for rename)
55 * * `submenu` - an object with the same structure as $.jstree.defaults.contextmenu.items which can be used to create a submenu - each key will be rendered as a separate option in a submenu that will appear once the current item is hovered
56 *
57 * @name $.jstree.defaults.contextmenu.items
58 * @plugin contextmenu
59 */
60 items : function (o, cb) { // Could be an object directly
61 return {
62 "create" : {
63 "separator_before" : false,
64 "separator_after" : true,
65 "_disabled" : false, //(this.check("create_node", data.reference, {}, "last")),
66 "label" : "Create",
67 "action" : function (data) {
68 var inst = $.jstree.reference(data.reference),
69 obj = inst.get_node(data.reference);
70 inst.create_node(obj, {}, "last", function (new_node) {
71 try {
72 inst.edit(new_node);
73 } catch (ex) {
74 setTimeout(function () { inst.edit(new_node); },0);
75 }
76 });
77 }
78 },
79 "rename" : {
80 "separator_before" : false,
81 "separator_after" : false,
82 "_disabled" : false, //(this.check("rename_node", data.reference, this.get_parent(data.reference), "")),
83 "label" : "Rename",
84 /*!
85 "shortcut" : 113,
86 "shortcut_label" : 'F2',
87 "icon" : "glyphicon glyphicon-leaf",
88 */
89 "action" : function (data) {
90 var inst = $.jstree.reference(data.reference),
91 obj = inst.get_node(data.reference);
92 inst.edit(obj);
93 }
94 },
95 "remove" : {
96 "separator_before" : false,
97 "icon" : false,
98 "separator_after" : false,
99 "_disabled" : false, //(this.check("delete_node", data.reference, this.get_parent(data.reference), "")),
100 "label" : "Delete",
101 "action" : function (data) {
102 var inst = $.jstree.reference(data.reference),
103 obj = inst.get_node(data.reference);
104 if(inst.is_selected(obj)) {
105 inst.delete_node(inst.get_selected());
106 }
107 else {
108 inst.delete_node(obj);
109 }
110 }
111 },
112 "ccp" : {
113 "separator_before" : true,
114 "icon" : false,
115 "separator_after" : false,
116 "label" : "Edit",
117 "action" : false,
118 "submenu" : {
119 "cut" : {
120 "separator_before" : false,
121 "separator_after" : false,
122 "label" : "Cut",
123 "action" : function (data) {
124 var inst = $.jstree.reference(data.reference),
125 obj = inst.get_node(data.reference);
126 if(inst.is_selected(obj)) {
127 inst.cut(inst.get_top_selected());
128 }
129 else {
130 inst.cut(obj);
131 }
132 }
133 },
134 "copy" : {
135 "separator_before" : false,
136 "icon" : false,
137 "separator_after" : false,
138 "label" : "Copy",
139 "action" : function (data) {
140 var inst = $.jstree.reference(data.reference),
141 obj = inst.get_node(data.reference);
142 if(inst.is_selected(obj)) {
143 inst.copy(inst.get_top_selected());
144 }
145 else {
146 inst.copy(obj);
147 }
148 }
149 },
150 "paste" : {
151 "separator_before" : false,
152 "icon" : false,
153 "_disabled" : function (data) {
154 return !$.jstree.reference(data.reference).can_paste();
155 },
156 "separator_after" : false,
157 "label" : "Paste",
158 "action" : function (data) {
159 var inst = $.jstree.reference(data.reference),
160 obj = inst.get_node(data.reference);
161 inst.paste(obj);
162 }
163 }
164 }
165 }
166 };
167 }
168 };
169  
170 $.jstree.plugins.contextmenu = function (options, parent) {
171 this.bind = function () {
172 parent.bind.call(this);
173  
174 var last_ts = 0, cto = null, ex, ey;
175 this.element
176 .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
177 this.get_container_ul().addClass('jstree-contextmenu');
178 }, this))
179 .on("contextmenu.jstree", ".jstree-anchor", $.proxy(function (e, data) {
180 if (e.target.tagName.toLowerCase() === 'input') {
181 return;
182 }
183 e.preventDefault();
184 last_ts = e.ctrlKey ? +new Date() : 0;
185 if(data || cto) {
186 last_ts = (+new Date()) + 10000;
187 }
188 if(cto) {
189 clearTimeout(cto);
190 }
191 if(!this.is_loading(e.currentTarget)) {
192 this.show_contextmenu(e.currentTarget, e.pageX, e.pageY, e);
193 }
194 }, this))
195 .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
196 if(this._data.contextmenu.visible && (!last_ts || (+new Date()) - last_ts > 250)) { // work around safari & macOS ctrl+click
197 $.vakata.context.hide();
198 }
199 last_ts = 0;
200 }, this))
201 .on("touchstart.jstree", ".jstree-anchor", function (e) {
202 if(!e.originalEvent || !e.originalEvent.changedTouches || !e.originalEvent.changedTouches[0]) {
203 return;
204 }
205 ex = e.originalEvent.changedTouches[0].clientX;
206 ey = e.originalEvent.changedTouches[0].clientY;
207 cto = setTimeout(function () {
208 $(e.currentTarget).trigger('contextmenu', true);
209 }, 750);
210 })
211 .on('touchmove.vakata.jstree', function (e) {
212 if(cto && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0] && (Math.abs(ex - e.originalEvent.changedTouches[0].clientX) > 50 || Math.abs(ey - e.originalEvent.changedTouches[0].clientY) > 50)) {
213 clearTimeout(cto);
214 }
215 })
216 .on('touchend.vakata.jstree', function (e) {
217 if(cto) {
218 clearTimeout(cto);
219 }
220 });
221  
222 /*!
223 if(!('oncontextmenu' in document.body) && ('ontouchstart' in document.body)) {
224 var el = null, tm = null;
225 this.element
226 .on("touchstart", ".jstree-anchor", function (e) {
227 el = e.currentTarget;
228 tm = +new Date();
229 $(document).one("touchend", function (e) {
230 e.target = document.elementFromPoint(e.originalEvent.targetTouches[0].pageX - window.pageXOffset, e.originalEvent.targetTouches[0].pageY - window.pageYOffset);
231 e.currentTarget = e.target;
232 tm = ((+(new Date())) - tm);
233 if(e.target === el && tm > 600 && tm < 1000) {
234 e.preventDefault();
235 $(el).trigger('contextmenu', e);
236 }
237 el = null;
238 tm = null;
239 });
240 });
241 }
242 */
243 $(document).on("context_hide.vakata.jstree", $.proxy(function (e, data) {
244 this._data.contextmenu.visible = false;
245 $(data.reference).removeClass('jstree-context');
246 }, this));
247 };
248 this.teardown = function () {
249 if(this._data.contextmenu.visible) {
250 $.vakata.context.hide();
251 }
252 parent.teardown.call(this);
253 };
254  
255 /**
256 * prepare and show the context menu for a node
257 * @name show_contextmenu(obj [, x, y])
258 * @param {mixed} obj the node
259 * @param {Number} x the x-coordinate relative to the document to show the menu at
260 * @param {Number} y the y-coordinate relative to the document to show the menu at
261 * @param {Object} e the event if available that triggered the contextmenu
262 * @plugin contextmenu
263 * @trigger show_contextmenu.jstree
264 */
265 this.show_contextmenu = function (obj, x, y, e) {
266 obj = this.get_node(obj);
267 if(!obj || obj.id === $.jstree.root) { return false; }
268 var s = this.settings.contextmenu,
269 d = this.get_node(obj, true),
270 a = d.children(".jstree-anchor"),
271 o = false,
272 i = false;
273 if(s.show_at_node || x === undefined || y === undefined) {
274 o = a.offset();
275 x = o.left;
276 y = o.top + this._data.core.li_height;
277 }
278 if(this.settings.contextmenu.select_node && !this.is_selected(obj)) {
279 this.activate_node(obj, e);
280 }
281  
282 i = s.items;
283 if($.isFunction(i)) {
284 i = i.call(this, obj, $.proxy(function (i) {
285 this._show_contextmenu(obj, x, y, i);
286 }, this));
287 }
288 if($.isPlainObject(i)) {
289 this._show_contextmenu(obj, x, y, i);
290 }
291 };
292 /**
293 * show the prepared context menu for a node
294 * @name _show_contextmenu(obj, x, y, i)
295 * @param {mixed} obj the node
296 * @param {Number} x the x-coordinate relative to the document to show the menu at
297 * @param {Number} y the y-coordinate relative to the document to show the menu at
298 * @param {Number} i the object of items to show
299 * @plugin contextmenu
300 * @trigger show_contextmenu.jstree
301 * @private
302 */
303 this._show_contextmenu = function (obj, x, y, i) {
304 var d = this.get_node(obj, true),
305 a = d.children(".jstree-anchor");
306 $(document).one("context_show.vakata.jstree", $.proxy(function (e, data) {
307 var cls = 'jstree-contextmenu jstree-' + this.get_theme() + '-contextmenu';
308 $(data.element).addClass(cls);
309 a.addClass('jstree-context');
310 }, this));
311 this._data.contextmenu.visible = true;
312 $.vakata.context.show(a, { 'x' : x, 'y' : y }, i);
313 /**
314 * triggered when the contextmenu is shown for a node
315 * @event
316 * @name show_contextmenu.jstree
317 * @param {Object} node the node
318 * @param {Number} x the x-coordinate of the menu relative to the document
319 * @param {Number} y the y-coordinate of the menu relative to the document
320 * @plugin contextmenu
321 */
322 this.trigger('show_contextmenu', { "node" : obj, "x" : x, "y" : y });
323 };
324 };
325  
326 // contextmenu helper
327 (function ($) {
328 var right_to_left = false,
329 vakata_context = {
330 element : false,
331 reference : false,
332 position_x : 0,
333 position_y : 0,
334 items : [],
335 html : "",
336 is_visible : false
337 };
338  
339 $.vakata.context = {
340 settings : {
341 hide_onmouseleave : 0,
342 icons : true
343 },
344 _trigger : function (event_name) {
345 $(document).triggerHandler("context_" + event_name + ".vakata", {
346 "reference" : vakata_context.reference,
347 "element" : vakata_context.element,
348 "position" : {
349 "x" : vakata_context.position_x,
350 "y" : vakata_context.position_y
351 }
352 });
353 },
354 _execute : function (i) {
355 i = vakata_context.items[i];
356 return i && (!i._disabled || ($.isFunction(i._disabled) && !i._disabled({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }))) && i.action ? i.action.call(null, {
357 "item" : i,
358 "reference" : vakata_context.reference,
359 "element" : vakata_context.element,
360 "position" : {
361 "x" : vakata_context.position_x,
362 "y" : vakata_context.position_y
363 }
364 }) : false;
365 },
366 _parse : function (o, is_callback) {
367 if(!o) { return false; }
368 if(!is_callback) {
369 vakata_context.html = "";
370 vakata_context.items = [];
371 }
372 var str = "",
373 sep = false,
374 tmp;
375  
376 if(is_callback) { str += "<"+"ul>"; }
377 $.each(o, function (i, val) {
378 if(!val) { return true; }
379 vakata_context.items.push(val);
380 if(!sep && val.separator_before) {
381 str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
382 }
383 sep = false;
384 str += "<"+"li class='" + (val._class || "") + (val._disabled === true || ($.isFunction(val._disabled) && val._disabled({ "item" : val, "reference" : vakata_context.reference, "element" : vakata_context.element })) ? " vakata-contextmenu-disabled " : "") + "' "+(val.shortcut?" data-shortcut='"+val.shortcut+"' ":'')+">";
385 str += "<"+"a href='#' rel='" + (vakata_context.items.length - 1) + "' " + (val.title ? "title='" + val.title + "'" : "") + ">";
386 if($.vakata.context.settings.icons) {
387 str += "<"+"i ";
388 if(val.icon) {
389 if(val.icon.indexOf("/") !== -1 || val.icon.indexOf(".") !== -1) { str += " style='background:url(\"" + val.icon + "\") center center no-repeat' "; }
390 else { str += " class='" + val.icon + "' "; }
391 }
392 str += "><"+"/i><"+"span class='vakata-contextmenu-sep'>&#160;<"+"/span>";
393 }
394 str += ($.isFunction(val.label) ? val.label({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }) : val.label) + (val.shortcut?' <span class="vakata-contextmenu-shortcut vakata-contextmenu-shortcut-'+val.shortcut+'">'+ (val.shortcut_label || '') +'</span>':'') + "<"+"/a>";
395 if(val.submenu) {
396 tmp = $.vakata.context._parse(val.submenu, true);
397 if(tmp) { str += tmp; }
398 }
399 str += "<"+"/li>";
400 if(val.separator_after) {
401 str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
402 sep = true;
403 }
404 });
405 str = str.replace(/
  • <\/li\>$/,"");
  • 406
  • <\/li\> if(is_callback) { str += "</ul>"; }
  • 407
  • <\/li\> /**
  • 408
  • <\/li\> * triggered on the document when the contextmenu is parsed (HTML is built)
  • 409
  • <\/li\> * @event
  • 410
  • <\/li\> * @plugin contextmenu
  • 411
  • <\/li\> * @name context_parse.vakata
  • 412
  • <\/li\> * @param {jQuery} reference the element that was right clicked
  • 413
  • <\/li\> * @param {jQuery} element the DOM element of the menu itself
  • 414
  • <\/li\> * @param {Object} position the x & y coordinates of the menu
  • 415
  • <\/li\> */
  • 416
  • <\/li\> if(!is_callback) { vakata_context.html = str; $.vakata.context._trigger("parse"); }
  • 417
  • <\/li\> return str.length > 10 ? str : false;
  • 418
  • <\/li\> },
  • 419
  • <\/li\> _show_submenu : function (o) {
  • 420
  • <\/li\> o = $(o);
  • 421
  • <\/li\> if(!o.length || !o.children("ul").length) { return; }
  • 422
  • <\/li\> var e = o.children("ul"),
  • 423
  • <\/li\> xl = o.offset().left,
  • 424
  • <\/li\> x = xl + o.outerWidth(),
  • 425
  • <\/li\> y = o.offset().top,
  • 426
  • <\/li\> w = e.width(),
  • 427
  • <\/li\> h = e.height(),
  • 428
  • <\/li\> dw = $(window).width() + $(window).scrollLeft(),
  • 429
  • <\/li\> dh = $(window).height() + $(window).scrollTop();
  • 430
  • <\/li\> // може да се спести е една проверка - дали няма някой от класовете вече нагоре
  • 431
  • <\/li\> if(right_to_left) {
  • 432
  • <\/li\> o[x - (w + 10 + o.outerWidth()) < 0 ? "addClass" : "removeClass"]("vakata-context-left");
  • 433
  • <\/li\> }
  • 434
  • <\/li\> else {
  • 435
  • <\/li\> o[x + w > dw && xl > dw - x ? "addClass" : "removeClass"]("vakata-context-right");
  • 436
  • <\/li\> }
  • 437
  • <\/li\> if(y + h + 10 > dh) {
  • 438
  • <\/li\> e.css("bottom","-1px");
  • 439
  • <\/li\> }
  • 440  
    441
  • <\/li\> //if does not fit - stick it to the side
  • 442
  • <\/li\> if (o.hasClass('vakata-context-right')) {
  • 443
  • <\/li\> if (xl < w) {
  • 444
  • <\/li\> e.css("margin-right", xl - w);
  • 445
  • <\/li\> }
  • 446
  • <\/li\> } else {
  • 447
  • <\/li\> if (dw - x < w) {
  • 448
  • <\/li\> e.css("margin-left", dw - x - w);
  • 449
  • <\/li\> }
  • 450
  • <\/li\> }
  • 451  
    452
  • <\/li\> e.show();
  • 453
  • <\/li\> },
  • 454
  • <\/li\> show : function (reference, position, data) {
  • 455
  • <\/li\> var o, e, x, y, w, h, dw, dh, cond = true;
  • 456
  • <\/li\> if(vakata_context.element && vakata_context.element.length) {
  • 457
  • <\/li\> vakata_context.element.width('');
  • 458
  • <\/li\> }
  • 459
  • <\/li\> switch(cond) {
  • 460
  • <\/li\> case (!position && !reference):
  • 461
  • <\/li\> return false;
  • 462
  • <\/li\> case (!!position && !!reference):
  • 463
  • <\/li\> vakata_context.reference = reference;
  • 464
  • <\/li\> vakata_context.position_x = position.x;
  • 465
  • <\/li\> vakata_context.position_y = position.y;
  • 466
  • <\/li\> break;
  • 467
  • <\/li\> case (!position && !!reference):
  • 468
  • <\/li\> vakata_context.reference = reference;
  • 469
  • <\/li\> o = reference.offset();
  • 470
  • <\/li\> vakata_context.position_x = o.left + reference.outerHeight();
  • 471
  • <\/li\> vakata_context.position_y = o.top;
  • 472
  • <\/li\> break;
  • 473
  • <\/li\> case (!!position && !reference):
  • 474
  • <\/li\> vakata_context.position_x = position.x;
  • 475
  • <\/li\> vakata_context.position_y = position.y;
  • 476
  • <\/li\> break;
  • 477
  • <\/li\> }
  • 478
  • <\/li\> if(!!reference && !data && $(reference).data('vakata_contextmenu')) {
  • 479
  • <\/li\> data = $(reference).data('vakata_contextmenu');
  • 480
  • <\/li\> }
  • 481
  • <\/li\> if($.vakata.context._parse(data)) {
  • 482
  • <\/li\> vakata_context.element.html(vakata_context.html);
  • 483
  • <\/li\> }
  • 484
  • <\/li\> if(vakata_context.items.length) {
  • 485
  • <\/li\> vakata_context.element.appendTo("body");
  • 486
  • <\/li\> e = vakata_context.element;
  • 487
  • <\/li\> x = vakata_context.position_x;
  • 488
  • <\/li\> y = vakata_context.position_y;
  • 489
  • <\/li\> w = e.width();
  • 490
  • <\/li\> h = e.height();
  • 491
  • <\/li\> dw = $(window).width() + $(window).scrollLeft();
  • 492
  • <\/li\> dh = $(window).height() + $(window).scrollTop();
  • 493
  • <\/li\> if(right_to_left) {
  • 494
  • <\/li\> x -= (e.outerWidth() - $(reference).outerWidth());
  • 495
  • <\/li\> if(x < $(window).scrollLeft() + 20) {
  • 496
  • <\/li\> x = $(window).scrollLeft() + 20;
  • 497
  • <\/li\> }
  • 498
  • <\/li\> }
  • 499
  • <\/li\> if(x + w + 20 > dw) {
  • 500
  • <\/li\> x = dw - (w + 20);
  • 501
  • <\/li\> }
  • 502
  • <\/li\> if(y + h + 20 > dh) {
  • 503
  • <\/li\> y = dh - (h + 20);
  • 504
  • <\/li\> }
  • 505  
    506
  • <\/li\> vakata_context.element
  • 507
  • <\/li\> .css({ "left" : x, "top" : y })
  • 508
  • <\/li\> .show()
  • 509
  • <\/li\> .find('a').first().focus().parent().addClass("vakata-context-hover");
  • 510
  • <\/li\> vakata_context.is_visible = true;
  • 511
  • <\/li\> /**
  • 512
  • <\/li\> * triggered on the document when the contextmenu is shown
  • 513
  • <\/li\> * @event
  • 514
  • <\/li\> * @plugin contextmenu
  • 515
  • <\/li\> * @name context_show.vakata
  • 516
  • <\/li\> * @param {jQuery} reference the element that was right clicked
  • 517
  • <\/li\> * @param {jQuery} element the DOM element of the menu itself
  • 518
  • <\/li\> * @param {Object} position the x & y coordinates of the menu
  • 519
  • <\/li\> */
  • 520
  • <\/li\> $.vakata.context._trigger("show");
  • 521
  • <\/li\> }
  • 522
  • <\/li\> },
  • 523
  • <\/li\> hide : function () {
  • 524
  • <\/li\> if(vakata_context.is_visible) {
  • 525
  • <\/li\> vakata_context.element.hide().find("ul").hide().end().find(':focus').blur().end().detach();
  • 526
  • <\/li\> vakata_context.is_visible = false;
  • 527
  • <\/li\> /**
  • 528
  • <\/li\> * triggered on the document when the contextmenu is hidden
  • 529
  • <\/li\> * @event
  • 530
  • <\/li\> * @plugin contextmenu
  • 531
  • <\/li\> * @name context_hide.vakata
  • 532
  • <\/li\> * @param {jQuery} reference the element that was right clicked
  • 533
  • <\/li\> * @param {jQuery} element the DOM element of the menu itself
  • 534
  • <\/li\> * @param {Object} position the x & y coordinates of the menu
  • 535
  • <\/li\> */
  • 536
  • <\/li\> $.vakata.context._trigger("hide");
  • 537
  • <\/li\> }
  • 538
  • <\/li\> }
  • 539
  • <\/li\> };
  • 540
  • <\/li\> $(function () {
  • 541
  • <\/li\> right_to_left = $("body").css("direction") === "rtl";
  • 542
  • <\/li\> var to = false;
  • 543  
    544
  • <\/li\> vakata_context.element = $("<ul class='vakata-context'></ul>");
  • 545
  • <\/li\> vakata_context.element
  • 546
  • <\/li\> .on("mouseenter", "li", function (e) {
  • 547
  • <\/li\> e.stopImmediatePropagation();
  • 548  
    549
  • <\/li\> if($.contains(this, e.relatedTarget)) {
  • 550
  • <\/li\> // премахнато заради delegate mouseleave по-долу
  • 551
  • <\/li\> // $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
  • 552
  • <\/li\> return;
  • 553
  • <\/li\> }
  • 554  
    555
  • <\/li\> if(to) { clearTimeout(to); }
  • 556
  • <\/li\> vakata_context.element.find(".vakata-context-hover").removeClass("vakata-context-hover").end();
  • 557  
    558
  • <\/li\> $(this)
  • 559
  • <\/li\> .siblings().find("ul").hide().end().end()
  • 560
  • <\/li\> .parentsUntil(".vakata-context", "li").addBack().addClass("vakata-context-hover");
  • 561
  • <\/li\> $.vakata.context._show_submenu(this);
  • 562
  • <\/li\> })
  • 563
  • <\/li\> // тестово - дали не натоварва?
  • 564
  • <\/li\> .on("mouseleave", "li", function (e) {
  • 565
  • <\/li\> if($.contains(this, e.relatedTarget)) { return; }
  • 566
  • <\/li\> $(this).find(".vakata-context-hover").addBack().removeClass("vakata-context-hover");
  • 567
  • <\/li\> })
  • 568
  • <\/li\> .on("mouseleave", function (e) {
  • 569
  • <\/li\> $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
  • 570
  • <\/li\> if($.vakata.context.settings.hide_onmouseleave) {
  • 571
  • <\/li\> to = setTimeout(
  • 572
  • <\/li\> (function (t) {
  • 573
  • <\/li\> return function () { $.vakata.context.hide(); };
  • 574
  • <\/li\> }(this)), $.vakata.context.settings.hide_onmouseleave);
  • 575
  • <\/li\> }
  • 576
  • <\/li\> })
  • 577
  • <\/li\> .on("click", "a", function (e) {
  • 578
  • <\/li\> e.preventDefault();
  • 579
  • <\/li\> //})
  • 580
  • <\/li\> //.on("mouseup", "a", function (e) {
  • 581
  • <\/li\> if(!$(this).blur().parent().hasClass("vakata-context-disabled") && $.vakata.context._execute($(this).attr("rel")) !== false) {
  • 582
  • <\/li\> $.vakata.context.hide();
  • 583
  • <\/li\> }
  • 584
  • <\/li\> })
  • 585
  • <\/li\> .on('keydown', 'a', function (e) {
  • 586
  • <\/li\> var o = null;
  • 587
  • <\/li\> switch(e.which) {
  • 588
  • <\/li\> case 13:
  • 589
  • <\/li\> case 32:
  • 590
  • <\/li\> e.type = "click";
  • 591
  • <\/li\> e.preventDefault();
  • 592
  • <\/li\> $(e.currentTarget).trigger(e);
  • 593
  • <\/li\> break;
  • 594
  • <\/li\> case 37:
  • 595
  • <\/li\> if(vakata_context.is_visible) {
  • 596
  • <\/li\> vakata_context.element.find(".vakata-context-hover").last().closest("li").first().find("ul").hide().find(".vakata-context-hover").removeClass("vakata-context-hover").end().end().children('a').focus();
  • 597
  • <\/li\> e.stopImmediatePropagation();
  • 598
  • <\/li\> e.preventDefault();
  • 599
  • <\/li\> }
  • 600
  • <\/li\> break;
  • 601
  • <\/li\> case 38:
  • 602
  • <\/li\> if(vakata_context.is_visible) {
  • 603
  • <\/li\> o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").prevAll("li:not(.vakata-context-separator)").first();
  • 604
  • <\/li\> if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").last(); }
  • 605
  • <\/li\> o.addClass("vakata-context-hover").children('a').focus();
  • 606
  • <\/li\> e.stopImmediatePropagation();
  • 607
  • <\/li\> e.preventDefault();
  • 608
  • <\/li\> }
  • 609
  • <\/li\> break;
  • 610
  • <\/li\> case 39:
  • 611
  • <\/li\> if(vakata_context.is_visible) {
  • 612
  • <\/li\> vakata_context.element.find(".vakata-context-hover").last().children("ul").show().children("li:not(.vakata-context-separator)").removeClass("vakata-context-hover").first().addClass("vakata-context-hover").children('a').focus();
  • 613
  • <\/li\> e.stopImmediatePropagation();
  • 614
  • <\/li\> e.preventDefault();
  • 615
  • <\/li\> }
  • 616
  • <\/li\> break;
  • 617
  • <\/li\> case 40:
  • 618
  • <\/li\> if(vakata_context.is_visible) {
  • 619
  • <\/li\> o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").nextAll("li:not(.vakata-context-separator)").first();
  • 620
  • <\/li\> if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").first(); }
  • 621
  • <\/li\> o.addClass("vakata-context-hover").children('a').focus();
  • 622
  • <\/li\> e.stopImmediatePropagation();
  • 623
  • <\/li\> e.preventDefault();
  • 624
  • <\/li\> }
  • 625
  • <\/li\> break;
  • 626
  • <\/li\> case 27:
  • 627
  • <\/li\> $.vakata.context.hide();
  • 628
  • <\/li\> e.preventDefault();
  • 629
  • <\/li\> break;
  • 630
  • <\/li\> default:
  • 631
  • <\/li\> //console.log(e.which);
  • 632
  • <\/li\> break;
  • 633
  • <\/li\> }
  • 634
  • <\/li\> })
  • 635
  • <\/li\> .on('keydown', function (e) {
  • 636
  • <\/li\> e.preventDefault();
  • 637
  • <\/li\> var a = vakata_context.element.find('.vakata-contextmenu-shortcut-' + e.which).parent();
  • 638
  • <\/li\> if(a.parent().not('.vakata-context-disabled')) {
  • 639
  • <\/li\> a.click();
  • 640
  • <\/li\> }
  • 641
  • <\/li\> });
  • 642  
    643
  • <\/li\> $(document)
  • 644
  • <\/li\> .on("mousedown.vakata.jstree", function (e) {
  • 645
  • <\/li\> if(vakata_context.is_visible && vakata_context.element[0] !== e.target && !$.contains(vakata_context.element[0], e.target)) {
  • 646
  • <\/li\> $.vakata.context.hide();
  • 647
  • <\/li\> }
  • 648
  • <\/li\> })
  • 649
  • <\/li\> .on("context_show.vakata.jstree", function (e, data) {
  • 650
  • <\/li\> vakata_context.element.find("li:has(ul)").children("a").addClass("vakata-context-parent");
  • 651
  • <\/li\> if(right_to_left) {
  • 652
  • <\/li\> vakata_context.element.addClass("vakata-context-rtl").css("direction", "rtl");
  • 653
  • <\/li\> }
  • 654
  • <\/li\> // also apply a RTL class?
  • 655
  • <\/li\> vakata_context.element.find("ul").hide().end();
  • 656
  • <\/li\> });
  • 657
  • <\/li\> });
  • 658
  • <\/li\> }($));
  • 659
  • <\/li\> // $.jstree.defaults.plugins.push("contextmenu");
  • 660
  • <\/li\>}));