jstree-rails 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/INSTALLER.sh +57 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/jstree-rails.gemspec +17 -0
- data/lib/jstree-rails/rails.rb +6 -0
- data/lib/jstree-rails/version.rb +5 -0
- data/lib/jstree-rails.rb +8 -0
- data/vendor/assets/images/jstree/themes/default/d.gif +0 -0
- data/vendor/assets/images/jstree/themes/default/d.png +0 -0
- data/vendor/assets/images/jstree/themes/default/throbber.gif +0 -0
- data/vendor/assets/images/jstree/themes/default-rtl/d.gif +0 -0
- data/vendor/assets/images/jstree/themes/default-rtl/d.png +0 -0
- data/vendor/assets/images/jstree/themes/default-rtl/dots.gif +0 -0
- data/vendor/assets/images/jstree/themes/default-rtl/throbber.gif +0 -0
- data/vendor/assets/javascripts/jstree/index.js +15 -0
- data/vendor/assets/javascripts/jstree/jstree.checkbox.js +187 -0
- data/vendor/assets/javascripts/jstree/jstree.contextmenu.js +145 -0
- data/vendor/assets/javascripts/jstree/jstree.dnd.js +162 -0
- data/vendor/assets/javascripts/jstree/jstree.hotkeys.js +138 -0
- data/vendor/assets/javascripts/jstree/jstree.html.js +69 -0
- data/vendor/assets/javascripts/jstree/jstree.js +1982 -0
- data/vendor/assets/javascripts/jstree/jstree.json.js +99 -0
- data/vendor/assets/javascripts/jstree/jstree.rules.js +145 -0
- data/vendor/assets/javascripts/jstree/jstree.sort.js +38 -0
- data/vendor/assets/javascripts/jstree/jstree.state.js +39 -0
- data/vendor/assets/javascripts/jstree/jstree.themes.js +215 -0
- data/vendor/assets/javascripts/jstree/jstree.ui.js +201 -0
- data/vendor/assets/javascripts/jstree/jstree.unique.js +33 -0
- data/vendor/assets/javascripts/jstree/jstree.xml.js +185 -0
- data/vendor/assets/javascripts/jstree/vakata.js +2079 -0
- data/vendor/assets/stylesheets/jstree/themes/default/style.css +79 -0
- data/vendor/assets/stylesheets/jstree/themes/default-rtl/style.css +84 -0
- metadata +80 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
/* File: jstree.json.js
|
2
|
+
This plugin makes it possible for jstree to use JSON data sources.
|
3
|
+
*/
|
4
|
+
/* Group: jstree json plugin */
|
5
|
+
(function ($) {
|
6
|
+
$.jstree.plugin("json", {
|
7
|
+
__construct : function () {
|
8
|
+
this.get_container()
|
9
|
+
.bind("__after_close.jstree", $.proxy(function (e, data) {
|
10
|
+
var t = $(data.rslt.obj);
|
11
|
+
if(this.get_settings(true).json.progressive_unload) {
|
12
|
+
t.data('jstree').children = this.get_json(t)[0].children;
|
13
|
+
t.children("ul").remove();
|
14
|
+
}
|
15
|
+
}, this));
|
16
|
+
},
|
17
|
+
defaults : {
|
18
|
+
data : false,
|
19
|
+
ajax : false,
|
20
|
+
progressive_render : false, // get_json, data on each node
|
21
|
+
progressive_unload : false
|
22
|
+
},
|
23
|
+
_fn : {
|
24
|
+
parse_json : function (node) {
|
25
|
+
var s = this.get_settings(true).json;
|
26
|
+
if($.isArray(node.children)) {
|
27
|
+
if(s.progressive_render) {
|
28
|
+
if(!node.data) { node.data = {}; }
|
29
|
+
if(!node.data.jstree) { node.data.jstree = {}; }
|
30
|
+
node.data.jstree.children = node.children;
|
31
|
+
node.children = true;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
return this.__call_old(true, node);
|
35
|
+
},
|
36
|
+
_append_json_data : function (dom, data) {
|
37
|
+
dom = this.get_node(dom);
|
38
|
+
if(dom === -1) { dom = this.get_container(); }
|
39
|
+
data = this.parse_json(data);
|
40
|
+
if(!data || !dom.length) { return false; }
|
41
|
+
if(!dom.children('ul').length) { dom.append('<ul />'); }
|
42
|
+
dom.children('ul').empty().append(data.children('li'));
|
43
|
+
return true;
|
44
|
+
},
|
45
|
+
_load_node : function (obj, callback) {
|
46
|
+
var d = false,
|
47
|
+
s = this.get_settings().json;
|
48
|
+
obj = this.get_node(obj);
|
49
|
+
if(!obj) { return false; }
|
50
|
+
|
51
|
+
switch(!0) {
|
52
|
+
// root node with data
|
53
|
+
case (obj === -1 && this.get_container().data('jstree') && $.isArray(this.get_container().data('jstree').children)):
|
54
|
+
d = this.get_container().data('jstree').children;
|
55
|
+
this.get_container().data('jstree').children = null;
|
56
|
+
return callback.call(this, this._append_json_data(obj, d));
|
57
|
+
// normal node with data
|
58
|
+
case (obj !== -1 && obj.length && obj.data('jstree') && $.isArray(obj.data('jstree').children)):
|
59
|
+
d = obj.data('jstree').children;
|
60
|
+
obj.data('jstree').children = null;
|
61
|
+
return callback.call(this, this._append_json_data(obj, d));
|
62
|
+
// no settings
|
63
|
+
case (!s.data && !s.ajax):
|
64
|
+
throw "Neither data nor ajax settings supplied.";
|
65
|
+
// data is function
|
66
|
+
case ($.isFunction(s.data)):
|
67
|
+
return s.data.call(this, obj, $.proxy(function (d) {
|
68
|
+
return callback.call(this, this._append_json_data(obj, d));
|
69
|
+
}, this));
|
70
|
+
// data is set, ajax is not set, or both are set, but we are dealing with root node
|
71
|
+
case ((!!s.data && !s.ajax) || (!!s.data && !!s.ajax && obj === -1)):
|
72
|
+
return callback.call(this, this._append_json_data(obj, s.data));
|
73
|
+
// data is not set, ajax is set, or both are set, but we are dealing with a normal node
|
74
|
+
case ((!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj !== -1)):
|
75
|
+
s.ajax.success = $.proxy(function (d, t, x) {
|
76
|
+
var s = this.get_settings().json.ajax;
|
77
|
+
if($.isFunction(s.success)) {
|
78
|
+
d = s.success.call(this, d, t, x) || d;
|
79
|
+
}
|
80
|
+
callback.call(this, this._append_json_data(obj, d));
|
81
|
+
}, this);
|
82
|
+
s.ajax.error = $.proxy(function (x, t, e) {
|
83
|
+
var s = this.get_settings().json.ajax;
|
84
|
+
if($.isFunction(s.error)) {
|
85
|
+
s.error.call(this, x, t, e);
|
86
|
+
}
|
87
|
+
callback.call(this, false);
|
88
|
+
}, this);
|
89
|
+
if(!s.ajax.dataType) { s.ajax.dataType = "json"; }
|
90
|
+
if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); }
|
91
|
+
if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); }
|
92
|
+
return $.ajax(s.ajax);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
});
|
97
|
+
// include the json plugin by default
|
98
|
+
// $.jstree.defaults.plugins.push("json");
|
99
|
+
})(jQuery);
|
@@ -0,0 +1,145 @@
|
|
1
|
+
/* File: jstree.rules.js
|
2
|
+
Sorts items alphabetically (or using any other function)
|
3
|
+
*/
|
4
|
+
/* Group: jstree rules plugin */
|
5
|
+
(function ($) {
|
6
|
+
var last_depth_node = false,
|
7
|
+
last_depth_value = 0;
|
8
|
+
$.jstree.plugin("rules", {
|
9
|
+
__construct : function () {
|
10
|
+
},
|
11
|
+
defaults : {
|
12
|
+
'check_max_depth' : true,
|
13
|
+
'check_max_children' : true,
|
14
|
+
'check_valid_children' : true,
|
15
|
+
'types' : { }
|
16
|
+
},
|
17
|
+
_fn : {
|
18
|
+
get_rules : function (obj) {
|
19
|
+
obj = this.get_node(obj);
|
20
|
+
if(obj === -1) {
|
21
|
+
obj = this.get_container();
|
22
|
+
obj = obj.data('jstree');
|
23
|
+
return {
|
24
|
+
'type' : false,
|
25
|
+
'max_depth' : obj && obj.max_depth ? obj.max_depth : -1,
|
26
|
+
'max_children' : obj && obj.max_children ? obj.max_children : -1,
|
27
|
+
'valid_children' : obj && obj.valid_children ? obj.valid_children : -1
|
28
|
+
};
|
29
|
+
}
|
30
|
+
if(!obj || !obj.length) { return false; }
|
31
|
+
obj = obj.data('jstree');
|
32
|
+
var s = this.get_settings().rules,
|
33
|
+
t = this.get_type(obj),
|
34
|
+
r = {
|
35
|
+
'type' : t,
|
36
|
+
'max_depth' : -1,
|
37
|
+
'max_children' : -1,
|
38
|
+
'valid_children' : -1
|
39
|
+
};
|
40
|
+
if(t && s[t]) {
|
41
|
+
if(s[t].max_depth) { r.max_depth = s[t].max_depth; }
|
42
|
+
if(s[t].max_children) { r.max_children = s[t].max_children; }
|
43
|
+
if(s[t].valid_children) { r.valid_children = s[t].valid_children; }
|
44
|
+
}
|
45
|
+
if(obj && obj.max_depth) { r.max_depth = obj.max_depth; }
|
46
|
+
if(obj && obj.max_children) { r.max_children = obj.max_children; }
|
47
|
+
if(obj && obj.valid_children) { r.valid_children = obj.valid_children; }
|
48
|
+
return r;
|
49
|
+
},
|
50
|
+
get_type : function (obj) {
|
51
|
+
obj = this.get_node(obj);
|
52
|
+
if(obj === -1) { obj = this.get_container(); }
|
53
|
+
if(!obj || !obj.length) { return false; }
|
54
|
+
obj = obj.data('jstree');
|
55
|
+
return obj && obj.type ? obj.type : false;
|
56
|
+
},
|
57
|
+
set_type : function (obj, type) {
|
58
|
+
obj = this.get_node(obj);
|
59
|
+
if(obj === -1) { obj = this.get_container(); }
|
60
|
+
if(!obj || !obj.length) { return false; }
|
61
|
+
var d = obj.data('jstree');
|
62
|
+
if(!d) { d = {}; }
|
63
|
+
d.type = type;
|
64
|
+
obj.data('jstree', d);
|
65
|
+
return true;
|
66
|
+
},
|
67
|
+
check : function (chk, obj, par, pos) {
|
68
|
+
if(this.__call_old() === false) { return false; }
|
69
|
+
var r = false,
|
70
|
+
s = this.get_settings().rules,
|
71
|
+
t = this,
|
72
|
+
o = false,
|
73
|
+
d = 0;
|
74
|
+
|
75
|
+
switch(chk) {
|
76
|
+
case "create_node":
|
77
|
+
case "move_node":
|
78
|
+
case "copy_node":
|
79
|
+
if(s.check_max_children || s.check_valid_children || s.check_max_depth) {
|
80
|
+
r = this.get_rules(par);
|
81
|
+
}
|
82
|
+
if(s.check_max_children) {
|
83
|
+
if(typeof r.max_children !== 'undefined' && r.max_children !== -1) {
|
84
|
+
if(par.find('> ul > li').not( chk === 'move_node' ? obj : null ).length + obj.length > r.max_children) {
|
85
|
+
return false;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
if(s.check_valid_children) {
|
90
|
+
if(typeof r.valid_children !== 'undefined' && r.valid_children !== -1) {
|
91
|
+
if(!$.isArray(r.valid_children)) { return false; }
|
92
|
+
obj.each(function () {
|
93
|
+
if($.inArray(t.get_type(this), r.valid_children) === -1) {
|
94
|
+
t = false;
|
95
|
+
return false;
|
96
|
+
}
|
97
|
+
});
|
98
|
+
if(t === false) {
|
99
|
+
return false;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
if(s.check_max_depth) {
|
104
|
+
if(typeof r.max_depth !== 'undefined' && r.max_depth !== -1) {
|
105
|
+
if(r.max_depth === 0) { return false; }
|
106
|
+
d = 0;
|
107
|
+
if(last_depth_node !== obj) {
|
108
|
+
o = obj;
|
109
|
+
while(o.length > 0) {
|
110
|
+
o = o.find("> ul > li");
|
111
|
+
d ++;
|
112
|
+
}
|
113
|
+
last_depth_value = d;
|
114
|
+
last_depth_node = obj;
|
115
|
+
}
|
116
|
+
else {
|
117
|
+
d = last_depth_value;
|
118
|
+
}
|
119
|
+
o = 0;
|
120
|
+
par.children("a:eq(0)").parentsUntil(".jstree","li").each(function (i) {
|
121
|
+
var d = t.get_rules(this);
|
122
|
+
if(typeof d.max_depth !== 'undefined' && d.max_depth >= 0 && d + i > d.max_depth) {
|
123
|
+
t = false;
|
124
|
+
return false;
|
125
|
+
}
|
126
|
+
o = i;
|
127
|
+
});
|
128
|
+
if(t === false) {
|
129
|
+
return false;
|
130
|
+
}
|
131
|
+
t = this.get_rules(-1);
|
132
|
+
if(typeof t.max_depth !== 'undefined' && t.max_depth >= 0 && d + o > t.max_depth) {
|
133
|
+
return false;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
break;
|
138
|
+
}
|
139
|
+
return true;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
});
|
143
|
+
// include the sort plugin by default
|
144
|
+
$.jstree.defaults.plugins.push("rules");
|
145
|
+
})(jQuery);
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/* File: jstree.sort.js
|
2
|
+
Sorts items alphabetically (or using any other function)
|
3
|
+
*/
|
4
|
+
/* Group: jstree sort plugin */
|
5
|
+
(function ($) {
|
6
|
+
$.jstree.plugin("sort", {
|
7
|
+
__construct : function () {
|
8
|
+
this.get_container()
|
9
|
+
.bind("load_node.jstree", $.proxy(function (e, data) {
|
10
|
+
var obj = this.get_node(data.rslt.obj);
|
11
|
+
obj = obj === -1 ? this.get_container_ul() : obj.children("ul");
|
12
|
+
this._sort(obj, true);
|
13
|
+
}, this))
|
14
|
+
.bind("rename_node.jstree create_node.jstree", $.proxy(function (e, data) {
|
15
|
+
this._sort(data.rslt.obj.parent(), false);
|
16
|
+
}, this))
|
17
|
+
.bind("move_node.jstree copy_node.jstree", $.proxy(function (e, data) {
|
18
|
+
var m = data.rslt.parent === -1 ? this.get_container_ul() : data.rslt.parent.children('ul');
|
19
|
+
this._sort(m, false);
|
20
|
+
}, this));
|
21
|
+
},
|
22
|
+
defaults : function (a, b) { return this.get_text(a, true) > this.get_text(b, true) ? 1 : -1; },
|
23
|
+
_fn : {
|
24
|
+
_sort : function (obj, deep) {
|
25
|
+
var s = this.get_settings(true).sort,
|
26
|
+
t = this;
|
27
|
+
obj.append($.makeArray(obj.children("li")).sort($.proxy(s, t)));
|
28
|
+
obj.children('li').each(function () { t.correct_node(this, false); });
|
29
|
+
if(deep) {
|
30
|
+
obj.find("> li > ul").each(function() { t._sort($(this)); });
|
31
|
+
t.correct_node(obj.children('li'), true);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
});
|
36
|
+
// include the sort plugin by default
|
37
|
+
$.jstree.defaults.plugins.push("sort");
|
38
|
+
})(jQuery);
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/* File: jstree.state.js
|
2
|
+
This plugin enables state saving between reloads.
|
3
|
+
*/
|
4
|
+
/* Group: jstree state plugin */
|
5
|
+
(function ($) {
|
6
|
+
$.jstree.plugin("state", {
|
7
|
+
__construct : function () {
|
8
|
+
if(typeof $.vakata.storage === "undefined") { throw "jsTree state plugin: vakata storage helper not included."; }
|
9
|
+
|
10
|
+
this.get_container()
|
11
|
+
.bind("__loaded.jstree", $.proxy(function (e, data) {
|
12
|
+
this.restore_state();
|
13
|
+
}, this))
|
14
|
+
.bind("__ready.jstree", $.proxy(function (e, data) {
|
15
|
+
this.get_container()
|
16
|
+
.bind(this.get_settings(true).state.events, $.proxy(function () {
|
17
|
+
this.save_state();
|
18
|
+
}, this));
|
19
|
+
}, this));
|
20
|
+
},
|
21
|
+
defaults : {
|
22
|
+
key : 'jstree', // pass unique name to work with many trees
|
23
|
+
events : 'select_node.jstree open_node.jstree close_node.jstree deselect_node.jstree deselect_all.jstree'
|
24
|
+
},
|
25
|
+
_fn : {
|
26
|
+
save_state : function () {
|
27
|
+
var s = this.get_settings(true).state;
|
28
|
+
$.vakata.storage.set(s.key, this.get_state());
|
29
|
+
},
|
30
|
+
restore_state : function () {
|
31
|
+
var s = this.get_settings(true).state,
|
32
|
+
k = $.vakata.storage.get(s.key);
|
33
|
+
if(!!k) { this.set_state(k); }
|
34
|
+
}
|
35
|
+
}
|
36
|
+
});
|
37
|
+
// include the state plugin by default
|
38
|
+
// $.jstree.defaults.plugins.push("state");
|
39
|
+
})(jQuery);
|
@@ -0,0 +1,215 @@
|
|
1
|
+
/* File: jstree.themes.js
|
2
|
+
Controls the looks of jstree, without this plugin you will get a functional tree, but it will look just like an ordinary UL list
|
3
|
+
*/
|
4
|
+
(function ($) {
|
5
|
+
var themes_loaded = [];
|
6
|
+
/*
|
7
|
+
Group: $.jstree.
|
8
|
+
|
9
|
+
Variable: $.jstree.THEMES_DIR
|
10
|
+
The location of all themes, this is used when setting a theme without supplying an URL (only by name).
|
11
|
+
Default is _false_. If left as _false_ the path will be autodetected when the DOM is ready.
|
12
|
+
The location of _jstree.js_ is used for the autodetection.
|
13
|
+
Normally you won't need to modify this (provided you leave the _themes_ folder in the same folder as _jquery.jstree.js_ and do not rename the file).
|
14
|
+
If you decide to move the folder or rename the file, but still want to load themes by name, simply set this to the new location of the _themes_ folder.
|
15
|
+
> <script type="text/javascript" src="jstree.js"></script>
|
16
|
+
> <script type="text/javascript">$.jstree.THEMES_DIR = "some/path/with-a-trailing-slash/";</script>
|
17
|
+
*/
|
18
|
+
$.jstree.THEMES_DIR = false;
|
19
|
+
|
20
|
+
$.jstree.plugin("themes", {
|
21
|
+
__construct : function () {
|
22
|
+
this.get_container()
|
23
|
+
.bind("__construct.jstree", $.proxy(function () {
|
24
|
+
var s = this.get_settings(true).themes;
|
25
|
+
this.data.themes.dots = s.dots;
|
26
|
+
this.data.themes.icons = s.icons;
|
27
|
+
|
28
|
+
if(s.url === false && s.theme === false) {
|
29
|
+
s.theme = this.data.core.rtl ? 'default-rtl' : 'default';
|
30
|
+
}
|
31
|
+
this.set_theme(s.theme, s.url);
|
32
|
+
|
33
|
+
this[ this.data.themes.dots ? "show_dots" : "hide_dots" ]();
|
34
|
+
this[ this.data.themes.icons ? "show_icons" : "hide_icons" ]();
|
35
|
+
}, this));
|
36
|
+
},
|
37
|
+
/* Class: jstree */
|
38
|
+
/*
|
39
|
+
Group: THEMES options
|
40
|
+
|
41
|
+
Variable: config.themes.theme
|
42
|
+
*string* the name of the theme you want to use. Default is _default_.
|
43
|
+
|
44
|
+
Variable: config.themes.url
|
45
|
+
*mixed* the URL of the stylesheet of the theme you want to use. Default is _false_. If left as _false_ the location will be autodetected using <$.jstree.THEMES_DIR>.
|
46
|
+
|
47
|
+
Variable: config.themes.dots
|
48
|
+
*boolean* whether to show dots or not. Default is _true_. The chosen theme should support this option.
|
49
|
+
|
50
|
+
Variable: config.themes.icons
|
51
|
+
*boolean* whether to show icons or not. Default is _true_.
|
52
|
+
*/
|
53
|
+
defaults : {
|
54
|
+
theme : false,
|
55
|
+
url : false,
|
56
|
+
dots : true,
|
57
|
+
icons : true
|
58
|
+
},
|
59
|
+
_fn : {
|
60
|
+
/*
|
61
|
+
Group: THEMES functions
|
62
|
+
|
63
|
+
Function: set_theme
|
64
|
+
Sets the tree theme. This function is automatically called at construction with the settings specified in <config.themes.theme> and <config.themes.theme.url>.
|
65
|
+
|
66
|
+
Parameters:
|
67
|
+
theme_name - the name of the theme to apply
|
68
|
+
theme_url - the URL of the stylesheet - leave this blank for autodetect
|
69
|
+
|
70
|
+
Example:
|
71
|
+
>// Set the theme and autodetect the location
|
72
|
+
>$("#div1").jstree("set_theme","classic");
|
73
|
+
>// A custom theme. Please note that if you place your own theme in the _themes_ folder ot will be autodetected too.
|
74
|
+
>$("#div2").jstree("set_theme","custom-theme","/some/path/theme.css");
|
75
|
+
*/
|
76
|
+
set_theme : function (theme_name, theme_url) {
|
77
|
+
if(!theme_name) { return false; }
|
78
|
+
if(!theme_url) { theme_url = $.jstree.THEMES_DIR + theme_name + '/style.css'; }
|
79
|
+
if($.inArray(theme_url, themes_loaded) === -1) {
|
80
|
+
$.vakata.css.add_sheet({ "url" : theme_url });
|
81
|
+
themes_loaded.push(theme_url);
|
82
|
+
}
|
83
|
+
if(this.data.themes.theme !== theme_name) {
|
84
|
+
this.get_container().removeClass('jstree-' + this.data.themes.theme);
|
85
|
+
this.data.themes.theme = theme_name;
|
86
|
+
}
|
87
|
+
this.get_container().addClass('jstree-' + theme_name);
|
88
|
+
this.__callback(theme_name);
|
89
|
+
},
|
90
|
+
get_theme : function () { return this.data.themes.theme; },
|
91
|
+
show_dots : function () { this.data.themes.dots = true; this.get_container().children("ul").removeClass("jstree-no-dots"); },
|
92
|
+
hide_dots : function () { this.data.themes.dots = false; this.get_container().children("ul").addClass("jstree-no-dots"); },
|
93
|
+
toggle_dots : function () { if(this.data.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
|
94
|
+
show_icons : function () { this.data.themes.icons = true; this.get_container().children("ul").removeClass("jstree-no-icons"); },
|
95
|
+
hide_icons : function () { this.data.themes.icons = false; this.get_container().children("ul").addClass("jstree-no-icons"); },
|
96
|
+
toggle_icons : function () { if(this.data.themes.icons) { this.hide_icons(); } else { this.show_icons(); } },
|
97
|
+
|
98
|
+
set_icon : function (obj, icon) {
|
99
|
+
obj = this.get_node(obj);
|
100
|
+
if(!obj || obj === -1 || !obj.length) { return false; }
|
101
|
+
obj = obj.find("> a > .jstree-themeicon");
|
102
|
+
if(icon === false) {
|
103
|
+
this.hide_icon(obj);
|
104
|
+
}
|
105
|
+
else if(icon.indexOf("/") === -1) {
|
106
|
+
obj.addClass(icon).attr("rel",icon);
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
obj.css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
|
110
|
+
}
|
111
|
+
return true;
|
112
|
+
},
|
113
|
+
get_icon : function (obj) {
|
114
|
+
obj = this.get_node(obj);
|
115
|
+
if(!obj || obj === -1 || !obj.length) { return null; }
|
116
|
+
obj = obj.find("> a > .jstree-themeicon");
|
117
|
+
if(obj.hasClass('jstree-themeicon-hidden')) { return false; }
|
118
|
+
obj = obj.attr("rel");
|
119
|
+
return (obj && obj.length) ? obj : null;
|
120
|
+
},
|
121
|
+
hide_icon : function (obj) {
|
122
|
+
obj = this.get_node(obj);
|
123
|
+
if(!obj || obj === -1 || !obj.length) { return false; }
|
124
|
+
obj.find('> a > .jstree-themeicon').addClass('jstree-themeicon-hidden');
|
125
|
+
return true;
|
126
|
+
},
|
127
|
+
show_icon : function (obj) {
|
128
|
+
obj = this.get_node(obj);
|
129
|
+
if(!obj || obj === -1 || !obj.length) { return false; }
|
130
|
+
obj.find('> a > .jstree-themeicon').removeClass('jstree-themeicon-hidden');
|
131
|
+
return true;
|
132
|
+
},
|
133
|
+
|
134
|
+
clean_node : function(obj) {
|
135
|
+
obj = this.__call_old();
|
136
|
+
var t = this;
|
137
|
+
return obj.each(function () {
|
138
|
+
var o = $(this),
|
139
|
+
d = o.data("jstree");
|
140
|
+
if(!o.find("> a > ins.jstree-themeicon").length) {
|
141
|
+
o.children("a").prepend("<ins class='jstree-icon jstree-themeicon'> </ins>");
|
142
|
+
}
|
143
|
+
if(d && typeof d.icon !== 'undefined') {
|
144
|
+
t.set_icon(o, d.icon);
|
145
|
+
delete d.icon;
|
146
|
+
}
|
147
|
+
});
|
148
|
+
},
|
149
|
+
get_state : function () {
|
150
|
+
var state = this.__call_old();
|
151
|
+
state.themes = { 'theme' : this.get_theme(), 'icons' : this.data.themes.icons, 'dots' : this.data.themes.dots };
|
152
|
+
return state;
|
153
|
+
},
|
154
|
+
set_state : function (state, callback) {
|
155
|
+
if(this.__call_old()) {
|
156
|
+
if(state.themes) {
|
157
|
+
if(state.themes.theme) {
|
158
|
+
this.set_theme(state.themes.theme);
|
159
|
+
}
|
160
|
+
if(typeof state.themes.dots !== 'undefined') {
|
161
|
+
this[ state.themes.dots ? "show_dots" : "hide_dots" ]();
|
162
|
+
}
|
163
|
+
if(typeof state.themes.icons !== 'undefined') {
|
164
|
+
this[ state.themes.icons ? "show_icons" : "hide_icons" ]();
|
165
|
+
}
|
166
|
+
delete state.themes;
|
167
|
+
this.set_state(state, callback);
|
168
|
+
return false;
|
169
|
+
}
|
170
|
+
return true;
|
171
|
+
}
|
172
|
+
return false;
|
173
|
+
},
|
174
|
+
get_json : function (obj, is_callback) {
|
175
|
+
var r = this.__call_old(), i;
|
176
|
+
if(is_callback) {
|
177
|
+
i = this.get_icon(obj);
|
178
|
+
if(typeof i !== 'undefined' && i !== null) {
|
179
|
+
r.data.jstree.icon = i;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
return r;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
});
|
186
|
+
$(function () {
|
187
|
+
// autodetect themes path
|
188
|
+
if($.jstree.THEMES_DIR === false) {
|
189
|
+
$("script").each(function () {
|
190
|
+
if(this.src.toString().match(/jstree[^\/]*?\.js(\?.*)?$/)) {
|
191
|
+
$.jstree.THEMES_DIR = this.src.toString().replace(/jstree[^\/]*?\.js(\?.*)?$/, "") + 'themes/';
|
192
|
+
return false;
|
193
|
+
}
|
194
|
+
});
|
195
|
+
}
|
196
|
+
if($.jstree.THEMES_DIR === false) { $.jstree.THEMES_DIR = "themes/"; }
|
197
|
+
// add themes specific CSS
|
198
|
+
var css_string = '' +
|
199
|
+
'.jstree a { text-decoration:none; } ' +
|
200
|
+
'.jstree a > .jstree-themeicon { height:16px; width:16px; margin-right:3px; } ' +
|
201
|
+
'.jstree-rtl a > .jstree-themeicon { margin-left:3px; margin-right:0; } ' +
|
202
|
+
'.jstree .jstree-no-icons .jstree-themeicon, .jstree .jstree-themeicon-hidden { display:none; } ';
|
203
|
+
// Correct IE 6 (does not support the > CSS selector)
|
204
|
+
if($.jstree.IS_IE6) {
|
205
|
+
css_string += '' +
|
206
|
+
'.jstree li a .jstree-themeicon { height:16px; width:16px; margin-right:3px; } ' +
|
207
|
+
'.jstree-rtl li a .jstree-themeicon { margin-right:0px; margin-left:3px; } ';
|
208
|
+
}
|
209
|
+
// the default stylesheet
|
210
|
+
$.vakata.css.add_sheet({ str : css_string, title : "jstree" });
|
211
|
+
});
|
212
|
+
// include the themes plugin by default
|
213
|
+
$.jstree.defaults.plugins.push("themes");
|
214
|
+
})(jQuery);
|
215
|
+
//*/
|