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.
Files changed (36) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/INSTALLER.sh +57 -0
  4. data/LICENSE +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +2 -0
  7. data/jstree-rails.gemspec +17 -0
  8. data/lib/jstree-rails/rails.rb +6 -0
  9. data/lib/jstree-rails/version.rb +5 -0
  10. data/lib/jstree-rails.rb +8 -0
  11. data/vendor/assets/images/jstree/themes/default/d.gif +0 -0
  12. data/vendor/assets/images/jstree/themes/default/d.png +0 -0
  13. data/vendor/assets/images/jstree/themes/default/throbber.gif +0 -0
  14. data/vendor/assets/images/jstree/themes/default-rtl/d.gif +0 -0
  15. data/vendor/assets/images/jstree/themes/default-rtl/d.png +0 -0
  16. data/vendor/assets/images/jstree/themes/default-rtl/dots.gif +0 -0
  17. data/vendor/assets/images/jstree/themes/default-rtl/throbber.gif +0 -0
  18. data/vendor/assets/javascripts/jstree/index.js +15 -0
  19. data/vendor/assets/javascripts/jstree/jstree.checkbox.js +187 -0
  20. data/vendor/assets/javascripts/jstree/jstree.contextmenu.js +145 -0
  21. data/vendor/assets/javascripts/jstree/jstree.dnd.js +162 -0
  22. data/vendor/assets/javascripts/jstree/jstree.hotkeys.js +138 -0
  23. data/vendor/assets/javascripts/jstree/jstree.html.js +69 -0
  24. data/vendor/assets/javascripts/jstree/jstree.js +1982 -0
  25. data/vendor/assets/javascripts/jstree/jstree.json.js +99 -0
  26. data/vendor/assets/javascripts/jstree/jstree.rules.js +145 -0
  27. data/vendor/assets/javascripts/jstree/jstree.sort.js +38 -0
  28. data/vendor/assets/javascripts/jstree/jstree.state.js +39 -0
  29. data/vendor/assets/javascripts/jstree/jstree.themes.js +215 -0
  30. data/vendor/assets/javascripts/jstree/jstree.ui.js +201 -0
  31. data/vendor/assets/javascripts/jstree/jstree.unique.js +33 -0
  32. data/vendor/assets/javascripts/jstree/jstree.xml.js +185 -0
  33. data/vendor/assets/javascripts/jstree/vakata.js +2079 -0
  34. data/vendor/assets/stylesheets/jstree/themes/default/style.css +79 -0
  35. data/vendor/assets/stylesheets/jstree/themes/default-rtl/style.css +84 -0
  36. metadata +80 -0
@@ -0,0 +1,201 @@
1
+ /* File: jstree.ui.js
2
+ This plugin enables selecting, deselecting and hovering tree items.
3
+ */
4
+ /* Group: jstree UI plugin */
5
+ (function ($) {
6
+ $.jstree.plugin("ui", {
7
+ __construct : function () {
8
+ this.data.ui.selected = $();
9
+ this.data.ui.hovered = null;
10
+ this.data.ui.last_selected = false;
11
+
12
+ this.get_container() // TODO: configurable event (click/dblclick/etc)
13
+ .delegate("a", "click.jstree", $.proxy(function (e) {
14
+ e.preventDefault();
15
+ e.currentTarget.blur();
16
+ var s = this.get_settings(true).ui,
17
+ obj = this.get_node(e.currentTarget),
18
+ is_selected = this.is_selected(obj),
19
+ is_multiple = s.select_multiple_modifier === "on" || (s.select_multiple_modifier !== false && e && e[s.select_multiple_modifier + "Key"]),
20
+ is_range = s.select_multiple_modifier === "on" || (s.select_range_modifier !== false && e && e[s.select_range_modifier + "Key"] && this.data.ui.last_selected && this.data.ui.last_selected[0] !== obj[0] && this.data.ui.last_selected.parent()[0] === obj.parent()[0]);
21
+
22
+ switch(!0) {
23
+ case (is_range && this.data.ui.last_selected !== false):
24
+ this.select_range(obj);
25
+ break;
26
+ case (is_range && this.data.ui.last_selected === false):
27
+ this.select_one(obj);
28
+ break;
29
+ case (is_selected && is_multiple):
30
+ this.deselect_node(obj);
31
+ break;
32
+ default:
33
+ this.select_one(obj, is_multiple);
34
+ break;
35
+ }
36
+ }, this))
37
+ .delegate("a", "mouseenter.jstree", $.proxy(function (e) {
38
+ this.hover_node(e.target);
39
+ }, this))
40
+ .delegate("a", "mouseleave.jstree", $.proxy(function (e) {
41
+ this.dehover_node(e.target);
42
+ }, this))
43
+ .bind("delete_node.jstree", $.proxy(function (event, data) {
44
+ var o = this.get_node(data.rslt.obj),
45
+ n = (o && o.length) ? o.find("a.jstree-clicked") : $(),
46
+ t = this;
47
+ n.each(function () { t.deselect_node(this); });
48
+ }, this))
49
+ .bind("move_node.jstree", $.proxy(function (event, data) {
50
+ if(data.rslt.cy) {
51
+ data.rslt.oc.find("a.jstree-clicked").removeClass("jstree-clicked");
52
+ }
53
+ }, this));
54
+ },
55
+ defaults : {
56
+ select_multiple_modifier : "ctrl", // on, or ctrl, shift, alt, or false
57
+ select_range_modifier : "shift", // on, or ctrl, shift, alt, or false
58
+ disable_nested_selection : true
59
+ },
60
+ _fn : {
61
+ get_node : function (obj, allow_multiple) {
62
+ if(typeof obj === "undefined" || obj === null) { return allow_multiple ? this.data.ui.selected : this.data.ui.last_selected; }
63
+ return this.__call_old();
64
+ },
65
+
66
+ hover_node : function (obj) {
67
+ obj = this.get_node(obj);
68
+ if(!obj || !obj.length || this.is_loading(obj)) { return false; }
69
+ if(!obj.hasClass("jstree-hovered")) { this.dehover_node(); }
70
+ this.data.ui.hovered = obj.children("a").addClass("jstree-hovered").parent();
71
+ this.scroll_to_node(obj);
72
+ this.__callback({ "obj" : obj });
73
+ },
74
+ dehover_node : function () {
75
+ var obj = this.data.ui.hovered, p;
76
+ if(!obj || !obj.length) { return false; }
77
+ p = obj.children("a").removeClass("jstree-hovered").parent();
78
+ if(this.data.ui.hovered[0] === p[0]) { this.data.ui.hovered = null; }
79
+ this.__callback({ "obj" : obj });
80
+ },
81
+ select_node : function (obj) {
82
+ var t = this;
83
+ obj = this.get_node(obj);
84
+ if(obj === -1 || !obj || !obj.length || this.is_loading(obj)) { return false; }
85
+ obj.children("a").addClass("jstree-clicked");
86
+ this.data.ui.last_selected = obj;
87
+ this.data.ui.selected = this.data.ui.selected.add(obj);
88
+ // this.scroll_to_node(obj.eq(0));
89
+ obj.parents(".jstree-closed").each(function () { t.open_node(this, false, 0); });
90
+ this.__callback({ "obj" : obj });
91
+ },
92
+ deselect_node : function (obj) {
93
+ obj = this.get_node(obj);
94
+ if(!obj || !obj.length) { return false; }
95
+ if(this.is_selected(obj)) {
96
+ obj.children("a").removeClass("jstree-clicked");
97
+ this.data.ui.selected = this.data.ui.selected.not(obj);
98
+ if(this.data.ui.last_selected.get(0) === obj.get(0)) { this.data.ui.last_selected = this.data.ui.selected.eq(0); }
99
+ this.__callback({ "obj" : obj });
100
+ }
101
+ },
102
+ deselect_all : function (context) {
103
+ var ret = context ? $(context).find("a.jstree-clicked").parent() : this.get_container().find("a.jstree-clicked").parent();
104
+ ret.children("a.jstree-clicked").removeClass("jstree-clicked");
105
+ this.data.ui.selected = $();
106
+ this.data.ui.last_selected = false;
107
+ this.__callback({ "obj" : ret });
108
+ },
109
+ is_selected : function (obj) { return this.data.ui.selected.index(this.get_node(obj)) >= 0; },
110
+ get_selected : function (context) { return context ? $(context).find("a.jstree-clicked").parent() : this.data.ui.selected; },
111
+
112
+ select_range : function (obj, start_node, keep_old_selection) {
113
+ var _this = this, i, s;
114
+ obj = this.get_node(obj);
115
+ if(!start_node) { s = true; start_node = this.data.ui.last_selected; }
116
+ start_node = this.get_node(start_node);
117
+ if(obj === -1 || !obj || !obj.length || this.is_loading(obj)) { return false; }
118
+ if(start_node === -1 || !start_node || !start_node.length || this.is_loading(start_node)) { return false; }
119
+
120
+ if(!keep_old_selection) { this.deselect_all(); }
121
+ i = (obj.index() < start_node.index());
122
+ start_node.addClass("jstree-last-selected");
123
+ obj = obj[ i ? "nextUntil" : "prevUntil" ](".jstree-last-selected").andSelf().add(".jstree-last-selected");
124
+ start_node.removeClass("jstree-last-selected");
125
+ if(!i) { obj = obj.vakata_reverse(); }
126
+ if(!obj.length) { return false; }
127
+ obj.each(function () { _this.select_node(this); });
128
+ if(s) { this.data.ui.last_selected = start_node; }
129
+ this.__callback({ "obj" : obj });
130
+ return true;
131
+ },
132
+ select_one : function (obj, keep_old_selection) {
133
+ obj = this.get_node(obj);
134
+ if(obj === -1 || !obj || !obj.length || this.is_loading(obj)) { return false; }
135
+ if(!keep_old_selection) { this.deselect_all(); }
136
+ else {
137
+ if(
138
+ this.get_settings(true).ui.disable_nested_selection &&
139
+ (
140
+ (obj.parentsUntil(".jstree","li").children("a.jstree-clicked:eq(0)").length) ||
141
+ (obj.children("ul").find("a.jstree-clicked:eq(0)").length)
142
+ )
143
+ ) {
144
+ return false;
145
+ }
146
+ }
147
+ this.select_node(obj);
148
+ // obj.each(function () { t.select_node(this); });
149
+ this.__callback({ "obj" : obj });
150
+ return true;
151
+ },
152
+
153
+ clean_node : function(obj) {
154
+ obj = this.__call_old();
155
+ var _this = this;
156
+ return obj.each(function () {
157
+ var t = $(this),
158
+ d = t.data("jstree");
159
+ t.find('.jstree-clicked').removeClass('jstree-clicked');
160
+ if(d && d.selected) {
161
+ _this.select_node(t);
162
+ delete d.selected;
163
+ }
164
+ });
165
+ },
166
+ get_state : function () {
167
+ var state = this.__call_old();
168
+ state.selected = [];
169
+ this.data.ui.selected.each(function () { state.selected.push(this.id); });
170
+ return state;
171
+ },
172
+ set_state : function (state, callback) {
173
+ if(this.__call_old()) {
174
+ if(state.selected) {
175
+ var _this = this;
176
+ this.deselect_all();
177
+ $.each(state.selected, function (i, v) {
178
+ _this.select_node(document.getElementById(v));
179
+ });
180
+ delete state.selected;
181
+ this.set_state(state, callback);
182
+ return false;
183
+ }
184
+ return true;
185
+ }
186
+ return false;
187
+ },
188
+ get_json : function (obj, is_callback) {
189
+ var r = this.__call_old();
190
+ if(is_callback) {
191
+ if(this.is_selected(obj)) {
192
+ r.data.jstree.selected = true;
193
+ }
194
+ }
195
+ return r;
196
+ }
197
+ }
198
+ });
199
+ // include the selection plugin by default
200
+ $.jstree.defaults.plugins.push("ui");
201
+ })(jQuery);
@@ -0,0 +1,33 @@
1
+ /* File: jstree.unique.js
2
+ Does not allow the same name amongst siblings (still a bit experimental).
3
+ */
4
+ /* Group: jstree drag'n'drop plugin */
5
+ (function ($) {
6
+ $.jstree.plugin("unique", {
7
+ // TODO: think about an option to work with HTML or not?
8
+ _fn : {
9
+ check : function (chk, obj, par, pos) {
10
+ if(!this.__call_old()) { return false; }
11
+
12
+ par = par === -1 ? this.get_container() : par;
13
+ var n = chk === "rename_node" ? $('<div />').html(pos).text() : this.get_text(obj, true),
14
+ c = [],
15
+ t = this;
16
+ par.children('ul').children('li').each(function () { c.push(t.get_text(this, true)); });
17
+ switch(chk) {
18
+ case "delete_node":
19
+ return true;
20
+ case "rename_node":
21
+ case "copy_node":
22
+ return ($.inArray(n, c) === -1);
23
+ case "move_node":
24
+ return (par.children('ul').children('li').index(obj) !== -1 || $.inArray(n, c) === -1);
25
+ }
26
+ return true;
27
+ }
28
+ }
29
+ });
30
+ // include the unique plugin by default
31
+ $.jstree.defaults.plugins.push("unique");
32
+ })(jQuery);
33
+ //*/
@@ -0,0 +1,185 @@
1
+ /* File: jstree.xml.js
2
+ This plugin makes it possible for jstree to use XML data sources.
3
+ */
4
+ /* Group: jstree xml plugin */
5
+ (function ($) {
6
+ var xsl = {
7
+ 'nest' : '' +
8
+ '<' + '?xml version="1.0" encoding="utf-8" ?>' +
9
+ '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >' +
10
+ '<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/html" />' +
11
+ '<xsl:template match="/">' +
12
+ ' <xsl:call-template name="nodes">' +
13
+ ' <xsl:with-param name="node" select="/root" />' +
14
+ ' </xsl:call-template>' +
15
+ '</xsl:template>' +
16
+ '<xsl:template name="nodes">' +
17
+ ' <xsl:param name="node" />' +
18
+ ' <ul>' +
19
+ ' <xsl:for-each select="$node/item">' +
20
+ ' <xsl:variable name="children" select="count(./item) &gt; 0" />' +
21
+ ' <li>' +
22
+ ' <xsl:for-each select="@*"><xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute></xsl:for-each>' +
23
+ ' <a>' +
24
+ ' <xsl:for-each select="./content/@*"><xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute></xsl:for-each>' +
25
+ ' <xsl:copy-of select="./content/child::node()" />' +
26
+ ' </a>' +
27
+ ' <xsl:if test="$children"><xsl:call-template name="nodes"><xsl:with-param name="node" select="current()" /></xsl:call-template></xsl:if>' +
28
+ ' </li>' +
29
+ ' </xsl:for-each>' +
30
+ ' </ul>' +
31
+ '</xsl:template>' +
32
+ '</xsl:stylesheet>',
33
+ 'flat' : '' +
34
+ '<' + '?xml version="1.0" encoding="utf-8" ?>' +
35
+ '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >' +
36
+ '<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/xml" />' +
37
+ '<xsl:template match="/">' +
38
+ ' <ul>' +
39
+ ' <xsl:for-each select="//item[not(@parent_id) or @parent_id=0 or not(@parent_id = //item/@id)]">' + /* the last `or` may be removed */
40
+ ' <xsl:call-template name="nodes">' +
41
+ ' <xsl:with-param name="node" select="." />' +
42
+ ' </xsl:call-template>' +
43
+ ' </xsl:for-each>' +
44
+ ' </ul>' +
45
+ '</xsl:template>' +
46
+ '<xsl:template name="nodes">' +
47
+ ' <xsl:param name="node" />' +
48
+ ' <xsl:variable name="children" select="count(//item[@parent_id=$node/attribute::id]) &gt; 0" />' +
49
+ ' <li>' +
50
+ ' <xsl:for-each select="@*">' +
51
+ ' <xsl:if test="name() != \'parent_id\'">' +
52
+ ' <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>' +
53
+ ' </xsl:if>' +
54
+ ' </xsl:for-each>' +
55
+ ' <a>' +
56
+ ' <xsl:for-each select="./content/@*"><xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute></xsl:for-each>' +
57
+ ' <xsl:copy-of select="./content/child::node()" />' +
58
+ ' </a>' +
59
+ ' <xsl:if test="$children">' +
60
+ ' <ul>' +
61
+ ' <xsl:for-each select="//item[@parent_id=$node/attribute::id]">' +
62
+ ' <xsl:call-template name="nodes">' +
63
+ ' <xsl:with-param name="node" select="." />' +
64
+ ' </xsl:call-template>' +
65
+ ' </xsl:for-each>' +
66
+ ' </ul>' +
67
+ ' </xsl:if>' +
68
+ ' </li>' +
69
+ '</xsl:template>' +
70
+ '</xsl:stylesheet>'
71
+ },
72
+ escape_xml = function(string) {
73
+ return string
74
+ .toString()
75
+ .replace(/&/g, '&amp;')
76
+ .replace(/</g, '&lt;')
77
+ .replace(/>/g, '&gt;')
78
+ .replace(/"/g, '&quot;')
79
+ .replace(/'/g, '&apos;');
80
+ };
81
+
82
+
83
+ $.jstree.plugin("xml", {
84
+ defaults : {
85
+ xsl : "flat",
86
+ data : false,
87
+ ajax : false
88
+ },
89
+ _fn : {
90
+ _append_xml_data : function (dom, data) {
91
+ data = $.vakata.xslt(data, xsl[this.get_settings().xml.xsl]);
92
+ if(data === false) { return false; }
93
+ data = $(data);
94
+ if(!data || !data.length || !data.is('ul, li')) { return false; }
95
+ dom = this.get_node(dom);
96
+ if(dom === -1) { dom = this.get_container(); }
97
+ if(!dom.length) { return false; }
98
+ if(!dom.children('ul').length) { dom.append('<ul />'); }
99
+ dom.children('ul').empty().append(data.is('ul') ? data.children('li') : data);
100
+ return true;
101
+ },
102
+ _load_node : function (obj, callback) {
103
+ var d = false,
104
+ s = this.get_settings().xml;
105
+ obj = this.get_node(obj);
106
+ if(!obj) { return false; }
107
+ switch(!0) {
108
+ // data is function
109
+ case ($.isFunction(s.data)):
110
+ return s.data.call(this, obj, $.proxy(function (d) {
111
+ return callback.call(this, this._append_xml_data(obj, d));
112
+ }, this));
113
+ // data is set, ajax is not set, or both are set, but we are dealing with root node
114
+ case ((!!s.data && !s.ajax) || (!!s.data && !!s.ajax && obj === -1)):
115
+ return callback.call(this, this._append_xml_data(obj, s.data));
116
+ // data is not set, ajax is set, or both are set, but we are dealing with a normal node
117
+ case ((!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj !== -1)):
118
+ s.ajax.success = $.proxy(function (d, t, x) {
119
+ var s = this.get_settings().xml.ajax;
120
+ if($.isFunction(s.success)) {
121
+ d = s.success.call(this, d, t, x) || d;
122
+ }
123
+ callback.call(this, this._append_xml_data(obj, d));
124
+ }, this);
125
+ s.ajax.error = $.proxy(function (x, t, e) {
126
+ var s = this.get_settings().xml.ajax;
127
+ if($.isFunction(s.error)) {
128
+ s.error.call(this, x, t, e);
129
+ }
130
+ callback.call(this, false);
131
+ }, this);
132
+ if(!s.ajax.dataType) { s.ajax.dataType = "xml"; }
133
+ if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); }
134
+ if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); }
135
+ return $.ajax(s.ajax);
136
+ }
137
+ },
138
+ get_xml : function (mode, obj, is_callback) {
139
+ var r = '';
140
+ if(!mode) { mode = 'flat'; }
141
+ if(typeof is_callback === 'undefined') {
142
+ obj = this.get_json(obj);
143
+ $.each(obj, $.proxy(function (i, v) {
144
+ r += this.get_xml(mode, v, true);
145
+ }, this));
146
+ return '' +
147
+ '<' + '?xml version="1.0" encoding="utf-8" ?>' +
148
+ '<root>' + r + '</root>';
149
+ }
150
+ r += '<item';
151
+ if(mode === 'flat' && is_callback !== true) {
152
+ r += ' parent_id="' + escape_xml(is_callback) + '"';
153
+ }
154
+ if(obj.data && !$.isEmptyObject(obj.data)) {
155
+ $.each(obj.data, function (i, v) {
156
+ if(!$.isEmptyObject(v)) {
157
+ r += ' data-' + i + '="' + escape_xml($.vakata.json.encode(v)) + '"';
158
+ }
159
+ });
160
+ }
161
+ $.each(obj.li_attr, function (i, v) {
162
+ r += ' ' + i + '="' + escape_xml(v) + '"';
163
+ });
164
+ r += '>';
165
+ r += '<content';
166
+ $.each(obj.a_attr, function (i, v) {
167
+ r += ' ' + i + '="' + escape_xml(v) + '"';
168
+ });
169
+ r += '><![CDATA[' + obj.title + ']]></content>';
170
+
171
+ if(mode === 'flat') { r += '</item>'; }
172
+ if(obj.children) {
173
+ $.each(obj.children, $.proxy(function (i, v) {
174
+ r += this.get_xml(mode, v, obj.li_attr && obj.li_attr.id ? obj.li_attr.id : true);
175
+ }, this));
176
+ }
177
+ if(mode === 'nest') { r += '</item>'; }
178
+ return r;
179
+ }
180
+ }
181
+ });
182
+ // include the html plugin by default
183
+ $.jstree.defaults.plugins.push("xml");
184
+ })(jQuery);
185
+ //*/