annotate vakata-jstree-3.3.5/src/misc.js @ 0:a42e58c71e5b draft default tip

planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
author mingchen0919
date Sun, 30 Dec 2018 12:55:49 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
1 /* global jQuery */
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
2
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
3 // disable all events
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
4 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
5 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
6 $.jstree.plugins.trigger = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
7 this.init = function (el, options) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
8 // do not forget parent
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
9 parent.init.call(this, el, options);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
10 this._data.trigger.disabled = false;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
11 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
12 this.trigger = function (ev, data) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
13 if(!this._data.trigger.disabled) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
14 parent.trigger.call(this, ev, data);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
15 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
16 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
17 this.disable_events = function () { this._data.trigger.disabled = true; };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
18 this.enable_events = function () { this._data.trigger.disabled = false; };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
19 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
20 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
21
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
22 // mapping
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
23 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
24 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
25 // use this if you need any options
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
26 $.jstree.defaults.mapper = {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
27 option_key : "option_value"
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
28 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
29 $.jstree.plugins.mapper = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
30 this._parse_model_from_json = function (d, p, ps) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
31 // d is the node from the server, it will be called recursively for children,
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
32 // so you do not need to process at once
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
33 /* // for example
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
34 for(var i in d) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
35 if(d.hasOwnProperty(i)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
36 d[i.toLowerCase()] = d[i];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
37 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
38 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
39 */
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
40 return parent._parse_model_from_json.call(this, d, p, ps);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
41 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
42 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
43 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
44
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
45 // no hover
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
46 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
47 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
48 $.jstree.plugins.nohover = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
49 this.hover_node = $.noop;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
50 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
51 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
52
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
53 // force multiple select
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
54 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
55 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
56 $.jstree.defaults.multiselect = {};
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
57 $.jstree.plugins.multiselect = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
58 this.activate_node = function (obj, e) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
59 e.ctrlKey = true;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
60 parent.activate_node.call(this, obj, e);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
61 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
62 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
63 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
64
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
65 // real checkboxes
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
66 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
67 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
68
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
69 var inp = document.createElement("INPUT");
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
70 inp.type = "checkbox";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
71 inp.className = "jstree-checkbox jstree-realcheckbox";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
72
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
73 $.jstree.defaults.realcheckboxes = {};
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
74
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
75 $.jstree.plugins.realcheckboxes = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
76 this.bind = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
77 parent.bind.call(this);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
78 this._data.realcheckboxes.uto = false;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
79 this.element
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
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 () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
81 // only if undetermined is in setting
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
82 if(this._data.realcheckboxes.uto) { clearTimeout(this._data.realcheckboxes.uto); }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
83 this._data.realcheckboxes.uto = setTimeout($.proxy(this._realcheckboxes, this), 50);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
84 }, this));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
85 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
86 this.redraw_node = function(obj, deep, callback, force_draw) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
87 obj = parent.redraw_node.call(this, obj, deep, callback, force_draw);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
88 if(obj) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
89 var i, j, tmp = null, chk = inp.cloneNode(true);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
90 for(i = 0, j = obj.childNodes.length; i < j; i++) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
91 if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
92 tmp = obj.childNodes[i];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
93 break;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
94 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
95 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
96 if(tmp) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
97 for(i = 0, j = tmp.childNodes.length; i < j; i++) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
98 if(tmp.childNodes[i] && tmp.childNodes[i].className && tmp.childNodes[i].className.indexOf("jstree-checkbox") !== -1) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
99 tmp = tmp.childNodes[i];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
100 break;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
101 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
102 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
103 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
104 if(tmp && tmp.tagName === "I") {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
105 tmp.style.backgroundColor = "transparent";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
106 tmp.style.backgroundImage = "none";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
107 tmp.appendChild(chk);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
108 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
109 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
110 return obj;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
111 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
112 this._realcheckboxes = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
113 var ts = this.settings.checkbox.tie_selection;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
114 console.log(ts);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
115 $('.jstree-realcheckbox').each(function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
116 this.checked = (!ts && this.parentNode.parentNode.className.indexOf("jstree-checked") !== -1) || (ts && this.parentNode.parentNode.className.indexOf('jstree-clicked') !== -1);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
117 this.indeterminate = this.parentNode.className.indexOf("jstree-undetermined") !== -1;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
118 this.disabled = this.parentNode.parentNode.className.indexOf("disabled") !== -1;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
119 });
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
120 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
121 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
122 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
123
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
124 // no state
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
125 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
126 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
127 $.jstree.plugins.nostate = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
128 this.set_state = function (state, callback) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
129 if(callback) { callback.call(this); }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
130 this.trigger('set_state');
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
131 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
132 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
133 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
134
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
135 // no selected in state
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
136 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
137 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
138 $.jstree.plugins.noselectedstate = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
139 this.get_state = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
140 var state = parent.get_state.call(this);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
141 delete state.core.selected;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
142 return state;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
143 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
144 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
145 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
146
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
147 // additional icon on node (outside of anchor)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
148 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
149 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
150 var img = document.createElement('IMG');
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
151 //img.src = "http://www.dpcd.vic.gov.au/__data/assets/image/0004/30667/help.gif";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
152 img.className = "jstree-questionmark";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
153
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
154 $.jstree.defaults.questionmark = $.noop;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
155 $.jstree.plugins.questionmark = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
156 this.bind = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
157 parent.bind.call(this);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
158 this.element
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
159 .on("click.jstree", ".jstree-questionmark", $.proxy(function (e) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
160 e.stopImmediatePropagation();
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
161 this.settings.questionmark.call(this, this.get_node(e.target));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
162 }, this));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
163 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
164 this.teardown = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
165 if(this.settings.questionmark) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
166 this.element.find(".jstree-questionmark").remove();
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
167 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
168 parent.teardown.call(this);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
169 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
170 this.redraw_node = function(obj, deep, callback, force_draw) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
171 obj = parent.redraw_node.call(this, obj, deep, callback, force_draw);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
172 if(obj) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
173 var tmp = img.cloneNode(true);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
174 obj.insertBefore(tmp, obj.childNodes[2]);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
175 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
176 return obj;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
177 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
178 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
179 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
180
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
181 // auto numbering
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
182 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
183 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
184 var span = document.createElement('SPAN');
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
185 span.className = "jstree-numbering";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
186
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
187 $.jstree.defaults.numbering = {};
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
188 $.jstree.plugins.numbering = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
189 this.teardown = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
190 if(this.settings.questionmark) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
191 this.element.find(".jstree-numbering").remove();
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
192 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
193 parent.teardown.call(this);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
194 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
195 this.get_number = function (obj) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
196 obj = this.get_node(obj);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
197 var ind = $.inArray(obj.id, this.get_node(obj.parent).children) + 1;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
198 return obj.parent === '#' ? ind : this.get_number(obj.parent) + '.' + ind;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
199 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
200 this.redraw_node = function(obj, deep, callback, force_draw) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
201 var i, j, tmp = null, elm = null, org = this.get_number(obj);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
202 obj = parent.redraw_node.call(this, obj, deep, callback, force_draw);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
203 if(obj) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
204 for(i = 0, j = obj.childNodes.length; i < j; i++) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
205 if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
206 tmp = obj.childNodes[i];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
207 break;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
208 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
209 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
210 if(tmp) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
211 elm = span.cloneNode(true);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
212 elm.innerHTML = org + '. ';
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
213 tmp.insertBefore(elm, tmp.childNodes[tmp.childNodes.length - 1]);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
214 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
215 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
216 return obj;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
217 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
218 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
219 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
220
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
221 // additional icon on node (inside anchor)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
222 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
223 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
224 var _s = document.createElement('SPAN');
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
225 _s.className = 'fa-stack jstree-stackedicon';
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
226 var _i = document.createElement('I');
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
227 _i.className = 'jstree-icon';
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
228 _i.setAttribute('role', 'presentation');
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
229
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
230 $.jstree.plugins.stackedicon = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
231 this.teardown = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
232 this.element.find(".jstree-stackedicon").remove();
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
233 parent.teardown.call(this);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
234 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
235 this.redraw_node = function(obj, deep, is_callback, force_render) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
236 obj = parent.redraw_node.apply(this, arguments);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
237 if(obj) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
238 var i, j, tmp = null, icon = null, temp = null;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
239 for(i = 0, j = obj.childNodes.length; i < j; i++) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
240 if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
241 tmp = obj.childNodes[i];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
242 break;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
243 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
244 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
245 if(tmp) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
246 if(this._model.data[obj.id].state.icons && this._model.data[obj.id].state.icons.length) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
247 icon = _s.cloneNode(false);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
248 for(i = 0, j = this._model.data[obj.id].state.icons.length; i < j; i++) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
249 temp = _i.cloneNode(false);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
250 temp.className += ' ' + this._model.data[obj.id].state.icons[i];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
251 icon.appendChild(temp);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
252 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
253 tmp.insertBefore(icon, tmp.childNodes[0]);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
254 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
255 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
256 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
257 return obj;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
258 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
259 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
260 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
261
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
262 // selecting a node opens it
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
263 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
264 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
265 $.jstree.plugins.selectopens = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
266 this.bind = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
267 parent.bind.call(this);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
268 this.element.on('select_node.jstree', function (e, data) { data.instance.open_node(data.node); });
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
269 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
270 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
271 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
272
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
273 // object as data
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
274 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
275 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
276 $.jstree.defaults.datamodel = {};
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
277 $.jstree.plugins.datamodel = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
278 this.init = function (el, options) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
279 this._data.datamodel = {};
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
280 parent.init.call(this, el, options);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
281 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
282 this._datamodel = function (id, nodes, callback) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
283 var i = 0, j = nodes.length, tmp = [], obj = null;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
284 for(; i < j; i++) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
285 this._data.datamodel[nodes[i].getID()] = nodes[i];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
286 obj = {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
287 id : nodes[i].getID(),
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
288 text : nodes[i].getText(),
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
289 children : nodes[i].hasChildren()
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
290 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
291 if(nodes[i].getExtra) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
292 obj = nodes[i].getExtra(obj); // icon, type
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
293 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
294 tmp.push(obj);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
295 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
296 return this._append_json_data(id, tmp, $.proxy(function (status) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
297 callback.call(this, status);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
298 }, this));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
299 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
300 this._load_node = function (obj, callback) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
301 var id = obj.id;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
302 var nd = obj.id === "#" ? this.settings.core.data : this._data.datamodel[obj.id].getChildren($.proxy(function (nodes) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
303 this._datamodel(id, nodes, callback);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
304 }, this));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
305 if($.isArray(nd)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
306 this._datamodel(id, nd, callback);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
307 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
308 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
309 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
310 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
311 /*
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
312 demo of the above
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
313 function treeNode(val) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
314 var id = ++treeNode.counter;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
315 this.getID = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
316 return id;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
317 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
318 this.getText = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
319 return val.toString();
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
320 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
321 this.getExtra = function (obj) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
322 obj.icon = false;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
323 return obj;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
324 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
325 this.hasChildren = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
326 return true;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
327 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
328 this.getChildren = function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
329 return [
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
330 new treeNode(Math.pow(val, 2)),
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
331 new treeNode(Math.sqrt(val)),
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
332 ];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
333 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
334 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
335 treeNode.counter = 0;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
336
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
337 $('#jstree').jstree({
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
338 'core': {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
339 'data': [
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
340 new treeNode(2),
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
341 new treeNode(3),
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
342 new treeNode(4),
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
343 new treeNode(5)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
344 ]
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
345 },
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
346 plugins : ['datamodel']
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
347 });
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
348 */
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
349
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
350 // untested sample plugin to keep all nodes in the DOM
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
351 (function ($, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
352 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
353 $.jstree.plugins.dom = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
354 this.redraw_node = function (node, deep, is_callback, force_render) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
355 return parent.redraw_node.call(this, node, deep, is_callback, true);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
356 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
357 this.close_node = function (obj, animation) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
358 var t1, t2, t, d;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
359 if($.isArray(obj)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
360 obj = obj.slice();
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
361 for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
362 this.close_node(obj[t1], animation);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
363 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
364 return true;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
365 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
366 obj = this.get_node(obj);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
367 if(!obj || obj.id === $.jstree.root) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
368 return false;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
369 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
370 if(this.is_closed(obj)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
371 return false;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
372 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
373 animation = animation === undefined ? this.settings.core.animation : animation;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
374 t = this;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
375 d = this.get_node(obj, true);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
376 if(d.length) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
377 if(!animation) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
378 d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
379 d.attr("aria-expanded", false);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
380 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
381 else {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
382 d
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
383 .children(".jstree-children").attr("style","display:block !important").end()
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
384 .removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded", false)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
385 .children(".jstree-children").stop(true, true).slideUp(animation, function () {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
386 this.style.display = "";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
387 t.trigger("after_close", { "node" : obj });
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
388 });
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
389 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
390 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
391 obj.state.opened = false;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
392 this.trigger('close_node',{ "node" : obj });
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
393 if(!animation || !d.length) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
394 this.trigger("after_close", { "node" : obj });
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
395 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
396 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
397 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
398 })(jQuery);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
399
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
400 // customize plugin by @Lusito
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
401 // https://github.com/Lusito/jstree/blob/node-customize/src/jstree-node-customize.js
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
402 /**
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
403 * ### Node Customize plugin
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
404 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
405 * Allows to customize nodes when they are drawn.
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
406 */
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
407 (function (factory) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
408 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
409 if (typeof define === 'function' && define.amd) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
410 define('jstree.node_customize', ['jquery','jstree'], factory);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
411 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
412 else if(typeof exports === 'object') {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
413 factory(require('jquery'), require('jstree'));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
414 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
415 else {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
416 factory(jQuery, jQuery.jstree);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
417 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
418 }(function ($, jstree, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
419 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
420
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
421 if($.jstree.plugins.node_customize) { return; }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
422
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
423 /**
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
424 * the settings object.
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
425 * key is the attribute name to select the customizer function from switch.
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
426 * switch is a key => function(el, node) map.
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
427 * default: function(el, node) will be called if the type could not be mapped
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
428 * @name $.jstree.defaults.node_customize
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
429 * @plugin node_customize
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
430 */
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
431 $.jstree.defaults.node_customize = {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
432 "key": "type",
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
433 "switch": {},
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
434 "default": null
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
435 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
436
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
437 $.jstree.plugins.node_customize = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
438 this.redraw_node = function (obj, deep, callback, force_draw) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
439 var node_id = obj;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
440 var el = parent.redraw_node.apply(this, arguments);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
441 if (el) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
442 var node = this._model.data[node_id];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
443 var cfg = this.settings.node_customize;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
444 var key = cfg.key;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
445 var type = (node && node.original && node.original[key]);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
446 var customizer = (type && cfg.switch[type]) || cfg.default;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
447 if(customizer)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
448 customizer(el, node);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
449 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
450 return el;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
451 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
452 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
453 }));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
454
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
455
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
456 // parentsload plugin by @ashl1
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
457 /**
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
458 * ### Parentsload plugin
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
459 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
460 * Change load_node() functionality in jsTree, to possible load not yes downloaded node with all it parent in a single request (only useful with lazy loading).
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
461 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
462 * version 1.0.0 (Alexey Shildyakov - ashl1future@gmail.com)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
463 * 2015: Compatible with jsTree-3.2.1
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
464 */
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
465 /*globals jQuery, define, exports, require, document */
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
466 (function (factory) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
467 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
468 if (typeof define === 'function' && define.amd) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
469 define('jstree.parentsload', ['jquery','jstree'], factory);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
470 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
471 else if(typeof exports === 'object') {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
472 factory(require('jquery'), require('jstree'));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
473 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
474 else {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
475 factory(jQuery, jQuery.jstree);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
476 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
477 }(function ($, jstree, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
478 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
479
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
480 if($.jstree.plugins.parentsload) { return; }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
481
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
482 /**
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
483 * parentsload configuration
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
484 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
485 * The configuration syntax is almost the same as for core.data option. You must set parenstload.data the following:
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
486 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
487 * parentsload: {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
488 * data: function(){} // this function overwrites core data.data options
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
489 * }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
490 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
491 * OR
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
492 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
493 * parentsload: {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
494 * data: {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
495 * url: function(node){} OR string,
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
496 * data: function(node){} OR associative array as json{data} jQuery parameter
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
497 * }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
498 * }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
499 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
500 * In last case at least on of 'url' or 'data' must be presented.
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
501 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
502 * At first, the plugin load_node() detects if the node already downloaded. If is - uses the core.data settings, if not - uses parentsload.data settings
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
503 * to fetch in one query the specified node and all its parent. The data must be in the first mentioned JSON format with set nested children[].
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
504 * Each node level should consist of all nodes on the level to properly work with the tree in the future. Otherwise, you must manually call load_node
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
505 * on every parent node to fetch all children nodes on that level.
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
506 *
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
507 * @name $.jstree.defaults.parentsload
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
508 * @plugin parentsload
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
509 */
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
510 $.jstree.defaults.parentsload = null;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
511 $.jstree.plugins.parentsload = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
512 this.init = function (el, options) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
513 parent.init.call(this, el, options);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
514 this.patch_data()
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
515 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
516 this.patch_data = function(){
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
517 var parentsloadSettings = this.settings.parentsload;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
518 var jsTreeDataSettings = this.settings.core.data;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
519 var self = this;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
520
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
521 var callError = function(number, message) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
522 self._data.core.last_error = { 'error' : 'configuration', 'plugin' : 'parentsload', 'id' : 'parentsload_' + number, 'reason' : message, 'data' : JSON.stringify({config: parentsloadSettings}) };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
523 self.settings.core.error.call(self, self._data.core.last_error);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
524 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
525
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
526 if(!parentsloadSettings) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
527 callError('01', 'The configuration must be presented')
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
528 return
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
529 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
530 parentsloadSettings = parentsloadSettings.data;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
531
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
532 var patchSettingsProperty = function (propertyName) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
533 var property = parentsloadSettings[propertyName],
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
534 coreProperty = jsTreeDataSettings[propertyName];
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
535 if (property) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
536 jsTreeDataSettings[propertyName] = function(node) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
537 if (this.get_node(node).parentsload_required) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
538 if ($.isFunction(property)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
539 return property.call(this, node)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
540 } else {// (typeof property === 'string')
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
541 return property
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
542 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
543 } else {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
544 if ($.isFunction(coreProperty)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
545 return coreProperty.call(this, node)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
546 } else { // (typeof coreProperty === 'string')
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
547 return coreProperty
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
548 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
549 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
550 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
551 } /* else {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
552 use jstree the same data[propertyName] settings
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
553 }*/
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
554 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
555
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
556 if($.isFunction(parentsloadSettings)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
557 this.settings.data = parentsloadSettings
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
558 } else if (typeof parentsloadSettings === 'object') {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
559 if (! (parentsloadSettings.url || parentsloadSettings.data)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
560 callError('02', 'The "data.url" or "data.data" must be presented in configuration')
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
561 return
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
562 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
563 patchSettingsProperty('url')
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
564 patchSettingsProperty('data')
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
565
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
566 } else {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
567 callError('03', 'The appropriate "data.url" or "data.data" must be presented in configuration')
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
568 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
569 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
570
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
571 this.load_node = function (obj, callback) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
572 if($.isArray(obj)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
573 // FIXME: _load_nodes will not load nodes not presented in the tree
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
574 this._load_nodes(obj.slice(), callback);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
575 return true;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
576 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
577 var foundObj = this.get_node(obj);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
578 if (foundObj) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
579 return parent.load_node.apply(this, arguments)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
580 } else {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
581 // node hasn't been loaded
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
582 var id = obj.id? obj.id: obj;
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
583 this._model.data[id] = {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
584 id : id,
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
585 parent : '#',
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
586 parents : [],
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
587 children : [],
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
588 children_d : [],
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
589 state : { loaded : false },
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
590 li_attr : {},
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
591 a_attr : {},
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
592 parentsload_required : true,
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
593 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
594 return parent.load_node.call(this, obj, function(obj, status){
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
595 obj.parentsload_required = !status
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
596 callback.call(this, obj, status)
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
597 })
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
598 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
599 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
600 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
601 }));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
602
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
603 // conditional deselect
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
604 (function (factory) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
605 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
606 if (typeof define === 'function' && define.amd) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
607 define('jstree.conditionaldeselect', ['jquery','jstree'], factory);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
608 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
609 else if(typeof exports === 'object') {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
610 factory(require('jquery'), require('jstree'));
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
611 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
612 else {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
613 factory(jQuery, jQuery.jstree);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
614 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
615 }(function ($, jstree, undefined) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
616 "use strict";
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
617
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
618 if($.jstree.plugins.conditionaldeselect) { return; }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
619 $.jstree.defaults.conditionaldeselect = function () { return true; };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
620 $.jstree.plugins.conditionaldeselect = function (options, parent) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
621 // own function
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
622 this.deselect_node = function (obj, supress_event, e) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
623 if(this.settings.conditionaldeselect.call(this, this.get_node(obj), e)) {
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
624 return parent.deselect_node.call(this, obj, supress_event, e);
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
625 }
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
626 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
627 };
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
628
a42e58c71e5b planemo upload commit 841d8b22bf9f1aaed6bfe8344b60617f45b275b2-dirty
mingchen0919
parents:
diff changeset
629 }));