right_api_helper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.md +66 -0
- data/Rakefile +7 -0
- data/bin/organize +193 -0
- data/demo/deployments.json +44 -0
- data/demo/index.html +83 -0
- data/demo/logo.png +0 -0
- data/demo/start_server.sh +12 -0
- data/demo/tree.jquery.js +2947 -0
- data/lib/right_api_helper/api15.rb +357 -0
- data/lib/right_api_helper/base.rb +54 -0
- data/lib/right_api_helper/cache.rb +53 -0
- data/lib/right_api_helper/deployments.rb +39 -0
- data/lib/right_api_helper/instances.rb +46 -0
- data/lib/right_api_helper/scripts/deployments_creator.rb +44 -0
- data/lib/right_api_helper/session.rb +76 -0
- data/lib/right_api_helper/version.rb +3 -0
- data/lib/right_api_helper.rb +32 -0
- data/right_api_helper.gemspec +30 -0
- data/spec/api15_spec.rb +280 -0
- data/spec/cache_spec.rb +57 -0
- data/spec/data/deployments.json +44 -0
- data/spec/deployments_spec.rb +57 -0
- data/spec/instances_spec.rb +41 -0
- data/spec/scripts/deployments_creator_spec.rb +59 -0
- data/spec/session_spec.rb +46 -0
- data/spec/spec_helper.rb +50 -0
- metadata +214 -0
data/demo/tree.jquery.js
ADDED
@@ -0,0 +1,2947 @@
|
|
1
|
+
// Generated by CoffeeScript 1.7.1
|
2
|
+
|
3
|
+
/*
|
4
|
+
Copyright 2013 Marco Braak
|
5
|
+
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
you may not use this file except in compliance with the License.
|
8
|
+
You may obtain a copy of the License at
|
9
|
+
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
See the License for the specific language governing permissions and
|
16
|
+
limitations under the License.
|
17
|
+
*/
|
18
|
+
|
19
|
+
(function() {
|
20
|
+
var $, BorderDropHint, DragAndDropHandler, DragElement, ElementsRenderer, FolderElement, GhostDropHint, HitAreasGenerator, JqTreeWidget, KeyHandler, MouseWidget, Node, NodeElement, Position, SaveStateHandler, ScrollHandler, SelectNodeHandler, SimpleWidget, VisibleNodeIterator, html_escape, indexOf, json_escapable, json_meta, json_quote, json_str, _indexOf,
|
21
|
+
__slice = [].slice,
|
22
|
+
__hasProp = {}.hasOwnProperty,
|
23
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
24
|
+
|
25
|
+
$ = this.jQuery;
|
26
|
+
|
27
|
+
SimpleWidget = (function() {
|
28
|
+
SimpleWidget.prototype.defaults = {};
|
29
|
+
|
30
|
+
function SimpleWidget(el, options) {
|
31
|
+
this.$el = $(el);
|
32
|
+
this.options = $.extend({}, this.defaults, options);
|
33
|
+
}
|
34
|
+
|
35
|
+
SimpleWidget.prototype.destroy = function() {
|
36
|
+
return this._deinit();
|
37
|
+
};
|
38
|
+
|
39
|
+
SimpleWidget.prototype._init = function() {
|
40
|
+
return null;
|
41
|
+
};
|
42
|
+
|
43
|
+
SimpleWidget.prototype._deinit = function() {
|
44
|
+
return null;
|
45
|
+
};
|
46
|
+
|
47
|
+
SimpleWidget.register = function(widget_class, widget_name) {
|
48
|
+
var callFunction, createWidget, destroyWidget, getDataKey, getWidgetData;
|
49
|
+
getDataKey = function() {
|
50
|
+
return "simple_widget_" + widget_name;
|
51
|
+
};
|
52
|
+
getWidgetData = function(el, data_key) {
|
53
|
+
var widget;
|
54
|
+
widget = $.data(el, data_key);
|
55
|
+
if (widget && (widget instanceof SimpleWidget)) {
|
56
|
+
return widget;
|
57
|
+
} else {
|
58
|
+
return null;
|
59
|
+
}
|
60
|
+
};
|
61
|
+
createWidget = function($el, options) {
|
62
|
+
var data_key, el, existing_widget, widget, _i, _len;
|
63
|
+
data_key = getDataKey();
|
64
|
+
for (_i = 0, _len = $el.length; _i < _len; _i++) {
|
65
|
+
el = $el[_i];
|
66
|
+
existing_widget = getWidgetData(el, data_key);
|
67
|
+
if (!existing_widget) {
|
68
|
+
widget = new widget_class(el, options);
|
69
|
+
if (!$.data(el, data_key)) {
|
70
|
+
$.data(el, data_key, widget);
|
71
|
+
}
|
72
|
+
widget._init();
|
73
|
+
}
|
74
|
+
}
|
75
|
+
return $el;
|
76
|
+
};
|
77
|
+
destroyWidget = function($el) {
|
78
|
+
var data_key, el, widget, _i, _len, _results;
|
79
|
+
data_key = getDataKey();
|
80
|
+
_results = [];
|
81
|
+
for (_i = 0, _len = $el.length; _i < _len; _i++) {
|
82
|
+
el = $el[_i];
|
83
|
+
widget = getWidgetData(el, data_key);
|
84
|
+
if (widget) {
|
85
|
+
widget.destroy();
|
86
|
+
}
|
87
|
+
_results.push($.removeData(el, data_key));
|
88
|
+
}
|
89
|
+
return _results;
|
90
|
+
};
|
91
|
+
callFunction = function($el, function_name, args) {
|
92
|
+
var el, result, widget, widget_function, _i, _len;
|
93
|
+
result = null;
|
94
|
+
for (_i = 0, _len = $el.length; _i < _len; _i++) {
|
95
|
+
el = $el[_i];
|
96
|
+
widget = $.data(el, getDataKey());
|
97
|
+
if (widget && (widget instanceof SimpleWidget)) {
|
98
|
+
widget_function = widget[function_name];
|
99
|
+
if (widget_function && (typeof widget_function === 'function')) {
|
100
|
+
result = widget_function.apply(widget, args);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
return result;
|
105
|
+
};
|
106
|
+
return $.fn[widget_name] = function() {
|
107
|
+
var $el, args, argument1, function_name, options;
|
108
|
+
argument1 = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
109
|
+
$el = this;
|
110
|
+
if (argument1 === void 0 || typeof argument1 === 'object') {
|
111
|
+
options = argument1;
|
112
|
+
return createWidget($el, options);
|
113
|
+
} else if (typeof argument1 === 'string' && argument1[0] !== '_') {
|
114
|
+
function_name = argument1;
|
115
|
+
if (function_name === 'destroy') {
|
116
|
+
return destroyWidget($el);
|
117
|
+
} else {
|
118
|
+
return callFunction($el, function_name, args);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
};
|
122
|
+
};
|
123
|
+
|
124
|
+
return SimpleWidget;
|
125
|
+
|
126
|
+
})();
|
127
|
+
|
128
|
+
this.SimpleWidget = SimpleWidget;
|
129
|
+
|
130
|
+
|
131
|
+
/*
|
132
|
+
This widget does the same a the mouse widget in jqueryui.
|
133
|
+
*/
|
134
|
+
|
135
|
+
MouseWidget = (function(_super) {
|
136
|
+
__extends(MouseWidget, _super);
|
137
|
+
|
138
|
+
function MouseWidget() {
|
139
|
+
return MouseWidget.__super__.constructor.apply(this, arguments);
|
140
|
+
}
|
141
|
+
|
142
|
+
MouseWidget.is_mouse_handled = false;
|
143
|
+
|
144
|
+
MouseWidget.prototype._init = function() {
|
145
|
+
this.$el.bind('mousedown.mousewidget', $.proxy(this._mouseDown, this));
|
146
|
+
this.$el.bind('touchstart.mousewidget', $.proxy(this._touchStart, this));
|
147
|
+
this.is_mouse_started = false;
|
148
|
+
this.mouse_delay = 0;
|
149
|
+
this._mouse_delay_timer = null;
|
150
|
+
this._is_mouse_delay_met = true;
|
151
|
+
return this.mouse_down_info = null;
|
152
|
+
};
|
153
|
+
|
154
|
+
MouseWidget.prototype._deinit = function() {
|
155
|
+
var $document;
|
156
|
+
this.$el.unbind('mousedown.mousewidget');
|
157
|
+
this.$el.unbind('touchstart.mousewidget');
|
158
|
+
$document = $(document);
|
159
|
+
$document.unbind('mousemove.mousewidget');
|
160
|
+
return $document.unbind('mouseup.mousewidget');
|
161
|
+
};
|
162
|
+
|
163
|
+
MouseWidget.prototype._mouseDown = function(e) {
|
164
|
+
var result;
|
165
|
+
if (e.which !== 1) {
|
166
|
+
return;
|
167
|
+
}
|
168
|
+
result = this._handleMouseDown(e, this._getPositionInfo(e));
|
169
|
+
if (result) {
|
170
|
+
e.preventDefault();
|
171
|
+
}
|
172
|
+
return result;
|
173
|
+
};
|
174
|
+
|
175
|
+
MouseWidget.prototype._handleMouseDown = function(e, position_info) {
|
176
|
+
if (MouseWidget.is_mouse_handled) {
|
177
|
+
return;
|
178
|
+
}
|
179
|
+
if (this.is_mouse_started) {
|
180
|
+
this._handleMouseUp(position_info);
|
181
|
+
}
|
182
|
+
this.mouse_down_info = position_info;
|
183
|
+
if (!this._mouseCapture(position_info)) {
|
184
|
+
return;
|
185
|
+
}
|
186
|
+
this._handleStartMouse();
|
187
|
+
this.is_mouse_handled = true;
|
188
|
+
return true;
|
189
|
+
};
|
190
|
+
|
191
|
+
MouseWidget.prototype._handleStartMouse = function() {
|
192
|
+
var $document;
|
193
|
+
$document = $(document);
|
194
|
+
$document.bind('mousemove.mousewidget', $.proxy(this._mouseMove, this));
|
195
|
+
$document.bind('touchmove.mousewidget', $.proxy(this._touchMove, this));
|
196
|
+
$document.bind('mouseup.mousewidget', $.proxy(this._mouseUp, this));
|
197
|
+
$document.bind('touchend.mousewidget', $.proxy(this._touchEnd, this));
|
198
|
+
if (this.mouse_delay) {
|
199
|
+
return this._startMouseDelayTimer();
|
200
|
+
}
|
201
|
+
};
|
202
|
+
|
203
|
+
MouseWidget.prototype._startMouseDelayTimer = function() {
|
204
|
+
if (this._mouse_delay_timer) {
|
205
|
+
clearTimeout(this._mouse_delay_timer);
|
206
|
+
}
|
207
|
+
this._mouse_delay_timer = setTimeout((function(_this) {
|
208
|
+
return function() {
|
209
|
+
return _this._is_mouse_delay_met = true;
|
210
|
+
};
|
211
|
+
})(this), this.mouse_delay);
|
212
|
+
return this._is_mouse_delay_met = false;
|
213
|
+
};
|
214
|
+
|
215
|
+
MouseWidget.prototype._mouseMove = function(e) {
|
216
|
+
return this._handleMouseMove(e, this._getPositionInfo(e));
|
217
|
+
};
|
218
|
+
|
219
|
+
MouseWidget.prototype._handleMouseMove = function(e, position_info) {
|
220
|
+
if (this.is_mouse_started) {
|
221
|
+
this._mouseDrag(position_info);
|
222
|
+
return e.preventDefault();
|
223
|
+
}
|
224
|
+
if (this.mouse_delay && !this._is_mouse_delay_met) {
|
225
|
+
return true;
|
226
|
+
}
|
227
|
+
this.is_mouse_started = this._mouseStart(this.mouse_down_info) !== false;
|
228
|
+
if (this.is_mouse_started) {
|
229
|
+
this._mouseDrag(position_info);
|
230
|
+
} else {
|
231
|
+
this._handleMouseUp(position_info);
|
232
|
+
}
|
233
|
+
return !this.is_mouse_started;
|
234
|
+
};
|
235
|
+
|
236
|
+
MouseWidget.prototype._getPositionInfo = function(e) {
|
237
|
+
return {
|
238
|
+
page_x: e.pageX,
|
239
|
+
page_y: e.pageY,
|
240
|
+
target: e.target,
|
241
|
+
original_event: e
|
242
|
+
};
|
243
|
+
};
|
244
|
+
|
245
|
+
MouseWidget.prototype._mouseUp = function(e) {
|
246
|
+
return this._handleMouseUp(this._getPositionInfo(e));
|
247
|
+
};
|
248
|
+
|
249
|
+
MouseWidget.prototype._handleMouseUp = function(position_info) {
|
250
|
+
var $document;
|
251
|
+
$document = $(document);
|
252
|
+
$document.unbind('mousemove.mousewidget');
|
253
|
+
$document.unbind('touchmove.mousewidget');
|
254
|
+
$document.unbind('mouseup.mousewidget');
|
255
|
+
$document.unbind('touchend.mousewidget');
|
256
|
+
if (this.is_mouse_started) {
|
257
|
+
this.is_mouse_started = false;
|
258
|
+
this._mouseStop(position_info);
|
259
|
+
}
|
260
|
+
};
|
261
|
+
|
262
|
+
MouseWidget.prototype._mouseCapture = function(position_info) {
|
263
|
+
return true;
|
264
|
+
};
|
265
|
+
|
266
|
+
MouseWidget.prototype._mouseStart = function(position_info) {
|
267
|
+
return null;
|
268
|
+
};
|
269
|
+
|
270
|
+
MouseWidget.prototype._mouseDrag = function(position_info) {
|
271
|
+
return null;
|
272
|
+
};
|
273
|
+
|
274
|
+
MouseWidget.prototype._mouseStop = function(position_info) {
|
275
|
+
return null;
|
276
|
+
};
|
277
|
+
|
278
|
+
MouseWidget.prototype.setMouseDelay = function(mouse_delay) {
|
279
|
+
return this.mouse_delay = mouse_delay;
|
280
|
+
};
|
281
|
+
|
282
|
+
MouseWidget.prototype._touchStart = function(e) {
|
283
|
+
var touch;
|
284
|
+
if (e.originalEvent.touches.length > 1) {
|
285
|
+
return;
|
286
|
+
}
|
287
|
+
touch = e.originalEvent.changedTouches[0];
|
288
|
+
return this._handleMouseDown(e, this._getPositionInfo(touch));
|
289
|
+
};
|
290
|
+
|
291
|
+
MouseWidget.prototype._touchMove = function(e) {
|
292
|
+
var touch;
|
293
|
+
if (e.originalEvent.touches.length > 1) {
|
294
|
+
return;
|
295
|
+
}
|
296
|
+
touch = e.originalEvent.changedTouches[0];
|
297
|
+
return this._handleMouseMove(e, this._getPositionInfo(touch));
|
298
|
+
};
|
299
|
+
|
300
|
+
MouseWidget.prototype._touchEnd = function(e) {
|
301
|
+
var touch;
|
302
|
+
if (e.originalEvent.touches.length > 1) {
|
303
|
+
return;
|
304
|
+
}
|
305
|
+
touch = e.originalEvent.changedTouches[0];
|
306
|
+
return this._handleMouseUp(this._getPositionInfo(touch));
|
307
|
+
};
|
308
|
+
|
309
|
+
return MouseWidget;
|
310
|
+
|
311
|
+
})(SimpleWidget);
|
312
|
+
|
313
|
+
this.Tree = {};
|
314
|
+
|
315
|
+
$ = this.jQuery;
|
316
|
+
|
317
|
+
Position = {
|
318
|
+
getName: function(position) {
|
319
|
+
return Position.strings[position - 1];
|
320
|
+
},
|
321
|
+
nameToIndex: function(name) {
|
322
|
+
var i, _i, _ref;
|
323
|
+
for (i = _i = 1, _ref = Position.strings.length; 1 <= _ref ? _i <= _ref : _i >= _ref; i = 1 <= _ref ? ++_i : --_i) {
|
324
|
+
if (Position.strings[i - 1] === name) {
|
325
|
+
return i;
|
326
|
+
}
|
327
|
+
}
|
328
|
+
return 0;
|
329
|
+
}
|
330
|
+
};
|
331
|
+
|
332
|
+
Position.BEFORE = 1;
|
333
|
+
|
334
|
+
Position.AFTER = 2;
|
335
|
+
|
336
|
+
Position.INSIDE = 3;
|
337
|
+
|
338
|
+
Position.NONE = 4;
|
339
|
+
|
340
|
+
Position.strings = ['before', 'after', 'inside', 'none'];
|
341
|
+
|
342
|
+
this.Tree.Position = Position;
|
343
|
+
|
344
|
+
Node = (function() {
|
345
|
+
function Node(o, is_root, node_class) {
|
346
|
+
if (is_root == null) {
|
347
|
+
is_root = false;
|
348
|
+
}
|
349
|
+
if (node_class == null) {
|
350
|
+
node_class = Node;
|
351
|
+
}
|
352
|
+
this.setData(o);
|
353
|
+
this.children = [];
|
354
|
+
this.parent = null;
|
355
|
+
if (is_root) {
|
356
|
+
this.id_mapping = {};
|
357
|
+
this.tree = this;
|
358
|
+
this.node_class = node_class;
|
359
|
+
}
|
360
|
+
}
|
361
|
+
|
362
|
+
Node.prototype.setData = function(o) {
|
363
|
+
var key, value, _results;
|
364
|
+
if (typeof o !== 'object') {
|
365
|
+
return this.name = o;
|
366
|
+
} else {
|
367
|
+
_results = [];
|
368
|
+
for (key in o) {
|
369
|
+
value = o[key];
|
370
|
+
if (key === 'label') {
|
371
|
+
_results.push(this.name = value);
|
372
|
+
} else {
|
373
|
+
_results.push(this[key] = value);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
return _results;
|
377
|
+
}
|
378
|
+
};
|
379
|
+
|
380
|
+
Node.prototype.initFromData = function(data) {
|
381
|
+
var addChildren, addNode;
|
382
|
+
addNode = (function(_this) {
|
383
|
+
return function(node_data) {
|
384
|
+
_this.setData(node_data);
|
385
|
+
if (node_data.children) {
|
386
|
+
return addChildren(node_data.children);
|
387
|
+
}
|
388
|
+
};
|
389
|
+
})(this);
|
390
|
+
addChildren = (function(_this) {
|
391
|
+
return function(children_data) {
|
392
|
+
var child, node, _i, _len;
|
393
|
+
for (_i = 0, _len = children_data.length; _i < _len; _i++) {
|
394
|
+
child = children_data[_i];
|
395
|
+
node = new _this.tree.node_class('');
|
396
|
+
node.initFromData(child);
|
397
|
+
_this.addChild(node);
|
398
|
+
}
|
399
|
+
return null;
|
400
|
+
};
|
401
|
+
})(this);
|
402
|
+
addNode(data);
|
403
|
+
return null;
|
404
|
+
};
|
405
|
+
|
406
|
+
|
407
|
+
/*
|
408
|
+
Create tree from data.
|
409
|
+
|
410
|
+
Structure of data is:
|
411
|
+
[
|
412
|
+
{
|
413
|
+
label: 'node1',
|
414
|
+
children: [
|
415
|
+
{ label: 'child1' },
|
416
|
+
{ label: 'child2' }
|
417
|
+
]
|
418
|
+
},
|
419
|
+
{
|
420
|
+
label: 'node2'
|
421
|
+
}
|
422
|
+
]
|
423
|
+
*/
|
424
|
+
|
425
|
+
Node.prototype.loadFromData = function(data) {
|
426
|
+
var node, o, _i, _len;
|
427
|
+
this.removeChildren();
|
428
|
+
for (_i = 0, _len = data.length; _i < _len; _i++) {
|
429
|
+
o = data[_i];
|
430
|
+
node = new this.tree.node_class(o);
|
431
|
+
this.addChild(node);
|
432
|
+
if (typeof o === 'object' && o.children) {
|
433
|
+
node.loadFromData(o.children);
|
434
|
+
}
|
435
|
+
}
|
436
|
+
return null;
|
437
|
+
};
|
438
|
+
|
439
|
+
|
440
|
+
/*
|
441
|
+
Add child.
|
442
|
+
|
443
|
+
tree.addChild(
|
444
|
+
new Node('child1')
|
445
|
+
);
|
446
|
+
*/
|
447
|
+
|
448
|
+
Node.prototype.addChild = function(node) {
|
449
|
+
this.children.push(node);
|
450
|
+
return node._setParent(this);
|
451
|
+
};
|
452
|
+
|
453
|
+
|
454
|
+
/*
|
455
|
+
Add child at position. Index starts at 0.
|
456
|
+
|
457
|
+
tree.addChildAtPosition(
|
458
|
+
new Node('abc'),
|
459
|
+
1
|
460
|
+
);
|
461
|
+
*/
|
462
|
+
|
463
|
+
Node.prototype.addChildAtPosition = function(node, index) {
|
464
|
+
this.children.splice(index, 0, node);
|
465
|
+
return node._setParent(this);
|
466
|
+
};
|
467
|
+
|
468
|
+
Node.prototype._setParent = function(parent) {
|
469
|
+
this.parent = parent;
|
470
|
+
this.tree = parent.tree;
|
471
|
+
return this.tree.addNodeToIndex(this);
|
472
|
+
};
|
473
|
+
|
474
|
+
|
475
|
+
/*
|
476
|
+
Remove child. This also removes the children of the node.
|
477
|
+
|
478
|
+
tree.removeChild(tree.children[0]);
|
479
|
+
*/
|
480
|
+
|
481
|
+
Node.prototype.removeChild = function(node) {
|
482
|
+
node.removeChildren();
|
483
|
+
return this._removeChild(node);
|
484
|
+
};
|
485
|
+
|
486
|
+
Node.prototype._removeChild = function(node) {
|
487
|
+
this.children.splice(this.getChildIndex(node), 1);
|
488
|
+
return this.tree.removeNodeFromIndex(node);
|
489
|
+
};
|
490
|
+
|
491
|
+
|
492
|
+
/*
|
493
|
+
Get child index.
|
494
|
+
|
495
|
+
var index = getChildIndex(node);
|
496
|
+
*/
|
497
|
+
|
498
|
+
Node.prototype.getChildIndex = function(node) {
|
499
|
+
return $.inArray(node, this.children);
|
500
|
+
};
|
501
|
+
|
502
|
+
|
503
|
+
/*
|
504
|
+
Does the tree have children?
|
505
|
+
|
506
|
+
if (tree.hasChildren()) {
|
507
|
+
//
|
508
|
+
}
|
509
|
+
*/
|
510
|
+
|
511
|
+
Node.prototype.hasChildren = function() {
|
512
|
+
return this.children.length !== 0;
|
513
|
+
};
|
514
|
+
|
515
|
+
Node.prototype.isFolder = function() {
|
516
|
+
return this.hasChildren() || this.load_on_demand;
|
517
|
+
};
|
518
|
+
|
519
|
+
|
520
|
+
/*
|
521
|
+
Iterate over all the nodes in the tree.
|
522
|
+
|
523
|
+
Calls callback with (node, level).
|
524
|
+
|
525
|
+
The callback must return true to continue the iteration on current node.
|
526
|
+
|
527
|
+
tree.iterate(
|
528
|
+
function(node, level) {
|
529
|
+
console.log(node.name);
|
530
|
+
|
531
|
+
// stop iteration after level 2
|
532
|
+
return (level <= 2);
|
533
|
+
}
|
534
|
+
);
|
535
|
+
*/
|
536
|
+
|
537
|
+
Node.prototype.iterate = function(callback) {
|
538
|
+
var _iterate;
|
539
|
+
_iterate = (function(_this) {
|
540
|
+
return function(node, level) {
|
541
|
+
var child, result, _i, _len, _ref;
|
542
|
+
if (node.children) {
|
543
|
+
_ref = node.children;
|
544
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
545
|
+
child = _ref[_i];
|
546
|
+
result = callback(child, level);
|
547
|
+
if (_this.hasChildren() && result) {
|
548
|
+
_iterate(child, level + 1);
|
549
|
+
}
|
550
|
+
}
|
551
|
+
return null;
|
552
|
+
}
|
553
|
+
};
|
554
|
+
})(this);
|
555
|
+
_iterate(this, 0);
|
556
|
+
return null;
|
557
|
+
};
|
558
|
+
|
559
|
+
|
560
|
+
/*
|
561
|
+
Move node relative to another node.
|
562
|
+
|
563
|
+
Argument position: Position.BEFORE, Position.AFTER or Position.Inside
|
564
|
+
|
565
|
+
// move node1 after node2
|
566
|
+
tree.moveNode(node1, node2, Position.AFTER);
|
567
|
+
*/
|
568
|
+
|
569
|
+
Node.prototype.moveNode = function(moved_node, target_node, position) {
|
570
|
+
if (moved_node.isParentOf(target_node)) {
|
571
|
+
return;
|
572
|
+
}
|
573
|
+
moved_node.parent._removeChild(moved_node);
|
574
|
+
if (position === Position.AFTER) {
|
575
|
+
return target_node.parent.addChildAtPosition(moved_node, target_node.parent.getChildIndex(target_node) + 1);
|
576
|
+
} else if (position === Position.BEFORE) {
|
577
|
+
return target_node.parent.addChildAtPosition(moved_node, target_node.parent.getChildIndex(target_node));
|
578
|
+
} else if (position === Position.INSIDE) {
|
579
|
+
return target_node.addChildAtPosition(moved_node, 0);
|
580
|
+
}
|
581
|
+
};
|
582
|
+
|
583
|
+
|
584
|
+
/*
|
585
|
+
Get the tree as data.
|
586
|
+
*/
|
587
|
+
|
588
|
+
Node.prototype.getData = function() {
|
589
|
+
var getDataFromNodes;
|
590
|
+
getDataFromNodes = (function(_this) {
|
591
|
+
return function(nodes) {
|
592
|
+
var data, k, node, tmp_node, v, _i, _len;
|
593
|
+
data = [];
|
594
|
+
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
|
595
|
+
node = nodes[_i];
|
596
|
+
tmp_node = {};
|
597
|
+
for (k in node) {
|
598
|
+
v = node[k];
|
599
|
+
if ((k !== 'parent' && k !== 'children' && k !== 'element' && k !== 'tree') && Object.prototype.hasOwnProperty.call(node, k)) {
|
600
|
+
tmp_node[k] = v;
|
601
|
+
}
|
602
|
+
}
|
603
|
+
if (node.hasChildren()) {
|
604
|
+
tmp_node.children = getDataFromNodes(node.children);
|
605
|
+
}
|
606
|
+
data.push(tmp_node);
|
607
|
+
}
|
608
|
+
return data;
|
609
|
+
};
|
610
|
+
})(this);
|
611
|
+
return getDataFromNodes(this.children);
|
612
|
+
};
|
613
|
+
|
614
|
+
Node.prototype.getNodeByName = function(name) {
|
615
|
+
var result;
|
616
|
+
result = null;
|
617
|
+
this.iterate(function(node) {
|
618
|
+
if (node.name === name) {
|
619
|
+
result = node;
|
620
|
+
return false;
|
621
|
+
} else {
|
622
|
+
return true;
|
623
|
+
}
|
624
|
+
});
|
625
|
+
return result;
|
626
|
+
};
|
627
|
+
|
628
|
+
Node.prototype.addAfter = function(node_info) {
|
629
|
+
var child_index, node;
|
630
|
+
if (!this.parent) {
|
631
|
+
return null;
|
632
|
+
} else {
|
633
|
+
node = new this.tree.node_class(node_info);
|
634
|
+
child_index = this.parent.getChildIndex(this);
|
635
|
+
this.parent.addChildAtPosition(node, child_index + 1);
|
636
|
+
return node;
|
637
|
+
}
|
638
|
+
};
|
639
|
+
|
640
|
+
Node.prototype.addBefore = function(node_info) {
|
641
|
+
var child_index, node;
|
642
|
+
if (!this.parent) {
|
643
|
+
return null;
|
644
|
+
} else {
|
645
|
+
node = new this.tree.node_class(node_info);
|
646
|
+
child_index = this.parent.getChildIndex(this);
|
647
|
+
this.parent.addChildAtPosition(node, child_index);
|
648
|
+
return node;
|
649
|
+
}
|
650
|
+
};
|
651
|
+
|
652
|
+
Node.prototype.addParent = function(node_info) {
|
653
|
+
var child, new_parent, original_parent, _i, _len, _ref;
|
654
|
+
if (!this.parent) {
|
655
|
+
return null;
|
656
|
+
} else {
|
657
|
+
new_parent = new this.tree.node_class(node_info);
|
658
|
+
new_parent._setParent(this.tree);
|
659
|
+
original_parent = this.parent;
|
660
|
+
_ref = original_parent.children;
|
661
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
662
|
+
child = _ref[_i];
|
663
|
+
new_parent.addChild(child);
|
664
|
+
}
|
665
|
+
original_parent.children = [];
|
666
|
+
original_parent.addChild(new_parent);
|
667
|
+
return new_parent;
|
668
|
+
}
|
669
|
+
};
|
670
|
+
|
671
|
+
Node.prototype.remove = function() {
|
672
|
+
if (this.parent) {
|
673
|
+
this.parent.removeChild(this);
|
674
|
+
return this.parent = null;
|
675
|
+
}
|
676
|
+
};
|
677
|
+
|
678
|
+
Node.prototype.append = function(node_info) {
|
679
|
+
var node;
|
680
|
+
node = new this.tree.node_class(node_info);
|
681
|
+
this.addChild(node);
|
682
|
+
return node;
|
683
|
+
};
|
684
|
+
|
685
|
+
Node.prototype.prepend = function(node_info) {
|
686
|
+
var node;
|
687
|
+
node = new this.tree.node_class(node_info);
|
688
|
+
this.addChildAtPosition(node, 0);
|
689
|
+
return node;
|
690
|
+
};
|
691
|
+
|
692
|
+
Node.prototype.isParentOf = function(node) {
|
693
|
+
var parent;
|
694
|
+
parent = node.parent;
|
695
|
+
while (parent) {
|
696
|
+
if (parent === this) {
|
697
|
+
return true;
|
698
|
+
}
|
699
|
+
parent = parent.parent;
|
700
|
+
}
|
701
|
+
return false;
|
702
|
+
};
|
703
|
+
|
704
|
+
Node.prototype.getLevel = function() {
|
705
|
+
var level, node;
|
706
|
+
level = 0;
|
707
|
+
node = this;
|
708
|
+
while (node.parent) {
|
709
|
+
level += 1;
|
710
|
+
node = node.parent;
|
711
|
+
}
|
712
|
+
return level;
|
713
|
+
};
|
714
|
+
|
715
|
+
Node.prototype.getNodeById = function(node_id) {
|
716
|
+
return this.id_mapping[node_id];
|
717
|
+
};
|
718
|
+
|
719
|
+
Node.prototype.addNodeToIndex = function(node) {
|
720
|
+
if (node.id != null) {
|
721
|
+
return this.id_mapping[node.id] = node;
|
722
|
+
}
|
723
|
+
};
|
724
|
+
|
725
|
+
Node.prototype.removeNodeFromIndex = function(node) {
|
726
|
+
if (node.id != null) {
|
727
|
+
return delete this.id_mapping[node.id];
|
728
|
+
}
|
729
|
+
};
|
730
|
+
|
731
|
+
Node.prototype.removeChildren = function() {
|
732
|
+
this.iterate((function(_this) {
|
733
|
+
return function(child) {
|
734
|
+
_this.tree.removeNodeFromIndex(child);
|
735
|
+
return true;
|
736
|
+
};
|
737
|
+
})(this));
|
738
|
+
return this.children = [];
|
739
|
+
};
|
740
|
+
|
741
|
+
Node.prototype.getPreviousSibling = function() {
|
742
|
+
var previous_index;
|
743
|
+
if (!this.parent) {
|
744
|
+
return null;
|
745
|
+
} else {
|
746
|
+
previous_index = this.parent.getChildIndex(this) - 1;
|
747
|
+
if (previous_index >= 0) {
|
748
|
+
return this.parent.children[previous_index];
|
749
|
+
} else {
|
750
|
+
return null;
|
751
|
+
}
|
752
|
+
}
|
753
|
+
};
|
754
|
+
|
755
|
+
Node.prototype.getNextSibling = function() {
|
756
|
+
var next_index;
|
757
|
+
if (!this.parent) {
|
758
|
+
return null;
|
759
|
+
} else {
|
760
|
+
next_index = this.parent.getChildIndex(this) + 1;
|
761
|
+
if (next_index < this.parent.children.length) {
|
762
|
+
return this.parent.children[next_index];
|
763
|
+
} else {
|
764
|
+
return null;
|
765
|
+
}
|
766
|
+
}
|
767
|
+
};
|
768
|
+
|
769
|
+
return Node;
|
770
|
+
|
771
|
+
})();
|
772
|
+
|
773
|
+
this.Tree.Node = Node;
|
774
|
+
|
775
|
+
ElementsRenderer = (function() {
|
776
|
+
function ElementsRenderer(tree_widget) {
|
777
|
+
this.tree_widget = tree_widget;
|
778
|
+
this.opened_icon_text = this.getHtmlText(tree_widget.options.openedIcon);
|
779
|
+
this.closed_icon_text = this.getHtmlText(tree_widget.options.closedIcon);
|
780
|
+
}
|
781
|
+
|
782
|
+
ElementsRenderer.prototype.render = function(from_node) {
|
783
|
+
if (from_node && from_node.parent) {
|
784
|
+
return this.renderFromNode(from_node);
|
785
|
+
} else {
|
786
|
+
return this.renderFromRoot();
|
787
|
+
}
|
788
|
+
};
|
789
|
+
|
790
|
+
ElementsRenderer.prototype.renderNode = function(node) {
|
791
|
+
var $li, $parent_ul, parent_node_element, previous_node;
|
792
|
+
$(node.element).remove();
|
793
|
+
parent_node_element = new NodeElement(node.parent, this.tree_widget);
|
794
|
+
$parent_ul = parent_node_element.getUl();
|
795
|
+
$li = this.createLi(node);
|
796
|
+
this.attachNodeData(node, $li);
|
797
|
+
previous_node = node.getPreviousSibling();
|
798
|
+
if (previous_node) {
|
799
|
+
$(previous_node.element).after($li);
|
800
|
+
} else {
|
801
|
+
parent_node_element.getUl().prepend($li);
|
802
|
+
}
|
803
|
+
if (node.children) {
|
804
|
+
return this.renderFromNode(node);
|
805
|
+
}
|
806
|
+
};
|
807
|
+
|
808
|
+
ElementsRenderer.prototype.renderFromRoot = function() {
|
809
|
+
var $element;
|
810
|
+
$element = this.tree_widget.element;
|
811
|
+
$element.empty();
|
812
|
+
return this.createDomElements($element[0], this.tree_widget.tree.children, true, true);
|
813
|
+
};
|
814
|
+
|
815
|
+
ElementsRenderer.prototype.renderFromNode = function(from_node) {
|
816
|
+
var node_element;
|
817
|
+
node_element = this.tree_widget._getNodeElementForNode(from_node);
|
818
|
+
node_element.getUl().remove();
|
819
|
+
return this.createDomElements(node_element.$element[0], from_node.children, false, false);
|
820
|
+
};
|
821
|
+
|
822
|
+
ElementsRenderer.prototype.createDomElements = function(element, children, is_root_node, is_open) {
|
823
|
+
var child, li, ul, _i, _len;
|
824
|
+
ul = this.createUl(is_root_node);
|
825
|
+
element.appendChild(ul);
|
826
|
+
for (_i = 0, _len = children.length; _i < _len; _i++) {
|
827
|
+
child = children[_i];
|
828
|
+
li = this.createLi(child);
|
829
|
+
ul.appendChild(li);
|
830
|
+
this.attachNodeData(child, li);
|
831
|
+
if (child.hasChildren()) {
|
832
|
+
this.createDomElements(li, child.children, false, child.is_open);
|
833
|
+
}
|
834
|
+
}
|
835
|
+
return null;
|
836
|
+
};
|
837
|
+
|
838
|
+
ElementsRenderer.prototype.attachNodeData = function(node, li) {
|
839
|
+
node.element = li;
|
840
|
+
return $(li).data('node', node);
|
841
|
+
};
|
842
|
+
|
843
|
+
ElementsRenderer.prototype.createUl = function(is_root_node) {
|
844
|
+
var class_string, ul;
|
845
|
+
if (is_root_node) {
|
846
|
+
class_string = 'jqtree-tree';
|
847
|
+
} else {
|
848
|
+
class_string = '';
|
849
|
+
}
|
850
|
+
ul = document.createElement('ul');
|
851
|
+
ul.className = "jqtree_common " + class_string;
|
852
|
+
return ul;
|
853
|
+
};
|
854
|
+
|
855
|
+
ElementsRenderer.prototype.createLi = function(node) {
|
856
|
+
var li;
|
857
|
+
if (node.isFolder()) {
|
858
|
+
li = this.createFolderLi(node);
|
859
|
+
} else {
|
860
|
+
li = this.createNodeLi(node);
|
861
|
+
}
|
862
|
+
if (this.tree_widget.options.onCreateLi) {
|
863
|
+
this.tree_widget.options.onCreateLi(node, $(li));
|
864
|
+
}
|
865
|
+
return li;
|
866
|
+
};
|
867
|
+
|
868
|
+
ElementsRenderer.prototype.createFolderLi = function(node) {
|
869
|
+
var button_char, button_classes, button_link, div, escaped_name, folder_classes, li, title_span;
|
870
|
+
button_classes = this.getButtonClasses(node);
|
871
|
+
folder_classes = this.getFolderClasses(node);
|
872
|
+
escaped_name = this.escapeIfNecessary(node.name);
|
873
|
+
if (node.is_open) {
|
874
|
+
button_char = this.opened_icon_text;
|
875
|
+
} else {
|
876
|
+
button_char = this.closed_icon_text;
|
877
|
+
}
|
878
|
+
li = document.createElement('li');
|
879
|
+
li.className = "jqtree_common " + folder_classes;
|
880
|
+
div = document.createElement('div');
|
881
|
+
div.className = "jqtree-element jqtree_common";
|
882
|
+
li.appendChild(div);
|
883
|
+
button_link = document.createElement('a');
|
884
|
+
button_link.className = "jqtree_common " + button_classes;
|
885
|
+
button_link.appendChild(document.createTextNode(button_char));
|
886
|
+
div.appendChild(button_link);
|
887
|
+
title_span = document.createElement('span');
|
888
|
+
title_span.className = "jqtree_common jqtree-title";
|
889
|
+
div.appendChild(title_span);
|
890
|
+
title_span.innerHTML = escaped_name;
|
891
|
+
return li;
|
892
|
+
};
|
893
|
+
|
894
|
+
ElementsRenderer.prototype.createNodeLi = function(node) {
|
895
|
+
var class_string, div, escaped_name, li, li_classes, title_span;
|
896
|
+
li_classes = ['jqtree_common'];
|
897
|
+
if (this.tree_widget.select_node_handler && this.tree_widget.select_node_handler.isNodeSelected(node)) {
|
898
|
+
li_classes.push('jqtree-selected');
|
899
|
+
}
|
900
|
+
class_string = li_classes.join(' ');
|
901
|
+
escaped_name = this.escapeIfNecessary(node.name);
|
902
|
+
li = document.createElement('li');
|
903
|
+
li.className = class_string;
|
904
|
+
div = document.createElement('div');
|
905
|
+
div.className = "jqtree-element jqtree_common";
|
906
|
+
li.appendChild(div);
|
907
|
+
title_span = document.createElement('span');
|
908
|
+
title_span.className = "jqtree-title jqtree_common";
|
909
|
+
title_span.innerHTML = escaped_name;
|
910
|
+
div.appendChild(title_span);
|
911
|
+
return li;
|
912
|
+
};
|
913
|
+
|
914
|
+
ElementsRenderer.prototype.getButtonClasses = function(node) {
|
915
|
+
var classes;
|
916
|
+
classes = ['jqtree-toggler'];
|
917
|
+
if (!node.is_open) {
|
918
|
+
classes.push('jqtree-closed');
|
919
|
+
}
|
920
|
+
return classes.join(' ');
|
921
|
+
};
|
922
|
+
|
923
|
+
ElementsRenderer.prototype.getFolderClasses = function(node) {
|
924
|
+
var classes;
|
925
|
+
classes = ['jqtree-folder'];
|
926
|
+
if (!node.is_open) {
|
927
|
+
classes.push('jqtree-closed');
|
928
|
+
}
|
929
|
+
if (this.tree_widget.select_node_handler && this.tree_widget.select_node_handler.isNodeSelected(node)) {
|
930
|
+
classes.push('jqtree-selected');
|
931
|
+
}
|
932
|
+
return classes.join(' ');
|
933
|
+
};
|
934
|
+
|
935
|
+
ElementsRenderer.prototype.escapeIfNecessary = function(value) {
|
936
|
+
if (this.tree_widget.options.autoEscape) {
|
937
|
+
return html_escape(value);
|
938
|
+
} else {
|
939
|
+
return value;
|
940
|
+
}
|
941
|
+
};
|
942
|
+
|
943
|
+
ElementsRenderer.prototype.getHtmlText = function(entity_text) {
|
944
|
+
return $(document.createElement('div')).html(entity_text).text();
|
945
|
+
};
|
946
|
+
|
947
|
+
return ElementsRenderer;
|
948
|
+
|
949
|
+
})();
|
950
|
+
|
951
|
+
|
952
|
+
/*
|
953
|
+
Copyright 2013 Marco Braak
|
954
|
+
|
955
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
956
|
+
you may not use this file except in compliance with the License.
|
957
|
+
You may obtain a copy of the License at
|
958
|
+
|
959
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
960
|
+
|
961
|
+
Unless required by applicable law or agreed to in writing, software
|
962
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
963
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
964
|
+
See the License for the specific language governing permissions and
|
965
|
+
limitations under the License.
|
966
|
+
*/
|
967
|
+
|
968
|
+
JqTreeWidget = (function(_super) {
|
969
|
+
__extends(JqTreeWidget, _super);
|
970
|
+
|
971
|
+
function JqTreeWidget() {
|
972
|
+
return JqTreeWidget.__super__.constructor.apply(this, arguments);
|
973
|
+
}
|
974
|
+
|
975
|
+
JqTreeWidget.prototype.defaults = {
|
976
|
+
autoOpen: false,
|
977
|
+
saveState: false,
|
978
|
+
dragAndDrop: false,
|
979
|
+
selectable: true,
|
980
|
+
useContextMenu: true,
|
981
|
+
onCanSelectNode: null,
|
982
|
+
onSetStateFromStorage: null,
|
983
|
+
onGetStateFromStorage: null,
|
984
|
+
onCreateLi: null,
|
985
|
+
onIsMoveHandle: null,
|
986
|
+
onCanMove: null,
|
987
|
+
onCanMoveTo: null,
|
988
|
+
onLoadFailed: null,
|
989
|
+
autoEscape: true,
|
990
|
+
dataUrl: null,
|
991
|
+
closedIcon: '►',
|
992
|
+
openedIcon: '▼',
|
993
|
+
slide: true,
|
994
|
+
nodeClass: Node,
|
995
|
+
dataFilter: null,
|
996
|
+
keyboardSupport: true,
|
997
|
+
openFolderDelay: 500
|
998
|
+
};
|
999
|
+
|
1000
|
+
JqTreeWidget.prototype.toggle = function(node, slide) {
|
1001
|
+
if (slide == null) {
|
1002
|
+
slide = true;
|
1003
|
+
}
|
1004
|
+
if (node.is_open) {
|
1005
|
+
return this.closeNode(node, slide);
|
1006
|
+
} else {
|
1007
|
+
return this.openNode(node, slide);
|
1008
|
+
}
|
1009
|
+
};
|
1010
|
+
|
1011
|
+
JqTreeWidget.prototype.getTree = function() {
|
1012
|
+
return this.tree;
|
1013
|
+
};
|
1014
|
+
|
1015
|
+
JqTreeWidget.prototype.selectNode = function(node) {
|
1016
|
+
return this._selectNode(node, false);
|
1017
|
+
};
|
1018
|
+
|
1019
|
+
JqTreeWidget.prototype._selectNode = function(node, must_toggle) {
|
1020
|
+
var canSelect, deselected_node, openParents, saveState;
|
1021
|
+
if (must_toggle == null) {
|
1022
|
+
must_toggle = false;
|
1023
|
+
}
|
1024
|
+
if (!this.select_node_handler) {
|
1025
|
+
return;
|
1026
|
+
}
|
1027
|
+
canSelect = (function(_this) {
|
1028
|
+
return function() {
|
1029
|
+
if (_this.options.onCanSelectNode) {
|
1030
|
+
return _this.options.selectable && _this.options.onCanSelectNode(node);
|
1031
|
+
} else {
|
1032
|
+
return _this.options.selectable;
|
1033
|
+
}
|
1034
|
+
};
|
1035
|
+
})(this);
|
1036
|
+
openParents = (function(_this) {
|
1037
|
+
return function() {
|
1038
|
+
var parent;
|
1039
|
+
parent = node.parent;
|
1040
|
+
if (parent && parent.parent && !parent.is_open) {
|
1041
|
+
return _this.openNode(parent, false);
|
1042
|
+
}
|
1043
|
+
};
|
1044
|
+
})(this);
|
1045
|
+
saveState = (function(_this) {
|
1046
|
+
return function() {
|
1047
|
+
if (_this.options.saveState) {
|
1048
|
+
return _this.save_state_handler.saveState();
|
1049
|
+
}
|
1050
|
+
};
|
1051
|
+
})(this);
|
1052
|
+
if (!node) {
|
1053
|
+
this._deselectCurrentNode();
|
1054
|
+
saveState();
|
1055
|
+
return;
|
1056
|
+
}
|
1057
|
+
if (!canSelect()) {
|
1058
|
+
return;
|
1059
|
+
}
|
1060
|
+
if (this.select_node_handler.isNodeSelected(node)) {
|
1061
|
+
if (must_toggle) {
|
1062
|
+
this._deselectCurrentNode();
|
1063
|
+
this._triggerEvent('tree.select', {
|
1064
|
+
node: null,
|
1065
|
+
previous_node: node
|
1066
|
+
});
|
1067
|
+
}
|
1068
|
+
} else {
|
1069
|
+
deselected_node = this.getSelectedNode();
|
1070
|
+
this._deselectCurrentNode();
|
1071
|
+
this.addToSelection(node);
|
1072
|
+
this._triggerEvent('tree.select', {
|
1073
|
+
node: node,
|
1074
|
+
deselected_node: deselected_node
|
1075
|
+
});
|
1076
|
+
openParents();
|
1077
|
+
}
|
1078
|
+
return saveState();
|
1079
|
+
};
|
1080
|
+
|
1081
|
+
JqTreeWidget.prototype.getSelectedNode = function() {
|
1082
|
+
return this.select_node_handler.getSelectedNode();
|
1083
|
+
};
|
1084
|
+
|
1085
|
+
JqTreeWidget.prototype.toJson = function() {
|
1086
|
+
return JSON.stringify(this.tree.getData());
|
1087
|
+
};
|
1088
|
+
|
1089
|
+
JqTreeWidget.prototype.loadData = function(data, parent_node) {
|
1090
|
+
return this._loadData(data, parent_node);
|
1091
|
+
};
|
1092
|
+
|
1093
|
+
JqTreeWidget.prototype.loadDataFromUrl = function(url, parent_node, on_finished) {
|
1094
|
+
if ($.type(url) !== 'string') {
|
1095
|
+
on_finished = parent_node;
|
1096
|
+
parent_node = url;
|
1097
|
+
url = null;
|
1098
|
+
}
|
1099
|
+
return this._loadDataFromUrl(url, parent_node, on_finished);
|
1100
|
+
};
|
1101
|
+
|
1102
|
+
JqTreeWidget.prototype.reload = function() {
|
1103
|
+
return this.loadDataFromUrl();
|
1104
|
+
};
|
1105
|
+
|
1106
|
+
JqTreeWidget.prototype._loadDataFromUrl = function(url_info, parent_node, on_finished) {
|
1107
|
+
var $el, addLoadingClass, parseUrlInfo, removeLoadingClass;
|
1108
|
+
$el = null;
|
1109
|
+
addLoadingClass = (function(_this) {
|
1110
|
+
return function() {
|
1111
|
+
var folder_element;
|
1112
|
+
if (!parent_node) {
|
1113
|
+
$el = _this.element;
|
1114
|
+
} else {
|
1115
|
+
folder_element = new FolderElement(parent_node, _this);
|
1116
|
+
$el = folder_element.getLi();
|
1117
|
+
}
|
1118
|
+
return $el.addClass('jqtree-loading');
|
1119
|
+
};
|
1120
|
+
})(this);
|
1121
|
+
removeLoadingClass = (function(_this) {
|
1122
|
+
return function() {
|
1123
|
+
if ($el) {
|
1124
|
+
return $el.removeClass('jqtree-loading');
|
1125
|
+
}
|
1126
|
+
};
|
1127
|
+
})(this);
|
1128
|
+
parseUrlInfo = (function(_this) {
|
1129
|
+
return function() {
|
1130
|
+
if ($.type(url_info) === 'string') {
|
1131
|
+
url_info = {
|
1132
|
+
url: url_info
|
1133
|
+
};
|
1134
|
+
}
|
1135
|
+
if (!url_info.method) {
|
1136
|
+
return url_info.method = 'get';
|
1137
|
+
}
|
1138
|
+
};
|
1139
|
+
})(this);
|
1140
|
+
addLoadingClass();
|
1141
|
+
if (!url_info) {
|
1142
|
+
url_info = this._getDataUrlInfo(parent_node);
|
1143
|
+
}
|
1144
|
+
parseUrlInfo();
|
1145
|
+
return $.ajax({
|
1146
|
+
url: url_info.url,
|
1147
|
+
data: url_info.data,
|
1148
|
+
type: url_info.method.toUpperCase(),
|
1149
|
+
cache: false,
|
1150
|
+
dataType: 'json',
|
1151
|
+
success: (function(_this) {
|
1152
|
+
return function(response) {
|
1153
|
+
var data;
|
1154
|
+
if ($.isArray(response) || typeof response === 'object') {
|
1155
|
+
data = response;
|
1156
|
+
} else {
|
1157
|
+
data = $.parseJSON(response);
|
1158
|
+
}
|
1159
|
+
if (_this.options.dataFilter) {
|
1160
|
+
data = _this.options.dataFilter(data);
|
1161
|
+
}
|
1162
|
+
removeLoadingClass();
|
1163
|
+
_this._loadData(data, parent_node);
|
1164
|
+
if (on_finished && $.isFunction(on_finished)) {
|
1165
|
+
return on_finished();
|
1166
|
+
}
|
1167
|
+
};
|
1168
|
+
})(this),
|
1169
|
+
error: (function(_this) {
|
1170
|
+
return function(response) {
|
1171
|
+
removeLoadingClass();
|
1172
|
+
if (_this.options.onLoadFailed) {
|
1173
|
+
return _this.options.onLoadFailed(response);
|
1174
|
+
}
|
1175
|
+
};
|
1176
|
+
})(this)
|
1177
|
+
});
|
1178
|
+
};
|
1179
|
+
|
1180
|
+
JqTreeWidget.prototype._loadData = function(data, parent_node) {
|
1181
|
+
var n, selected_nodes_under_parent, _i, _len;
|
1182
|
+
if (!data) {
|
1183
|
+
return;
|
1184
|
+
}
|
1185
|
+
this._triggerEvent('tree.load_data', {
|
1186
|
+
tree_data: data
|
1187
|
+
});
|
1188
|
+
if (!parent_node) {
|
1189
|
+
this._initTree(data);
|
1190
|
+
} else {
|
1191
|
+
selected_nodes_under_parent = this.select_node_handler.getSelectedNodesUnder(parent_node);
|
1192
|
+
for (_i = 0, _len = selected_nodes_under_parent.length; _i < _len; _i++) {
|
1193
|
+
n = selected_nodes_under_parent[_i];
|
1194
|
+
this.select_node_handler.removeFromSelection(n);
|
1195
|
+
}
|
1196
|
+
parent_node.loadFromData(data);
|
1197
|
+
parent_node.load_on_demand = false;
|
1198
|
+
this._refreshElements(parent_node.parent);
|
1199
|
+
}
|
1200
|
+
if (this.is_dragging) {
|
1201
|
+
return this.dnd_handler.refreshHitAreas();
|
1202
|
+
}
|
1203
|
+
};
|
1204
|
+
|
1205
|
+
JqTreeWidget.prototype.getNodeById = function(node_id) {
|
1206
|
+
return this.tree.getNodeById(node_id);
|
1207
|
+
};
|
1208
|
+
|
1209
|
+
JqTreeWidget.prototype.getNodeByName = function(name) {
|
1210
|
+
return this.tree.getNodeByName(name);
|
1211
|
+
};
|
1212
|
+
|
1213
|
+
JqTreeWidget.prototype.openNode = function(node, slide) {
|
1214
|
+
if (slide == null) {
|
1215
|
+
slide = true;
|
1216
|
+
}
|
1217
|
+
return this._openNode(node, slide);
|
1218
|
+
};
|
1219
|
+
|
1220
|
+
JqTreeWidget.prototype._openNode = function(node, slide, on_finished) {
|
1221
|
+
var doOpenNode, parent;
|
1222
|
+
if (slide == null) {
|
1223
|
+
slide = true;
|
1224
|
+
}
|
1225
|
+
doOpenNode = (function(_this) {
|
1226
|
+
return function(_node, _slide, _on_finished) {
|
1227
|
+
var folder_element;
|
1228
|
+
folder_element = new FolderElement(_node, _this);
|
1229
|
+
return folder_element.open(_on_finished, _slide);
|
1230
|
+
};
|
1231
|
+
})(this);
|
1232
|
+
if (node.isFolder()) {
|
1233
|
+
if (node.load_on_demand) {
|
1234
|
+
return this._loadFolderOnDemand(node, slide, on_finished);
|
1235
|
+
} else {
|
1236
|
+
parent = node.parent;
|
1237
|
+
while (parent && !parent.is_open) {
|
1238
|
+
if (parent.parent) {
|
1239
|
+
doOpenNode(parent, false, null);
|
1240
|
+
}
|
1241
|
+
parent = parent.parent;
|
1242
|
+
}
|
1243
|
+
doOpenNode(node, slide, on_finished);
|
1244
|
+
return this._saveState();
|
1245
|
+
}
|
1246
|
+
}
|
1247
|
+
};
|
1248
|
+
|
1249
|
+
JqTreeWidget.prototype._loadFolderOnDemand = function(node, slide, on_finished) {
|
1250
|
+
if (slide == null) {
|
1251
|
+
slide = true;
|
1252
|
+
}
|
1253
|
+
return this._loadDataFromUrl(null, node, (function(_this) {
|
1254
|
+
return function() {
|
1255
|
+
return _this._openNode(node, slide, on_finished);
|
1256
|
+
};
|
1257
|
+
})(this));
|
1258
|
+
};
|
1259
|
+
|
1260
|
+
JqTreeWidget.prototype.closeNode = function(node, slide) {
|
1261
|
+
if (slide == null) {
|
1262
|
+
slide = true;
|
1263
|
+
}
|
1264
|
+
if (node.isFolder()) {
|
1265
|
+
new FolderElement(node, this).close(slide);
|
1266
|
+
return this._saveState();
|
1267
|
+
}
|
1268
|
+
};
|
1269
|
+
|
1270
|
+
JqTreeWidget.prototype.isDragging = function() {
|
1271
|
+
return this.is_dragging;
|
1272
|
+
};
|
1273
|
+
|
1274
|
+
JqTreeWidget.prototype.refreshHitAreas = function() {
|
1275
|
+
return this.dnd_handler.refreshHitAreas();
|
1276
|
+
};
|
1277
|
+
|
1278
|
+
JqTreeWidget.prototype.addNodeAfter = function(new_node_info, existing_node) {
|
1279
|
+
var new_node;
|
1280
|
+
new_node = existing_node.addAfter(new_node_info);
|
1281
|
+
this._refreshElements(existing_node.parent);
|
1282
|
+
return new_node;
|
1283
|
+
};
|
1284
|
+
|
1285
|
+
JqTreeWidget.prototype.addNodeBefore = function(new_node_info, existing_node) {
|
1286
|
+
var new_node;
|
1287
|
+
new_node = existing_node.addBefore(new_node_info);
|
1288
|
+
this._refreshElements(existing_node.parent);
|
1289
|
+
return new_node;
|
1290
|
+
};
|
1291
|
+
|
1292
|
+
JqTreeWidget.prototype.addParentNode = function(new_node_info, existing_node) {
|
1293
|
+
var new_node;
|
1294
|
+
new_node = existing_node.addParent(new_node_info);
|
1295
|
+
this._refreshElements(new_node.parent);
|
1296
|
+
return new_node;
|
1297
|
+
};
|
1298
|
+
|
1299
|
+
JqTreeWidget.prototype.removeNode = function(node) {
|
1300
|
+
var parent;
|
1301
|
+
parent = node.parent;
|
1302
|
+
if (parent) {
|
1303
|
+
this.select_node_handler.removeFromSelection(node, true);
|
1304
|
+
node.remove();
|
1305
|
+
return this._refreshElements(parent.parent);
|
1306
|
+
}
|
1307
|
+
};
|
1308
|
+
|
1309
|
+
JqTreeWidget.prototype.appendNode = function(new_node_info, parent_node) {
|
1310
|
+
var is_already_folder_node, node;
|
1311
|
+
if (!parent_node) {
|
1312
|
+
parent_node = this.tree;
|
1313
|
+
}
|
1314
|
+
is_already_folder_node = parent_node.isFolder();
|
1315
|
+
node = parent_node.append(new_node_info);
|
1316
|
+
if (is_already_folder_node) {
|
1317
|
+
this._refreshElements(parent_node);
|
1318
|
+
} else {
|
1319
|
+
this._refreshElements(parent_node.parent);
|
1320
|
+
}
|
1321
|
+
return node;
|
1322
|
+
};
|
1323
|
+
|
1324
|
+
JqTreeWidget.prototype.prependNode = function(new_node_info, parent_node) {
|
1325
|
+
var node;
|
1326
|
+
if (!parent_node) {
|
1327
|
+
parent_node = this.tree;
|
1328
|
+
}
|
1329
|
+
node = parent_node.prepend(new_node_info);
|
1330
|
+
this._refreshElements(parent_node);
|
1331
|
+
return node;
|
1332
|
+
};
|
1333
|
+
|
1334
|
+
JqTreeWidget.prototype.updateNode = function(node, data) {
|
1335
|
+
var id_is_changed;
|
1336
|
+
id_is_changed = data.id && data.id !== node.id;
|
1337
|
+
if (id_is_changed) {
|
1338
|
+
this.tree.removeNodeFromIndex(node);
|
1339
|
+
}
|
1340
|
+
node.setData(data);
|
1341
|
+
if (id_is_changed) {
|
1342
|
+
this.tree.addNodeToIndex(node);
|
1343
|
+
}
|
1344
|
+
this.renderer.renderNode(node);
|
1345
|
+
return this._selectCurrentNode();
|
1346
|
+
};
|
1347
|
+
|
1348
|
+
JqTreeWidget.prototype.moveNode = function(node, target_node, position) {
|
1349
|
+
var position_index;
|
1350
|
+
position_index = Position.nameToIndex(position);
|
1351
|
+
this.tree.moveNode(node, target_node, position_index);
|
1352
|
+
return this._refreshElements();
|
1353
|
+
};
|
1354
|
+
|
1355
|
+
JqTreeWidget.prototype.getStateFromStorage = function() {
|
1356
|
+
return this.save_state_handler.getStateFromStorage();
|
1357
|
+
};
|
1358
|
+
|
1359
|
+
JqTreeWidget.prototype.addToSelection = function(node) {
|
1360
|
+
this.select_node_handler.addToSelection(node);
|
1361
|
+
return this._getNodeElementForNode(node).select();
|
1362
|
+
};
|
1363
|
+
|
1364
|
+
JqTreeWidget.prototype.getSelectedNodes = function() {
|
1365
|
+
return this.select_node_handler.getSelectedNodes();
|
1366
|
+
};
|
1367
|
+
|
1368
|
+
JqTreeWidget.prototype.isNodeSelected = function(node) {
|
1369
|
+
return this.select_node_handler.isNodeSelected(node);
|
1370
|
+
};
|
1371
|
+
|
1372
|
+
JqTreeWidget.prototype.removeFromSelection = function(node) {
|
1373
|
+
this.select_node_handler.removeFromSelection(node);
|
1374
|
+
return this._getNodeElementForNode(node).deselect();
|
1375
|
+
};
|
1376
|
+
|
1377
|
+
JqTreeWidget.prototype.scrollToNode = function(node) {
|
1378
|
+
var $element, top;
|
1379
|
+
$element = $(node.element);
|
1380
|
+
top = $element.offset().top - this.$el.offset().top;
|
1381
|
+
return this.scroll_handler.scrollTo(top);
|
1382
|
+
};
|
1383
|
+
|
1384
|
+
JqTreeWidget.prototype.getState = function() {
|
1385
|
+
return this.save_state_handler.getState();
|
1386
|
+
};
|
1387
|
+
|
1388
|
+
JqTreeWidget.prototype.setState = function(state) {
|
1389
|
+
this.save_state_handler.setState(state);
|
1390
|
+
return this._refreshElements();
|
1391
|
+
};
|
1392
|
+
|
1393
|
+
JqTreeWidget.prototype.setOption = function(option, value) {
|
1394
|
+
return this.options[option] = value;
|
1395
|
+
};
|
1396
|
+
|
1397
|
+
JqTreeWidget.prototype._init = function() {
|
1398
|
+
JqTreeWidget.__super__._init.call(this);
|
1399
|
+
this.element = this.$el;
|
1400
|
+
this.mouse_delay = 300;
|
1401
|
+
this.is_initialized = false;
|
1402
|
+
this.renderer = new ElementsRenderer(this);
|
1403
|
+
if (typeof SaveStateHandler !== "undefined" && SaveStateHandler !== null) {
|
1404
|
+
this.save_state_handler = new SaveStateHandler(this);
|
1405
|
+
} else {
|
1406
|
+
this.options.saveState = false;
|
1407
|
+
}
|
1408
|
+
if (typeof SelectNodeHandler !== "undefined" && SelectNodeHandler !== null) {
|
1409
|
+
this.select_node_handler = new SelectNodeHandler(this);
|
1410
|
+
}
|
1411
|
+
if (typeof DragAndDropHandler !== "undefined" && DragAndDropHandler !== null) {
|
1412
|
+
this.dnd_handler = new DragAndDropHandler(this);
|
1413
|
+
} else {
|
1414
|
+
this.options.dragAndDrop = false;
|
1415
|
+
}
|
1416
|
+
if (typeof ScrollHandler !== "undefined" && ScrollHandler !== null) {
|
1417
|
+
this.scroll_handler = new ScrollHandler(this);
|
1418
|
+
}
|
1419
|
+
if ((typeof KeyHandler !== "undefined" && KeyHandler !== null) && (typeof SelectNodeHandler !== "undefined" && SelectNodeHandler !== null)) {
|
1420
|
+
this.key_handler = new KeyHandler(this);
|
1421
|
+
}
|
1422
|
+
this._initData();
|
1423
|
+
this.element.click($.proxy(this._click, this));
|
1424
|
+
this.element.dblclick($.proxy(this._dblclick, this));
|
1425
|
+
if (this.options.useContextMenu) {
|
1426
|
+
return this.element.bind('contextmenu', $.proxy(this._contextmenu, this));
|
1427
|
+
}
|
1428
|
+
};
|
1429
|
+
|
1430
|
+
JqTreeWidget.prototype._deinit = function() {
|
1431
|
+
this.element.empty();
|
1432
|
+
this.element.unbind();
|
1433
|
+
this.key_handler.deinit();
|
1434
|
+
this.tree = null;
|
1435
|
+
return JqTreeWidget.__super__._deinit.call(this);
|
1436
|
+
};
|
1437
|
+
|
1438
|
+
JqTreeWidget.prototype._initData = function() {
|
1439
|
+
if (this.options.data) {
|
1440
|
+
return this._loadData(this.options.data);
|
1441
|
+
} else {
|
1442
|
+
return this._loadDataFromUrl(this._getDataUrlInfo());
|
1443
|
+
}
|
1444
|
+
};
|
1445
|
+
|
1446
|
+
JqTreeWidget.prototype._getDataUrlInfo = function(node) {
|
1447
|
+
var data_url, getUrlFromString;
|
1448
|
+
data_url = this.options.dataUrl || this.element.data('url');
|
1449
|
+
getUrlFromString = (function(_this) {
|
1450
|
+
return function() {
|
1451
|
+
var data, selected_node_id, url_info;
|
1452
|
+
url_info = {
|
1453
|
+
url: data_url
|
1454
|
+
};
|
1455
|
+
if (node && node.id) {
|
1456
|
+
data = {
|
1457
|
+
node: node.id
|
1458
|
+
};
|
1459
|
+
url_info['data'] = data;
|
1460
|
+
} else {
|
1461
|
+
selected_node_id = _this._getNodeIdToBeSelected();
|
1462
|
+
if (selected_node_id) {
|
1463
|
+
data = {
|
1464
|
+
selected_node: selected_node_id
|
1465
|
+
};
|
1466
|
+
url_info['data'] = data;
|
1467
|
+
}
|
1468
|
+
}
|
1469
|
+
return url_info;
|
1470
|
+
};
|
1471
|
+
})(this);
|
1472
|
+
if ($.isFunction(data_url)) {
|
1473
|
+
return data_url(node);
|
1474
|
+
} else if ($.type(data_url) === 'string') {
|
1475
|
+
return getUrlFromString();
|
1476
|
+
} else {
|
1477
|
+
return data_url;
|
1478
|
+
}
|
1479
|
+
};
|
1480
|
+
|
1481
|
+
JqTreeWidget.prototype._getNodeIdToBeSelected = function() {
|
1482
|
+
if (this.options.saveState) {
|
1483
|
+
return this.save_state_handler.getNodeIdToBeSelected();
|
1484
|
+
} else {
|
1485
|
+
return null;
|
1486
|
+
}
|
1487
|
+
};
|
1488
|
+
|
1489
|
+
JqTreeWidget.prototype._initTree = function(data) {
|
1490
|
+
this.tree = new this.options.nodeClass(null, true, this.options.nodeClass);
|
1491
|
+
if (this.select_node_handler) {
|
1492
|
+
this.select_node_handler.clear();
|
1493
|
+
}
|
1494
|
+
this.tree.loadFromData(data);
|
1495
|
+
this._openNodes();
|
1496
|
+
this._refreshElements();
|
1497
|
+
if (!this.is_initialized) {
|
1498
|
+
this.is_initialized = true;
|
1499
|
+
return this._triggerEvent('tree.init');
|
1500
|
+
}
|
1501
|
+
};
|
1502
|
+
|
1503
|
+
JqTreeWidget.prototype._openNodes = function() {
|
1504
|
+
var max_level;
|
1505
|
+
if (this.options.saveState) {
|
1506
|
+
if (this.save_state_handler.restoreState()) {
|
1507
|
+
return;
|
1508
|
+
}
|
1509
|
+
}
|
1510
|
+
if (this.options.autoOpen === false) {
|
1511
|
+
return;
|
1512
|
+
} else if (this.options.autoOpen === true) {
|
1513
|
+
max_level = -1;
|
1514
|
+
} else {
|
1515
|
+
max_level = parseInt(this.options.autoOpen);
|
1516
|
+
}
|
1517
|
+
return this.tree.iterate(function(node, level) {
|
1518
|
+
if (node.hasChildren()) {
|
1519
|
+
node.is_open = true;
|
1520
|
+
}
|
1521
|
+
return level !== max_level;
|
1522
|
+
});
|
1523
|
+
};
|
1524
|
+
|
1525
|
+
JqTreeWidget.prototype._refreshElements = function(from_node) {
|
1526
|
+
if (from_node == null) {
|
1527
|
+
from_node = null;
|
1528
|
+
}
|
1529
|
+
this.renderer.render(from_node);
|
1530
|
+
return this._triggerEvent('tree.refresh');
|
1531
|
+
};
|
1532
|
+
|
1533
|
+
JqTreeWidget.prototype._click = function(e) {
|
1534
|
+
var click_target, event, node;
|
1535
|
+
click_target = this._getClickTarget(e.target);
|
1536
|
+
if (click_target) {
|
1537
|
+
if (click_target.type === 'button') {
|
1538
|
+
this.toggle(click_target.node, this.options.slide);
|
1539
|
+
e.preventDefault();
|
1540
|
+
return e.stopPropagation();
|
1541
|
+
} else if (click_target.type === 'label') {
|
1542
|
+
node = click_target.node;
|
1543
|
+
event = this._triggerEvent('tree.click', {
|
1544
|
+
node: node,
|
1545
|
+
click_event: e
|
1546
|
+
});
|
1547
|
+
if (!event.isDefaultPrevented()) {
|
1548
|
+
return this._selectNode(node, true);
|
1549
|
+
}
|
1550
|
+
}
|
1551
|
+
}
|
1552
|
+
};
|
1553
|
+
|
1554
|
+
JqTreeWidget.prototype._dblclick = function(e) {
|
1555
|
+
var click_target;
|
1556
|
+
click_target = this._getClickTarget(e.target);
|
1557
|
+
if (click_target && click_target.type === 'label') {
|
1558
|
+
return this._triggerEvent('tree.dblclick', {
|
1559
|
+
node: click_target.node,
|
1560
|
+
click_event: e
|
1561
|
+
});
|
1562
|
+
}
|
1563
|
+
};
|
1564
|
+
|
1565
|
+
JqTreeWidget.prototype._getClickTarget = function(element) {
|
1566
|
+
var $button, $el, $target, node;
|
1567
|
+
$target = $(element);
|
1568
|
+
$button = $target.closest('.jqtree-toggler');
|
1569
|
+
if ($button.length) {
|
1570
|
+
node = this._getNode($button);
|
1571
|
+
if (node) {
|
1572
|
+
return {
|
1573
|
+
type: 'button',
|
1574
|
+
node: node
|
1575
|
+
};
|
1576
|
+
}
|
1577
|
+
} else {
|
1578
|
+
$el = $target.closest('.jqtree-element');
|
1579
|
+
if ($el.length) {
|
1580
|
+
node = this._getNode($el);
|
1581
|
+
if (node) {
|
1582
|
+
return {
|
1583
|
+
type: 'label',
|
1584
|
+
node: node
|
1585
|
+
};
|
1586
|
+
}
|
1587
|
+
}
|
1588
|
+
}
|
1589
|
+
return null;
|
1590
|
+
};
|
1591
|
+
|
1592
|
+
JqTreeWidget.prototype._getNode = function($element) {
|
1593
|
+
var $li;
|
1594
|
+
$li = $element.closest('li');
|
1595
|
+
if ($li.length === 0) {
|
1596
|
+
return null;
|
1597
|
+
} else {
|
1598
|
+
return $li.data('node');
|
1599
|
+
}
|
1600
|
+
};
|
1601
|
+
|
1602
|
+
JqTreeWidget.prototype._getNodeElementForNode = function(node) {
|
1603
|
+
if (node.isFolder()) {
|
1604
|
+
return new FolderElement(node, this);
|
1605
|
+
} else {
|
1606
|
+
return new NodeElement(node, this);
|
1607
|
+
}
|
1608
|
+
};
|
1609
|
+
|
1610
|
+
JqTreeWidget.prototype._getNodeElement = function($element) {
|
1611
|
+
var node;
|
1612
|
+
node = this._getNode($element);
|
1613
|
+
if (node) {
|
1614
|
+
return this._getNodeElementForNode(node);
|
1615
|
+
} else {
|
1616
|
+
return null;
|
1617
|
+
}
|
1618
|
+
};
|
1619
|
+
|
1620
|
+
JqTreeWidget.prototype._contextmenu = function(e) {
|
1621
|
+
var $div, node;
|
1622
|
+
$div = $(e.target).closest('ul.jqtree-tree .jqtree-element');
|
1623
|
+
if ($div.length) {
|
1624
|
+
node = this._getNode($div);
|
1625
|
+
if (node) {
|
1626
|
+
e.preventDefault();
|
1627
|
+
e.stopPropagation();
|
1628
|
+
this._triggerEvent('tree.contextmenu', {
|
1629
|
+
node: node,
|
1630
|
+
click_event: e
|
1631
|
+
});
|
1632
|
+
return false;
|
1633
|
+
}
|
1634
|
+
}
|
1635
|
+
};
|
1636
|
+
|
1637
|
+
JqTreeWidget.prototype._saveState = function() {
|
1638
|
+
if (this.options.saveState) {
|
1639
|
+
return this.save_state_handler.saveState();
|
1640
|
+
}
|
1641
|
+
};
|
1642
|
+
|
1643
|
+
JqTreeWidget.prototype._mouseCapture = function(position_info) {
|
1644
|
+
if (this.options.dragAndDrop) {
|
1645
|
+
return this.dnd_handler.mouseCapture(position_info);
|
1646
|
+
} else {
|
1647
|
+
return false;
|
1648
|
+
}
|
1649
|
+
};
|
1650
|
+
|
1651
|
+
JqTreeWidget.prototype._mouseStart = function(position_info) {
|
1652
|
+
if (this.options.dragAndDrop) {
|
1653
|
+
return this.dnd_handler.mouseStart(position_info);
|
1654
|
+
} else {
|
1655
|
+
return false;
|
1656
|
+
}
|
1657
|
+
};
|
1658
|
+
|
1659
|
+
JqTreeWidget.prototype._mouseDrag = function(position_info) {
|
1660
|
+
var result;
|
1661
|
+
if (this.options.dragAndDrop) {
|
1662
|
+
result = this.dnd_handler.mouseDrag(position_info);
|
1663
|
+
if (this.scroll_handler) {
|
1664
|
+
this.scroll_handler.checkScrolling();
|
1665
|
+
}
|
1666
|
+
return result;
|
1667
|
+
} else {
|
1668
|
+
return false;
|
1669
|
+
}
|
1670
|
+
};
|
1671
|
+
|
1672
|
+
JqTreeWidget.prototype._mouseStop = function(position_info) {
|
1673
|
+
if (this.options.dragAndDrop) {
|
1674
|
+
return this.dnd_handler.mouseStop(position_info);
|
1675
|
+
} else {
|
1676
|
+
return false;
|
1677
|
+
}
|
1678
|
+
};
|
1679
|
+
|
1680
|
+
JqTreeWidget.prototype._triggerEvent = function(event_name, values) {
|
1681
|
+
var event;
|
1682
|
+
event = $.Event(event_name);
|
1683
|
+
$.extend(event, values);
|
1684
|
+
this.element.trigger(event);
|
1685
|
+
return event;
|
1686
|
+
};
|
1687
|
+
|
1688
|
+
JqTreeWidget.prototype.testGenerateHitAreas = function(moving_node) {
|
1689
|
+
this.dnd_handler.current_item = this._getNodeElementForNode(moving_node);
|
1690
|
+
this.dnd_handler.generateHitAreas();
|
1691
|
+
return this.dnd_handler.hit_areas;
|
1692
|
+
};
|
1693
|
+
|
1694
|
+
JqTreeWidget.prototype._selectCurrentNode = function() {
|
1695
|
+
var node, node_element;
|
1696
|
+
node = this.getSelectedNode();
|
1697
|
+
if (node) {
|
1698
|
+
node_element = this._getNodeElementForNode(node);
|
1699
|
+
if (node_element) {
|
1700
|
+
return node_element.select();
|
1701
|
+
}
|
1702
|
+
}
|
1703
|
+
};
|
1704
|
+
|
1705
|
+
JqTreeWidget.prototype._deselectCurrentNode = function() {
|
1706
|
+
var node;
|
1707
|
+
node = this.getSelectedNode();
|
1708
|
+
if (node) {
|
1709
|
+
return this.removeFromSelection(node);
|
1710
|
+
}
|
1711
|
+
};
|
1712
|
+
|
1713
|
+
return JqTreeWidget;
|
1714
|
+
|
1715
|
+
})(MouseWidget);
|
1716
|
+
|
1717
|
+
SimpleWidget.register(JqTreeWidget, 'tree');
|
1718
|
+
|
1719
|
+
NodeElement = (function() {
|
1720
|
+
function NodeElement(node, tree_widget) {
|
1721
|
+
this.init(node, tree_widget);
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
NodeElement.prototype.init = function(node, tree_widget) {
|
1725
|
+
this.node = node;
|
1726
|
+
this.tree_widget = tree_widget;
|
1727
|
+
return this.$element = $(node.element);
|
1728
|
+
};
|
1729
|
+
|
1730
|
+
NodeElement.prototype.getUl = function() {
|
1731
|
+
return this.$element.children('ul:first');
|
1732
|
+
};
|
1733
|
+
|
1734
|
+
NodeElement.prototype.getSpan = function() {
|
1735
|
+
return this.$element.children('.jqtree-element').find('span.jqtree-title');
|
1736
|
+
};
|
1737
|
+
|
1738
|
+
NodeElement.prototype.getLi = function() {
|
1739
|
+
return this.$element;
|
1740
|
+
};
|
1741
|
+
|
1742
|
+
NodeElement.prototype.addDropHint = function(position) {
|
1743
|
+
if (position === Position.INSIDE) {
|
1744
|
+
return new BorderDropHint(this.$element);
|
1745
|
+
} else {
|
1746
|
+
return new GhostDropHint(this.node, this.$element, position);
|
1747
|
+
}
|
1748
|
+
};
|
1749
|
+
|
1750
|
+
NodeElement.prototype.select = function() {
|
1751
|
+
return this.getLi().addClass('jqtree-selected');
|
1752
|
+
};
|
1753
|
+
|
1754
|
+
NodeElement.prototype.deselect = function() {
|
1755
|
+
return this.getLi().removeClass('jqtree-selected');
|
1756
|
+
};
|
1757
|
+
|
1758
|
+
return NodeElement;
|
1759
|
+
|
1760
|
+
})();
|
1761
|
+
|
1762
|
+
FolderElement = (function(_super) {
|
1763
|
+
__extends(FolderElement, _super);
|
1764
|
+
|
1765
|
+
function FolderElement() {
|
1766
|
+
return FolderElement.__super__.constructor.apply(this, arguments);
|
1767
|
+
}
|
1768
|
+
|
1769
|
+
FolderElement.prototype.open = function(on_finished, slide) {
|
1770
|
+
var $button, doOpen;
|
1771
|
+
if (slide == null) {
|
1772
|
+
slide = true;
|
1773
|
+
}
|
1774
|
+
if (!this.node.is_open) {
|
1775
|
+
this.node.is_open = true;
|
1776
|
+
$button = this.getButton();
|
1777
|
+
$button.removeClass('jqtree-closed');
|
1778
|
+
$button.html(this.tree_widget.options.openedIcon);
|
1779
|
+
doOpen = (function(_this) {
|
1780
|
+
return function() {
|
1781
|
+
_this.getLi().removeClass('jqtree-closed');
|
1782
|
+
if (on_finished) {
|
1783
|
+
on_finished();
|
1784
|
+
}
|
1785
|
+
return _this.tree_widget._triggerEvent('tree.open', {
|
1786
|
+
node: _this.node
|
1787
|
+
});
|
1788
|
+
};
|
1789
|
+
})(this);
|
1790
|
+
if (slide) {
|
1791
|
+
return this.getUl().slideDown('fast', doOpen);
|
1792
|
+
} else {
|
1793
|
+
this.getUl().show();
|
1794
|
+
return doOpen();
|
1795
|
+
}
|
1796
|
+
}
|
1797
|
+
};
|
1798
|
+
|
1799
|
+
FolderElement.prototype.close = function(slide) {
|
1800
|
+
var $button, doClose;
|
1801
|
+
if (slide == null) {
|
1802
|
+
slide = true;
|
1803
|
+
}
|
1804
|
+
if (this.node.is_open) {
|
1805
|
+
this.node.is_open = false;
|
1806
|
+
$button = this.getButton();
|
1807
|
+
$button.addClass('jqtree-closed');
|
1808
|
+
$button.html(this.tree_widget.options.closedIcon);
|
1809
|
+
doClose = (function(_this) {
|
1810
|
+
return function() {
|
1811
|
+
_this.getLi().addClass('jqtree-closed');
|
1812
|
+
return _this.tree_widget._triggerEvent('tree.close', {
|
1813
|
+
node: _this.node
|
1814
|
+
});
|
1815
|
+
};
|
1816
|
+
})(this);
|
1817
|
+
if (slide) {
|
1818
|
+
return this.getUl().slideUp('fast', doClose);
|
1819
|
+
} else {
|
1820
|
+
this.getUl().hide();
|
1821
|
+
return doClose();
|
1822
|
+
}
|
1823
|
+
}
|
1824
|
+
};
|
1825
|
+
|
1826
|
+
FolderElement.prototype.getButton = function() {
|
1827
|
+
return this.$element.children('.jqtree-element').find('a.jqtree-toggler');
|
1828
|
+
};
|
1829
|
+
|
1830
|
+
FolderElement.prototype.addDropHint = function(position) {
|
1831
|
+
if (!this.node.is_open && position === Position.INSIDE) {
|
1832
|
+
return new BorderDropHint(this.$element);
|
1833
|
+
} else {
|
1834
|
+
return new GhostDropHint(this.node, this.$element, position);
|
1835
|
+
}
|
1836
|
+
};
|
1837
|
+
|
1838
|
+
return FolderElement;
|
1839
|
+
|
1840
|
+
})(NodeElement);
|
1841
|
+
|
1842
|
+
html_escape = function(string) {
|
1843
|
+
return ('' + string).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g, '/');
|
1844
|
+
};
|
1845
|
+
|
1846
|
+
_indexOf = function(array, item) {
|
1847
|
+
var i, value, _i, _len;
|
1848
|
+
for (i = _i = 0, _len = array.length; _i < _len; i = ++_i) {
|
1849
|
+
value = array[i];
|
1850
|
+
if (value === item) {
|
1851
|
+
return i;
|
1852
|
+
}
|
1853
|
+
}
|
1854
|
+
return -1;
|
1855
|
+
};
|
1856
|
+
|
1857
|
+
indexOf = function(array, item) {
|
1858
|
+
if (array.indexOf) {
|
1859
|
+
return array.indexOf(item);
|
1860
|
+
} else {
|
1861
|
+
return _indexOf(array, item);
|
1862
|
+
}
|
1863
|
+
};
|
1864
|
+
|
1865
|
+
this.Tree.indexOf = indexOf;
|
1866
|
+
|
1867
|
+
this.Tree._indexOf = _indexOf;
|
1868
|
+
|
1869
|
+
if (!((this.JSON != null) && (this.JSON.stringify != null) && typeof this.JSON.stringify === 'function')) {
|
1870
|
+
json_escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
1871
|
+
json_meta = {
|
1872
|
+
'\b': '\\b',
|
1873
|
+
'\t': '\\t',
|
1874
|
+
'\n': '\\n',
|
1875
|
+
'\f': '\\f',
|
1876
|
+
'\r': '\\r',
|
1877
|
+
'"': '\\"',
|
1878
|
+
'\\': '\\\\'
|
1879
|
+
};
|
1880
|
+
json_quote = function(string) {
|
1881
|
+
json_escapable.lastIndex = 0;
|
1882
|
+
if (json_escapable.test(string)) {
|
1883
|
+
return '"' + string.replace(json_escapable, function(a) {
|
1884
|
+
var c;
|
1885
|
+
c = json_meta[a];
|
1886
|
+
return (typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4));
|
1887
|
+
}) + '"';
|
1888
|
+
} else {
|
1889
|
+
return '"' + string + '"';
|
1890
|
+
}
|
1891
|
+
};
|
1892
|
+
json_str = function(key, holder) {
|
1893
|
+
var i, k, partial, v, value, _i, _len;
|
1894
|
+
value = holder[key];
|
1895
|
+
switch (typeof value) {
|
1896
|
+
case 'string':
|
1897
|
+
return json_quote(value);
|
1898
|
+
case 'number':
|
1899
|
+
if (isFinite(value)) {
|
1900
|
+
return String(value);
|
1901
|
+
} else {
|
1902
|
+
return 'null';
|
1903
|
+
}
|
1904
|
+
case 'boolean':
|
1905
|
+
case 'null':
|
1906
|
+
return String(value);
|
1907
|
+
case 'object':
|
1908
|
+
if (!value) {
|
1909
|
+
return 'null';
|
1910
|
+
}
|
1911
|
+
partial = [];
|
1912
|
+
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
1913
|
+
for (i = _i = 0, _len = value.length; _i < _len; i = ++_i) {
|
1914
|
+
v = value[i];
|
1915
|
+
partial[i] = json_str(i, value) || 'null';
|
1916
|
+
}
|
1917
|
+
return (partial.length === 0 ? '[]' : '[' + partial.join(',') + ']');
|
1918
|
+
}
|
1919
|
+
for (k in value) {
|
1920
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
1921
|
+
v = json_str(k, value);
|
1922
|
+
if (v) {
|
1923
|
+
partial.push(json_quote(k) + ':' + v);
|
1924
|
+
}
|
1925
|
+
}
|
1926
|
+
}
|
1927
|
+
return (partial.length === 0 ? '{}' : '{' + partial.join(',') + '}');
|
1928
|
+
}
|
1929
|
+
};
|
1930
|
+
if (this.JSON == null) {
|
1931
|
+
this.JSON = {};
|
1932
|
+
}
|
1933
|
+
this.JSON.stringify = function(value) {
|
1934
|
+
return json_str('', {
|
1935
|
+
'': value
|
1936
|
+
});
|
1937
|
+
};
|
1938
|
+
}
|
1939
|
+
|
1940
|
+
SaveStateHandler = (function() {
|
1941
|
+
function SaveStateHandler(tree_widget) {
|
1942
|
+
this.tree_widget = tree_widget;
|
1943
|
+
}
|
1944
|
+
|
1945
|
+
SaveStateHandler.prototype.saveState = function() {
|
1946
|
+
var state;
|
1947
|
+
state = JSON.stringify(this.getState());
|
1948
|
+
if (this.tree_widget.options.onSetStateFromStorage) {
|
1949
|
+
return this.tree_widget.options.onSetStateFromStorage(state);
|
1950
|
+
} else if (this.supportsLocalStorage()) {
|
1951
|
+
return localStorage.setItem(this.getCookieName(), state);
|
1952
|
+
} else if ($.cookie) {
|
1953
|
+
$.cookie.raw = true;
|
1954
|
+
return $.cookie(this.getCookieName(), state, {
|
1955
|
+
path: '/'
|
1956
|
+
});
|
1957
|
+
}
|
1958
|
+
};
|
1959
|
+
|
1960
|
+
SaveStateHandler.prototype.restoreState = function() {
|
1961
|
+
var state;
|
1962
|
+
state = this.getStateFromStorage();
|
1963
|
+
if (state) {
|
1964
|
+
this.setState($.parseJSON(state));
|
1965
|
+
return true;
|
1966
|
+
} else {
|
1967
|
+
return false;
|
1968
|
+
}
|
1969
|
+
};
|
1970
|
+
|
1971
|
+
SaveStateHandler.prototype.getStateFromStorage = function() {
|
1972
|
+
if (this.tree_widget.options.onGetStateFromStorage) {
|
1973
|
+
return this.tree_widget.options.onGetStateFromStorage();
|
1974
|
+
} else if (this.supportsLocalStorage()) {
|
1975
|
+
return localStorage.getItem(this.getCookieName());
|
1976
|
+
} else if ($.cookie) {
|
1977
|
+
$.cookie.raw = true;
|
1978
|
+
return $.cookie(this.getCookieName());
|
1979
|
+
} else {
|
1980
|
+
return null;
|
1981
|
+
}
|
1982
|
+
};
|
1983
|
+
|
1984
|
+
SaveStateHandler.prototype.getState = function() {
|
1985
|
+
var open_nodes, selected_node, selected_node_id;
|
1986
|
+
open_nodes = [];
|
1987
|
+
this.tree_widget.tree.iterate((function(_this) {
|
1988
|
+
return function(node) {
|
1989
|
+
if (node.is_open && node.id && node.hasChildren()) {
|
1990
|
+
open_nodes.push(node.id);
|
1991
|
+
}
|
1992
|
+
return true;
|
1993
|
+
};
|
1994
|
+
})(this));
|
1995
|
+
selected_node = this.tree_widget.getSelectedNode();
|
1996
|
+
if (selected_node) {
|
1997
|
+
selected_node_id = selected_node.id;
|
1998
|
+
} else {
|
1999
|
+
selected_node_id = '';
|
2000
|
+
}
|
2001
|
+
return {
|
2002
|
+
open_nodes: open_nodes,
|
2003
|
+
selected_node: selected_node_id
|
2004
|
+
};
|
2005
|
+
};
|
2006
|
+
|
2007
|
+
SaveStateHandler.prototype.setState = function(state) {
|
2008
|
+
var open_nodes, selected_node, selected_node_id;
|
2009
|
+
if (state) {
|
2010
|
+
open_nodes = state.open_nodes;
|
2011
|
+
selected_node_id = state.selected_node;
|
2012
|
+
this.tree_widget.tree.iterate((function(_this) {
|
2013
|
+
return function(node) {
|
2014
|
+
node.is_open = node.id && node.hasChildren() && (indexOf(open_nodes, node.id) >= 0);
|
2015
|
+
return true;
|
2016
|
+
};
|
2017
|
+
})(this));
|
2018
|
+
if (selected_node_id && this.tree_widget.select_node_handler) {
|
2019
|
+
this.tree_widget.select_node_handler.clear();
|
2020
|
+
selected_node = this.tree_widget.getNodeById(selected_node_id);
|
2021
|
+
if (selected_node) {
|
2022
|
+
return this.tree_widget.select_node_handler.addToSelection(selected_node);
|
2023
|
+
}
|
2024
|
+
}
|
2025
|
+
}
|
2026
|
+
};
|
2027
|
+
|
2028
|
+
SaveStateHandler.prototype.getCookieName = function() {
|
2029
|
+
if (typeof this.tree_widget.options.saveState === 'string') {
|
2030
|
+
return this.tree_widget.options.saveState;
|
2031
|
+
} else {
|
2032
|
+
return 'tree';
|
2033
|
+
}
|
2034
|
+
};
|
2035
|
+
|
2036
|
+
SaveStateHandler.prototype.supportsLocalStorage = function() {
|
2037
|
+
var testSupport;
|
2038
|
+
testSupport = function() {
|
2039
|
+
var error, key;
|
2040
|
+
if (typeof localStorage === "undefined" || localStorage === null) {
|
2041
|
+
return false;
|
2042
|
+
} else {
|
2043
|
+
try {
|
2044
|
+
key = '_storage_test';
|
2045
|
+
sessionStorage.setItem(key, true);
|
2046
|
+
sessionStorage.removeItem(key);
|
2047
|
+
} catch (_error) {
|
2048
|
+
error = _error;
|
2049
|
+
return false;
|
2050
|
+
}
|
2051
|
+
return true;
|
2052
|
+
}
|
2053
|
+
};
|
2054
|
+
if (this._supportsLocalStorage == null) {
|
2055
|
+
this._supportsLocalStorage = testSupport();
|
2056
|
+
}
|
2057
|
+
return this._supportsLocalStorage;
|
2058
|
+
};
|
2059
|
+
|
2060
|
+
SaveStateHandler.prototype.getNodeIdToBeSelected = function() {
|
2061
|
+
var state, state_json;
|
2062
|
+
state_json = this.getStateFromStorage();
|
2063
|
+
if (state_json) {
|
2064
|
+
state = $.parseJSON(state_json);
|
2065
|
+
return state.selected_node;
|
2066
|
+
} else {
|
2067
|
+
return null;
|
2068
|
+
}
|
2069
|
+
};
|
2070
|
+
|
2071
|
+
return SaveStateHandler;
|
2072
|
+
|
2073
|
+
})();
|
2074
|
+
|
2075
|
+
SelectNodeHandler = (function() {
|
2076
|
+
function SelectNodeHandler(tree_widget) {
|
2077
|
+
this.tree_widget = tree_widget;
|
2078
|
+
this.clear();
|
2079
|
+
}
|
2080
|
+
|
2081
|
+
SelectNodeHandler.prototype.getSelectedNode = function() {
|
2082
|
+
var selected_nodes;
|
2083
|
+
selected_nodes = this.getSelectedNodes();
|
2084
|
+
if (selected_nodes.length) {
|
2085
|
+
return selected_nodes[0];
|
2086
|
+
} else {
|
2087
|
+
return false;
|
2088
|
+
}
|
2089
|
+
};
|
2090
|
+
|
2091
|
+
SelectNodeHandler.prototype.getSelectedNodes = function() {
|
2092
|
+
var id, node, selected_nodes;
|
2093
|
+
if (this.selected_single_node) {
|
2094
|
+
return [this.selected_single_node];
|
2095
|
+
} else {
|
2096
|
+
selected_nodes = [];
|
2097
|
+
for (id in this.selected_nodes) {
|
2098
|
+
node = this.tree_widget.getNodeById(id);
|
2099
|
+
if (node) {
|
2100
|
+
selected_nodes.push(node);
|
2101
|
+
}
|
2102
|
+
}
|
2103
|
+
return selected_nodes;
|
2104
|
+
}
|
2105
|
+
};
|
2106
|
+
|
2107
|
+
SelectNodeHandler.prototype.getSelectedNodesUnder = function(parent) {
|
2108
|
+
var id, node, selected_nodes;
|
2109
|
+
if (this.selected_single_node) {
|
2110
|
+
if (parent.isParentOf(selected_single_node)) {
|
2111
|
+
return this.selected_single_node;
|
2112
|
+
} else {
|
2113
|
+
return null;
|
2114
|
+
}
|
2115
|
+
} else {
|
2116
|
+
selected_nodes = [];
|
2117
|
+
for (id in this.selected_nodes) {
|
2118
|
+
node = this.tree_widget.getNodeById(id);
|
2119
|
+
if (node && parent.isParentOf(node)) {
|
2120
|
+
selected_nodes.push(node);
|
2121
|
+
}
|
2122
|
+
}
|
2123
|
+
return selected_nodes;
|
2124
|
+
}
|
2125
|
+
};
|
2126
|
+
|
2127
|
+
SelectNodeHandler.prototype.isNodeSelected = function(node) {
|
2128
|
+
if (node.id) {
|
2129
|
+
return this.selected_nodes[node.id];
|
2130
|
+
} else if (this.selected_single_node) {
|
2131
|
+
return this.selected_single_node.element === node.element;
|
2132
|
+
} else {
|
2133
|
+
return false;
|
2134
|
+
}
|
2135
|
+
};
|
2136
|
+
|
2137
|
+
SelectNodeHandler.prototype.clear = function() {
|
2138
|
+
this.selected_nodes = {};
|
2139
|
+
return this.selected_single_node = null;
|
2140
|
+
};
|
2141
|
+
|
2142
|
+
SelectNodeHandler.prototype.removeFromSelection = function(node, include_children) {
|
2143
|
+
if (include_children == null) {
|
2144
|
+
include_children = false;
|
2145
|
+
}
|
2146
|
+
if (!node.id) {
|
2147
|
+
if (this.selected_single_node && node.element === this.selected_single_node.element) {
|
2148
|
+
return this.selected_single_node = null;
|
2149
|
+
}
|
2150
|
+
} else {
|
2151
|
+
delete this.selected_nodes[node.id];
|
2152
|
+
if (include_children) {
|
2153
|
+
return node.iterate((function(_this) {
|
2154
|
+
return function(n) {
|
2155
|
+
delete _this.selected_nodes[node.id];
|
2156
|
+
return true;
|
2157
|
+
};
|
2158
|
+
})(this));
|
2159
|
+
}
|
2160
|
+
}
|
2161
|
+
};
|
2162
|
+
|
2163
|
+
SelectNodeHandler.prototype.addToSelection = function(node) {
|
2164
|
+
if (node.id) {
|
2165
|
+
return this.selected_nodes[node.id] = true;
|
2166
|
+
} else {
|
2167
|
+
return this.selected_single_node = node;
|
2168
|
+
}
|
2169
|
+
};
|
2170
|
+
|
2171
|
+
return SelectNodeHandler;
|
2172
|
+
|
2173
|
+
})();
|
2174
|
+
|
2175
|
+
DragAndDropHandler = (function() {
|
2176
|
+
function DragAndDropHandler(tree_widget) {
|
2177
|
+
this.tree_widget = tree_widget;
|
2178
|
+
this.hovered_area = null;
|
2179
|
+
this.$ghost = null;
|
2180
|
+
this.hit_areas = [];
|
2181
|
+
this.is_dragging = false;
|
2182
|
+
}
|
2183
|
+
|
2184
|
+
DragAndDropHandler.prototype.mouseCapture = function(position_info) {
|
2185
|
+
var $element, node_element;
|
2186
|
+
$element = $(position_info.target);
|
2187
|
+
if (this.tree_widget.options.onIsMoveHandle && !this.tree_widget.options.onIsMoveHandle($element)) {
|
2188
|
+
return null;
|
2189
|
+
}
|
2190
|
+
node_element = this.tree_widget._getNodeElement($element);
|
2191
|
+
if (node_element && this.tree_widget.options.onCanMove) {
|
2192
|
+
if (!this.tree_widget.options.onCanMove(node_element.node)) {
|
2193
|
+
node_element = null;
|
2194
|
+
}
|
2195
|
+
}
|
2196
|
+
this.current_item = node_element;
|
2197
|
+
return this.current_item !== null;
|
2198
|
+
};
|
2199
|
+
|
2200
|
+
DragAndDropHandler.prototype.mouseStart = function(position_info) {
|
2201
|
+
var offset;
|
2202
|
+
this.refreshHitAreas();
|
2203
|
+
offset = $(position_info.target).offset();
|
2204
|
+
this.drag_element = new DragElement(this.current_item.node, position_info.page_x - offset.left, position_info.page_y - offset.top, this.tree_widget.element);
|
2205
|
+
this.is_dragging = true;
|
2206
|
+
this.current_item.$element.addClass('jqtree-moving');
|
2207
|
+
return true;
|
2208
|
+
};
|
2209
|
+
|
2210
|
+
DragAndDropHandler.prototype.mouseDrag = function(position_info) {
|
2211
|
+
var area, can_move_to;
|
2212
|
+
this.drag_element.move(position_info.page_x, position_info.page_y);
|
2213
|
+
area = this.findHoveredArea(position_info.page_x, position_info.page_y);
|
2214
|
+
can_move_to = this.canMoveToArea(area);
|
2215
|
+
if (can_move_to && area) {
|
2216
|
+
if (this.hovered_area !== area) {
|
2217
|
+
this.hovered_area = area;
|
2218
|
+
if (this.mustOpenFolderTimer(area)) {
|
2219
|
+
this.startOpenFolderTimer(area.node);
|
2220
|
+
}
|
2221
|
+
this.updateDropHint();
|
2222
|
+
}
|
2223
|
+
} else {
|
2224
|
+
this.removeHover();
|
2225
|
+
this.removeDropHint();
|
2226
|
+
this.stopOpenFolderTimer();
|
2227
|
+
}
|
2228
|
+
return true;
|
2229
|
+
};
|
2230
|
+
|
2231
|
+
DragAndDropHandler.prototype.canMoveToArea = function(area) {
|
2232
|
+
var position_name;
|
2233
|
+
if (!area) {
|
2234
|
+
return false;
|
2235
|
+
} else if (this.tree_widget.options.onCanMoveTo) {
|
2236
|
+
position_name = Position.getName(area.position);
|
2237
|
+
return this.tree_widget.options.onCanMoveTo(this.current_item.node, area.node, position_name);
|
2238
|
+
} else {
|
2239
|
+
return true;
|
2240
|
+
}
|
2241
|
+
};
|
2242
|
+
|
2243
|
+
DragAndDropHandler.prototype.mouseStop = function(position_info) {
|
2244
|
+
this.moveItem(position_info);
|
2245
|
+
this.clear();
|
2246
|
+
this.removeHover();
|
2247
|
+
this.removeDropHint();
|
2248
|
+
this.removeHitAreas();
|
2249
|
+
if (this.current_item) {
|
2250
|
+
this.current_item.$element.removeClass('jqtree-moving');
|
2251
|
+
}
|
2252
|
+
this.is_dragging = false;
|
2253
|
+
return false;
|
2254
|
+
};
|
2255
|
+
|
2256
|
+
DragAndDropHandler.prototype.refreshHitAreas = function() {
|
2257
|
+
this.removeHitAreas();
|
2258
|
+
return this.generateHitAreas();
|
2259
|
+
};
|
2260
|
+
|
2261
|
+
DragAndDropHandler.prototype.removeHitAreas = function() {
|
2262
|
+
return this.hit_areas = [];
|
2263
|
+
};
|
2264
|
+
|
2265
|
+
DragAndDropHandler.prototype.clear = function() {
|
2266
|
+
this.drag_element.remove();
|
2267
|
+
return this.drag_element = null;
|
2268
|
+
};
|
2269
|
+
|
2270
|
+
DragAndDropHandler.prototype.removeDropHint = function() {
|
2271
|
+
if (this.previous_ghost) {
|
2272
|
+
return this.previous_ghost.remove();
|
2273
|
+
}
|
2274
|
+
};
|
2275
|
+
|
2276
|
+
DragAndDropHandler.prototype.removeHover = function() {
|
2277
|
+
return this.hovered_area = null;
|
2278
|
+
};
|
2279
|
+
|
2280
|
+
DragAndDropHandler.prototype.generateHitAreas = function() {
|
2281
|
+
var hit_areas_generator;
|
2282
|
+
hit_areas_generator = new HitAreasGenerator(this.tree_widget.tree, this.current_item.node, this.getTreeDimensions().bottom);
|
2283
|
+
return this.hit_areas = hit_areas_generator.generate();
|
2284
|
+
};
|
2285
|
+
|
2286
|
+
DragAndDropHandler.prototype.findHoveredArea = function(x, y) {
|
2287
|
+
var area, dimensions, high, low, mid;
|
2288
|
+
dimensions = this.getTreeDimensions();
|
2289
|
+
if (x < dimensions.left || y < dimensions.top || x > dimensions.right || y > dimensions.bottom) {
|
2290
|
+
return null;
|
2291
|
+
}
|
2292
|
+
low = 0;
|
2293
|
+
high = this.hit_areas.length;
|
2294
|
+
while (low < high) {
|
2295
|
+
mid = (low + high) >> 1;
|
2296
|
+
area = this.hit_areas[mid];
|
2297
|
+
if (y < area.top) {
|
2298
|
+
high = mid;
|
2299
|
+
} else if (y > area.bottom) {
|
2300
|
+
low = mid + 1;
|
2301
|
+
} else {
|
2302
|
+
return area;
|
2303
|
+
}
|
2304
|
+
}
|
2305
|
+
return null;
|
2306
|
+
};
|
2307
|
+
|
2308
|
+
DragAndDropHandler.prototype.mustOpenFolderTimer = function(area) {
|
2309
|
+
var node;
|
2310
|
+
node = area.node;
|
2311
|
+
return node.isFolder() && !node.is_open && area.position === Position.INSIDE;
|
2312
|
+
};
|
2313
|
+
|
2314
|
+
DragAndDropHandler.prototype.updateDropHint = function() {
|
2315
|
+
var node_element;
|
2316
|
+
if (!this.hovered_area) {
|
2317
|
+
return;
|
2318
|
+
}
|
2319
|
+
this.removeDropHint();
|
2320
|
+
node_element = this.tree_widget._getNodeElementForNode(this.hovered_area.node);
|
2321
|
+
return this.previous_ghost = node_element.addDropHint(this.hovered_area.position);
|
2322
|
+
};
|
2323
|
+
|
2324
|
+
DragAndDropHandler.prototype.startOpenFolderTimer = function(folder) {
|
2325
|
+
var openFolder;
|
2326
|
+
openFolder = (function(_this) {
|
2327
|
+
return function() {
|
2328
|
+
return _this.tree_widget._openNode(folder, _this.tree_widget.options.slide, function() {
|
2329
|
+
_this.refreshHitAreas();
|
2330
|
+
return _this.updateDropHint();
|
2331
|
+
});
|
2332
|
+
};
|
2333
|
+
})(this);
|
2334
|
+
this.stopOpenFolderTimer();
|
2335
|
+
return this.open_folder_timer = setTimeout(openFolder, this.tree_widget.options.openFolderDelay);
|
2336
|
+
};
|
2337
|
+
|
2338
|
+
DragAndDropHandler.prototype.stopOpenFolderTimer = function() {
|
2339
|
+
if (this.open_folder_timer) {
|
2340
|
+
clearTimeout(this.open_folder_timer);
|
2341
|
+
return this.open_folder_timer = null;
|
2342
|
+
}
|
2343
|
+
};
|
2344
|
+
|
2345
|
+
DragAndDropHandler.prototype.moveItem = function(position_info) {
|
2346
|
+
var doMove, event, moved_node, position, previous_parent, target_node;
|
2347
|
+
if (this.hovered_area && this.hovered_area.position !== Position.NONE && this.canMoveToArea(this.hovered_area)) {
|
2348
|
+
moved_node = this.current_item.node;
|
2349
|
+
target_node = this.hovered_area.node;
|
2350
|
+
position = this.hovered_area.position;
|
2351
|
+
previous_parent = moved_node.parent;
|
2352
|
+
if (position === Position.INSIDE) {
|
2353
|
+
this.hovered_area.node.is_open = true;
|
2354
|
+
}
|
2355
|
+
doMove = (function(_this) {
|
2356
|
+
return function() {
|
2357
|
+
_this.tree_widget.tree.moveNode(moved_node, target_node, position);
|
2358
|
+
_this.tree_widget.element.empty();
|
2359
|
+
return _this.tree_widget._refreshElements();
|
2360
|
+
};
|
2361
|
+
})(this);
|
2362
|
+
event = this.tree_widget._triggerEvent('tree.move', {
|
2363
|
+
move_info: {
|
2364
|
+
moved_node: moved_node,
|
2365
|
+
target_node: target_node,
|
2366
|
+
position: Position.getName(position),
|
2367
|
+
previous_parent: previous_parent,
|
2368
|
+
do_move: doMove,
|
2369
|
+
original_event: position_info.original_event
|
2370
|
+
}
|
2371
|
+
});
|
2372
|
+
if (!event.isDefaultPrevented()) {
|
2373
|
+
return doMove();
|
2374
|
+
}
|
2375
|
+
}
|
2376
|
+
};
|
2377
|
+
|
2378
|
+
DragAndDropHandler.prototype.getTreeDimensions = function() {
|
2379
|
+
var offset;
|
2380
|
+
offset = this.tree_widget.element.offset();
|
2381
|
+
return {
|
2382
|
+
left: offset.left,
|
2383
|
+
top: offset.top,
|
2384
|
+
right: offset.left + this.tree_widget.element.width(),
|
2385
|
+
bottom: offset.top + this.tree_widget.element.height() + 16
|
2386
|
+
};
|
2387
|
+
};
|
2388
|
+
|
2389
|
+
return DragAndDropHandler;
|
2390
|
+
|
2391
|
+
})();
|
2392
|
+
|
2393
|
+
VisibleNodeIterator = (function() {
|
2394
|
+
function VisibleNodeIterator(tree) {
|
2395
|
+
this.tree = tree;
|
2396
|
+
}
|
2397
|
+
|
2398
|
+
VisibleNodeIterator.prototype.iterate = function() {
|
2399
|
+
var is_first_node, _iterateNode;
|
2400
|
+
is_first_node = true;
|
2401
|
+
_iterateNode = (function(_this) {
|
2402
|
+
return function(node, next_node) {
|
2403
|
+
var $element, child, children_length, i, must_iterate_inside, _i, _len, _ref;
|
2404
|
+
must_iterate_inside = (node.is_open || !node.element) && node.hasChildren();
|
2405
|
+
if (node.element) {
|
2406
|
+
$element = $(node.element);
|
2407
|
+
if (!$element.is(':visible')) {
|
2408
|
+
return;
|
2409
|
+
}
|
2410
|
+
if (is_first_node) {
|
2411
|
+
_this.handleFirstNode(node, $element);
|
2412
|
+
is_first_node = false;
|
2413
|
+
}
|
2414
|
+
if (!node.hasChildren()) {
|
2415
|
+
_this.handleNode(node, next_node, $element);
|
2416
|
+
} else if (node.is_open) {
|
2417
|
+
if (!_this.handleOpenFolder(node, $element)) {
|
2418
|
+
must_iterate_inside = false;
|
2419
|
+
}
|
2420
|
+
} else {
|
2421
|
+
_this.handleClosedFolder(node, next_node, $element);
|
2422
|
+
}
|
2423
|
+
}
|
2424
|
+
if (must_iterate_inside) {
|
2425
|
+
children_length = node.children.length;
|
2426
|
+
_ref = node.children;
|
2427
|
+
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
2428
|
+
child = _ref[i];
|
2429
|
+
if (i === (children_length - 1)) {
|
2430
|
+
_iterateNode(node.children[i], null);
|
2431
|
+
} else {
|
2432
|
+
_iterateNode(node.children[i], node.children[i + 1]);
|
2433
|
+
}
|
2434
|
+
}
|
2435
|
+
if (node.is_open) {
|
2436
|
+
return _this.handleAfterOpenFolder(node, next_node, $element);
|
2437
|
+
}
|
2438
|
+
}
|
2439
|
+
};
|
2440
|
+
})(this);
|
2441
|
+
return _iterateNode(this.tree, null);
|
2442
|
+
};
|
2443
|
+
|
2444
|
+
VisibleNodeIterator.prototype.handleNode = function(node, next_node, $element) {};
|
2445
|
+
|
2446
|
+
VisibleNodeIterator.prototype.handleOpenFolder = function(node, $element) {};
|
2447
|
+
|
2448
|
+
VisibleNodeIterator.prototype.handleClosedFolder = function(node, next_node, $element) {};
|
2449
|
+
|
2450
|
+
VisibleNodeIterator.prototype.handleAfterOpenFolder = function(node, next_node, $element) {};
|
2451
|
+
|
2452
|
+
VisibleNodeIterator.prototype.handleFirstNode = function(node, $element) {};
|
2453
|
+
|
2454
|
+
return VisibleNodeIterator;
|
2455
|
+
|
2456
|
+
})();
|
2457
|
+
|
2458
|
+
HitAreasGenerator = (function(_super) {
|
2459
|
+
__extends(HitAreasGenerator, _super);
|
2460
|
+
|
2461
|
+
function HitAreasGenerator(tree, current_node, tree_bottom) {
|
2462
|
+
HitAreasGenerator.__super__.constructor.call(this, tree);
|
2463
|
+
this.current_node = current_node;
|
2464
|
+
this.tree_bottom = tree_bottom;
|
2465
|
+
}
|
2466
|
+
|
2467
|
+
HitAreasGenerator.prototype.generate = function() {
|
2468
|
+
this.positions = [];
|
2469
|
+
this.last_top = 0;
|
2470
|
+
this.iterate();
|
2471
|
+
return this.generateHitAreas(this.positions);
|
2472
|
+
};
|
2473
|
+
|
2474
|
+
HitAreasGenerator.prototype.getTop = function($element) {
|
2475
|
+
return $element.offset().top;
|
2476
|
+
};
|
2477
|
+
|
2478
|
+
HitAreasGenerator.prototype.addPosition = function(node, position, top) {
|
2479
|
+
var area;
|
2480
|
+
area = {
|
2481
|
+
top: top,
|
2482
|
+
node: node,
|
2483
|
+
position: position
|
2484
|
+
};
|
2485
|
+
this.positions.push(area);
|
2486
|
+
return this.last_top = top;
|
2487
|
+
};
|
2488
|
+
|
2489
|
+
HitAreasGenerator.prototype.handleNode = function(node, next_node, $element) {
|
2490
|
+
var top;
|
2491
|
+
top = this.getTop($element);
|
2492
|
+
if (node === this.current_node) {
|
2493
|
+
this.addPosition(node, Position.NONE, top);
|
2494
|
+
} else {
|
2495
|
+
this.addPosition(node, Position.INSIDE, top);
|
2496
|
+
}
|
2497
|
+
if (next_node === this.current_node || node === this.current_node) {
|
2498
|
+
return this.addPosition(node, Position.NONE, top);
|
2499
|
+
} else {
|
2500
|
+
return this.addPosition(node, Position.AFTER, top);
|
2501
|
+
}
|
2502
|
+
};
|
2503
|
+
|
2504
|
+
HitAreasGenerator.prototype.handleOpenFolder = function(node, $element) {
|
2505
|
+
if (node === this.current_node) {
|
2506
|
+
return false;
|
2507
|
+
}
|
2508
|
+
if (node.children[0] !== this.current_node) {
|
2509
|
+
this.addPosition(node, Position.INSIDE, this.getTop($element));
|
2510
|
+
}
|
2511
|
+
return true;
|
2512
|
+
};
|
2513
|
+
|
2514
|
+
HitAreasGenerator.prototype.handleClosedFolder = function(node, next_node, $element) {
|
2515
|
+
var top;
|
2516
|
+
top = this.getTop($element);
|
2517
|
+
if (node === this.current_node) {
|
2518
|
+
return this.addPosition(node, Position.NONE, top);
|
2519
|
+
} else {
|
2520
|
+
this.addPosition(node, Position.INSIDE, top);
|
2521
|
+
if (next_node !== this.current_node) {
|
2522
|
+
return this.addPosition(node, Position.AFTER, top);
|
2523
|
+
}
|
2524
|
+
}
|
2525
|
+
};
|
2526
|
+
|
2527
|
+
HitAreasGenerator.prototype.handleFirstNode = function(node, $element) {
|
2528
|
+
if (node !== this.current_node) {
|
2529
|
+
return this.addPosition(node, Position.BEFORE, this.getTop($(node.element)));
|
2530
|
+
}
|
2531
|
+
};
|
2532
|
+
|
2533
|
+
HitAreasGenerator.prototype.handleAfterOpenFolder = function(node, next_node, $element) {
|
2534
|
+
if (node === this.current_node.node || next_node === this.current_node.node) {
|
2535
|
+
return this.addPosition(node, Position.NONE, this.last_top);
|
2536
|
+
} else {
|
2537
|
+
return this.addPosition(node, Position.AFTER, this.last_top);
|
2538
|
+
}
|
2539
|
+
};
|
2540
|
+
|
2541
|
+
HitAreasGenerator.prototype.generateHitAreas = function(positions) {
|
2542
|
+
var group, hit_areas, position, previous_top, _i, _len;
|
2543
|
+
previous_top = -1;
|
2544
|
+
group = [];
|
2545
|
+
hit_areas = [];
|
2546
|
+
for (_i = 0, _len = positions.length; _i < _len; _i++) {
|
2547
|
+
position = positions[_i];
|
2548
|
+
if (position.top !== previous_top && group.length) {
|
2549
|
+
if (group.length) {
|
2550
|
+
this.generateHitAreasForGroup(hit_areas, group, previous_top, position.top);
|
2551
|
+
}
|
2552
|
+
previous_top = position.top;
|
2553
|
+
group = [];
|
2554
|
+
}
|
2555
|
+
group.push(position);
|
2556
|
+
}
|
2557
|
+
this.generateHitAreasForGroup(hit_areas, group, previous_top, this.tree_bottom);
|
2558
|
+
return hit_areas;
|
2559
|
+
};
|
2560
|
+
|
2561
|
+
HitAreasGenerator.prototype.generateHitAreasForGroup = function(hit_areas, positions_in_group, top, bottom) {
|
2562
|
+
var area_height, area_top, i, position, position_count;
|
2563
|
+
position_count = Math.min(positions_in_group.length, 4);
|
2564
|
+
area_height = Math.round((bottom - top) / position_count);
|
2565
|
+
area_top = top;
|
2566
|
+
i = 0;
|
2567
|
+
while (i < position_count) {
|
2568
|
+
position = positions_in_group[i];
|
2569
|
+
hit_areas.push({
|
2570
|
+
top: area_top,
|
2571
|
+
bottom: area_top + area_height,
|
2572
|
+
node: position.node,
|
2573
|
+
position: position.position
|
2574
|
+
});
|
2575
|
+
area_top += area_height;
|
2576
|
+
i += 1;
|
2577
|
+
}
|
2578
|
+
return null;
|
2579
|
+
};
|
2580
|
+
|
2581
|
+
return HitAreasGenerator;
|
2582
|
+
|
2583
|
+
})(VisibleNodeIterator);
|
2584
|
+
|
2585
|
+
DragElement = (function() {
|
2586
|
+
function DragElement(node, offset_x, offset_y, $tree) {
|
2587
|
+
this.offset_x = offset_x;
|
2588
|
+
this.offset_y = offset_y;
|
2589
|
+
this.$element = $("<span class=\"jqtree-title jqtree-dragging\">" + node.name + "</span>");
|
2590
|
+
this.$element.css("position", "absolute");
|
2591
|
+
$tree.append(this.$element);
|
2592
|
+
}
|
2593
|
+
|
2594
|
+
DragElement.prototype.move = function(page_x, page_y) {
|
2595
|
+
return this.$element.offset({
|
2596
|
+
left: page_x - this.offset_x,
|
2597
|
+
top: page_y - this.offset_y
|
2598
|
+
});
|
2599
|
+
};
|
2600
|
+
|
2601
|
+
DragElement.prototype.remove = function() {
|
2602
|
+
return this.$element.remove();
|
2603
|
+
};
|
2604
|
+
|
2605
|
+
return DragElement;
|
2606
|
+
|
2607
|
+
})();
|
2608
|
+
|
2609
|
+
GhostDropHint = (function() {
|
2610
|
+
function GhostDropHint(node, $element, position) {
|
2611
|
+
this.$element = $element;
|
2612
|
+
this.node = node;
|
2613
|
+
this.$ghost = $('<li class="jqtree_common jqtree-ghost"><span class="jqtree_common jqtree-circle"></span><span class="jqtree_common jqtree-line"></span></li>');
|
2614
|
+
if (position === Position.AFTER) {
|
2615
|
+
this.moveAfter();
|
2616
|
+
} else if (position === Position.BEFORE) {
|
2617
|
+
this.moveBefore();
|
2618
|
+
} else if (position === Position.INSIDE) {
|
2619
|
+
if (node.isFolder() && node.is_open) {
|
2620
|
+
this.moveInsideOpenFolder();
|
2621
|
+
} else {
|
2622
|
+
this.moveInside();
|
2623
|
+
}
|
2624
|
+
}
|
2625
|
+
}
|
2626
|
+
|
2627
|
+
GhostDropHint.prototype.remove = function() {
|
2628
|
+
return this.$ghost.remove();
|
2629
|
+
};
|
2630
|
+
|
2631
|
+
GhostDropHint.prototype.moveAfter = function() {
|
2632
|
+
return this.$element.after(this.$ghost);
|
2633
|
+
};
|
2634
|
+
|
2635
|
+
GhostDropHint.prototype.moveBefore = function() {
|
2636
|
+
return this.$element.before(this.$ghost);
|
2637
|
+
};
|
2638
|
+
|
2639
|
+
GhostDropHint.prototype.moveInsideOpenFolder = function() {
|
2640
|
+
return $(this.node.children[0].element).before(this.$ghost);
|
2641
|
+
};
|
2642
|
+
|
2643
|
+
GhostDropHint.prototype.moveInside = function() {
|
2644
|
+
this.$element.after(this.$ghost);
|
2645
|
+
return this.$ghost.addClass('jqtree-inside');
|
2646
|
+
};
|
2647
|
+
|
2648
|
+
return GhostDropHint;
|
2649
|
+
|
2650
|
+
})();
|
2651
|
+
|
2652
|
+
BorderDropHint = (function() {
|
2653
|
+
function BorderDropHint($element) {
|
2654
|
+
var $div, width;
|
2655
|
+
$div = $element.children('.jqtree-element');
|
2656
|
+
width = $element.width() - 4;
|
2657
|
+
this.$hint = $('<span class="jqtree-border"></span>');
|
2658
|
+
$div.append(this.$hint);
|
2659
|
+
this.$hint.css({
|
2660
|
+
width: width,
|
2661
|
+
height: $div.height() - 4
|
2662
|
+
});
|
2663
|
+
}
|
2664
|
+
|
2665
|
+
BorderDropHint.prototype.remove = function() {
|
2666
|
+
return this.$hint.remove();
|
2667
|
+
};
|
2668
|
+
|
2669
|
+
return BorderDropHint;
|
2670
|
+
|
2671
|
+
})();
|
2672
|
+
|
2673
|
+
ScrollHandler = (function() {
|
2674
|
+
function ScrollHandler(tree_widget) {
|
2675
|
+
this.tree_widget = tree_widget;
|
2676
|
+
this.previous_top = -1;
|
2677
|
+
this._initScrollParent();
|
2678
|
+
}
|
2679
|
+
|
2680
|
+
ScrollHandler.prototype._initScrollParent = function() {
|
2681
|
+
var $scroll_parent, getParentWithOverflow, setDocumentAsScrollParent;
|
2682
|
+
getParentWithOverflow = (function(_this) {
|
2683
|
+
return function() {
|
2684
|
+
var css_values, el, hasOverFlow, _i, _len, _ref;
|
2685
|
+
css_values = ['overflow', 'overflow-y'];
|
2686
|
+
hasOverFlow = function(el) {
|
2687
|
+
var css_value, _i, _len, _ref;
|
2688
|
+
for (_i = 0, _len = css_values.length; _i < _len; _i++) {
|
2689
|
+
css_value = css_values[_i];
|
2690
|
+
if ((_ref = $.css(el, css_value)) === 'auto' || _ref === 'scroll') {
|
2691
|
+
return true;
|
2692
|
+
}
|
2693
|
+
}
|
2694
|
+
return false;
|
2695
|
+
};
|
2696
|
+
if (hasOverFlow(_this.tree_widget.$el[0])) {
|
2697
|
+
return _this.tree_widget.$el;
|
2698
|
+
}
|
2699
|
+
_ref = _this.tree_widget.$el.parents();
|
2700
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2701
|
+
el = _ref[_i];
|
2702
|
+
if (hasOverFlow(el)) {
|
2703
|
+
return $(el);
|
2704
|
+
}
|
2705
|
+
}
|
2706
|
+
return null;
|
2707
|
+
};
|
2708
|
+
})(this);
|
2709
|
+
setDocumentAsScrollParent = (function(_this) {
|
2710
|
+
return function() {
|
2711
|
+
_this.scroll_parent_top = 0;
|
2712
|
+
return _this.$scroll_parent = null;
|
2713
|
+
};
|
2714
|
+
})(this);
|
2715
|
+
if (this.tree_widget.$el.css('position') === 'fixed') {
|
2716
|
+
setDocumentAsScrollParent();
|
2717
|
+
}
|
2718
|
+
$scroll_parent = getParentWithOverflow();
|
2719
|
+
if ($scroll_parent && $scroll_parent.length && $scroll_parent[0].tagName !== 'HTML') {
|
2720
|
+
this.$scroll_parent = $scroll_parent;
|
2721
|
+
return this.scroll_parent_top = this.$scroll_parent.offset().top;
|
2722
|
+
} else {
|
2723
|
+
return setDocumentAsScrollParent();
|
2724
|
+
}
|
2725
|
+
};
|
2726
|
+
|
2727
|
+
ScrollHandler.prototype.checkScrolling = function() {
|
2728
|
+
var hovered_area;
|
2729
|
+
hovered_area = this.tree_widget.dnd_handler.hovered_area;
|
2730
|
+
if (hovered_area && hovered_area.top !== this.previous_top) {
|
2731
|
+
this.previous_top = hovered_area.top;
|
2732
|
+
if (this.$scroll_parent) {
|
2733
|
+
return this._handleScrollingWithScrollParent(hovered_area);
|
2734
|
+
} else {
|
2735
|
+
return this._handleScrollingWithDocument(hovered_area);
|
2736
|
+
}
|
2737
|
+
}
|
2738
|
+
};
|
2739
|
+
|
2740
|
+
ScrollHandler.prototype._handleScrollingWithScrollParent = function(area) {
|
2741
|
+
var distance_bottom;
|
2742
|
+
distance_bottom = this.scroll_parent_top + this.$scroll_parent[0].offsetHeight - area.bottom;
|
2743
|
+
if (distance_bottom < 20) {
|
2744
|
+
this.$scroll_parent[0].scrollTop += 20;
|
2745
|
+
this.tree_widget.refreshHitAreas();
|
2746
|
+
return this.previous_top = -1;
|
2747
|
+
} else if ((area.top - this.scroll_parent_top) < 20) {
|
2748
|
+
this.$scroll_parent[0].scrollTop -= 20;
|
2749
|
+
this.tree_widget.refreshHitAreas();
|
2750
|
+
return this.previous_top = -1;
|
2751
|
+
}
|
2752
|
+
};
|
2753
|
+
|
2754
|
+
ScrollHandler.prototype._handleScrollingWithDocument = function(area) {
|
2755
|
+
var distance_top;
|
2756
|
+
distance_top = area.top - $(document).scrollTop();
|
2757
|
+
if (distance_top < 20) {
|
2758
|
+
return $(document).scrollTop($(document).scrollTop() - 20);
|
2759
|
+
} else if ($(window).height() - (area.bottom - $(document).scrollTop()) < 20) {
|
2760
|
+
return $(document).scrollTop($(document).scrollTop() + 20);
|
2761
|
+
}
|
2762
|
+
};
|
2763
|
+
|
2764
|
+
ScrollHandler.prototype.scrollTo = function(top) {
|
2765
|
+
var tree_top;
|
2766
|
+
if (this.$scroll_parent) {
|
2767
|
+
return this.$scroll_parent[0].scrollTop = top;
|
2768
|
+
} else {
|
2769
|
+
tree_top = this.tree_widget.$el.offset().top;
|
2770
|
+
return $(document).scrollTop(top + tree_top);
|
2771
|
+
}
|
2772
|
+
};
|
2773
|
+
|
2774
|
+
ScrollHandler.prototype.isScrolledIntoView = function(element) {
|
2775
|
+
var $element, element_bottom, element_top, view_bottom, view_top;
|
2776
|
+
$element = $(element);
|
2777
|
+
if (this.$scroll_parent) {
|
2778
|
+
view_top = 0;
|
2779
|
+
view_bottom = this.$scroll_parent.height();
|
2780
|
+
element_top = $element.offset().top - this.scroll_parent_top;
|
2781
|
+
element_bottom = element_top + $element.height();
|
2782
|
+
} else {
|
2783
|
+
view_top = $(window).scrollTop();
|
2784
|
+
view_bottom = view_top + $(window).height();
|
2785
|
+
element_top = $element.offset().top;
|
2786
|
+
element_bottom = element_top + $element.height();
|
2787
|
+
}
|
2788
|
+
return (element_bottom <= view_bottom) && (element_top >= view_top);
|
2789
|
+
};
|
2790
|
+
|
2791
|
+
return ScrollHandler;
|
2792
|
+
|
2793
|
+
})();
|
2794
|
+
|
2795
|
+
KeyHandler = (function() {
|
2796
|
+
var DOWN, LEFT, RIGHT, UP;
|
2797
|
+
|
2798
|
+
LEFT = 37;
|
2799
|
+
|
2800
|
+
UP = 38;
|
2801
|
+
|
2802
|
+
RIGHT = 39;
|
2803
|
+
|
2804
|
+
DOWN = 40;
|
2805
|
+
|
2806
|
+
function KeyHandler(tree_widget) {
|
2807
|
+
this.tree_widget = tree_widget;
|
2808
|
+
if (tree_widget.options.keyboardSupport) {
|
2809
|
+
$(document).bind('keydown.jqtree', $.proxy(this.handleKeyDown, this));
|
2810
|
+
}
|
2811
|
+
}
|
2812
|
+
|
2813
|
+
KeyHandler.prototype.deinit = function() {
|
2814
|
+
return $(document).unbind('keydown.jqtree');
|
2815
|
+
};
|
2816
|
+
|
2817
|
+
KeyHandler.prototype.handleKeyDown = function(e) {
|
2818
|
+
var current_node, key, moveDown, moveLeft, moveRight, moveUp, selectNode;
|
2819
|
+
if (!this.tree_widget.options.keyboardSupport) {
|
2820
|
+
return;
|
2821
|
+
}
|
2822
|
+
if ($(document.activeElement).is('textarea,input')) {
|
2823
|
+
return true;
|
2824
|
+
}
|
2825
|
+
current_node = this.tree_widget.getSelectedNode();
|
2826
|
+
selectNode = (function(_this) {
|
2827
|
+
return function(node) {
|
2828
|
+
if (node) {
|
2829
|
+
_this.tree_widget.selectNode(node);
|
2830
|
+
if (_this.tree_widget.scroll_handler && (!_this.tree_widget.scroll_handler.isScrolledIntoView($(node.element).find('.jqtree-element')))) {
|
2831
|
+
_this.tree_widget.scrollToNode(node);
|
2832
|
+
}
|
2833
|
+
return false;
|
2834
|
+
} else {
|
2835
|
+
return true;
|
2836
|
+
}
|
2837
|
+
};
|
2838
|
+
})(this);
|
2839
|
+
moveDown = (function(_this) {
|
2840
|
+
return function() {
|
2841
|
+
return selectNode(_this.getNextNode(current_node));
|
2842
|
+
};
|
2843
|
+
})(this);
|
2844
|
+
moveUp = (function(_this) {
|
2845
|
+
return function() {
|
2846
|
+
return selectNode(_this.getPreviousNode(current_node));
|
2847
|
+
};
|
2848
|
+
})(this);
|
2849
|
+
moveRight = (function(_this) {
|
2850
|
+
return function() {
|
2851
|
+
if (current_node.isFolder() && !current_node.is_open) {
|
2852
|
+
_this.tree_widget.openNode(current_node);
|
2853
|
+
return false;
|
2854
|
+
} else {
|
2855
|
+
return true;
|
2856
|
+
}
|
2857
|
+
};
|
2858
|
+
})(this);
|
2859
|
+
moveLeft = (function(_this) {
|
2860
|
+
return function() {
|
2861
|
+
if (current_node.isFolder() && current_node.is_open) {
|
2862
|
+
_this.tree_widget.closeNode(current_node);
|
2863
|
+
return false;
|
2864
|
+
} else {
|
2865
|
+
return true;
|
2866
|
+
}
|
2867
|
+
};
|
2868
|
+
})(this);
|
2869
|
+
if (!current_node) {
|
2870
|
+
return true;
|
2871
|
+
} else {
|
2872
|
+
key = e.which;
|
2873
|
+
switch (key) {
|
2874
|
+
case DOWN:
|
2875
|
+
return moveDown();
|
2876
|
+
case UP:
|
2877
|
+
return moveUp();
|
2878
|
+
case RIGHT:
|
2879
|
+
return moveRight();
|
2880
|
+
case LEFT:
|
2881
|
+
return moveLeft();
|
2882
|
+
}
|
2883
|
+
}
|
2884
|
+
};
|
2885
|
+
|
2886
|
+
KeyHandler.prototype.getNextNode = function(node, include_children) {
|
2887
|
+
var next_sibling;
|
2888
|
+
if (include_children == null) {
|
2889
|
+
include_children = true;
|
2890
|
+
}
|
2891
|
+
if (include_children && node.hasChildren() && node.is_open) {
|
2892
|
+
return node.children[0];
|
2893
|
+
} else {
|
2894
|
+
if (!node.parent) {
|
2895
|
+
return null;
|
2896
|
+
} else {
|
2897
|
+
next_sibling = node.getNextSibling();
|
2898
|
+
if (next_sibling) {
|
2899
|
+
return next_sibling;
|
2900
|
+
} else {
|
2901
|
+
return this.getNextNode(node.parent, false);
|
2902
|
+
}
|
2903
|
+
}
|
2904
|
+
}
|
2905
|
+
};
|
2906
|
+
|
2907
|
+
KeyHandler.prototype.getPreviousNode = function(node) {
|
2908
|
+
var previous_sibling;
|
2909
|
+
if (!node.parent) {
|
2910
|
+
return null;
|
2911
|
+
} else {
|
2912
|
+
previous_sibling = node.getPreviousSibling();
|
2913
|
+
if (previous_sibling) {
|
2914
|
+
if (!previous_sibling.hasChildren() || !previous_sibling.is_open) {
|
2915
|
+
return previous_sibling;
|
2916
|
+
} else {
|
2917
|
+
return this.getLastChild(previous_sibling);
|
2918
|
+
}
|
2919
|
+
} else {
|
2920
|
+
if (node.parent.parent) {
|
2921
|
+
return node.parent;
|
2922
|
+
} else {
|
2923
|
+
return null;
|
2924
|
+
}
|
2925
|
+
}
|
2926
|
+
}
|
2927
|
+
};
|
2928
|
+
|
2929
|
+
KeyHandler.prototype.getLastChild = function(node) {
|
2930
|
+
var last_child;
|
2931
|
+
if (!node.hasChildren()) {
|
2932
|
+
return null;
|
2933
|
+
} else {
|
2934
|
+
last_child = node.children[node.children.length - 1];
|
2935
|
+
if (!last_child.hasChildren() || !last_child.is_open) {
|
2936
|
+
return last_child;
|
2937
|
+
} else {
|
2938
|
+
return this.getLastChild(last_child);
|
2939
|
+
}
|
2940
|
+
}
|
2941
|
+
};
|
2942
|
+
|
2943
|
+
return KeyHandler;
|
2944
|
+
|
2945
|
+
})();
|
2946
|
+
|
2947
|
+
}).call(this);
|