| 875 |
lars |
1 |
/* global jQuery */
|
|
|
2 |
|
|
|
3 |
// disable all events
|
|
|
4 |
(function ($, undefined) {
|
|
|
5 |
"use strict";
|
|
|
6 |
$.jstree.plugins.trigger = function (options, parent) {
|
|
|
7 |
this.init = function (el, options) {
|
|
|
8 |
// do not forget parent
|
|
|
9 |
parent.init.call(this, el, options);
|
|
|
10 |
this._data.trigger.disabled = false;
|
|
|
11 |
};
|
|
|
12 |
this.trigger = function (ev, data) {
|
|
|
13 |
if(!this._data.trigger.disabled) {
|
|
|
14 |
parent.trigger.call(this, ev, data);
|
|
|
15 |
}
|
|
|
16 |
};
|
|
|
17 |
this.disable_events = function () { this._data.trigger.disabled = true; };
|
|
|
18 |
this.enable_events = function () { this._data.trigger.disabled = false; };
|
|
|
19 |
};
|
|
|
20 |
})(jQuery);
|
|
|
21 |
|
|
|
22 |
// mapping
|
|
|
23 |
(function ($, undefined) {
|
|
|
24 |
"use strict";
|
|
|
25 |
// use this if you need any options
|
|
|
26 |
$.jstree.defaults.mapper = {
|
|
|
27 |
option_key : "option_value"
|
|
|
28 |
};
|
|
|
29 |
$.jstree.plugins.mapper = function () {
|
|
|
30 |
this._parse_model_from_json = function (d, p, ps) {
|
|
|
31 |
// d is the node from the server, it will be called recursively for children,
|
|
|
32 |
// so you do not need to process at once
|
|
|
33 |
/* // for example
|
|
|
34 |
for(var i in d) {
|
|
|
35 |
if(d.hasOwnProperty(i)) {
|
|
|
36 |
d[i.toLowerCase()] = d[i];
|
|
|
37 |
}
|
|
|
38 |
}
|
|
|
39 |
*/
|
|
|
40 |
return parent._parse_model_from_json.call(this, d, p, ps);
|
|
|
41 |
};
|
|
|
42 |
};
|
|
|
43 |
})(jQuery);
|
|
|
44 |
|
|
|
45 |
// no hover
|
|
|
46 |
(function ($, undefined) {
|
|
|
47 |
"use strict";
|
|
|
48 |
$.jstree.plugins.nohover = function () {
|
|
|
49 |
this.hover_node = $.noop;
|
|
|
50 |
};
|
|
|
51 |
})(jQuery);
|
|
|
52 |
|
|
|
53 |
// force multiple select
|
|
|
54 |
(function ($, undefined) {
|
|
|
55 |
"use strict";
|
|
|
56 |
$.jstree.defaults.multiselect = {};
|
|
|
57 |
$.jstree.plugins.multiselect = function (options, parent) {
|
|
|
58 |
this.activate_node = function (obj, e) {
|
|
|
59 |
e.ctrlKey = true;
|
|
|
60 |
parent.activate_node.call(this, obj, e);
|
|
|
61 |
};
|
|
|
62 |
};
|
|
|
63 |
})(jQuery);
|
|
|
64 |
|
|
|
65 |
// real checkboxes
|
|
|
66 |
(function ($, undefined) {
|
|
|
67 |
"use strict";
|
|
|
68 |
|
|
|
69 |
var inp = document.createElement("INPUT");
|
|
|
70 |
inp.type = "checkbox";
|
|
|
71 |
inp.className = "jstree-checkbox jstree-realcheckbox";
|
|
|
72 |
|
|
|
73 |
$.jstree.defaults.realcheckboxes = {};
|
|
|
74 |
|
|
|
75 |
$.jstree.plugins.realcheckboxes = function (options, parent) {
|
|
|
76 |
this.bind = function () {
|
|
|
77 |
parent.bind.call(this);
|
|
|
78 |
this._data.realcheckboxes.uto = false;
|
|
|
79 |
this.element
|
|
|
80 |
.on('changed.jstree uncheck_node.jstree check_node.jstree uncheck_all.jstree check_all.jstree move_node.jstree copy_node.jstree redraw.jstree open_node.jstree ready.jstree loaded.jstree', $.proxy(function () {
|
|
|
81 |
// only if undetermined is in setting
|
|
|
82 |
if(this._data.realcheckboxes.uto) { clearTimeout(this._data.realcheckboxes.uto); }
|
|
|
83 |
this._data.realcheckboxes.uto = setTimeout($.proxy(this._realcheckboxes, this), 50);
|
|
|
84 |
}, this));
|
|
|
85 |
};
|
|
|
86 |
this.redraw_node = function(obj, deep, callback, force_draw) {
|
|
|
87 |
obj = parent.redraw_node.call(this, obj, deep, callback, force_draw);
|
|
|
88 |
if(obj) {
|
|
|
89 |
var i, j, tmp = null, chk = inp.cloneNode(true);
|
|
|
90 |
for(i = 0, j = obj.childNodes.length; i < j; i++) {
|
|
|
91 |
if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
|
|
|
92 |
tmp = obj.childNodes[i];
|
|
|
93 |
break;
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
if(tmp) {
|
|
|
97 |
for(i = 0, j = tmp.childNodes.length; i < j; i++) {
|
|
|
98 |
if(tmp.childNodes[i] && tmp.childNodes[i].className && tmp.childNodes[i].className.indexOf("jstree-checkbox") !== -1) {
|
|
|
99 |
tmp = tmp.childNodes[i];
|
|
|
100 |
break;
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
if(tmp && tmp.tagName === "I") {
|
|
|
105 |
tmp.style.backgroundColor = "transparent";
|
|
|
106 |
tmp.style.backgroundImage = "none";
|
|
|
107 |
tmp.appendChild(chk);
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
return obj;
|
|
|
111 |
};
|
|
|
112 |
this._realcheckboxes = function () {
|
|
|
113 |
var ts = this.settings.checkbox.tie_selection;
|
|
|
114 |
console.log(ts);
|
|
|
115 |
$('.jstree-realcheckbox').each(function () {
|
|
|
116 |
this.checked = (!ts && this.parentNode.parentNode.className.indexOf("jstree-checked") !== -1) || (ts && this.parentNode.parentNode.className.indexOf('jstree-clicked') !== -1);
|
|
|
117 |
this.indeterminate = this.parentNode.className.indexOf("jstree-undetermined") !== -1;
|
|
|
118 |
this.disabled = this.parentNode.parentNode.className.indexOf("disabled") !== -1;
|
|
|
119 |
});
|
|
|
120 |
};
|
|
|
121 |
};
|
|
|
122 |
})(jQuery);
|
|
|
123 |
|
|
|
124 |
// no state
|
|
|
125 |
(function ($, undefined) {
|
|
|
126 |
"use strict";
|
|
|
127 |
$.jstree.plugins.nostate = function () {
|
|
|
128 |
this.set_state = function (state, callback) {
|
|
|
129 |
if(callback) { callback.call(this); }
|
|
|
130 |
this.trigger('set_state');
|
|
|
131 |
};
|
|
|
132 |
};
|
|
|
133 |
})(jQuery);
|
|
|
134 |
|
|
|
135 |
// no selected in state
|
|
|
136 |
(function ($, undefined) {
|
|
|
137 |
"use strict";
|
|
|
138 |
$.jstree.plugins.noselectedstate = function (options, parent) {
|
|
|
139 |
this.get_state = function () {
|
|
|
140 |
var state = parent.get_state.call(this);
|
|
|
141 |
delete state.core.selected;
|
|
|
142 |
return state;
|
|
|
143 |
};
|
|
|
144 |
};
|
|
|
145 |
})(jQuery);
|
|
|
146 |
|
|
|
147 |
// additional icon on node (outside of anchor)
|
|
|
148 |
(function ($, undefined) {
|
|
|
149 |
"use strict";
|
|
|
150 |
var img = document.createElement('IMG');
|
|
|
151 |
//img.src = "http://www.dpcd.vic.gov.au/__data/assets/image/0004/30667/help.gif";
|
|
|
152 |
img.className = "jstree-questionmark";
|
|
|
153 |
|
|
|
154 |
$.jstree.defaults.questionmark = $.noop;
|
|
|
155 |
$.jstree.plugins.questionmark = function (options, parent) {
|
|
|
156 |
this.bind = function () {
|
|
|
157 |
parent.bind.call(this);
|
|
|
158 |
this.element
|
|
|
159 |
.on("click.jstree", ".jstree-questionmark", $.proxy(function (e) {
|
|
|
160 |
e.stopImmediatePropagation();
|
|
|
161 |
this.settings.questionmark.call(this, this.get_node(e.target));
|
|
|
162 |
}, this));
|
|
|
163 |
};
|
|
|
164 |
this.teardown = function () {
|
|
|
165 |
if(this.settings.questionmark) {
|
|
|
166 |
this.element.find(".jstree-questionmark").remove();
|
|
|
167 |
}
|
|
|
168 |
parent.teardown.call(this);
|
|
|
169 |
};
|
|
|
170 |
this.redraw_node = function(obj, deep, callback, force_draw) {
|
|
|
171 |
obj = parent.redraw_node.call(this, obj, deep, callback, force_draw);
|
|
|
172 |
if(obj) {
|
|
|
173 |
var tmp = img.cloneNode(true);
|
|
|
174 |
obj.insertBefore(tmp, obj.childNodes[2]);
|
|
|
175 |
}
|
|
|
176 |
return obj;
|
|
|
177 |
};
|
|
|
178 |
};
|
|
|
179 |
})(jQuery);
|
|
|
180 |
|
|
|
181 |
// auto numbering
|
|
|
182 |
(function ($, undefined) {
|
|
|
183 |
"use strict";
|
|
|
184 |
var span = document.createElement('SPAN');
|
|
|
185 |
span.className = "jstree-numbering";
|
|
|
186 |
|
|
|
187 |
$.jstree.defaults.numbering = {};
|
|
|
188 |
$.jstree.plugins.numbering = function (options, parent) {
|
|
|
189 |
this.teardown = function () {
|
|
|
190 |
if(this.settings.questionmark) {
|
|
|
191 |
this.element.find(".jstree-numbering").remove();
|
|
|
192 |
}
|
|
|
193 |
parent.teardown.call(this);
|
|
|
194 |
};
|
|
|
195 |
this.get_number = function (obj) {
|
|
|
196 |
obj = this.get_node(obj);
|
|
|
197 |
var ind = $.inArray(obj.id, this.get_node(obj.parent).children) + 1;
|
|
|
198 |
return obj.parent === '#' ? ind : this.get_number(obj.parent) + '.' + ind;
|
|
|
199 |
};
|
|
|
200 |
this.redraw_node = function(obj, deep, callback, force_draw) {
|
|
|
201 |
var i, j, tmp = null, elm = null, org = this.get_number(obj);
|
|
|
202 |
obj = parent.redraw_node.call(this, obj, deep, callback, force_draw);
|
|
|
203 |
if(obj) {
|
|
|
204 |
for(i = 0, j = obj.childNodes.length; i < j; i++) {
|
|
|
205 |
if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
|
|
|
206 |
tmp = obj.childNodes[i];
|
|
|
207 |
break;
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
if(tmp) {
|
|
|
211 |
elm = span.cloneNode(true);
|
|
|
212 |
elm.innerHTML = org + '. ';
|
|
|
213 |
tmp.insertBefore(elm, tmp.childNodes[tmp.childNodes.length - 1]);
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
return obj;
|
|
|
217 |
};
|
|
|
218 |
};
|
|
|
219 |
})(jQuery);
|
|
|
220 |
|
|
|
221 |
// additional icon on node (inside anchor)
|
|
|
222 |
(function ($, undefined) {
|
|
|
223 |
"use strict";
|
|
|
224 |
var _s = document.createElement('SPAN');
|
|
|
225 |
_s.className = 'fa-stack jstree-stackedicon';
|
|
|
226 |
var _i = document.createElement('I');
|
|
|
227 |
_i.className = 'jstree-icon';
|
|
|
228 |
_i.setAttribute('role', 'presentation');
|
|
|
229 |
|
|
|
230 |
$.jstree.plugins.stackedicon = function (options, parent) {
|
|
|
231 |
this.teardown = function () {
|
|
|
232 |
this.element.find(".jstree-stackedicon").remove();
|
|
|
233 |
parent.teardown.call(this);
|
|
|
234 |
};
|
|
|
235 |
this.redraw_node = function(obj, deep, is_callback, force_render) {
|
|
|
236 |
obj = parent.redraw_node.apply(this, arguments);
|
|
|
237 |
if(obj) {
|
|
|
238 |
var i, j, tmp = null, icon = null, temp = null;
|
|
|
239 |
for(i = 0, j = obj.childNodes.length; i < j; i++) {
|
|
|
240 |
if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
|
|
|
241 |
tmp = obj.childNodes[i];
|
|
|
242 |
break;
|
|
|
243 |
}
|
|
|
244 |
}
|
|
|
245 |
if(tmp) {
|
|
|
246 |
if(this._model.data[obj.id].state.icons && this._model.data[obj.id].state.icons.length) {
|
|
|
247 |
icon = _s.cloneNode(false);
|
|
|
248 |
for(i = 0, j = this._model.data[obj.id].state.icons.length; i < j; i++) {
|
|
|
249 |
temp = _i.cloneNode(false);
|
|
|
250 |
temp.className += ' ' + this._model.data[obj.id].state.icons[i];
|
|
|
251 |
icon.appendChild(temp);
|
|
|
252 |
}
|
|
|
253 |
tmp.insertBefore(icon, tmp.childNodes[0]);
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
return obj;
|
|
|
258 |
};
|
|
|
259 |
};
|
|
|
260 |
})(jQuery);
|
|
|
261 |
|
|
|
262 |
// selecting a node opens it
|
|
|
263 |
(function ($, undefined) {
|
|
|
264 |
"use strict";
|
|
|
265 |
$.jstree.plugins.selectopens = function (options, parent) {
|
|
|
266 |
this.bind = function () {
|
|
|
267 |
parent.bind.call(this);
|
|
|
268 |
this.element.on('select_node.jstree', function (e, data) { data.instance.open_node(data.node); });
|
|
|
269 |
};
|
|
|
270 |
};
|
|
|
271 |
})(jQuery);
|
|
|
272 |
|
|
|
273 |
// object as data
|
|
|
274 |
(function ($, undefined) {
|
|
|
275 |
"use strict";
|
|
|
276 |
$.jstree.defaults.datamodel = {};
|
|
|
277 |
$.jstree.plugins.datamodel = function (options, parent) {
|
|
|
278 |
this.init = function (el, options) {
|
|
|
279 |
this._data.datamodel = {};
|
|
|
280 |
parent.init.call(this, el, options);
|
|
|
281 |
};
|
|
|
282 |
this._datamodel = function (id, nodes, callback) {
|
|
|
283 |
var i = 0, j = nodes.length, tmp = [], obj = null;
|
|
|
284 |
for(; i < j; i++) {
|
|
|
285 |
this._data.datamodel[nodes[i].getID()] = nodes[i];
|
|
|
286 |
obj = {
|
|
|
287 |
id : nodes[i].getID(),
|
|
|
288 |
text : nodes[i].getText(),
|
|
|
289 |
children : nodes[i].hasChildren()
|
|
|
290 |
};
|
|
|
291 |
if(nodes[i].getExtra) {
|
|
|
292 |
obj = nodes[i].getExtra(obj); // icon, type
|
|
|
293 |
}
|
|
|
294 |
tmp.push(obj);
|
|
|
295 |
}
|
|
|
296 |
return this._append_json_data(id, tmp, $.proxy(function (status) {
|
|
|
297 |
callback.call(this, status);
|
|
|
298 |
}, this));
|
|
|
299 |
};
|
|
|
300 |
this._load_node = function (obj, callback) {
|
|
|
301 |
var id = obj.id;
|
|
|
302 |
var nd = obj.id === "#" ? this.settings.core.data : this._data.datamodel[obj.id].getChildren($.proxy(function (nodes) {
|
|
|
303 |
this._datamodel(id, nodes, callback);
|
|
|
304 |
}, this));
|
|
|
305 |
if($.isArray(nd)) {
|
|
|
306 |
this._datamodel(id, nd, callback);
|
|
|
307 |
}
|
|
|
308 |
};
|
|
|
309 |
};
|
|
|
310 |
})(jQuery);
|
|
|
311 |
/*
|
|
|
312 |
demo of the above
|
|
|
313 |
function treeNode(val) {
|
|
|
314 |
var id = ++treeNode.counter;
|
|
|
315 |
this.getID = function () {
|
|
|
316 |
return id;
|
|
|
317 |
};
|
|
|
318 |
this.getText = function () {
|
|
|
319 |
return val.toString();
|
|
|
320 |
};
|
|
|
321 |
this.getExtra = function (obj) {
|
|
|
322 |
obj.icon = false;
|
|
|
323 |
return obj;
|
|
|
324 |
};
|
|
|
325 |
this.hasChildren = function () {
|
|
|
326 |
return true;
|
|
|
327 |
};
|
|
|
328 |
this.getChildren = function () {
|
|
|
329 |
return [
|
|
|
330 |
new treeNode(Math.pow(val, 2)),
|
|
|
331 |
new treeNode(Math.sqrt(val)),
|
|
|
332 |
];
|
|
|
333 |
};
|
|
|
334 |
}
|
|
|
335 |
treeNode.counter = 0;
|
|
|
336 |
|
|
|
337 |
$('#jstree').jstree({
|
|
|
338 |
'core': {
|
|
|
339 |
'data': [
|
|
|
340 |
new treeNode(2),
|
|
|
341 |
new treeNode(3),
|
|
|
342 |
new treeNode(4),
|
|
|
343 |
new treeNode(5)
|
|
|
344 |
]
|
|
|
345 |
},
|
|
|
346 |
plugins : ['datamodel']
|
|
|
347 |
});
|
|
|
348 |
*/
|
|
|
349 |
|
|
|
350 |
// untested sample plugin to keep all nodes in the DOM
|
|
|
351 |
(function ($, undefined) {
|
|
|
352 |
"use strict";
|
|
|
353 |
$.jstree.plugins.dom = function (options, parent) {
|
|
|
354 |
this.redraw_node = function (node, deep, is_callback, force_render) {
|
|
|
355 |
return parent.redraw_node.call(this, node, deep, is_callback, true);
|
|
|
356 |
};
|
|
|
357 |
this.close_node = function (obj, animation) {
|
|
|
358 |
var t1, t2, t, d;
|
|
|
359 |
if($.isArray(obj)) {
|
|
|
360 |
obj = obj.slice();
|
|
|
361 |
for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
|
|
|
362 |
this.close_node(obj[t1], animation);
|
|
|
363 |
}
|
|
|
364 |
return true;
|
|
|
365 |
}
|
|
|
366 |
obj = this.get_node(obj);
|
|
|
367 |
if(!obj || obj.id === $.jstree.root) {
|
|
|
368 |
return false;
|
|
|
369 |
}
|
|
|
370 |
if(this.is_closed(obj)) {
|
|
|
371 |
return false;
|
|
|
372 |
}
|
|
|
373 |
animation = animation === undefined ? this.settings.core.animation : animation;
|
|
|
374 |
t = this;
|
|
|
375 |
d = this.get_node(obj, true);
|
|
|
376 |
if(d.length) {
|
|
|
377 |
if(!animation) {
|
|
|
378 |
d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
|
|
|
379 |
d.attr("aria-expanded", false);
|
|
|
380 |
}
|
|
|
381 |
else {
|
|
|
382 |
d
|
|
|
383 |
.children(".jstree-children").attr("style","display:block !important").end()
|
|
|
384 |
.removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded", false)
|
|
|
385 |
.children(".jstree-children").stop(true, true).slideUp(animation, function () {
|
|
|
386 |
this.style.display = "";
|
|
|
387 |
t.trigger("after_close", { "node" : obj });
|
|
|
388 |
});
|
|
|
389 |
}
|
|
|
390 |
}
|
|
|
391 |
obj.state.opened = false;
|
|
|
392 |
this.trigger('close_node',{ "node" : obj });
|
|
|
393 |
if(!animation || !d.length) {
|
|
|
394 |
this.trigger("after_close", { "node" : obj });
|
|
|
395 |
}
|
|
|
396 |
};
|
|
|
397 |
};
|
|
|
398 |
})(jQuery);
|