Initialize the UI code
[holmes/rule-management.git] / rulemgt / src / main / frontend / src / public / framework / browser / thirdparty / js / tree.jquery.js
1 /*
2  JqTree 1.3.6
3
4  Copyright 2015 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 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
19     var $, DragAndDropHandler, DragElement, HitAreasGenerator, Position, VisibleNodeIterator, node_module, util,
20         extend = 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; },
21         hasProp = {}.hasOwnProperty;
22
23     node_module = require('./node');
24
25     util = require('./util');
26
27     Position = node_module.Position;
28
29     $ = jQuery;
30
31     DragAndDropHandler = (function() {
32         function DragAndDropHandler(tree_widget) {
33             this.tree_widget = tree_widget;
34             this.hovered_area = null;
35             this.$ghost = null;
36             this.hit_areas = [];
37             this.is_dragging = false;
38             this.current_item = null;
39         }
40
41         DragAndDropHandler.prototype.mouseCapture = function(position_info) {
42             var $element, node_element;
43             $element = $(position_info.target);
44             if (!this.mustCaptureElement($element)) {
45                 return null;
46             }
47             if (this.tree_widget.options.onIsMoveHandle && !this.tree_widget.options.onIsMoveHandle($element)) {
48                 return null;
49             }
50             node_element = this.tree_widget._getNodeElement($element);
51             if (node_element && this.tree_widget.options.onCanMove) {
52                 if (!this.tree_widget.options.onCanMove(node_element.node)) {
53                     node_element = null;
54                 }
55             }
56             this.current_item = node_element;
57             return this.current_item !== null;
58         };
59
60         DragAndDropHandler.prototype.mouseStart = function(position_info) {
61             var node, node_name, offset;
62             this.refresh();
63             offset = $(position_info.target).offset();
64             node = this.current_item.node;
65             if (this.tree_widget.options.autoEscape) {
66                 node_name = util.html_escape(node.name);
67             } else {
68                 node_name = node.name;
69             }
70             this.drag_element = new DragElement(node_name, position_info.page_x - offset.left, position_info.page_y - offset.top, this.tree_widget.element);
71             this.is_dragging = true;
72             this.current_item.$element.addClass('jqtree-moving');
73             return true;
74         };
75
76         DragAndDropHandler.prototype.mouseDrag = function(position_info) {
77             var area, can_move_to;
78             this.drag_element.move(position_info.page_x, position_info.page_y);
79             area = this.findHoveredArea(position_info.page_x, position_info.page_y);
80             can_move_to = this.canMoveToArea(area);
81             if (can_move_to && area) {
82                 if (!area.node.isFolder()) {
83                     this.stopOpenFolderTimer();
84                 }
85                 if (this.hovered_area !== area) {
86                     this.hovered_area = area;
87                     if (this.mustOpenFolderTimer(area)) {
88                         this.startOpenFolderTimer(area.node);
89                     } else {
90                         this.stopOpenFolderTimer();
91                     }
92                     this.updateDropHint();
93                 }
94             } else {
95                 this.removeHover();
96                 this.removeDropHint();
97                 this.stopOpenFolderTimer();
98             }
99             if (!area) {
100                 if (this.tree_widget.options.onDragMove != null) {
101                     this.tree_widget.options.onDragMove(this.current_item.node, position_info.original_event);
102                 }
103             }
104             return true;
105         };
106
107         DragAndDropHandler.prototype.mustCaptureElement = function($element) {
108             return !$element.is('input,select,textarea');
109         };
110
111         DragAndDropHandler.prototype.canMoveToArea = function(area) {
112             var position_name;
113             if (!area) {
114                 return false;
115             } else if (this.tree_widget.options.onCanMoveTo) {
116                 position_name = Position.getName(area.position);
117                 return this.tree_widget.options.onCanMoveTo(this.current_item.node, area.node, position_name);
118             } else {
119                 return true;
120             }
121         };
122
123         DragAndDropHandler.prototype.mouseStop = function(position_info) {
124             var current_item;
125             this.moveItem(position_info);
126             this.clear();
127             this.removeHover();
128             this.removeDropHint();
129             this.removeHitAreas();
130             current_item = this.current_item;
131             if (this.current_item) {
132                 this.current_item.$element.removeClass('jqtree-moving');
133                 this.current_item = null;
134             }
135             this.is_dragging = false;
136             if (!this.hovered_area && current_item) {
137                 if (this.tree_widget.options.onDragStop != null) {
138                     this.tree_widget.options.onDragStop(current_item.node, position_info.original_event);
139                 }
140             }
141             return false;
142         };
143
144         DragAndDropHandler.prototype.refresh = function() {
145             this.removeHitAreas();
146             if (this.current_item) {
147                 this.generateHitAreas();
148                 this.current_item = this.tree_widget._getNodeElementForNode(this.current_item.node);
149                 if (this.is_dragging) {
150                     return this.current_item.$element.addClass('jqtree-moving');
151                 }
152             }
153         };
154
155         DragAndDropHandler.prototype.removeHitAreas = function() {
156             return this.hit_areas = [];
157         };
158
159         DragAndDropHandler.prototype.clear = function() {
160             this.drag_element.remove();
161             return this.drag_element = null;
162         };
163
164         DragAndDropHandler.prototype.removeDropHint = function() {
165             if (this.previous_ghost) {
166                 return this.previous_ghost.remove();
167             }
168         };
169
170         DragAndDropHandler.prototype.removeHover = function() {
171             return this.hovered_area = null;
172         };
173
174         DragAndDropHandler.prototype.generateHitAreas = function() {
175             var hit_areas_generator;
176             hit_areas_generator = new HitAreasGenerator(this.tree_widget.tree, this.current_item.node, this.getTreeDimensions().bottom);
177             return this.hit_areas = hit_areas_generator.generate();
178         };
179
180         DragAndDropHandler.prototype.findHoveredArea = function(x, y) {
181             var area, dimensions, high, low, mid;
182             dimensions = this.getTreeDimensions();
183             if (x < dimensions.left || y < dimensions.top || x > dimensions.right || y > dimensions.bottom) {
184                 return null;
185             }
186             low = 0;
187             high = this.hit_areas.length;
188             while (low < high) {
189                 mid = (low + high) >> 1;
190                 area = this.hit_areas[mid];
191                 if (y < area.top) {
192                     high = mid;
193                 } else if (y > area.bottom) {
194                     low = mid + 1;
195                 } else {
196                     return area;
197                 }
198             }
199             return null;
200         };
201
202         DragAndDropHandler.prototype.mustOpenFolderTimer = function(area) {
203             var node;
204             node = area.node;
205             return node.isFolder() && !node.is_open && area.position === Position.INSIDE;
206         };
207
208         DragAndDropHandler.prototype.updateDropHint = function() {
209             var node_element;
210             if (!this.hovered_area) {
211                 return;
212             }
213             this.removeDropHint();
214             node_element = this.tree_widget._getNodeElementForNode(this.hovered_area.node);
215             return this.previous_ghost = node_element.addDropHint(this.hovered_area.position);
216         };
217
218         DragAndDropHandler.prototype.startOpenFolderTimer = function(folder) {
219             var openFolder;
220             openFolder = (function(_this) {
221                 return function() {
222                     return _this.tree_widget._openNode(folder, _this.tree_widget.options.slide, function() {
223                         _this.refresh();
224                         return _this.updateDropHint();
225                     });
226                 };
227             })(this);
228             this.stopOpenFolderTimer();
229             return this.open_folder_timer = setTimeout(openFolder, this.tree_widget.options.openFolderDelay);
230         };
231
232         DragAndDropHandler.prototype.stopOpenFolderTimer = function() {
233             if (this.open_folder_timer) {
234                 clearTimeout(this.open_folder_timer);
235                 return this.open_folder_timer = null;
236             }
237         };
238
239         DragAndDropHandler.prototype.moveItem = function(position_info) {
240             var doMove, event, moved_node, position, previous_parent, target_node;
241             if (this.hovered_area && this.hovered_area.position !== Position.NONE && this.canMoveToArea(this.hovered_area)) {
242                 moved_node = this.current_item.node;
243                 target_node = this.hovered_area.node;
244                 position = this.hovered_area.position;
245                 previous_parent = moved_node.parent;
246                 if (position === Position.INSIDE) {
247                     this.hovered_area.node.is_open = true;
248                 }
249                 doMove = (function(_this) {
250                     return function() {
251                         _this.tree_widget.tree.moveNode(moved_node, target_node, position);
252                         _this.tree_widget.element.empty();
253                         return _this.tree_widget._refreshElements();
254                     };
255                 })(this);
256                 event = this.tree_widget._triggerEvent('tree.move', {
257                     move_info: {
258                         moved_node: moved_node,
259                         target_node: target_node,
260                         position: Position.getName(position),
261                         previous_parent: previous_parent,
262                         do_move: doMove,
263                         original_event: position_info.original_event
264                     }
265                 });
266                 if (!event.isDefaultPrevented()) {
267                     return doMove();
268                 }
269             }
270         };
271
272         DragAndDropHandler.prototype.getTreeDimensions = function() {
273             var offset;
274             offset = this.tree_widget.element.offset();
275             return {
276                 left: offset.left,
277                 top: offset.top,
278                 right: offset.left + this.tree_widget.element.width(),
279                 bottom: offset.top + this.tree_widget.element.height() + 16
280             };
281         };
282
283         return DragAndDropHandler;
284
285     })();
286
287     VisibleNodeIterator = (function() {
288         function VisibleNodeIterator(tree) {
289             this.tree = tree;
290         }
291
292         VisibleNodeIterator.prototype.iterate = function() {
293             var _iterateNode, is_first_node;
294             is_first_node = true;
295             _iterateNode = (function(_this) {
296                 return function(node, next_node) {
297                     var $element, child, children_length, i, j, len, must_iterate_inside, ref;
298                     must_iterate_inside = (node.is_open || !node.element) && node.hasChildren();
299                     if (node.element) {
300                         $element = $(node.element);
301                         if (!$element.is(':visible')) {
302                             return;
303                         }
304                         if (is_first_node) {
305                             _this.handleFirstNode(node, $element);
306                             is_first_node = false;
307                         }
308                         if (!node.hasChildren()) {
309                             _this.handleNode(node, next_node, $element);
310                         } else if (node.is_open) {
311                             if (!_this.handleOpenFolder(node, $element)) {
312                                 must_iterate_inside = false;
313                             }
314                         } else {
315                             _this.handleClosedFolder(node, next_node, $element);
316                         }
317                     }
318                     if (must_iterate_inside) {
319                         children_length = node.children.length;
320                         ref = node.children;
321                         for (i = j = 0, len = ref.length; j < len; i = ++j) {
322                             child = ref[i];
323                             if (i === (children_length - 1)) {
324                                 _iterateNode(node.children[i], null);
325                             } else {
326                                 _iterateNode(node.children[i], node.children[i + 1]);
327                             }
328                         }
329                         if (node.is_open) {
330                             return _this.handleAfterOpenFolder(node, next_node, $element);
331                         }
332                     }
333                 };
334             })(this);
335             return _iterateNode(this.tree, null);
336         };
337
338         VisibleNodeIterator.prototype.handleNode = function(node, next_node, $element) {};
339
340         VisibleNodeIterator.prototype.handleOpenFolder = function(node, $element) {};
341
342         VisibleNodeIterator.prototype.handleClosedFolder = function(node, next_node, $element) {};
343
344         VisibleNodeIterator.prototype.handleAfterOpenFolder = function(node, next_node, $element) {};
345
346         VisibleNodeIterator.prototype.handleFirstNode = function(node, $element) {};
347
348         return VisibleNodeIterator;
349
350     })();
351
352     HitAreasGenerator = (function(superClass) {
353         extend(HitAreasGenerator, superClass);
354
355         function HitAreasGenerator(tree, current_node, tree_bottom) {
356             HitAreasGenerator.__super__.constructor.call(this, tree);
357             this.current_node = current_node;
358             this.tree_bottom = tree_bottom;
359         }
360
361         HitAreasGenerator.prototype.generate = function() {
362             this.positions = [];
363             this.last_top = 0;
364             this.iterate();
365             return this.generateHitAreas(this.positions);
366         };
367
368         HitAreasGenerator.prototype.getTop = function($element) {
369             return $element.offset().top;
370         };
371
372         HitAreasGenerator.prototype.addPosition = function(node, position, top) {
373             var area;
374             area = {
375                 top: top,
376                 node: node,
377                 position: position
378             };
379             this.positions.push(area);
380             return this.last_top = top;
381         };
382
383         HitAreasGenerator.prototype.handleNode = function(node, next_node, $element) {
384             var top;
385             top = this.getTop($element);
386             if (node === this.current_node) {
387                 this.addPosition(node, Position.NONE, top);
388             } else {
389                 this.addPosition(node, Position.INSIDE, top);
390             }
391             if (next_node === this.current_node || node === this.current_node) {
392                 return this.addPosition(node, Position.NONE, top);
393             } else {
394                 return this.addPosition(node, Position.AFTER, top);
395             }
396         };
397
398         HitAreasGenerator.prototype.handleOpenFolder = function(node, $element) {
399             if (node === this.current_node) {
400                 return false;
401             }
402             if (node.children[0] !== this.current_node) {
403                 this.addPosition(node, Position.INSIDE, this.getTop($element));
404             }
405             return true;
406         };
407
408         HitAreasGenerator.prototype.handleClosedFolder = function(node, next_node, $element) {
409             var top;
410             top = this.getTop($element);
411             if (node === this.current_node) {
412                 return this.addPosition(node, Position.NONE, top);
413             } else {
414                 this.addPosition(node, Position.INSIDE, top);
415                 if (next_node !== this.current_node) {
416                     return this.addPosition(node, Position.AFTER, top);
417                 }
418             }
419         };
420
421         HitAreasGenerator.prototype.handleFirstNode = function(node, $element) {
422             if (node !== this.current_node) {
423                 return this.addPosition(node, Position.BEFORE, this.getTop($(node.element)));
424             }
425         };
426
427         HitAreasGenerator.prototype.handleAfterOpenFolder = function(node, next_node, $element) {
428             if (node === this.current_node.node || next_node === this.current_node.node) {
429                 return this.addPosition(node, Position.NONE, this.last_top);
430             } else {
431                 return this.addPosition(node, Position.AFTER, this.last_top);
432             }
433         };
434
435         HitAreasGenerator.prototype.generateHitAreas = function(positions) {
436             var group, hit_areas, j, len, position, previous_top;
437             previous_top = -1;
438             group = [];
439             hit_areas = [];
440             for (j = 0, len = positions.length; j < len; j++) {
441                 position = positions[j];
442                 if (position.top !== previous_top && group.length) {
443                     if (group.length) {
444                         this.generateHitAreasForGroup(hit_areas, group, previous_top, position.top);
445                     }
446                     previous_top = position.top;
447                     group = [];
448                 }
449                 group.push(position);
450             }
451             this.generateHitAreasForGroup(hit_areas, group, previous_top, this.tree_bottom);
452             return hit_areas;
453         };
454
455         HitAreasGenerator.prototype.generateHitAreasForGroup = function(hit_areas, positions_in_group, top, bottom) {
456             var area_height, area_top, i, position, position_count;
457             position_count = Math.min(positions_in_group.length, 4);
458             area_height = Math.round((bottom - top) / position_count);
459             area_top = top;
460             i = 0;
461             while (i < position_count) {
462                 position = positions_in_group[i];
463                 hit_areas.push({
464                     top: area_top,
465                     bottom: area_top + area_height,
466                     node: position.node,
467                     position: position.position
468                 });
469                 area_top += area_height;
470                 i += 1;
471             }
472             return null;
473         };
474
475         return HitAreasGenerator;
476
477     })(VisibleNodeIterator);
478
479     DragElement = (function() {
480         function DragElement(node_name, offset_x, offset_y, $tree) {
481             this.offset_x = offset_x;
482             this.offset_y = offset_y;
483             this.$element = $("<span class=\"jqtree-title jqtree-dragging\">" + node_name + "</span>");
484             this.$element.css("position", "absolute");
485             $tree.append(this.$element);
486         }
487
488         DragElement.prototype.move = function(page_x, page_y) {
489             return this.$element.offset({
490                 left: page_x - this.offset_x,
491                 top: page_y - this.offset_y
492             });
493         };
494
495         DragElement.prototype.remove = function() {
496             return this.$element.remove();
497         };
498
499         return DragElement;
500
501     })();
502
503     module.exports = {
504         DragAndDropHandler: DragAndDropHandler,
505         DragElement: DragElement,
506         HitAreasGenerator: HitAreasGenerator
507     };
508
509 },{"./node":5,"./util":12}],2:[function(require,module,exports){
510     var $, ElementsRenderer, NodeElement, html_escape, node_element, util;
511
512     node_element = require('./node_element');
513
514     NodeElement = node_element.NodeElement;
515
516     util = require('./util');
517
518     html_escape = util.html_escape;
519
520     $ = jQuery;
521
522     ElementsRenderer = (function() {
523         function ElementsRenderer(tree_widget) {
524             this.tree_widget = tree_widget;
525             this.opened_icon_element = this.createButtonElement(tree_widget.options.openedIcon);
526             this.closed_icon_element = this.createButtonElement(tree_widget.options.closedIcon);
527         }
528
529         ElementsRenderer.prototype.render = function(from_node) {
530             if (from_node && from_node.parent) {
531                 return this.renderFromNode(from_node);
532             } else {
533                 return this.renderFromRoot();
534             }
535         };
536
537         ElementsRenderer.prototype.renderFromRoot = function() {
538             var $element;
539             $element = this.tree_widget.element;
540             $element.empty();
541             return this.createDomElements($element[0], this.tree_widget.tree.children, true, true, 1);
542         };
543
544         ElementsRenderer.prototype.renderFromNode = function(node) {
545             var $previous_li, li;
546             $previous_li = $(node.element);
547             li = this.createLi(node, node.getLevel());
548             this.attachNodeData(node, li);
549             $previous_li.after(li);
550             $previous_li.remove();
551             if (node.children) {
552                 return this.createDomElements(li, node.children, false, false, node.getLevel() + 1);
553             }
554         };
555
556         ElementsRenderer.prototype.createDomElements = function(element, children, is_root_node, is_open, level) {
557             var child, i, len, li, ul;
558             ul = this.createUl(is_root_node);
559             element.appendChild(ul);
560             for (i = 0, len = children.length; i < len; i++) {
561                 child = children[i];
562                 li = this.createLi(child, level);
563                 ul.appendChild(li);
564                 this.attachNodeData(child, li);
565                 if (child.hasChildren()) {
566                     this.createDomElements(li, child.children, false, child.is_open, level + 1);
567                 }
568             }
569             return null;
570         };
571
572         ElementsRenderer.prototype.attachNodeData = function(node, li) {
573             node.element = li;
574             return $(li).data('node', node);
575         };
576
577         ElementsRenderer.prototype.createUl = function(is_root_node) {
578             var class_string, role, ul;
579             if (!is_root_node) {
580                 class_string = '';
581                 role = 'group';
582             } else {
583                 class_string = 'jqtree-tree';
584                 role = 'tree';
585                 if (this.tree_widget.options.rtl) {
586                     class_string += ' jqtree-rtl';
587                 }
588             }
589             ul = document.createElement('ul');
590             ul.className = "jqtree_common " + class_string;
591             ul.setAttribute('role', role);
592             return ul;
593         };
594
595         ElementsRenderer.prototype.createLi = function(node, level) {
596             var is_selected, li;
597             is_selected = this.tree_widget.select_node_handler && this.tree_widget.select_node_handler.isNodeSelected(node);
598             if (node.isFolder()) {
599                 li = this.createFolderLi(node, level, is_selected);
600             } else {
601                 li = this.createNodeLi(node, level, is_selected);
602             }
603             if (this.tree_widget.options.onCreateLi) {
604                 this.tree_widget.options.onCreateLi(node, $(li));
605             }
606             return li;
607         };
608
609         ElementsRenderer.prototype.createFolderLi = function(node, level, is_selected) {
610             var button_classes, button_link, div, folder_classes, icon_element, is_folder, li;
611             button_classes = this.getButtonClasses(node);
612             folder_classes = this.getFolderClasses(node, is_selected);
613             if (node.is_open) {
614                 icon_element = this.opened_icon_element;
615             } else {
616                 icon_element = this.closed_icon_element;
617             }
618             li = document.createElement('li');
619             li.className = "jqtree_common " + folder_classes;
620             li.setAttribute('role', 'presentation');
621             div = document.createElement('div');
622             div.className = "jqtree-element jqtree_common";
623             div.setAttribute('role', 'presentation');
624             li.appendChild(div);
625             button_link = document.createElement('a');
626             button_link.className = button_classes;
627             button_link.appendChild(icon_element.cloneNode(false));
628             button_link.setAttribute('role', 'presentation');
629             button_link.setAttribute('aria-hidden', 'true');
630             if (this.tree_widget.options.buttonLeft) {
631                 div.appendChild(button_link);
632             }
633             div.appendChild(this.createTitleSpan(node.name, level, is_selected, node.is_open, is_folder = true));
634             if (!this.tree_widget.options.buttonLeft) {
635                 div.appendChild(button_link);
636             }
637             return li;
638         };
639
640         ElementsRenderer.prototype.createNodeLi = function(node, level, is_selected) {
641             var class_string, div, is_folder, li, li_classes;
642             li_classes = ['jqtree_common'];
643             if (is_selected) {
644                 li_classes.push('jqtree-selected');
645             }
646             class_string = li_classes.join(' ');
647             li = document.createElement('li');
648             li.className = class_string;
649             li.setAttribute('role', 'presentation');
650             div = document.createElement('div');
651             div.className = "jqtree-element jqtree_common";
652             div.setAttribute('role', 'presentation');
653             li.appendChild(div);
654             div.appendChild(this.createTitleSpan(node.name, level, is_selected, node.is_open, is_folder = false));
655             return li;
656         };
657
658         ElementsRenderer.prototype.createTitleSpan = function(node_name, level, is_selected, is_open, is_folder) {
659             var classes, title_span;
660             title_span = document.createElement('span');
661             classes = "jqtree-title jqtree_common";
662             if (is_folder) {
663                 classes += " jqtree-title-folder";
664             }
665             title_span.className = classes;
666             title_span.setAttribute('role', 'treeitem');
667             title_span.setAttribute('aria-level', level);
668             title_span.setAttribute('aria-selected', util.getBoolString(is_selected));
669             title_span.setAttribute('aria-expanded', util.getBoolString(is_open));
670             if (is_selected) {
671                 title_span.setAttribute('tabindex', 0);
672             }
673             title_span.innerHTML = this.escapeIfNecessary(node_name);
674             return title_span;
675         };
676
677         ElementsRenderer.prototype.getButtonClasses = function(node) {
678             var classes;
679             classes = ['jqtree-toggler', 'jqtree_common'];
680             if (!node.is_open) {
681                 classes.push('jqtree-closed');
682             }
683             if (this.tree_widget.options.buttonLeft) {
684                 classes.push('jqtree-toggler-left');
685             } else {
686                 classes.push('jqtree-toggler-right');
687             }
688             return classes.join(' ');
689         };
690
691         ElementsRenderer.prototype.getFolderClasses = function(node, is_selected) {
692             var classes;
693             classes = ['jqtree-folder'];
694             if (!node.is_open) {
695                 classes.push('jqtree-closed');
696             }
697             if (is_selected) {
698                 classes.push('jqtree-selected');
699             }
700             if (node.is_loading) {
701                 classes.push('jqtree-loading');
702             }
703             return classes.join(' ');
704         };
705
706         ElementsRenderer.prototype.escapeIfNecessary = function(value) {
707             if (this.tree_widget.options.autoEscape) {
708                 return html_escape(value);
709             } else {
710                 return value;
711             }
712         };
713
714         ElementsRenderer.prototype.createButtonElement = function(value) {
715             var div;
716             if (typeof value === 'string') {
717                 div = document.createElement('div');
718                 div.innerHTML = value;
719                 return document.createTextNode(div.innerHTML);
720             } else {
721                 return $(value)[0];
722             }
723         };
724
725         return ElementsRenderer;
726
727     })();
728
729     module.exports = ElementsRenderer;
730
731 },{"./node_element":6,"./util":12}],3:[function(require,module,exports){
732     var $, KeyHandler,
733         bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
734
735     $ = jQuery;
736
737     KeyHandler = (function() {
738         var DOWN, LEFT, RIGHT, UP;
739
740         LEFT = 37;
741
742         UP = 38;
743
744         RIGHT = 39;
745
746         DOWN = 40;
747
748         function KeyHandler(tree_widget) {
749             this.selectNode = bind(this.selectNode, this);
750             this.tree_widget = tree_widget;
751             if (tree_widget.options.keyboardSupport) {
752                 $(document).bind('keydown.jqtree', $.proxy(this.handleKeyDown, this));
753             }
754         }
755
756         KeyHandler.prototype.deinit = function() {
757             return $(document).unbind('keydown.jqtree');
758         };
759
760         KeyHandler.prototype.moveDown = function() {
761             var node;
762             node = this.tree_widget.getSelectedNode();
763             if (node) {
764                 return this.selectNode(node.getNextNode());
765             } else {
766                 return false;
767             }
768         };
769
770         KeyHandler.prototype.moveUp = function() {
771             var node;
772             node = this.tree_widget.getSelectedNode();
773             if (node) {
774                 return this.selectNode(node.getPreviousNode());
775             } else {
776                 return false;
777             }
778         };
779
780         KeyHandler.prototype.moveRight = function() {
781             var node;
782             node = this.tree_widget.getSelectedNode();
783             if (!node) {
784                 return true;
785             } else if (!node.isFolder()) {
786                 return true;
787             } else {
788                 if (node.is_open) {
789                     return this.selectNode(node.getNextNode());
790                 } else {
791                     this.tree_widget.openNode(node);
792                     return false;
793                 }
794             }
795         };
796
797         KeyHandler.prototype.moveLeft = function() {
798             var node;
799             node = this.tree_widget.getSelectedNode();
800             if (!node) {
801                 return true;
802             } else if (node.isFolder() && node.is_open) {
803                 this.tree_widget.closeNode(node);
804                 return false;
805             } else {
806                 return this.selectNode(node.getParent());
807             }
808         };
809
810         KeyHandler.prototype.handleKeyDown = function(e) {
811             var key;
812             if (!this.tree_widget.options.keyboardSupport) {
813                 return true;
814             }
815             if ($(document.activeElement).is('textarea,input,select')) {
816                 return true;
817             }
818             if (!this.tree_widget.getSelectedNode()) {
819                 return true;
820             }
821             key = e.which;
822             switch (key) {
823                 case DOWN:
824                     return this.moveDown();
825                 case UP:
826                     return this.moveUp();
827                 case RIGHT:
828                     return this.moveRight();
829                 case LEFT:
830                     return this.moveLeft();
831             }
832             return true;
833         };
834
835         KeyHandler.prototype.selectNode = function(node) {
836             if (!node) {
837                 return true;
838             } else {
839                 this.tree_widget.selectNode(node);
840                 if (this.tree_widget.scroll_handler && (!this.tree_widget.scroll_handler.isScrolledIntoView($(node.element).find('.jqtree-element')))) {
841                     this.tree_widget.scrollToNode(node);
842                 }
843                 return false;
844             }
845         };
846
847         return KeyHandler;
848
849     })();
850
851     module.exports = KeyHandler;
852
853 },{}],4:[function(require,module,exports){
854
855     /*
856      This widget does the same a the mouse widget in jqueryui.
857      */
858     var $, MouseWidget, SimpleWidget,
859         extend = 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; },
860         hasProp = {}.hasOwnProperty;
861
862     SimpleWidget = require('./simple.widget');
863
864     $ = jQuery;
865
866     MouseWidget = (function(superClass) {
867         extend(MouseWidget, superClass);
868
869         function MouseWidget() {
870             return MouseWidget.__super__.constructor.apply(this, arguments);
871         }
872
873         MouseWidget.is_mouse_handled = false;
874
875         MouseWidget.prototype._init = function() {
876             this.$el.bind('mousedown.mousewidget', $.proxy(this._mouseDown, this));
877             this.$el.bind('touchstart.mousewidget', $.proxy(this._touchStart, this));
878             this.is_mouse_started = false;
879             this.mouse_delay = 0;
880             this._mouse_delay_timer = null;
881             this._is_mouse_delay_met = true;
882             return this.mouse_down_info = null;
883         };
884
885         MouseWidget.prototype._deinit = function() {
886             var $document;
887             this.$el.unbind('mousedown.mousewidget');
888             this.$el.unbind('touchstart.mousewidget');
889             $document = $(document);
890             $document.unbind('mousemove.mousewidget');
891             return $document.unbind('mouseup.mousewidget');
892         };
893
894         MouseWidget.prototype._mouseDown = function(e) {
895             var result;
896             if (e.which !== 1) {
897                 return;
898             }
899             result = this._handleMouseDown(e, this._getPositionInfo(e));
900             if (result) {
901                 e.preventDefault();
902             }
903             return result;
904         };
905
906         MouseWidget.prototype._handleMouseDown = function(e, position_info) {
907             if (MouseWidget.is_mouse_handled) {
908                 return;
909             }
910             if (this.is_mouse_started) {
911                 this._handleMouseUp(position_info);
912             }
913             this.mouse_down_info = position_info;
914             if (!this._mouseCapture(position_info)) {
915                 return;
916             }
917             this._handleStartMouse();
918             this.is_mouse_handled = true;
919             return true;
920         };
921
922         MouseWidget.prototype._handleStartMouse = function() {
923             var $document;
924             $document = $(document);
925             $document.bind('mousemove.mousewidget', $.proxy(this._mouseMove, this));
926             $document.bind('touchmove.mousewidget', $.proxy(this._touchMove, this));
927             $document.bind('mouseup.mousewidget', $.proxy(this._mouseUp, this));
928             $document.bind('touchend.mousewidget', $.proxy(this._touchEnd, this));
929             if (this.mouse_delay) {
930                 return this._startMouseDelayTimer();
931             }
932         };
933
934         MouseWidget.prototype._startMouseDelayTimer = function() {
935             if (this._mouse_delay_timer) {
936                 clearTimeout(this._mouse_delay_timer);
937             }
938             this._mouse_delay_timer = setTimeout((function(_this) {
939                 return function() {
940                     return _this._is_mouse_delay_met = true;
941                 };
942             })(this), this.mouse_delay);
943             return this._is_mouse_delay_met = false;
944         };
945
946         MouseWidget.prototype._mouseMove = function(e) {
947             return this._handleMouseMove(e, this._getPositionInfo(e));
948         };
949
950         MouseWidget.prototype._handleMouseMove = function(e, position_info) {
951             if (this.is_mouse_started) {
952                 this._mouseDrag(position_info);
953                 return e.preventDefault();
954             }
955             if (this.mouse_delay && !this._is_mouse_delay_met) {
956                 return true;
957             }
958             this.is_mouse_started = this._mouseStart(this.mouse_down_info) !== false;
959             if (this.is_mouse_started) {
960                 this._mouseDrag(position_info);
961             } else {
962                 this._handleMouseUp(position_info);
963             }
964             return !this.is_mouse_started;
965         };
966
967         MouseWidget.prototype._getPositionInfo = function(e) {
968             return {
969                 page_x: e.pageX,
970                 page_y: e.pageY,
971                 target: e.target,
972                 original_event: e
973             };
974         };
975
976         MouseWidget.prototype._mouseUp = function(e) {
977             return this._handleMouseUp(this._getPositionInfo(e));
978         };
979
980         MouseWidget.prototype._handleMouseUp = function(position_info) {
981             var $document;
982             $document = $(document);
983             $document.unbind('mousemove.mousewidget');
984             $document.unbind('touchmove.mousewidget');
985             $document.unbind('mouseup.mousewidget');
986             $document.unbind('touchend.mousewidget');
987             if (this.is_mouse_started) {
988                 this.is_mouse_started = false;
989                 this._mouseStop(position_info);
990             }
991         };
992
993         MouseWidget.prototype._mouseCapture = function(position_info) {
994             return true;
995         };
996
997         MouseWidget.prototype._mouseStart = function(position_info) {
998             return null;
999         };
1000
1001         MouseWidget.prototype._mouseDrag = function(position_info) {
1002             return null;
1003         };
1004
1005         MouseWidget.prototype._mouseStop = function(position_info) {
1006             return null;
1007         };
1008
1009         MouseWidget.prototype.setMouseDelay = function(mouse_delay) {
1010             return this.mouse_delay = mouse_delay;
1011         };
1012
1013         MouseWidget.prototype._touchStart = function(e) {
1014             var touch;
1015             if (e.originalEvent.touches.length > 1) {
1016                 return;
1017             }
1018             touch = e.originalEvent.changedTouches[0];
1019             return this._handleMouseDown(e, this._getPositionInfo(touch));
1020         };
1021
1022         MouseWidget.prototype._touchMove = function(e) {
1023             var touch;
1024             if (e.originalEvent.touches.length > 1) {
1025                 return;
1026             }
1027             touch = e.originalEvent.changedTouches[0];
1028             return this._handleMouseMove(e, this._getPositionInfo(touch));
1029         };
1030
1031         MouseWidget.prototype._touchEnd = function(e) {
1032             var touch;
1033             if (e.originalEvent.touches.length > 1) {
1034                 return;
1035             }
1036             touch = e.originalEvent.changedTouches[0];
1037             return this._handleMouseUp(this._getPositionInfo(touch));
1038         };
1039
1040         return MouseWidget;
1041
1042     })(SimpleWidget);
1043
1044     module.exports = MouseWidget;
1045
1046 },{"./simple.widget":10}],5:[function(require,module,exports){
1047     var $, Node, Position;
1048
1049     $ = jQuery;
1050
1051     Position = {
1052         getName: function(position) {
1053             return Position.strings[position - 1];
1054         },
1055         nameToIndex: function(name) {
1056             var i, j, ref;
1057             for (i = j = 1, ref = Position.strings.length; 1 <= ref ? j <= ref : j >= ref; i = 1 <= ref ? ++j : --j) {
1058                 if (Position.strings[i - 1] === name) {
1059                     return i;
1060                 }
1061             }
1062             return 0;
1063         }
1064     };
1065
1066     Position.BEFORE = 1;
1067
1068     Position.AFTER = 2;
1069
1070     Position.INSIDE = 3;
1071
1072     Position.NONE = 4;
1073
1074     Position.strings = ['before', 'after', 'inside', 'none'];
1075
1076     Node = (function() {
1077         function Node(o, is_root, node_class) {
1078             if (is_root == null) {
1079                 is_root = false;
1080             }
1081             if (node_class == null) {
1082                 node_class = Node;
1083             }
1084             this.name = '';
1085             this.setData(o);
1086             this.children = [];
1087             this.parent = null;
1088             if (is_root) {
1089                 this.id_mapping = {};
1090                 this.tree = this;
1091                 this.node_class = node_class;
1092             }
1093         }
1094
1095         Node.prototype.setData = function(o) {
1096
1097             /*
1098              Set the data of this node.
1099
1100              setData(string): set the name of the node
1101              setdata(object): set attributes of the node
1102
1103              Examples:
1104              setdata('node1')
1105
1106              setData({ name: 'node1', id: 1});
1107
1108              setData({ name: 'node2', id: 2, color: 'green'});
1109
1110              * This is an internal function; it is not in the docs
1111              * Does not remove existing node values
1112              */
1113             var key, setName, value;
1114             setName = (function(_this) {
1115                 return function(name) {
1116                     if (name !== null) {
1117                         return _this.name = name;
1118                     }
1119                 };
1120             })(this);
1121             if (typeof o !== 'object') {
1122                 setName(o);
1123             } else {
1124                 for (key in o) {
1125                     value = o[key];
1126                     if (key === 'label') {
1127                         setName(value);
1128                     } else if (key !== 'children') {
1129                         this[key] = value;
1130                     }
1131                 }
1132             }
1133             return null;
1134         };
1135
1136         Node.prototype.initFromData = function(data) {
1137             var addChildren, addNode;
1138             addNode = (function(_this) {
1139                 return function(node_data) {
1140                     _this.setData(node_data);
1141                     if (node_data.children) {
1142                         return addChildren(node_data.children);
1143                     }
1144                 };
1145             })(this);
1146             addChildren = (function(_this) {
1147                 return function(children_data) {
1148                     var child, j, len, node;
1149                     for (j = 0, len = children_data.length; j < len; j++) {
1150                         child = children_data[j];
1151                         node = new _this.tree.node_class('');
1152                         node.initFromData(child);
1153                         _this.addChild(node);
1154                     }
1155                     return null;
1156                 };
1157             })(this);
1158             addNode(data);
1159             return null;
1160         };
1161
1162
1163         /*
1164          Create tree from data.
1165
1166          Structure of data is:
1167          [
1168          {
1169          label: 'node1',
1170          children: [
1171          { label: 'child1' },
1172          { label: 'child2' }
1173          ]
1174          },
1175          {
1176          label: 'node2'
1177          }
1178          ]
1179          */
1180
1181         Node.prototype.loadFromData = function(data) {
1182             var j, len, node, o;
1183             this.removeChildren();
1184             for (j = 0, len = data.length; j < len; j++) {
1185                 o = data[j];
1186                 node = new this.tree.node_class(o);
1187                 this.addChild(node);
1188                 if (typeof o === 'object' && o.children) {
1189                     node.loadFromData(o.children);
1190                 }
1191             }
1192             return null;
1193         };
1194
1195
1196         /*
1197          Add child.
1198
1199          tree.addChild(
1200          new Node('child1')
1201          );
1202          */
1203
1204         Node.prototype.addChild = function(node) {
1205             this.children.push(node);
1206             return node._setParent(this);
1207         };
1208
1209
1210         /*
1211          Add child at position. Index starts at 0.
1212
1213          tree.addChildAtPosition(
1214          new Node('abc'),
1215          1
1216          );
1217          */
1218
1219         Node.prototype.addChildAtPosition = function(node, index) {
1220             this.children.splice(index, 0, node);
1221             return node._setParent(this);
1222         };
1223
1224         Node.prototype._setParent = function(parent) {
1225             this.parent = parent;
1226             this.tree = parent.tree;
1227             return this.tree.addNodeToIndex(this);
1228         };
1229
1230
1231         /*
1232          Remove child. This also removes the children of the node.
1233
1234          tree.removeChild(tree.children[0]);
1235          */
1236
1237         Node.prototype.removeChild = function(node) {
1238             node.removeChildren();
1239             return this._removeChild(node);
1240         };
1241
1242         Node.prototype._removeChild = function(node) {
1243             this.children.splice(this.getChildIndex(node), 1);
1244             return this.tree.removeNodeFromIndex(node);
1245         };
1246
1247
1248         /*
1249          Get child index.
1250
1251          var index = getChildIndex(node);
1252          */
1253
1254         Node.prototype.getChildIndex = function(node) {
1255             return $.inArray(node, this.children);
1256         };
1257
1258
1259         /*
1260          Does the tree have children?
1261
1262          if (tree.hasChildren()) {
1263          //
1264          }
1265          */
1266
1267         Node.prototype.hasChildren = function() {
1268             return this.children.length !== 0;
1269         };
1270
1271         Node.prototype.isFolder = function() {
1272             return this.hasChildren() || this.load_on_demand;
1273         };
1274
1275
1276         /*
1277          Iterate over all the nodes in the tree.
1278
1279          Calls callback with (node, level).
1280
1281          The callback must return true to continue the iteration on current node.
1282
1283          tree.iterate(
1284          function(node, level) {
1285          console.log(node.name);
1286
1287          // stop iteration after level 2
1288          return (level <= 2);
1289          }
1290          );
1291          */
1292
1293         Node.prototype.iterate = function(callback) {
1294             var _iterate;
1295             _iterate = function(node, level) {
1296                 var child, j, len, ref, result;
1297                 if (node.children) {
1298                     ref = node.children;
1299                     for (j = 0, len = ref.length; j < len; j++) {
1300                         child = ref[j];
1301                         result = callback(child, level);
1302                         if (result && child.hasChildren()) {
1303                             _iterate(child, level + 1);
1304                         }
1305                     }
1306                     return null;
1307                 }
1308             };
1309             _iterate(this, 0);
1310             return null;
1311         };
1312
1313
1314         /*
1315          Move node relative to another node.
1316
1317          Argument position: Position.BEFORE, Position.AFTER or Position.Inside
1318
1319          // move node1 after node2
1320          tree.moveNode(node1, node2, Position.AFTER);
1321          */
1322
1323         Node.prototype.moveNode = function(moved_node, target_node, position) {
1324             if (moved_node.isParentOf(target_node)) {
1325                 return;
1326             }
1327             moved_node.parent._removeChild(moved_node);
1328             if (position === Position.AFTER) {
1329                 return target_node.parent.addChildAtPosition(moved_node, target_node.parent.getChildIndex(target_node) + 1);
1330             } else if (position === Position.BEFORE) {
1331                 return target_node.parent.addChildAtPosition(moved_node, target_node.parent.getChildIndex(target_node));
1332             } else if (position === Position.INSIDE) {
1333                 return target_node.addChildAtPosition(moved_node, 0);
1334             }
1335         };
1336
1337
1338         /*
1339          Get the tree as data.
1340          */
1341
1342         Node.prototype.getData = function(include_parent) {
1343             var getDataFromNodes;
1344             if (include_parent == null) {
1345                 include_parent = false;
1346             }
1347             getDataFromNodes = function(nodes) {
1348                 var data, j, k, len, node, tmp_node, v;
1349                 data = [];
1350                 for (j = 0, len = nodes.length; j < len; j++) {
1351                     node = nodes[j];
1352                     tmp_node = {};
1353                     for (k in node) {
1354                         v = node[k];
1355                         if ((k !== 'parent' && k !== 'children' && k !== 'element' && k !== 'tree') && Object.prototype.hasOwnProperty.call(node, k)) {
1356                             tmp_node[k] = v;
1357                         }
1358                     }
1359                     if (node.hasChildren()) {
1360                         tmp_node.children = getDataFromNodes(node.children);
1361                     }
1362                     data.push(tmp_node);
1363                 }
1364                 return data;
1365             };
1366             if (include_parent) {
1367                 return getDataFromNodes([this]);
1368             } else {
1369                 return getDataFromNodes(this.children);
1370             }
1371         };
1372
1373         Node.prototype.getNodeByName = function(name) {
1374             return this.getNodeByCallback(function(node) {
1375                 return node.name === name;
1376             });
1377         };
1378
1379         Node.prototype.getNodeByCallback = function(callback) {
1380             var result;
1381             result = null;
1382             this.iterate(function(node) {
1383                 if (callback(node)) {
1384                     result = node;
1385                     return false;
1386                 } else {
1387                     return true;
1388                 }
1389             });
1390             return result;
1391         };
1392
1393         Node.prototype.addAfter = function(node_info) {
1394             var child_index, node;
1395             if (!this.parent) {
1396                 return null;
1397             } else {
1398                 node = new this.tree.node_class(node_info);
1399                 child_index = this.parent.getChildIndex(this);
1400                 this.parent.addChildAtPosition(node, child_index + 1);
1401                 if (typeof node_info === 'object' && node_info.children && node_info.children.length) {
1402                     node.loadFromData(node_info.children);
1403                 }
1404                 return node;
1405             }
1406         };
1407
1408         Node.prototype.addBefore = function(node_info) {
1409             var child_index, node;
1410             if (!this.parent) {
1411                 return null;
1412             } else {
1413                 node = new this.tree.node_class(node_info);
1414                 child_index = this.parent.getChildIndex(this);
1415                 this.parent.addChildAtPosition(node, child_index);
1416                 if (typeof node_info === 'object' && node_info.children && node_info.children.length) {
1417                     node.loadFromData(node_info.children);
1418                 }
1419                 return node;
1420             }
1421         };
1422
1423         Node.prototype.addParent = function(node_info) {
1424             var child, j, len, new_parent, original_parent, ref;
1425             if (!this.parent) {
1426                 return null;
1427             } else {
1428                 new_parent = new this.tree.node_class(node_info);
1429                 new_parent._setParent(this.tree);
1430                 original_parent = this.parent;
1431                 ref = original_parent.children;
1432                 for (j = 0, len = ref.length; j < len; j++) {
1433                     child = ref[j];
1434                     new_parent.addChild(child);
1435                 }
1436                 original_parent.children = [];
1437                 original_parent.addChild(new_parent);
1438                 return new_parent;
1439             }
1440         };
1441
1442         Node.prototype.remove = function() {
1443             if (this.parent) {
1444                 this.parent.removeChild(this);
1445                 return this.parent = null;
1446             }
1447         };
1448
1449         Node.prototype.append = function(node_info) {
1450             var node;
1451             node = new this.tree.node_class(node_info);
1452             this.addChild(node);
1453             if (typeof node_info === 'object' && node_info.children && node_info.children.length) {
1454                 node.loadFromData(node_info.children);
1455             }
1456             return node;
1457         };
1458
1459         Node.prototype.prepend = function(node_info) {
1460             var node;
1461             node = new this.tree.node_class(node_info);
1462             this.addChildAtPosition(node, 0);
1463             if (typeof node_info === 'object' && node_info.children && node_info.children.length) {
1464                 node.loadFromData(node_info.children);
1465             }
1466             return node;
1467         };
1468
1469         Node.prototype.isParentOf = function(node) {
1470             var parent;
1471             parent = node.parent;
1472             while (parent) {
1473                 if (parent === this) {
1474                     return true;
1475                 }
1476                 parent = parent.parent;
1477             }
1478             return false;
1479         };
1480
1481         Node.prototype.getLevel = function() {
1482             var level, node;
1483             level = 0;
1484             node = this;
1485             while (node.parent) {
1486                 level += 1;
1487                 node = node.parent;
1488             }
1489             return level;
1490         };
1491
1492         Node.prototype.getNodeById = function(node_id) {
1493             return this.id_mapping[node_id];
1494         };
1495
1496         Node.prototype.addNodeToIndex = function(node) {
1497             if (node.id != null) {
1498                 return this.id_mapping[node.id] = node;
1499             }
1500         };
1501
1502         Node.prototype.removeNodeFromIndex = function(node) {
1503             if (node.id != null) {
1504                 return delete this.id_mapping[node.id];
1505             }
1506         };
1507
1508         Node.prototype.removeChildren = function() {
1509             this.iterate((function(_this) {
1510                 return function(child) {
1511                     _this.tree.removeNodeFromIndex(child);
1512                     return true;
1513                 };
1514             })(this));
1515             return this.children = [];
1516         };
1517
1518         Node.prototype.getPreviousSibling = function() {
1519             var previous_index;
1520             if (!this.parent) {
1521                 return null;
1522             } else {
1523                 previous_index = this.parent.getChildIndex(this) - 1;
1524                 if (previous_index >= 0) {
1525                     return this.parent.children[previous_index];
1526                 } else {
1527                     return null;
1528                 }
1529             }
1530         };
1531
1532         Node.prototype.getNextSibling = function() {
1533             var next_index;
1534             if (!this.parent) {
1535                 return null;
1536             } else {
1537                 next_index = this.parent.getChildIndex(this) + 1;
1538                 if (next_index < this.parent.children.length) {
1539                     return this.parent.children[next_index];
1540                 } else {
1541                     return null;
1542                 }
1543             }
1544         };
1545
1546         Node.prototype.getNodesByProperty = function(key, value) {
1547             return this.filter(function(node) {
1548                 return node[key] === value;
1549             });
1550         };
1551
1552         Node.prototype.filter = function(f) {
1553             var result;
1554             result = [];
1555             this.iterate(function(node) {
1556                 if (f(node)) {
1557                     result.push(node);
1558                 }
1559                 return true;
1560             });
1561             return result;
1562         };
1563
1564         Node.prototype.getNextNode = function(include_children) {
1565             var next_sibling;
1566             if (include_children == null) {
1567                 include_children = true;
1568             }
1569             if (include_children && this.hasChildren() && this.is_open) {
1570                 return this.children[0];
1571             } else {
1572                 if (!this.parent) {
1573                     return null;
1574                 } else {
1575                     next_sibling = this.getNextSibling();
1576                     if (next_sibling) {
1577                         return next_sibling;
1578                     } else {
1579                         return this.parent.getNextNode(false);
1580                     }
1581                 }
1582             }
1583         };
1584
1585         Node.prototype.getPreviousNode = function() {
1586             var previous_sibling;
1587             if (!this.parent) {
1588                 return null;
1589             } else {
1590                 previous_sibling = this.getPreviousSibling();
1591                 if (previous_sibling) {
1592                     if (!previous_sibling.hasChildren() || !previous_sibling.is_open) {
1593                         return previous_sibling;
1594                     } else {
1595                         return previous_sibling.getLastChild();
1596                     }
1597                 } else {
1598                     return this.getParent();
1599                 }
1600             }
1601         };
1602
1603         Node.prototype.getParent = function() {
1604             if (!this.parent) {
1605                 return null;
1606             } else if (!this.parent.parent) {
1607                 return null;
1608             } else {
1609                 return this.parent;
1610             }
1611         };
1612
1613         Node.prototype.getLastChild = function() {
1614             var last_child;
1615             if (!this.hasChildren()) {
1616                 return null;
1617             } else {
1618                 last_child = this.children[this.children.length - 1];
1619                 if (!last_child.hasChildren() || !last_child.is_open) {
1620                     return last_child;
1621                 } else {
1622                     return last_child.getLastChild();
1623                 }
1624             }
1625         };
1626
1627         return Node;
1628
1629     })();
1630
1631     module.exports = {
1632         Node: Node,
1633         Position: Position
1634     };
1635
1636 },{}],6:[function(require,module,exports){
1637     var $, BorderDropHint, FolderElement, GhostDropHint, NodeElement, Position, node,
1638         extend = 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; },
1639         hasProp = {}.hasOwnProperty;
1640
1641     node = require('./node');
1642
1643     Position = node.Position;
1644
1645     $ = jQuery;
1646
1647     NodeElement = (function() {
1648         function NodeElement(node, tree_widget) {
1649             this.init(node, tree_widget);
1650         }
1651
1652         NodeElement.prototype.init = function(node, tree_widget) {
1653             this.node = node;
1654             this.tree_widget = tree_widget;
1655             if (!node.element) {
1656                 node.element = this.tree_widget.element;
1657             }
1658             return this.$element = $(node.element);
1659         };
1660
1661         NodeElement.prototype.getUl = function() {
1662             return this.$element.children('ul:first');
1663         };
1664
1665         NodeElement.prototype.getSpan = function() {
1666             return this.$element.children('.jqtree-element').find('span.jqtree-title');
1667         };
1668
1669         NodeElement.prototype.getLi = function() {
1670             return this.$element;
1671         };
1672
1673         NodeElement.prototype.addDropHint = function(position) {
1674             if (position === Position.INSIDE) {
1675                 return new BorderDropHint(this.$element);
1676             } else {
1677                 return new GhostDropHint(this.node, this.$element, position);
1678             }
1679         };
1680
1681         NodeElement.prototype.select = function() {
1682             var $li, $span;
1683             $li = this.getLi();
1684             $li.addClass('jqtree-selected');
1685             $li.attr('aria-selected', 'true');
1686             $span = this.getSpan();
1687             return $span.attr('tabindex', 0);
1688         };
1689
1690         NodeElement.prototype.deselect = function() {
1691             var $li, $span;
1692             $li = this.getLi();
1693             $li.removeClass('jqtree-selected');
1694             $li.attr('aria-selected', 'false');
1695             $span = this.getSpan();
1696             return $span.attr('tabindex', -1);
1697         };
1698
1699         return NodeElement;
1700
1701     })();
1702
1703     FolderElement = (function(superClass) {
1704         extend(FolderElement, superClass);
1705
1706         function FolderElement() {
1707             return FolderElement.__super__.constructor.apply(this, arguments);
1708         }
1709
1710         FolderElement.prototype.open = function(on_finished, slide) {
1711             var $button, doOpen;
1712             if (slide == null) {
1713                 slide = true;
1714             }
1715             if (!this.node.is_open) {
1716                 this.node.is_open = true;
1717                 $button = this.getButton();
1718                 $button.removeClass('jqtree-closed');
1719                 $button.html('');
1720                 $button.append(this.tree_widget.renderer.opened_icon_element.cloneNode(false));
1721                 doOpen = (function(_this) {
1722                     return function() {
1723                         var $li, $span;
1724                         $li = _this.getLi();
1725                         $li.removeClass('jqtree-closed');
1726                         $span = _this.getSpan();
1727                         $span.attr('aria-expanded', 'true');
1728                         if (on_finished) {
1729                             on_finished();
1730                         }
1731                         return _this.tree_widget._triggerEvent('tree.open', {
1732                             node: _this.node
1733                         });
1734                     };
1735                 })(this);
1736                 if (slide) {
1737                     return this.getUl().slideDown('fast', doOpen);
1738                 } else {
1739                     this.getUl().show();
1740                     return doOpen();
1741                 }
1742             }
1743         };
1744
1745         FolderElement.prototype.close = function(slide) {
1746             var $button, doClose;
1747             if (slide == null) {
1748                 slide = true;
1749             }
1750             if (this.node.is_open) {
1751                 this.node.is_open = false;
1752                 $button = this.getButton();
1753                 $button.addClass('jqtree-closed');
1754                 $button.html('');
1755                 $button.append(this.tree_widget.renderer.closed_icon_element.cloneNode(false));
1756                 doClose = (function(_this) {
1757                     return function() {
1758                         var $li, $span;
1759                         $li = _this.getLi();
1760                         $li.addClass('jqtree-closed');
1761                         $span = _this.getSpan();
1762                         $span.attr('aria-expanded', 'false');
1763                         return _this.tree_widget._triggerEvent('tree.close', {
1764                             node: _this.node
1765                         });
1766                     };
1767                 })(this);
1768                 if (slide) {
1769                     return this.getUl().slideUp('fast', doClose);
1770                 } else {
1771                     this.getUl().hide();
1772                     return doClose();
1773                 }
1774             }
1775         };
1776
1777         FolderElement.prototype.getButton = function() {
1778             return this.$element.children('.jqtree-element').find('a.jqtree-toggler');
1779         };
1780
1781         FolderElement.prototype.addDropHint = function(position) {
1782             if (!this.node.is_open && position === Position.INSIDE) {
1783                 return new BorderDropHint(this.$element);
1784             } else {
1785                 return new GhostDropHint(this.node, this.$element, position);
1786             }
1787         };
1788
1789         return FolderElement;
1790
1791     })(NodeElement);
1792
1793     BorderDropHint = (function() {
1794         function BorderDropHint($element) {
1795             var $div, width;
1796             $div = $element.children('.jqtree-element');
1797             width = $element.width() - 4;
1798             this.$hint = $('<span class="jqtree-border"></span>');
1799             $div.append(this.$hint);
1800             this.$hint.css({
1801                 width: width,
1802                 height: $div.outerHeight() - 4
1803             });
1804         }
1805
1806         BorderDropHint.prototype.remove = function() {
1807             return this.$hint.remove();
1808         };
1809
1810         return BorderDropHint;
1811
1812     })();
1813
1814     GhostDropHint = (function() {
1815         function GhostDropHint(node, $element, position) {
1816             this.$element = $element;
1817             this.node = node;
1818             this.$ghost = $('<li class="jqtree_common jqtree-ghost"><span class="jqtree_common jqtree-circle"></span><span class="jqtree_common jqtree-line"></span></li>');
1819             if (position === Position.AFTER) {
1820                 this.moveAfter();
1821             } else if (position === Position.BEFORE) {
1822                 this.moveBefore();
1823             } else if (position === Position.INSIDE) {
1824                 if (node.isFolder() && node.is_open) {
1825                     this.moveInsideOpenFolder();
1826                 } else {
1827                     this.moveInside();
1828                 }
1829             }
1830         }
1831
1832         GhostDropHint.prototype.remove = function() {
1833             return this.$ghost.remove();
1834         };
1835
1836         GhostDropHint.prototype.moveAfter = function() {
1837             return this.$element.after(this.$ghost);
1838         };
1839
1840         GhostDropHint.prototype.moveBefore = function() {
1841             return this.$element.before(this.$ghost);
1842         };
1843
1844         GhostDropHint.prototype.moveInsideOpenFolder = function() {
1845             return $(this.node.children[0].element).before(this.$ghost);
1846         };
1847
1848         GhostDropHint.prototype.moveInside = function() {
1849             this.$element.after(this.$ghost);
1850             return this.$ghost.addClass('jqtree-inside');
1851         };
1852
1853         return GhostDropHint;
1854
1855     })();
1856
1857     module.exports = {
1858         BorderDropHint: BorderDropHint,
1859         FolderElement: FolderElement,
1860         GhostDropHint: GhostDropHint,
1861         NodeElement: NodeElement
1862     };
1863
1864 },{"./node":5}],7:[function(require,module,exports){
1865     var $, SaveStateHandler, indexOf, isInt, util;
1866
1867     util = require('./util');
1868
1869     indexOf = util.indexOf;
1870
1871     isInt = util.isInt;
1872
1873     $ = jQuery;
1874
1875     SaveStateHandler = (function() {
1876         function SaveStateHandler(tree_widget) {
1877             this.tree_widget = tree_widget;
1878         }
1879
1880         SaveStateHandler.prototype.saveState = function() {
1881             var state;
1882             state = JSON.stringify(this.getState());
1883             if (this.tree_widget.options.onSetStateFromStorage) {
1884                 return this.tree_widget.options.onSetStateFromStorage(state);
1885             } else if (this.supportsLocalStorage()) {
1886                 return localStorage.setItem(this.getCookieName(), state);
1887             } else if ($.cookie) {
1888                 $.cookie.raw = true;
1889                 return $.cookie(this.getCookieName(), state, {
1890                     path: '/'
1891                 });
1892             }
1893         };
1894
1895         SaveStateHandler.prototype.getStateFromStorage = function() {
1896             var json_data;
1897             json_data = this._loadFromStorage();
1898             if (json_data) {
1899                 return this._parseState(json_data);
1900             } else {
1901                 return null;
1902             }
1903         };
1904
1905         SaveStateHandler.prototype._parseState = function(json_data) {
1906             var state;
1907             state = $.parseJSON(json_data);
1908             if (state && state.selected_node && isInt(state.selected_node)) {
1909                 state.selected_node = [state.selected_node];
1910             }
1911             return state;
1912         };
1913
1914         SaveStateHandler.prototype._loadFromStorage = function() {
1915             if (this.tree_widget.options.onGetStateFromStorage) {
1916                 return this.tree_widget.options.onGetStateFromStorage();
1917             } else if (this.supportsLocalStorage()) {
1918                 return localStorage.getItem(this.getCookieName());
1919             } else if ($.cookie) {
1920                 $.cookie.raw = true;
1921                 return $.cookie(this.getCookieName());
1922             } else {
1923                 return null;
1924             }
1925         };
1926
1927         SaveStateHandler.prototype.getState = function() {
1928             var getOpenNodeIds, getSelectedNodeIds;
1929             getOpenNodeIds = (function(_this) {
1930                 return function() {
1931                     var open_nodes;
1932                     open_nodes = [];
1933                     _this.tree_widget.tree.iterate(function(node) {
1934                         if (node.is_open && node.id && node.hasChildren()) {
1935                             open_nodes.push(node.id);
1936                         }
1937                         return true;
1938                     });
1939                     return open_nodes;
1940                 };
1941             })(this);
1942             getSelectedNodeIds = (function(_this) {
1943                 return function() {
1944                     var n;
1945                     return (function() {
1946                         var i, len, ref, results;
1947                         ref = this.tree_widget.getSelectedNodes();
1948                         results = [];
1949                         for (i = 0, len = ref.length; i < len; i++) {
1950                             n = ref[i];
1951                             results.push(n.id);
1952                         }
1953                         return results;
1954                     }).call(_this);
1955                 };
1956             })(this);
1957             return {
1958                 open_nodes: getOpenNodeIds(),
1959                 selected_node: getSelectedNodeIds()
1960             };
1961         };
1962
1963         SaveStateHandler.prototype.setInitialState = function(state) {
1964             var must_load_on_demand;
1965             if (!state) {
1966                 return false;
1967             } else {
1968                 must_load_on_demand = this._openInitialNodes(state.open_nodes);
1969                 this._selectInitialNodes(state.selected_node);
1970                 return must_load_on_demand;
1971             }
1972         };
1973
1974         SaveStateHandler.prototype._openInitialNodes = function(node_ids) {
1975             var i, len, must_load_on_demand, node, node_id;
1976             must_load_on_demand = false;
1977             for (i = 0, len = node_ids.length; i < len; i++) {
1978                 node_id = node_ids[i];
1979                 node = this.tree_widget.getNodeById(node_id);
1980                 if (node) {
1981                     if (!node.load_on_demand) {
1982                         node.is_open = true;
1983                     } else {
1984                         must_load_on_demand = true;
1985                     }
1986                 }
1987             }
1988             return must_load_on_demand;
1989         };
1990
1991         SaveStateHandler.prototype._selectInitialNodes = function(node_ids) {
1992             var i, len, node, node_id, select_count;
1993             select_count = 0;
1994             for (i = 0, len = node_ids.length; i < len; i++) {
1995                 node_id = node_ids[i];
1996                 node = this.tree_widget.getNodeById(node_id);
1997                 if (node) {
1998                     select_count += 1;
1999                     this.tree_widget.select_node_handler.addToSelection(node);
2000                 }
2001             }
2002             return select_count !== 0;
2003         };
2004
2005         SaveStateHandler.prototype.setInitialStateOnDemand = function(state, cb_finished) {
2006             if (state) {
2007                 return this._setInitialStateOnDemand(state.open_nodes, state.selected_node, cb_finished);
2008             } else {
2009                 return cb_finished();
2010             }
2011         };
2012
2013         SaveStateHandler.prototype._setInitialStateOnDemand = function(node_ids, selected_nodes, cb_finished) {
2014             var loadAndOpenNode, loading_count, openNodes;
2015             loading_count = 0;
2016             openNodes = (function(_this) {
2017                 return function() {
2018                     var i, len, new_nodes_ids, node, node_id;
2019                     new_nodes_ids = [];
2020                     for (i = 0, len = node_ids.length; i < len; i++) {
2021                         node_id = node_ids[i];
2022                         node = _this.tree_widget.getNodeById(node_id);
2023                         if (!node) {
2024                             new_nodes_ids.push(node_id);
2025                         } else {
2026                             if (!node.is_loading) {
2027                                 if (node.load_on_demand) {
2028                                     loadAndOpenNode(node);
2029                                 } else {
2030                                     _this.tree_widget._openNode(node, false);
2031                                 }
2032                             }
2033                         }
2034                     }
2035                     node_ids = new_nodes_ids;
2036                     if (_this._selectInitialNodes(selected_nodes)) {
2037                         _this.tree_widget._refreshElements();
2038                     }
2039                     if (loading_count === 0) {
2040                         return cb_finished();
2041                     }
2042                 };
2043             })(this);
2044             loadAndOpenNode = (function(_this) {
2045                 return function(node) {
2046                     loading_count += 1;
2047                     return _this.tree_widget._openNode(node, false, function() {
2048                         loading_count -= 1;
2049                         return openNodes();
2050                     });
2051                 };
2052             })(this);
2053             return openNodes();
2054         };
2055
2056         SaveStateHandler.prototype.getCookieName = function() {
2057             if (typeof this.tree_widget.options.saveState === 'string') {
2058                 return this.tree_widget.options.saveState;
2059             } else {
2060                 return 'tree';
2061             }
2062         };
2063
2064         SaveStateHandler.prototype.supportsLocalStorage = function() {
2065             var testSupport;
2066             testSupport = function() {
2067                 var error, key;
2068                 if (typeof localStorage === "undefined" || localStorage === null) {
2069                     return false;
2070                 } else {
2071                     try {
2072                         key = '_storage_test';
2073                         sessionStorage.setItem(key, true);
2074                         sessionStorage.removeItem(key);
2075                     } catch (error1) {
2076                         error = error1;
2077                         return false;
2078                     }
2079                     return true;
2080                 }
2081             };
2082             if (this._supportsLocalStorage == null) {
2083                 this._supportsLocalStorage = testSupport();
2084             }
2085             return this._supportsLocalStorage;
2086         };
2087
2088         SaveStateHandler.prototype.getNodeIdToBeSelected = function() {
2089             var state;
2090             state = this.getStateFromStorage();
2091             if (state && state.selected_node) {
2092                 return state.selected_node[0];
2093             } else {
2094                 return null;
2095             }
2096         };
2097
2098         return SaveStateHandler;
2099
2100     })();
2101
2102     module.exports = SaveStateHandler;
2103
2104 },{"./util":12}],8:[function(require,module,exports){
2105     var $, ScrollHandler;
2106
2107     $ = jQuery;
2108
2109     ScrollHandler = (function() {
2110         function ScrollHandler(tree_widget) {
2111             this.tree_widget = tree_widget;
2112             this.previous_top = -1;
2113             this.is_initialized = false;
2114             this._initScrollParent();
2115         }
2116
2117         ScrollHandler.prototype._initScrollParent = function() {
2118             var $scroll_parent, getParentWithOverflow, setDocumentAsScrollParent;
2119             getParentWithOverflow = (function(_this) {
2120                 return function() {
2121                     var css_values, el, hasOverFlow, i, len, ref;
2122                     css_values = ['overflow', 'overflow-y'];
2123                     hasOverFlow = function(el) {
2124                         var css_value, i, len, ref;
2125                         for (i = 0, len = css_values.length; i < len; i++) {
2126                             css_value = css_values[i];
2127                             if ((ref = $.css(el, css_value)) === 'auto' || ref === 'scroll') {
2128                                 return true;
2129                             }
2130                         }
2131                         return false;
2132                     };
2133                     if (hasOverFlow(_this.tree_widget.$el[0])) {
2134                         return _this.tree_widget.$el;
2135                     }
2136                     ref = _this.tree_widget.$el.parents();
2137                     for (i = 0, len = ref.length; i < len; i++) {
2138                         el = ref[i];
2139                         if (hasOverFlow(el)) {
2140                             return $(el);
2141                         }
2142                     }
2143                     return null;
2144                 };
2145             })(this);
2146             setDocumentAsScrollParent = (function(_this) {
2147                 return function() {
2148                     _this.scroll_parent_top = 0;
2149                     return _this.$scroll_parent = null;
2150                 };
2151             })(this);
2152             if (this.tree_widget.$el.css('position') === 'fixed') {
2153                 setDocumentAsScrollParent();
2154             }
2155             $scroll_parent = getParentWithOverflow();
2156             if ($scroll_parent && $scroll_parent.length && $scroll_parent[0].tagName !== 'HTML') {
2157                 this.$scroll_parent = $scroll_parent;
2158                 this.scroll_parent_top = this.$scroll_parent.offset().top;
2159             } else {
2160                 setDocumentAsScrollParent();
2161             }
2162             return this.is_initialized = true;
2163         };
2164
2165         ScrollHandler.prototype._ensureInit = function() {
2166             if (!this.is_initialized) {
2167                 return this._initScrollParent();
2168             }
2169         };
2170
2171         ScrollHandler.prototype.checkScrolling = function() {
2172             var hovered_area;
2173             this._ensureInit();
2174             hovered_area = this.tree_widget.dnd_handler.hovered_area;
2175             if (hovered_area && hovered_area.top !== this.previous_top) {
2176                 this.previous_top = hovered_area.top;
2177                 if (this.$scroll_parent) {
2178                     return this._handleScrollingWithScrollParent(hovered_area);
2179                 } else {
2180                     return this._handleScrollingWithDocument(hovered_area);
2181                 }
2182             }
2183         };
2184
2185         ScrollHandler.prototype._handleScrollingWithScrollParent = function(area) {
2186             var distance_bottom;
2187             distance_bottom = this.scroll_parent_top + this.$scroll_parent[0].offsetHeight - area.bottom;
2188             if (distance_bottom < 20) {
2189                 this.$scroll_parent[0].scrollTop += 20;
2190                 this.tree_widget.refreshHitAreas();
2191                 return this.previous_top = -1;
2192             } else if ((area.top - this.scroll_parent_top) < 20) {
2193                 this.$scroll_parent[0].scrollTop -= 20;
2194                 this.tree_widget.refreshHitAreas();
2195                 return this.previous_top = -1;
2196             }
2197         };
2198
2199         ScrollHandler.prototype._handleScrollingWithDocument = function(area) {
2200             var distance_top;
2201             distance_top = area.top - $(document).scrollTop();
2202             if (distance_top < 20) {
2203                 return $(document).scrollTop($(document).scrollTop() - 20);
2204             } else if ($(window).height() - (area.bottom - $(document).scrollTop()) < 20) {
2205                 return $(document).scrollTop($(document).scrollTop() + 20);
2206             }
2207         };
2208
2209         ScrollHandler.prototype.scrollTo = function(top) {
2210             var tree_top;
2211             this._ensureInit();
2212             if (this.$scroll_parent) {
2213                 return this.$scroll_parent[0].scrollTop = top;
2214             } else {
2215                 tree_top = this.tree_widget.$el.offset().top;
2216                 return $(document).scrollTop(top + tree_top);
2217             }
2218         };
2219
2220         ScrollHandler.prototype.isScrolledIntoView = function(element) {
2221             var $element, element_bottom, element_top, view_bottom, view_top;
2222             this._ensureInit();
2223             $element = $(element);
2224             if (this.$scroll_parent) {
2225                 view_top = 0;
2226                 view_bottom = this.$scroll_parent.height();
2227                 element_top = $element.offset().top - this.scroll_parent_top;
2228                 element_bottom = element_top + $element.height();
2229             } else {
2230                 view_top = $(window).scrollTop();
2231                 view_bottom = view_top + $(window).height();
2232                 element_top = $element.offset().top;
2233                 element_bottom = element_top + $element.height();
2234             }
2235             return (element_bottom <= view_bottom) && (element_top >= view_top);
2236         };
2237
2238         return ScrollHandler;
2239
2240     })();
2241
2242     module.exports = ScrollHandler;
2243
2244 },{}],9:[function(require,module,exports){
2245     var $, SelectNodeHandler;
2246
2247     $ = jQuery;
2248
2249     SelectNodeHandler = (function() {
2250         function SelectNodeHandler(tree_widget) {
2251             this.tree_widget = tree_widget;
2252             this.clear();
2253         }
2254
2255         SelectNodeHandler.prototype.getSelectedNode = function() {
2256             var selected_nodes;
2257             selected_nodes = this.getSelectedNodes();
2258             if (selected_nodes.length) {
2259                 return selected_nodes[0];
2260             } else {
2261                 return false;
2262             }
2263         };
2264
2265         SelectNodeHandler.prototype.getSelectedNodes = function() {
2266             var id, node, selected_nodes;
2267             if (this.selected_single_node) {
2268                 return [this.selected_single_node];
2269             } else {
2270                 selected_nodes = [];
2271                 for (id in this.selected_nodes) {
2272                     node = this.tree_widget.getNodeById(id);
2273                     if (node) {
2274                         selected_nodes.push(node);
2275                     }
2276                 }
2277                 return selected_nodes;
2278             }
2279         };
2280
2281         SelectNodeHandler.prototype.getSelectedNodesUnder = function(parent) {
2282             var id, node, selected_nodes;
2283             if (this.selected_single_node) {
2284                 if (parent.isParentOf(this.selected_single_node)) {
2285                     return [this.selected_single_node];
2286                 } else {
2287                     return [];
2288                 }
2289             } else {
2290                 selected_nodes = [];
2291                 for (id in this.selected_nodes) {
2292                     node = this.tree_widget.getNodeById(id);
2293                     if (node && parent.isParentOf(node)) {
2294                         selected_nodes.push(node);
2295                     }
2296                 }
2297                 return selected_nodes;
2298             }
2299         };
2300
2301         SelectNodeHandler.prototype.isNodeSelected = function(node) {
2302             if (!node) {
2303                 return false;
2304             } else if (node.id) {
2305                 if (this.selected_nodes[node.id]) {
2306                     return true;
2307                 } else {
2308                     return false;
2309                 }
2310             } else if (this.selected_single_node) {
2311                 return this.selected_single_node.element === node.element;
2312             } else {
2313                 return false;
2314             }
2315         };
2316
2317         SelectNodeHandler.prototype.clear = function() {
2318             this.selected_nodes = {};
2319             return this.selected_single_node = null;
2320         };
2321
2322         SelectNodeHandler.prototype.removeFromSelection = function(node, include_children) {
2323             if (include_children == null) {
2324                 include_children = false;
2325             }
2326             if (!node.id) {
2327                 if (this.selected_single_node && node.element === this.selected_single_node.element) {
2328                     return this.selected_single_node = null;
2329                 }
2330             } else {
2331                 delete this.selected_nodes[node.id];
2332                 if (include_children) {
2333                     return node.iterate((function(_this) {
2334                         return function(n) {
2335                             delete _this.selected_nodes[node.id];
2336                             return true;
2337                         };
2338                     })(this));
2339                 }
2340             }
2341         };
2342
2343         SelectNodeHandler.prototype.addToSelection = function(node) {
2344             if (node.id) {
2345                 return this.selected_nodes[node.id] = true;
2346             } else {
2347                 return this.selected_single_node = node;
2348             }
2349         };
2350
2351         return SelectNodeHandler;
2352
2353     })();
2354
2355     module.exports = SelectNodeHandler;
2356
2357 },{}],10:[function(require,module,exports){
2358
2359     /*
2360      Copyright 2013 Marco Braak
2361
2362      Licensed under the Apache License, Version 2.0 (the "License");
2363      you may not use this file except in compliance with the License.
2364      You may obtain a copy of the License at
2365
2366      http://www.apache.org/licenses/LICENSE-2.0
2367
2368      Unless required by applicable law or agreed to in writing, software
2369      distributed under the License is distributed on an "AS IS" BASIS,
2370      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2371      See the License for the specific language governing permissions and
2372      limitations under the License.
2373      */
2374     var $, SimpleWidget,
2375         slice = [].slice;
2376
2377     $ = jQuery;
2378
2379     SimpleWidget = (function() {
2380         SimpleWidget.prototype.defaults = {};
2381
2382         function SimpleWidget(el, options) {
2383             this.$el = $(el);
2384             this.options = $.extend({}, this.defaults, options);
2385         }
2386
2387         SimpleWidget.prototype.destroy = function() {
2388             return this._deinit();
2389         };
2390
2391         SimpleWidget.prototype._init = function() {
2392             return null;
2393         };
2394
2395         SimpleWidget.prototype._deinit = function() {
2396             return null;
2397         };
2398
2399         SimpleWidget.register = function(widget_class, widget_name) {
2400             var callFunction, createWidget, destroyWidget, getDataKey, getWidgetData;
2401             getDataKey = function() {
2402                 return "simple_widget_" + widget_name;
2403             };
2404             getWidgetData = function(el, data_key) {
2405                 var widget;
2406                 widget = $.data(el, data_key);
2407                 if (widget && (widget instanceof SimpleWidget)) {
2408                     return widget;
2409                 } else {
2410                     return null;
2411                 }
2412             };
2413             createWidget = function($el, options) {
2414                 var data_key, el, existing_widget, i, len, widget;
2415                 data_key = getDataKey();
2416                 for (i = 0, len = $el.length; i < len; i++) {
2417                     el = $el[i];
2418                     existing_widget = getWidgetData(el, data_key);
2419                     if (!existing_widget) {
2420                         widget = new widget_class(el, options);
2421                         if (!$.data(el, data_key)) {
2422                             $.data(el, data_key, widget);
2423                         }
2424                         widget._init();
2425                     }
2426                 }
2427                 return $el;
2428             };
2429             destroyWidget = function($el) {
2430                 var data_key, el, i, len, results, widget;
2431                 data_key = getDataKey();
2432                 results = [];
2433                 for (i = 0, len = $el.length; i < len; i++) {
2434                     el = $el[i];
2435                     widget = getWidgetData(el, data_key);
2436                     if (widget) {
2437                         widget.destroy();
2438                     }
2439                     results.push($.removeData(el, data_key));
2440                 }
2441                 return results;
2442             };
2443             callFunction = function($el, function_name, args) {
2444                 var el, i, len, result, widget, widget_function;
2445                 result = null;
2446                 for (i = 0, len = $el.length; i < len; i++) {
2447                     el = $el[i];
2448                     widget = $.data(el, getDataKey());
2449                     if (widget && (widget instanceof SimpleWidget)) {
2450                         widget_function = widget[function_name];
2451                         if (widget_function && (typeof widget_function === 'function')) {
2452                             result = widget_function.apply(widget, args);
2453                         }
2454                     }
2455                 }
2456                 return result;
2457             };
2458             return $.fn[widget_name] = function() {
2459                 var $el, args, argument1, function_name, options;
2460                 argument1 = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
2461                 $el = this;
2462                 if (argument1 === void 0 || typeof argument1 === 'object') {
2463                     options = argument1;
2464                     return createWidget($el, options);
2465                 } else if (typeof argument1 === 'string' && argument1[0] !== '_') {
2466                     function_name = argument1;
2467                     if (function_name === 'destroy') {
2468                         return destroyWidget($el);
2469                     } else if (function_name === 'get_widget_class') {
2470                         return widget_class;
2471                     } else {
2472                         return callFunction($el, function_name, args);
2473                     }
2474                 }
2475             };
2476         };
2477
2478         return SimpleWidget;
2479
2480     })();
2481
2482     module.exports = SimpleWidget;
2483
2484 },{}],11:[function(require,module,exports){
2485     var $, BorderDropHint, DragAndDropHandler, DragElement, ElementsRenderer, FolderElement, GhostDropHint, HitAreasGenerator, JqTreeWidget, KeyHandler, MouseWidget, Node, NodeElement, Position, SaveStateHandler, ScrollHandler, SelectNodeHandler, SimpleWidget, __version__, drag_and_drop_handler, node_module, ref, util_module,
2486         extend = 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; },
2487         hasProp = {}.hasOwnProperty;
2488
2489     __version__ = require('./version');
2490
2491     drag_and_drop_handler = require('./drag_and_drop_handler');
2492
2493     ElementsRenderer = require('./elements_renderer');
2494
2495     KeyHandler = require('./key_handler');
2496
2497     MouseWidget = require('./mouse.widget');
2498
2499     SaveStateHandler = require('./save_state_handler');
2500
2501     ScrollHandler = require('./scroll_handler');
2502
2503     SelectNodeHandler = require('./select_node_handler');
2504
2505     SimpleWidget = require('./simple.widget');
2506
2507     node_module = require('./node');
2508
2509     Node = node_module.Node;
2510
2511     Position = node_module.Position;
2512
2513     util_module = require('./util');
2514
2515     ref = require('./node_element'), BorderDropHint = ref.BorderDropHint, FolderElement = ref.FolderElement, GhostDropHint = ref.GhostDropHint, NodeElement = ref.NodeElement;
2516
2517     DragAndDropHandler = drag_and_drop_handler.DragAndDropHandler, DragElement = drag_and_drop_handler.DragElement, HitAreasGenerator = drag_and_drop_handler.HitAreasGenerator;
2518
2519     $ = jQuery;
2520
2521     JqTreeWidget = (function(superClass) {
2522         extend(JqTreeWidget, superClass);
2523
2524         function JqTreeWidget() {
2525             return JqTreeWidget.__super__.constructor.apply(this, arguments);
2526         }
2527
2528         JqTreeWidget.prototype.BorderDropHint = BorderDropHint;
2529
2530         JqTreeWidget.prototype.DragElement = DragElement;
2531
2532         JqTreeWidget.prototype.DragAndDropHandler = DragAndDropHandler;
2533
2534         JqTreeWidget.prototype.ElementsRenderer = ElementsRenderer;
2535
2536         JqTreeWidget.prototype.GhostDropHint = GhostDropHint;
2537
2538         JqTreeWidget.prototype.HitAreasGenerator = HitAreasGenerator;
2539
2540         JqTreeWidget.prototype.Node = Node;
2541
2542         JqTreeWidget.prototype.SaveStateHandler = SaveStateHandler;
2543
2544         JqTreeWidget.prototype.ScrollHandler = ScrollHandler;
2545
2546         JqTreeWidget.prototype.SelectNodeHandler = SelectNodeHandler;
2547
2548         JqTreeWidget.prototype.defaults = {
2549             autoOpen: false,
2550             saveState: false,
2551             dragAndDrop: false,
2552             selectable: true,
2553             useContextMenu: true,
2554             onCanSelectNode: null,
2555             onSetStateFromStorage: null,
2556             onGetStateFromStorage: null,
2557             onCreateLi: null,
2558             onIsMoveHandle: null,
2559             onCanMove: null,
2560             onCanMoveTo: null,
2561             onLoadFailed: null,
2562             autoEscape: true,
2563             dataUrl: null,
2564             closedIcon: null,
2565             openedIcon: '&#x25bc;',
2566             slide: true,
2567             nodeClass: Node,
2568             dataFilter: null,
2569             keyboardSupport: true,
2570             openFolderDelay: 500,
2571             rtl: null,
2572             onDragMove: null,
2573             onDragStop: null,
2574             buttonLeft: true,
2575             onLoading: null
2576         };
2577
2578         JqTreeWidget.prototype.toggle = function(node, slide) {
2579             if (slide == null) {
2580                 slide = null;
2581             }
2582             if (slide === null) {
2583                 slide = this.options.slide;
2584             }
2585             if (node.is_open) {
2586                 this.closeNode(node, slide);
2587             } else {
2588                 this.openNode(node, slide);
2589             }
2590             return this.element;
2591         };
2592
2593         JqTreeWidget.prototype.getTree = function() {
2594             return this.tree;
2595         };
2596
2597         JqTreeWidget.prototype.selectNode = function(node) {
2598             this._selectNode(node, false);
2599             return this.element;
2600         };
2601
2602         JqTreeWidget.prototype._selectNode = function(node, must_toggle) {
2603             var canSelect, deselected_node, openParents, saveState;
2604             if (must_toggle == null) {
2605                 must_toggle = false;
2606             }
2607             if (!this.select_node_handler) {
2608                 return;
2609             }
2610             canSelect = (function(_this) {
2611                 return function() {
2612                     if (_this.options.onCanSelectNode) {
2613                         return _this.options.selectable && _this.options.onCanSelectNode(node);
2614                     } else {
2615                         return _this.options.selectable;
2616                     }
2617                 };
2618             })(this);
2619             openParents = (function(_this) {
2620                 return function() {
2621                     var parent;
2622                     parent = node.parent;
2623                     if (parent && parent.parent && !parent.is_open) {
2624                         return _this.openNode(parent, false);
2625                     }
2626                 };
2627             })(this);
2628             saveState = (function(_this) {
2629                 return function() {
2630                     if (_this.options.saveState) {
2631                         return _this.save_state_handler.saveState();
2632                     }
2633                 };
2634             })(this);
2635             if (!node) {
2636                 this._deselectCurrentNode();
2637                 saveState();
2638                 return;
2639             }
2640             if (!canSelect()) {
2641                 return;
2642             }
2643             if (this.select_node_handler.isNodeSelected(node)) {
2644                 if (must_toggle) {
2645                     this._deselectCurrentNode();
2646                     this._triggerEvent('tree.select', {
2647                         node: null,
2648                         previous_node: node
2649                     });
2650                 }
2651             } else {
2652                 deselected_node = this.getSelectedNode();
2653                 this._deselectCurrentNode();
2654                 this.addToSelection(node);
2655                 this._triggerEvent('tree.select', {
2656                     node: node,
2657                     deselected_node: deselected_node
2658                 });
2659                 openParents();
2660             }
2661             return saveState();
2662         };
2663
2664         JqTreeWidget.prototype.getSelectedNode = function() {
2665             if (this.select_node_handler) {
2666                 return this.select_node_handler.getSelectedNode();
2667             } else {
2668                 return null;
2669             }
2670         };
2671
2672         JqTreeWidget.prototype.toJson = function() {
2673             return JSON.stringify(this.tree.getData());
2674         };
2675
2676         JqTreeWidget.prototype.loadData = function(data, parent_node) {
2677             this._loadData(data, parent_node);
2678             return this.element;
2679         };
2680
2681
2682         /*
2683          signatures:
2684          - loadDataFromUrl(url, parent_node=null, on_finished=null)
2685          loadDataFromUrl('/my_data');
2686          loadDataFromUrl('/my_data', node1);
2687          loadDataFromUrl('/my_data', node1, function() { console.log('finished'); });
2688          loadDataFromUrl('/my_data', null, function() { console.log('finished'); });
2689
2690          - loadDataFromUrl(parent_node=null, on_finished=null)
2691          loadDataFromUrl();
2692          loadDataFromUrl(node1);
2693          loadDataFromUrl(null, function() { console.log('finished'); });
2694          loadDataFromUrl(node1, function() { console.log('finished'); });
2695          */
2696
2697         JqTreeWidget.prototype.loadDataFromUrl = function(param1, param2, param3) {
2698             if ($.type(param1) === 'string') {
2699                 this._loadDataFromUrl(param1, param2, param3);
2700             } else {
2701                 this._loadDataFromUrl(null, param1, param2);
2702             }
2703             return this.element;
2704         };
2705
2706         JqTreeWidget.prototype.reload = function(on_finished) {
2707             this._loadDataFromUrl(null, null, on_finished);
2708             return this.element;
2709         };
2710
2711         JqTreeWidget.prototype._loadDataFromUrl = function(url_info, parent_node, on_finished) {
2712             var $el, addLoadingClass, handeLoadData, handleError, handleSuccess, loadDataFromUrlInfo, parseUrlInfo, removeLoadingClass;
2713             $el = null;
2714             addLoadingClass = (function(_this) {
2715                 return function() {
2716                     if (parent_node) {
2717                         $el = $(parent_node.element);
2718                     } else {
2719                         $el = _this.element;
2720                     }
2721                     $el.addClass('jqtree-loading');
2722                     return _this._notifyLoading(true, parent_node, $el);
2723                 };
2724             })(this);
2725             removeLoadingClass = (function(_this) {
2726                 return function() {
2727                     if ($el) {
2728                         $el.removeClass('jqtree-loading');
2729                         return _this._notifyLoading(false, parent_node, $el);
2730                     }
2731                 };
2732             })(this);
2733             parseUrlInfo = function() {
2734                 if ($.type(url_info) === 'string') {
2735                     return {
2736                         url: url_info
2737                     };
2738                 }
2739                 if (!url_info.method) {
2740                     url_info.method = 'get';
2741                 }
2742                 return url_info;
2743             };
2744             handeLoadData = (function(_this) {
2745                 return function(data) {
2746                     removeLoadingClass();
2747                     _this._loadData(data, parent_node);
2748                     if (on_finished && $.isFunction(on_finished)) {
2749                         return on_finished();
2750                     }
2751                 };
2752             })(this);
2753             handleSuccess = (function(_this) {
2754                 return function(response) {
2755                     var data;
2756                     if ($.isArray(response) || typeof response === 'object') {
2757                         data = response;
2758                     } else if (data != null) {
2759                         data = $.parseJSON(response);
2760                     } else {
2761                         data = [];
2762                     }
2763                     if (_this.options.dataFilter) {
2764                         data = _this.options.dataFilter(data);
2765                     }
2766                     return handeLoadData(data);
2767                 };
2768             })(this);
2769             handleError = (function(_this) {
2770                 return function(response) {
2771                     removeLoadingClass();
2772                     if (_this.options.onLoadFailed) {
2773                         return _this.options.onLoadFailed(response);
2774                     }
2775                 };
2776             })(this);
2777             loadDataFromUrlInfo = function() {
2778                 url_info = parseUrlInfo();
2779                 return $.ajax($.extend({}, url_info, {
2780                     method: url_info.method != null ? url_info.method.toUpperCase() : 'GET',
2781                     cache: false,
2782                     dataType: 'json',
2783                     success: handleSuccess,
2784                     error: handleError
2785                 }));
2786             };
2787             if (!url_info) {
2788                 url_info = this._getDataUrlInfo(parent_node);
2789             }
2790             addLoadingClass();
2791             if (!url_info) {
2792                 removeLoadingClass();
2793             } else if ($.isArray(url_info)) {
2794                 handeLoadData(url_info);
2795             } else {
2796                 loadDataFromUrlInfo();
2797             }
2798         };
2799
2800         JqTreeWidget.prototype._loadData = function(data, parent_node) {
2801             var deselectNodes, loadSubtree;
2802             if (parent_node == null) {
2803                 parent_node = null;
2804             }
2805             deselectNodes = (function(_this) {
2806                 return function() {
2807                     var i, len, n, selected_nodes_under_parent;
2808                     if (_this.select_node_handler) {
2809                         selected_nodes_under_parent = _this.select_node_handler.getSelectedNodesUnder(parent_node);
2810                         for (i = 0, len = selected_nodes_under_parent.length; i < len; i++) {
2811                             n = selected_nodes_under_parent[i];
2812                             _this.select_node_handler.removeFromSelection(n);
2813                         }
2814                     }
2815                     return null;
2816                 };
2817             })(this);
2818             loadSubtree = (function(_this) {
2819                 return function() {
2820                     parent_node.loadFromData(data);
2821                     parent_node.load_on_demand = false;
2822                     parent_node.is_loading = false;
2823                     return _this._refreshElements(parent_node);
2824                 };
2825             })(this);
2826             if (!data) {
2827                 return;
2828             }
2829             this._triggerEvent('tree.load_data', {
2830                 tree_data: data
2831             });
2832             if (!parent_node) {
2833                 this._initTree(data);
2834             } else {
2835                 deselectNodes();
2836                 loadSubtree();
2837             }
2838             if (this.isDragging()) {
2839                 return this.dnd_handler.refresh();
2840             }
2841         };
2842
2843         JqTreeWidget.prototype.getNodeById = function(node_id) {
2844             return this.tree.getNodeById(node_id);
2845         };
2846
2847         JqTreeWidget.prototype.getNodeByName = function(name) {
2848             return this.tree.getNodeByName(name);
2849         };
2850
2851         JqTreeWidget.prototype.getNodesByProperty = function(key, value) {
2852             return this.tree.getNodesByProperty(key, value);
2853         };
2854
2855         JqTreeWidget.prototype.getNodeByHtmlElement = function(element) {
2856             return this._getNode($(element));
2857         };
2858
2859         JqTreeWidget.prototype.getNodeByCallback = function(callback) {
2860             return this.tree.getNodeByCallback(callback);
2861         };
2862
2863         JqTreeWidget.prototype.openNode = function(node, slide) {
2864             if (slide == null) {
2865                 slide = null;
2866             }
2867             if (node) {
2868                 if (slide === null) {
2869                     slide = this.options.slide;
2870                 }
2871                 this._openNode(node, slide);
2872             }
2873             return this.element;
2874         };
2875
2876         JqTreeWidget.prototype._openNode = function(node, slide, on_finished) {
2877             var doOpenNode, parent;
2878             if (slide == null) {
2879                 slide = true;
2880             }
2881             doOpenNode = (function(_this) {
2882                 return function(_node, _slide, _on_finished) {
2883                     var folder_element;
2884                     folder_element = new FolderElement(_node, _this);
2885                     return folder_element.open(_on_finished, _slide);
2886                 };
2887             })(this);
2888             if (node.isFolder()) {
2889                 if (node.load_on_demand) {
2890                     return this._loadFolderOnDemand(node, slide, on_finished);
2891                 } else {
2892                     parent = node.parent;
2893                     while (parent) {
2894                         if (parent.parent) {
2895                             doOpenNode(parent, false, null);
2896                         }
2897                         parent = parent.parent;
2898                     }
2899                     doOpenNode(node, slide, on_finished);
2900                     return this._saveState();
2901                 }
2902             }
2903         };
2904
2905         JqTreeWidget.prototype._loadFolderOnDemand = function(node, slide, on_finished) {
2906             if (slide == null) {
2907                 slide = true;
2908             }
2909             node.is_loading = true;
2910             return this._loadDataFromUrl(null, node, (function(_this) {
2911                 return function() {
2912                     return _this._openNode(node, slide, on_finished);
2913                 };
2914             })(this));
2915         };
2916
2917         JqTreeWidget.prototype.closeNode = function(node, slide) {
2918             if (slide == null) {
2919                 slide = null;
2920             }
2921             if (slide === null) {
2922                 slide = this.options.slide;
2923             }
2924             if (node.isFolder()) {
2925                 new FolderElement(node, this).close(slide);
2926                 this._saveState();
2927             }
2928             return this.element;
2929         };
2930
2931         JqTreeWidget.prototype.isDragging = function() {
2932             if (this.dnd_handler) {
2933                 return this.dnd_handler.is_dragging;
2934             } else {
2935                 return false;
2936             }
2937         };
2938
2939         JqTreeWidget.prototype.refreshHitAreas = function() {
2940             this.dnd_handler.refresh();
2941             return this.element;
2942         };
2943
2944         JqTreeWidget.prototype.addNodeAfter = function(new_node_info, existing_node) {
2945             var new_node;
2946             new_node = existing_node.addAfter(new_node_info);
2947             this._refreshElements(existing_node.parent);
2948             return new_node;
2949         };
2950
2951         JqTreeWidget.prototype.addNodeBefore = function(new_node_info, existing_node) {
2952             var new_node;
2953             new_node = existing_node.addBefore(new_node_info);
2954             this._refreshElements(existing_node.parent);
2955             return new_node;
2956         };
2957
2958         JqTreeWidget.prototype.addParentNode = function(new_node_info, existing_node) {
2959             var new_node;
2960             new_node = existing_node.addParent(new_node_info);
2961             this._refreshElements(new_node.parent);
2962             return new_node;
2963         };
2964
2965         JqTreeWidget.prototype.removeNode = function(node) {
2966             var parent;
2967             parent = node.parent;
2968             if (parent) {
2969                 this.select_node_handler.removeFromSelection(node, true);
2970                 node.remove();
2971                 this._refreshElements(parent);
2972             }
2973             return this.element;
2974         };
2975
2976         JqTreeWidget.prototype.appendNode = function(new_node_info, parent_node) {
2977             var node;
2978             parent_node = parent_node || this.tree;
2979             node = parent_node.append(new_node_info);
2980             this._refreshElements(parent_node);
2981             return node;
2982         };
2983
2984         JqTreeWidget.prototype.prependNode = function(new_node_info, parent_node) {
2985             var node;
2986             if (!parent_node) {
2987                 parent_node = this.tree;
2988             }
2989             node = parent_node.prepend(new_node_info);
2990             this._refreshElements(parent_node);
2991             return node;
2992         };
2993
2994         JqTreeWidget.prototype.updateNode = function(node, data) {
2995             var id_is_changed;
2996             id_is_changed = data.id && data.id !== node.id;
2997             if (id_is_changed) {
2998                 this.tree.removeNodeFromIndex(node);
2999             }
3000             node.setData(data);
3001             if (id_is_changed) {
3002                 this.tree.addNodeToIndex(node);
3003             }
3004             if (typeof data === 'object' && data.children) {
3005                 node.removeChildren();
3006                 if (data.children.length) {
3007                     node.loadFromData(data.children);
3008                 }
3009             }
3010             this.renderer.renderFromNode(node);
3011             this._selectCurrentNode();
3012             return this.element;
3013         };
3014
3015         JqTreeWidget.prototype.moveNode = function(node, target_node, position) {
3016             var position_index;
3017             position_index = Position.nameToIndex(position);
3018             this.tree.moveNode(node, target_node, position_index);
3019             this._refreshElements();
3020             return this.element;
3021         };
3022
3023         JqTreeWidget.prototype.getStateFromStorage = function() {
3024             return this.save_state_handler.getStateFromStorage();
3025         };
3026
3027         JqTreeWidget.prototype.addToSelection = function(node) {
3028             if (node) {
3029                 this.select_node_handler.addToSelection(node);
3030                 this._getNodeElementForNode(node).select();
3031                 this._saveState();
3032             }
3033             return this.element;
3034         };
3035
3036         JqTreeWidget.prototype.getSelectedNodes = function() {
3037             return this.select_node_handler.getSelectedNodes();
3038         };
3039
3040         JqTreeWidget.prototype.isNodeSelected = function(node) {
3041             return this.select_node_handler.isNodeSelected(node);
3042         };
3043
3044         JqTreeWidget.prototype.removeFromSelection = function(node) {
3045             this.select_node_handler.removeFromSelection(node);
3046             this._getNodeElementForNode(node).deselect();
3047             this._saveState();
3048             return this.element;
3049         };
3050
3051         JqTreeWidget.prototype.scrollToNode = function(node) {
3052             var $element, top;
3053             $element = $(node.element);
3054             top = $element.offset().top - this.$el.offset().top;
3055             this.scroll_handler.scrollTo(top);
3056             return this.element;
3057         };
3058
3059         JqTreeWidget.prototype.getState = function() {
3060             return this.save_state_handler.getState();
3061         };
3062
3063         JqTreeWidget.prototype.setState = function(state) {
3064             this.save_state_handler.setInitialState(state);
3065             this._refreshElements();
3066             return this.element;
3067         };
3068
3069         JqTreeWidget.prototype.setOption = function(option, value) {
3070             this.options[option] = value;
3071             return this.element;
3072         };
3073
3074         JqTreeWidget.prototype.moveDown = function() {
3075             if (this.key_handler) {
3076                 this.key_handler.moveDown();
3077             }
3078             return this.element;
3079         };
3080
3081         JqTreeWidget.prototype.moveUp = function() {
3082             if (this.key_handler) {
3083                 this.key_handler.moveUp();
3084             }
3085             return this.element;
3086         };
3087
3088         JqTreeWidget.prototype.getVersion = function() {
3089             return __version__;
3090         };
3091
3092         JqTreeWidget.prototype._init = function() {
3093             JqTreeWidget.__super__._init.call(this);
3094             this.element = this.$el;
3095             this.mouse_delay = 300;
3096             this.is_initialized = false;
3097             this.options.rtl = this._getRtlOption();
3098             if (!this.options.closedIcon) {
3099                 this.options.closedIcon = this._getDefaultClosedIcon();
3100             }
3101             this.renderer = new ElementsRenderer(this);
3102             if (SaveStateHandler != null) {
3103                 this.save_state_handler = new SaveStateHandler(this);
3104             } else {
3105                 this.options.saveState = false;
3106             }
3107             if (SelectNodeHandler != null) {
3108                 this.select_node_handler = new SelectNodeHandler(this);
3109             }
3110             if (DragAndDropHandler != null) {
3111                 this.dnd_handler = new DragAndDropHandler(this);
3112             } else {
3113                 this.options.dragAndDrop = false;
3114             }
3115             if (ScrollHandler != null) {
3116                 this.scroll_handler = new ScrollHandler(this);
3117             }
3118             if ((KeyHandler != null) && (SelectNodeHandler != null)) {
3119                 this.key_handler = new KeyHandler(this);
3120             }
3121             this._initData();
3122             this.element.click($.proxy(this._click, this));
3123             this.element.dblclick($.proxy(this._dblclick, this));
3124             if (this.options.useContextMenu) {
3125                 return this.element.bind('contextmenu', $.proxy(this._contextmenu, this));
3126             }
3127         };
3128
3129         JqTreeWidget.prototype._deinit = function() {
3130             this.element.empty();
3131             this.element.unbind();
3132             if (this.key_handler) {
3133                 this.key_handler.deinit();
3134             }
3135             this.tree = null;
3136             return JqTreeWidget.__super__._deinit.call(this);
3137         };
3138
3139         JqTreeWidget.prototype._initData = function() {
3140             var data_url;
3141             if (this.options.data) {
3142                 return this._loadData(this.options.data);
3143             } else {
3144                 data_url = this._getDataUrlInfo();
3145                 if (data_url) {
3146                     return this._loadDataFromUrl();
3147                 } else {
3148                     return this._loadData([]);
3149                 }
3150             }
3151         };
3152
3153         JqTreeWidget.prototype._getDataUrlInfo = function(node) {
3154             var data_url, getUrlFromString;
3155             data_url = this.options.dataUrl || this.element.data('url');
3156             getUrlFromString = (function(_this) {
3157                 return function() {
3158                     var data, selected_node_id, url_info;
3159                     url_info = {
3160                         url: data_url
3161                     };
3162                     if (node && node.id) {
3163                         data = {
3164                             node: node.id
3165                         };
3166                         url_info['data'] = data;
3167                     } else {
3168                         selected_node_id = _this._getNodeIdToBeSelected();
3169                         if (selected_node_id) {
3170                             data = {
3171                                 selected_node: selected_node_id
3172                             };
3173                             url_info['data'] = data;
3174                         }
3175                     }
3176                     return url_info;
3177                 };
3178             })(this);
3179             if ($.isFunction(data_url)) {
3180                 return data_url(node);
3181             } else if ($.type(data_url) === 'string') {
3182                 return getUrlFromString();
3183             } else {
3184                 return data_url;
3185             }
3186         };
3187
3188         JqTreeWidget.prototype._getNodeIdToBeSelected = function() {
3189             if (this.options.saveState) {
3190                 return this.save_state_handler.getNodeIdToBeSelected();
3191             } else {
3192                 return null;
3193             }
3194         };
3195
3196         JqTreeWidget.prototype._initTree = function(data) {
3197             var doInit, must_load_on_demand;
3198             doInit = (function(_this) {
3199                 return function() {
3200                     if (!_this.is_initialized) {
3201                         _this.is_initialized = true;
3202                         return _this._triggerEvent('tree.init');
3203                     }
3204                 };
3205             })(this);
3206             this.tree = new this.options.nodeClass(null, true, this.options.nodeClass);
3207             if (this.select_node_handler) {
3208                 this.select_node_handler.clear();
3209             }
3210             this.tree.loadFromData(data);
3211             must_load_on_demand = this._setInitialState();
3212             this._refreshElements();
3213             if (!must_load_on_demand) {
3214                 return doInit();
3215             } else {
3216                 return this._setInitialStateOnDemand(doInit);
3217             }
3218         };
3219
3220         JqTreeWidget.prototype._setInitialState = function() {
3221             var autoOpenNodes, is_restored, must_load_on_demand, ref1, restoreState;
3222             restoreState = (function(_this) {
3223                 return function() {
3224                     var must_load_on_demand, state;
3225                     if (!(_this.options.saveState && _this.save_state_handler)) {
3226                         return [false, false];
3227                     } else {
3228                         state = _this.save_state_handler.getStateFromStorage();
3229                         if (!state) {
3230                             return [false, false];
3231                         } else {
3232                             must_load_on_demand = _this.save_state_handler.setInitialState(state);
3233                             return [true, must_load_on_demand];
3234                         }
3235                     }
3236                 };
3237             })(this);
3238             autoOpenNodes = (function(_this) {
3239                 return function() {
3240                     var max_level, must_load_on_demand;
3241                     if (_this.options.autoOpen === false) {
3242                         return false;
3243                     }
3244                     max_level = _this._getAutoOpenMaxLevel();
3245                     must_load_on_demand = false;
3246                     _this.tree.iterate(function(node, level) {
3247                         if (node.load_on_demand) {
3248                             must_load_on_demand = true;
3249                             return false;
3250                         } else if (!node.hasChildren()) {
3251                             return false;
3252                         } else {
3253                             node.is_open = true;
3254                             return level !== max_level;
3255                         }
3256                     });
3257                     return must_load_on_demand;
3258                 };
3259             })(this);
3260             ref1 = restoreState(), is_restored = ref1[0], must_load_on_demand = ref1[1];
3261             if (!is_restored) {
3262                 must_load_on_demand = autoOpenNodes();
3263             }
3264             return must_load_on_demand;
3265         };
3266
3267         JqTreeWidget.prototype._setInitialStateOnDemand = function(cb_finished) {
3268             var autoOpenNodes, restoreState;
3269             restoreState = (function(_this) {
3270                 return function() {
3271                     var state;
3272                     if (!(_this.options.saveState && _this.save_state_handler)) {
3273                         return false;
3274                     } else {
3275                         state = _this.save_state_handler.getStateFromStorage();
3276                         if (!state) {
3277                             return false;
3278                         } else {
3279                             _this.save_state_handler.setInitialStateOnDemand(state, cb_finished);
3280                             return true;
3281                         }
3282                     }
3283                 };
3284             })(this);
3285             autoOpenNodes = (function(_this) {
3286                 return function() {
3287                     var loadAndOpenNode, loading_count, max_level, openNodes;
3288                     max_level = _this._getAutoOpenMaxLevel();
3289                     loading_count = 0;
3290                     loadAndOpenNode = function(node) {
3291                         loading_count += 1;
3292                         return _this._openNode(node, false, function() {
3293                             loading_count -= 1;
3294                             return openNodes();
3295                         });
3296                     };
3297                     openNodes = function() {
3298                         _this.tree.iterate(function(node, level) {
3299                             if (node.load_on_demand) {
3300                                 if (!node.is_loading) {
3301                                     loadAndOpenNode(node);
3302                                 }
3303                                 return false;
3304                             } else {
3305                                 _this._openNode(node, false);
3306                                 return level !== max_level;
3307                             }
3308                         });
3309                         if (loading_count === 0) {
3310                             return cb_finished();
3311                         }
3312                     };
3313                     return openNodes();
3314                 };
3315             })(this);
3316             if (!restoreState()) {
3317                 return autoOpenNodes();
3318             }
3319         };
3320
3321         JqTreeWidget.prototype._getAutoOpenMaxLevel = function() {
3322             if (this.options.autoOpen === true) {
3323                 return -1;
3324             } else {
3325                 return parseInt(this.options.autoOpen);
3326             }
3327         };
3328
3329
3330         /*
3331          Redraw the tree or part of the tree.
3332          * from_node: redraw this subtree
3333          */
3334
3335         JqTreeWidget.prototype._refreshElements = function(from_node) {
3336             if (from_node == null) {
3337                 from_node = null;
3338             }
3339             this.renderer.render(from_node);
3340             return this._triggerEvent('tree.refresh');
3341         };
3342
3343         JqTreeWidget.prototype._click = function(e) {
3344             var click_target, event, node;
3345             click_target = this._getClickTarget(e.target);
3346             if (click_target) {
3347                 if (click_target.type === 'button') {
3348                     this.toggle(click_target.node, this.options.slide);
3349                     e.preventDefault();
3350                     return e.stopPropagation();
3351                 } else if (click_target.type === 'label') {
3352                     node = click_target.node;
3353                     event = this._triggerEvent('tree.click', {
3354                         node: node,
3355                         click_event: e
3356                     });
3357                     if (!event.isDefaultPrevented()) {
3358                         return this._selectNode(node, true);
3359                     }
3360                 }
3361             }
3362         };
3363
3364         JqTreeWidget.prototype._dblclick = function(e) {
3365             var click_target;
3366             click_target = this._getClickTarget(e.target);
3367             if (click_target && click_target.type === 'label') {
3368                 return this._triggerEvent('tree.dblclick', {
3369                     node: click_target.node,
3370                     click_event: e
3371                 });
3372             }
3373         };
3374
3375         JqTreeWidget.prototype._getClickTarget = function(element) {
3376             var $button, $el, $target, node;
3377             $target = $(element);
3378             $button = $target.closest('.jqtree-toggler');
3379             if ($button.length) {
3380                 node = this._getNode($button);
3381                 if (node) {
3382                     return {
3383                         type: 'button',
3384                         node: node
3385                     };
3386                 }
3387             } else {
3388                 $el = $target.closest('.jqtree-element');
3389                 if ($el.length) {
3390                     node = this._getNode($el);
3391                     if (node) {
3392                         return {
3393                             type: 'label',
3394                             node: node
3395                         };
3396                     }
3397                 }
3398             }
3399             return null;
3400         };
3401
3402         JqTreeWidget.prototype._getNode = function($element) {
3403             var $li;
3404             $li = $element.closest('li.jqtree_common');
3405             if ($li.length === 0) {
3406                 return null;
3407             } else {
3408                 return $li.data('node');
3409             }
3410         };
3411
3412         JqTreeWidget.prototype._getNodeElementForNode = function(node) {
3413             if (node.isFolder()) {
3414                 return new FolderElement(node, this);
3415             } else {
3416                 return new NodeElement(node, this);
3417             }
3418         };
3419
3420         JqTreeWidget.prototype._getNodeElement = function($element) {
3421             var node;
3422             node = this._getNode($element);
3423             if (node) {
3424                 return this._getNodeElementForNode(node);
3425             } else {
3426                 return null;
3427             }
3428         };
3429
3430         JqTreeWidget.prototype._contextmenu = function(e) {
3431             var $div, node;
3432             $div = $(e.target).closest('ul.jqtree-tree .jqtree-element');
3433             if ($div.length) {
3434                 node = this._getNode($div);
3435                 if (node) {
3436                     e.preventDefault();
3437                     e.stopPropagation();
3438                     this._triggerEvent('tree.contextmenu', {
3439                         node: node,
3440                         click_event: e
3441                     });
3442                     return false;
3443                 }
3444             }
3445         };
3446
3447         JqTreeWidget.prototype._saveState = function() {
3448             if (this.options.saveState) {
3449                 return this.save_state_handler.saveState();
3450             }
3451         };
3452
3453         JqTreeWidget.prototype._mouseCapture = function(position_info) {
3454             if (this.options.dragAndDrop) {
3455                 return this.dnd_handler.mouseCapture(position_info);
3456             } else {
3457                 return false;
3458             }
3459         };
3460
3461         JqTreeWidget.prototype._mouseStart = function(position_info) {
3462             if (this.options.dragAndDrop) {
3463                 return this.dnd_handler.mouseStart(position_info);
3464             } else {
3465                 return false;
3466             }
3467         };
3468
3469         JqTreeWidget.prototype._mouseDrag = function(position_info) {
3470             var result;
3471             if (this.options.dragAndDrop) {
3472                 result = this.dnd_handler.mouseDrag(position_info);
3473                 if (this.scroll_handler) {
3474                     this.scroll_handler.checkScrolling();
3475                 }
3476                 return result;
3477             } else {
3478                 return false;
3479             }
3480         };
3481
3482         JqTreeWidget.prototype._mouseStop = function(position_info) {
3483             if (this.options.dragAndDrop) {
3484                 return this.dnd_handler.mouseStop(position_info);
3485             } else {
3486                 return false;
3487             }
3488         };
3489
3490         JqTreeWidget.prototype._triggerEvent = function(event_name, values) {
3491             var event;
3492             event = $.Event(event_name);
3493             $.extend(event, values);
3494             this.element.trigger(event);
3495             return event;
3496         };
3497
3498         JqTreeWidget.prototype.testGenerateHitAreas = function(moving_node) {
3499             this.dnd_handler.current_item = this._getNodeElementForNode(moving_node);
3500             this.dnd_handler.generateHitAreas();
3501             return this.dnd_handler.hit_areas;
3502         };
3503
3504         JqTreeWidget.prototype._selectCurrentNode = function() {
3505             var node, node_element;
3506             node = this.getSelectedNode();
3507             if (node) {
3508                 node_element = this._getNodeElementForNode(node);
3509                 if (node_element) {
3510                     return node_element.select();
3511                 }
3512             }
3513         };
3514
3515         JqTreeWidget.prototype._deselectCurrentNode = function() {
3516             var node;
3517             node = this.getSelectedNode();
3518             if (node) {
3519                 return this.removeFromSelection(node);
3520             }
3521         };
3522
3523         JqTreeWidget.prototype._getDefaultClosedIcon = function() {
3524             if (this.options.rtl) {
3525                 return '&#x25c0;';
3526             } else {
3527                 return '&#x25ba;';
3528             }
3529         };
3530
3531         JqTreeWidget.prototype._getRtlOption = function() {
3532             var data_rtl;
3533             if (this.options.rtl !== null) {
3534                 return this.options.rtl;
3535             } else {
3536                 data_rtl = this.element.data('rtl');
3537                 if ((data_rtl != null) && data_rtl !== false) {
3538                     return true;
3539                 } else {
3540                     return false;
3541                 }
3542             }
3543         };
3544
3545         JqTreeWidget.prototype._notifyLoading = function(is_loading, node, $el) {
3546             if (this.options.onLoading) {
3547                 return this.options.onLoading(is_loading, node, $el);
3548             }
3549         };
3550
3551         return JqTreeWidget;
3552
3553     })(MouseWidget);
3554
3555     JqTreeWidget.getModule = function(name) {
3556         var modules;
3557         modules = {
3558             'node': node_module,
3559             'util': util_module,
3560             'drag_and_drop_handler': drag_and_drop_handler
3561         };
3562         return modules[name];
3563     };
3564
3565     SimpleWidget.register(JqTreeWidget, 'tree');
3566
3567 },{"./drag_and_drop_handler":1,"./elements_renderer":2,"./key_handler":3,"./mouse.widget":4,"./node":5,"./node_element":6,"./save_state_handler":7,"./scroll_handler":8,"./select_node_handler":9,"./simple.widget":10,"./util":12,"./version":13}],12:[function(require,module,exports){
3568     var _indexOf, getBoolString, html_escape, indexOf, isInt;
3569
3570     _indexOf = function(array, item) {
3571         var i, j, len, value;
3572         for (i = j = 0, len = array.length; j < len; i = ++j) {
3573             value = array[i];
3574             if (value === item) {
3575                 return i;
3576             }
3577         }
3578         return -1;
3579     };
3580
3581     indexOf = function(array, item) {
3582         if (array.indexOf) {
3583             return array.indexOf(item);
3584         } else {
3585             return _indexOf(array, item);
3586         }
3587     };
3588
3589     isInt = function(n) {
3590         return typeof n === 'number' && n % 1 === 0;
3591     };
3592
3593     html_escape = function(string) {
3594         return ('' + string).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g, '&#x2F;');
3595     };
3596
3597     getBoolString = function(value) {
3598         if (value) {
3599             return 'true';
3600         } else {
3601             return 'false';
3602         }
3603     };
3604
3605     module.exports = {
3606         _indexOf: _indexOf,
3607         getBoolString: getBoolString,
3608         html_escape: html_escape,
3609         indexOf: indexOf,
3610         isInt: isInt
3611     };
3612
3613 },{}],13:[function(require,module,exports){
3614     module.exports = '1.3.6';
3615
3616 },{}]},{},[11]);