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,162 @@
|
|
1
|
+
/* File: jstree.dnd.js
|
2
|
+
Enables drag'n'drop.
|
3
|
+
*/
|
4
|
+
/* Group: jstree drag'n'drop plugin */
|
5
|
+
|
6
|
+
(function ($) {
|
7
|
+
$.jstree.plugin("dnd", {
|
8
|
+
__construct : function () {
|
9
|
+
this.get_container()
|
10
|
+
.delegate('a', 'mousedown', $.proxy(function (e) {
|
11
|
+
var obj = this.get_node(e.target);
|
12
|
+
if(obj && obj !== -1 && obj.length && e.which === 1) { // TODO: think about e.which
|
13
|
+
this.get_container().trigger('mousedown.jstree');
|
14
|
+
return $.vakata.dnd.start(e, { 'jstree' : true, 'origin' : this, 'obj' : obj }, '<div id="jstree-dnd" class="' + (this.data.themes ? 'jstree-' + this.get_theme() : '') + '"><ins class="jstree-icon jstree-er"> </ins>' + this.get_text(e.currentTarget, true) + '<ins class="jstree-copy" style="display:none;">+</ins></div>');
|
15
|
+
}
|
16
|
+
}, this));
|
17
|
+
},
|
18
|
+
// TODO: is check_timeout or is it OK as is?
|
19
|
+
// TODO: drag foreign items / drop foreign items (pretty easy with dnd events, but need to move marker placement in a function)
|
20
|
+
defaults : {
|
21
|
+
copy_modifier : 'ctrl',
|
22
|
+
open_timeout : 500
|
23
|
+
}
|
24
|
+
});
|
25
|
+
|
26
|
+
$(function() {
|
27
|
+
// bind only once for all instances
|
28
|
+
var lastmv = false,
|
29
|
+
opento = false,
|
30
|
+
marker = $('<div id="jstree-marker"> </div>').hide().appendTo('body');
|
31
|
+
|
32
|
+
$(document)
|
33
|
+
.bind('dnd_start.vakata', function (e, data) {
|
34
|
+
lastmv = false;
|
35
|
+
})
|
36
|
+
.bind('dnd_move.vakata', function (e, data) {
|
37
|
+
if(opento) { clearTimeout(opento); }
|
38
|
+
if(!data.data.jstree) { return; }
|
39
|
+
|
40
|
+
// if we are hovering the marker image do nothing (can happen on "inside" drags)
|
41
|
+
if(data.event.target.id && data.event.target.id === 'jstree-marker') {
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
|
45
|
+
var ins = $.jstree._reference(data.event.target),
|
46
|
+
ref = false,
|
47
|
+
off = false,
|
48
|
+
rel = false,
|
49
|
+
l, t, h, p, i, o;
|
50
|
+
// if we are over an instance
|
51
|
+
if(ins && ins.data && ins.data.dnd) {
|
52
|
+
marker.attr('class', (ins.data.themes ? 'jstree-' + ins.get_theme() : ''));
|
53
|
+
data.helper
|
54
|
+
.children().attr('class', (ins.data.themes ? 'jstree-' + ins.get_theme() : ''))
|
55
|
+
.find('.jstree-copy:eq(0)')[ data.event[data.data.origin.get_settings().dnd.copy_modifier + "Key"] ? 'show' : 'hide' ]();
|
56
|
+
|
57
|
+
|
58
|
+
// if are hovering the container itself add a new root node
|
59
|
+
if(data.event.target === ins.get_container()[0] || data.event.target === ins.get_container_ul()[0]) {
|
60
|
+
if(ins.check( (data.event[data.data.origin.get_settings().dnd.copy_modifier + "Key"] ? "copy_node" : "move_node"), data.data.obj, -1, 'last')) {
|
61
|
+
lastmv = { 'ins' : ins, 'par' : -1, 'pos' : 'last' };
|
62
|
+
marker.hide();
|
63
|
+
data.helper.find('.jstree-icon:eq(0)').removeClass('jstree-er').addClass('jstree-ok');
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
// if we are hovering a tree node
|
69
|
+
ref = $(data.event.target).closest('a');
|
70
|
+
if(ref && ref.length && ref.parent().is('.jstree-closed, .jstree-open, .jstree-leaf')) {
|
71
|
+
off = ref.offset();
|
72
|
+
rel = data.event.pageY - off.top;
|
73
|
+
h = ref.height();
|
74
|
+
if(rel < h / 3) {
|
75
|
+
o = ['b', 'i', 'a'];
|
76
|
+
}
|
77
|
+
else if(rel > h - h / 3) {
|
78
|
+
o = ['a', 'i', 'b'];
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
o = rel > h / 2 ? ['i', 'a', 'b'] : ['i', 'b', 'a'];
|
82
|
+
}
|
83
|
+
$.each(o, function (j, v) {
|
84
|
+
switch(v) {
|
85
|
+
case 'b':
|
86
|
+
l = off.left - 6;
|
87
|
+
t = off.top - 5;
|
88
|
+
p = ins.get_parent(ref);
|
89
|
+
i = ref.parent().index();
|
90
|
+
break;
|
91
|
+
case 'i':
|
92
|
+
l = off.left - 2;
|
93
|
+
t = off.top - 5 + h / 2 + 1;
|
94
|
+
p = ref.parent();
|
95
|
+
i = 0;
|
96
|
+
break;
|
97
|
+
case 'a':
|
98
|
+
l = off.left - 6;
|
99
|
+
t = off.top - 5 + h + 2;
|
100
|
+
p = ins.get_parent(ref);
|
101
|
+
i = ref.parent().index() + 1;
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
/*
|
105
|
+
// TODO: moving inside, but the node is not yet loaded?
|
106
|
+
// the check will work anyway, as when moving the node will be loaded first and checked again
|
107
|
+
if(v === 'i' && !ins.is_loaded(p)) { }
|
108
|
+
*/
|
109
|
+
if(ins.check((data.event[data.data.origin.get_settings().dnd.copy_modifier + "Key"] ? "copy_node" : "move_node"),data.data.obj, p, i)) {
|
110
|
+
if(v === 'i' && ref.parent().is('.jstree-closed') && ins.get_settings(true).dnd.open_timeout) {
|
111
|
+
opento = setTimeout((function (x, z) { return function () { x.open_node(z); }; })(ins, ref), ins.get_settings(true).dnd.open_timeout);
|
112
|
+
}
|
113
|
+
lastmv = { 'ins' : ins, 'par' : p, 'pos' : i };
|
114
|
+
marker.css({ 'left' : l + 'px', 'top' : t + 'px' }).show();
|
115
|
+
data.helper.find('.jstree-icon:eq(0)').removeClass('jstree-er').addClass('jstree-ok');
|
116
|
+
o = true;
|
117
|
+
return false;
|
118
|
+
}
|
119
|
+
});
|
120
|
+
if(o === true) { return; }
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
lastmv = false;
|
125
|
+
data.helper.find('.jstree-icon').removeClass('jstree-ok').addClass('jstree-er');
|
126
|
+
marker.hide();
|
127
|
+
})
|
128
|
+
.bind('dnd_scroll.vakata', function (e, data) {
|
129
|
+
if(!data.data.jstree) { return; }
|
130
|
+
marker.hide();
|
131
|
+
lastmv = false;
|
132
|
+
data.helper.find('.jstree-icon:eq(0)').removeClass('jstree-ok').addClass('jstree-er');
|
133
|
+
})
|
134
|
+
.bind('dnd_stop.vakata', function (e, data) {
|
135
|
+
if(opento) { clearTimeout(opento); }
|
136
|
+
if(!data.data.jstree) { return; }
|
137
|
+
marker.hide();
|
138
|
+
if(lastmv) {
|
139
|
+
lastmv.ins[ data.event[data.data.origin.get_settings().dnd.copy_modifier + "Key"] ? 'copy_node' : 'move_node' ]
|
140
|
+
(data.data.obj, lastmv.par, lastmv.pos);
|
141
|
+
}
|
142
|
+
})
|
143
|
+
.bind('keyup keydown', function (e, data) {
|
144
|
+
data = $.vakata.dnd._get();
|
145
|
+
if(data.data && data.data.jstree) {
|
146
|
+
data.helper.find('.jstree-copy:eq(0)')[ e[data.data.origin.get_settings().dnd.copy_modifier + "Key"] ? 'show' : 'hide' ]();
|
147
|
+
}
|
148
|
+
});
|
149
|
+
|
150
|
+
// add DND CSS
|
151
|
+
var css_string = '' +
|
152
|
+
'#jstree-marker { position: absolute; top:0; left:0; margin:0; padding:0; border-right:0; border-top:5px solid transparent; border-bottom:5px solid transparent; border-left:5px solid; width:0; height:0; font-size:0; line-height:0; _border-top-color:pink; _border-botton-color:pink; _filter:chroma(color=pink); } ' +
|
153
|
+
'#jstree-dnd { line-height:16px; margin:0; padding:4px; } ' +
|
154
|
+
'#jstree-dnd .jstree-icon, #jstree-dnd .jstree-copy { display:inline-block; text-decoration:none; margin:0 2px 0 0; padding:0; width:16px; height:16px; } ' +
|
155
|
+
'#jstree-dnd .jstree-ok { background:green; } ' +
|
156
|
+
'#jstree-dnd .jstree-er { background:red; } ' +
|
157
|
+
'#jstree-dnd .jstree-copy { margin:0 2px 0 2px; }';
|
158
|
+
$.vakata.css.add_sheet({ str : css_string, title : "jstree" });
|
159
|
+
});
|
160
|
+
// include the dnd plugin by default
|
161
|
+
$.jstree.defaults.plugins.push("dnd");
|
162
|
+
})(jQuery);
|
@@ -0,0 +1,138 @@
|
|
1
|
+
/* File: jstree.hotkeys.js
|
2
|
+
Enables keyboard shortcuts. Depends on jQuery.hotkeys (included in vakata.js).
|
3
|
+
*/
|
4
|
+
/* Group: jstree hotkeys plugin */
|
5
|
+
(function ($) {
|
6
|
+
if(typeof $.hotkeys === "undefined" && typeof $.vakata_hotkeys === "undefined") { throw "jsTree hotkeys: jQuery hotkeys plugin not included."; }
|
7
|
+
|
8
|
+
var bound = [];
|
9
|
+
function exec(i, event) {
|
10
|
+
var f = $.jstree._focused(), tmp;
|
11
|
+
if(f && f.data && f.data.hotkeys && f.data.hotkeys.enabled) {
|
12
|
+
tmp = f.get_settings(true).hotkeys[i];
|
13
|
+
if(tmp) { return tmp.call(f, event); }
|
14
|
+
}
|
15
|
+
}
|
16
|
+
$.jstree.plugin("hotkeys", {
|
17
|
+
__construct : function () {
|
18
|
+
if(!this.data.ui) { throw "jsTree hotkeys: jsTree UI plugin not included."; }
|
19
|
+
$.each(this.get_settings(true).hotkeys, function (i, v) {
|
20
|
+
if(v !== false && $.inArray(i, bound) === -1) {
|
21
|
+
$(document).bind("keydown", i, function (event) { return exec(i, event); });
|
22
|
+
bound.push(i);
|
23
|
+
}
|
24
|
+
});
|
25
|
+
this.get_container()
|
26
|
+
.bind("lock.jstree", $.proxy(function () {
|
27
|
+
if(this.data.hotkeys.enabled) { this.data.hotkeys.enabled = false; this.data.hotkeys.revert = true; }
|
28
|
+
}, this))
|
29
|
+
.bind("unlock.jstree", $.proxy(function () {
|
30
|
+
if(this.data.hotkeys.revert) { this.data.hotkeys.enabled = true; }
|
31
|
+
}, this));
|
32
|
+
this.enable_hotkeys();
|
33
|
+
},
|
34
|
+
defaults : {
|
35
|
+
"up" : function () {
|
36
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
|
37
|
+
this.hover_node(this.get_prev(o));
|
38
|
+
return false;
|
39
|
+
},
|
40
|
+
"ctrl+up" : function () {
|
41
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
|
42
|
+
this.hover_node(this.get_prev(o));
|
43
|
+
return false;
|
44
|
+
},
|
45
|
+
"shift+up" : function () {
|
46
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
|
47
|
+
this.hover_node(this.get_prev(o));
|
48
|
+
return false;
|
49
|
+
},
|
50
|
+
"down" : function () {
|
51
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
|
52
|
+
this.hover_node(this.get_next(o));
|
53
|
+
return false;
|
54
|
+
},
|
55
|
+
"ctrl+down" : function () {
|
56
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
|
57
|
+
this.hover_node(this.get_next(o));
|
58
|
+
return false;
|
59
|
+
},
|
60
|
+
"shift+down" : function () {
|
61
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected || -1;
|
62
|
+
this.hover_node(this.get_next(o));
|
63
|
+
return false;
|
64
|
+
},
|
65
|
+
"left" : function () {
|
66
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected;
|
67
|
+
if(o) {
|
68
|
+
if(o.hasClass("jstree-open")) { this.close_node(o); }
|
69
|
+
else { this.hover_node(this.get_prev(o)); }
|
70
|
+
}
|
71
|
+
return false;
|
72
|
+
},
|
73
|
+
"ctrl+left" : function () {
|
74
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected;
|
75
|
+
if(o) {
|
76
|
+
if(o.hasClass("jstree-open")) { this.close_node(o); }
|
77
|
+
else { this.hover_node(this.get_prev(o)); }
|
78
|
+
}
|
79
|
+
return false;
|
80
|
+
},
|
81
|
+
"shift+left" : function () {
|
82
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected;
|
83
|
+
if(o) {
|
84
|
+
if(o.hasClass("jstree-open")) { this.close_node(o); }
|
85
|
+
else { this.hover_node(this.get_prev(o)); }
|
86
|
+
}
|
87
|
+
return false;
|
88
|
+
},
|
89
|
+
"right" : function () {
|
90
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected;
|
91
|
+
if(o && o.length) {
|
92
|
+
if(o.hasClass("jstree-closed")) { this.open_node(o); }
|
93
|
+
else { this.hover_node(this.get_next(o)); }
|
94
|
+
}
|
95
|
+
return false;
|
96
|
+
},
|
97
|
+
"ctrl+right" : function () {
|
98
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected;
|
99
|
+
if(o && o.length) {
|
100
|
+
if(o.hasClass("jstree-closed")) { this.open_node(o); }
|
101
|
+
else { this.hover_node(this.get_next(o)); }
|
102
|
+
}
|
103
|
+
return false;
|
104
|
+
},
|
105
|
+
"shift+right" : function () {
|
106
|
+
var o = this.data.ui.hovered || this.data.ui.last_selected;
|
107
|
+
if(o && o.length) {
|
108
|
+
if(o.hasClass("jstree-closed")) { this.open_node(o); }
|
109
|
+
else { this.hover_node(this.get_next(o)); }
|
110
|
+
}
|
111
|
+
return false;
|
112
|
+
},
|
113
|
+
"space" : function () {
|
114
|
+
if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").click(); }
|
115
|
+
return false;
|
116
|
+
},
|
117
|
+
"ctrl+space" : function (event) {
|
118
|
+
event.type = "click";
|
119
|
+
if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").trigger(event); }
|
120
|
+
return false;
|
121
|
+
},
|
122
|
+
"shift+space" : function (event) {
|
123
|
+
event.type = "click";
|
124
|
+
if(this.data.ui.hovered) { this.data.ui.hovered.children("a:eq(0)").trigger(event); }
|
125
|
+
return false;
|
126
|
+
}
|
127
|
+
},
|
128
|
+
_fn : {
|
129
|
+
enable_hotkeys : function () {
|
130
|
+
this.data.hotkeys.enabled = true;
|
131
|
+
},
|
132
|
+
disable_hotkeys : function () {
|
133
|
+
this.data.hotkeys.enabled = false;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
});
|
137
|
+
$.jstree.defaults.plugins.push("hotkeys");
|
138
|
+
})(jQuery);
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/* File: jstree.html.js
|
2
|
+
This plugin makes it possible for jstree to use HTML data sources (other than the container's initial HTML).
|
3
|
+
*/
|
4
|
+
/* Group: jstree html plugin */
|
5
|
+
(function ($) {
|
6
|
+
$.jstree.plugin("html", {
|
7
|
+
defaults : {
|
8
|
+
data : false,
|
9
|
+
ajax : false
|
10
|
+
},
|
11
|
+
_fn : {
|
12
|
+
_append_html_data : function (dom, data) {
|
13
|
+
data = $(data);
|
14
|
+
if(!data || !data.length || !data.is('ul, li')) { return false; }
|
15
|
+
dom = this.get_node(dom);
|
16
|
+
if(dom === -1) { dom = this.get_container(); }
|
17
|
+
if(!dom.length) { return false; }
|
18
|
+
if(!dom.children('ul').length) { dom.append('<ul />'); }
|
19
|
+
dom.children('ul').empty().append(data.is('ul') ? data.children('li') : data);
|
20
|
+
return true;
|
21
|
+
},
|
22
|
+
_load_node : function (obj, callback) {
|
23
|
+
var d = false,
|
24
|
+
s = this.get_settings().html;
|
25
|
+
obj = this.get_node(obj);
|
26
|
+
if(!obj) { return false; }
|
27
|
+
|
28
|
+
switch(!0) {
|
29
|
+
// no settings - user original html
|
30
|
+
case (!s.data && !s.ajax):
|
31
|
+
if(obj === -1) {
|
32
|
+
this._append_html_data(-1, this.data.core.original_container_html.clone(true));
|
33
|
+
}
|
34
|
+
return callback.call(this, true);
|
35
|
+
// data is function
|
36
|
+
case ($.isFunction(s.data)):
|
37
|
+
return s.data.call(this, obj, $.proxy(function (d) {
|
38
|
+
return callback.call(this, this._append_html_data(obj, d));
|
39
|
+
}, this));
|
40
|
+
// data is set, ajax is not set, or both are set, but we are dealing with root node
|
41
|
+
case ((!!s.data && !s.ajax) || (!!s.data && !!s.ajax && obj === -1)):
|
42
|
+
return callback.call(this, this._append_html_data(obj, s.data));
|
43
|
+
// data is not set, ajax is set, or both are set, but we are dealing with a normal node
|
44
|
+
case ((!s.data && !!s.ajax) || (!!s.data && !!s.ajax && obj !== -1)):
|
45
|
+
s.ajax.success = $.proxy(function (d, t, x) {
|
46
|
+
var s = this.get_settings().html.ajax;
|
47
|
+
if($.isFunction(s.success)) {
|
48
|
+
d = s.success.call(this, d, t, x) || d;
|
49
|
+
}
|
50
|
+
callback.call(this, this._append_html_data(obj, d));
|
51
|
+
}, this);
|
52
|
+
s.ajax.error = $.proxy(function (x, t, e) {
|
53
|
+
var s = this.get_settings().html.ajax;
|
54
|
+
if($.isFunction(s.error)) {
|
55
|
+
s.error.call(this, x, t, e);
|
56
|
+
}
|
57
|
+
callback.call(this, false);
|
58
|
+
}, this);
|
59
|
+
if(!s.ajax.dataType) { s.ajax.dataType = "html"; }
|
60
|
+
if($.isFunction(s.ajax.url)) { s.ajax.url = s.ajax.url.call(this, obj); }
|
61
|
+
if($.isFunction(s.ajax.data)) { s.ajax.data = s.ajax.data.call(this, obj); }
|
62
|
+
return $.ajax(s.ajax);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
});
|
67
|
+
// include the html plugin by default
|
68
|
+
$.jstree.defaults.plugins.push("html");
|
69
|
+
})(jQuery);
|