annotate vakata-jstree-3.3.5/src/jstree.contextmenu.js @ 3:071638eddf9c draft

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