nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jqTree / tree.jquery.js
1 /*
2 JqTree 1.3.7
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(_this.node);
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   }
2115
2116   ScrollHandler.prototype._initScrollParent = function() {
2117     var $scroll_parent, getParentWithOverflow, setDocumentAsScrollParent;
2118     getParentWithOverflow = (function(_this) {
2119       return function() {
2120         var css_values, el, hasOverFlow, i, len, ref;
2121         css_values = ['overflow', 'overflow-y'];
2122         hasOverFlow = function(el) {
2123           var css_value, i, len, ref;
2124           for (i = 0, len = css_values.length; i < len; i++) {
2125             css_value = css_values[i];
2126             if ((ref = $.css(el, css_value)) === 'auto' || ref === 'scroll') {
2127               return true;
2128             }
2129           }
2130           return false;
2131         };
2132         if (hasOverFlow(_this.tree_widget.$el[0])) {
2133           return _this.tree_widget.$el;
2134         }
2135         ref = _this.tree_widget.$el.parents();
2136         for (i = 0, len = ref.length; i < len; i++) {
2137           el = ref[i];
2138           if (hasOverFlow(el)) {
2139             return $(el);
2140           }
2141         }
2142         return null;
2143       };
2144     })(this);
2145     setDocumentAsScrollParent = (function(_this) {
2146       return function() {
2147         _this.scroll_parent_top = 0;
2148         return _this.$scroll_parent = null;
2149       };
2150     })(this);
2151     if (this.tree_widget.$el.css('position') === 'fixed') {
2152       setDocumentAsScrollParent();
2153     }
2154     $scroll_parent = getParentWithOverflow();
2155     if ($scroll_parent && $scroll_parent.length && $scroll_parent[0].tagName !== 'HTML') {
2156       this.$scroll_parent = $scroll_parent;
2157       this.scroll_parent_top = this.$scroll_parent.offset().top;
2158     } else {
2159       setDocumentAsScrollParent();
2160     }
2161     return this.is_initialized = true;
2162   };
2163
2164   ScrollHandler.prototype._ensureInit = function() {
2165     if (!this.is_initialized) {
2166       return this._initScrollParent();
2167     }
2168   };
2169
2170   ScrollHandler.prototype.checkScrolling = function() {
2171     var hovered_area;
2172     this._ensureInit();
2173     hovered_area = this.tree_widget.dnd_handler.hovered_area;
2174     if (hovered_area && hovered_area.top !== this.previous_top) {
2175       this.previous_top = hovered_area.top;
2176       if (this.$scroll_parent) {
2177         return this._handleScrollingWithScrollParent(hovered_area);
2178       } else {
2179         return this._handleScrollingWithDocument(hovered_area);
2180       }
2181     }
2182   };
2183
2184   ScrollHandler.prototype._handleScrollingWithScrollParent = function(area) {
2185     var distance_bottom;
2186     distance_bottom = this.scroll_parent_top + this.$scroll_parent[0].offsetHeight - area.bottom;
2187     if (distance_bottom < 20) {
2188       this.$scroll_parent[0].scrollTop += 20;
2189       this.tree_widget.refreshHitAreas();
2190       return this.previous_top = -1;
2191     } else if ((area.top - this.scroll_parent_top) < 20) {
2192       this.$scroll_parent[0].scrollTop -= 20;
2193       this.tree_widget.refreshHitAreas();
2194       return this.previous_top = -1;
2195     }
2196   };
2197
2198   ScrollHandler.prototype._handleScrollingWithDocument = function(area) {
2199     var distance_top;
2200     distance_top = area.top - $(document).scrollTop();
2201     if (distance_top < 20) {
2202       return $(document).scrollTop($(document).scrollTop() - 20);
2203     } else if ($(window).height() - (area.bottom - $(document).scrollTop()) < 20) {
2204       return $(document).scrollTop($(document).scrollTop() + 20);
2205     }
2206   };
2207
2208   ScrollHandler.prototype.scrollTo = function(top) {
2209     var tree_top;
2210     this._ensureInit();
2211     if (this.$scroll_parent) {
2212       return this.$scroll_parent[0].scrollTop = top;
2213     } else {
2214       tree_top = this.tree_widget.$el.offset().top;
2215       return $(document).scrollTop(top + tree_top);
2216     }
2217   };
2218
2219   ScrollHandler.prototype.isScrolledIntoView = function(element) {
2220     var $element, element_bottom, element_top, view_bottom, view_top;
2221     this._ensureInit();
2222     $element = $(element);
2223     if (this.$scroll_parent) {
2224       view_top = 0;
2225       view_bottom = this.$scroll_parent.height();
2226       element_top = $element.offset().top - this.scroll_parent_top;
2227       element_bottom = element_top + $element.height();
2228     } else {
2229       view_top = $(window).scrollTop();
2230       view_bottom = view_top + $(window).height();
2231       element_top = $element.offset().top;
2232       element_bottom = element_top + $element.height();
2233     }
2234     return (element_bottom <= view_bottom) && (element_top >= view_top);
2235   };
2236
2237   return ScrollHandler;
2238
2239 })();
2240
2241 module.exports = ScrollHandler;
2242
2243 },{}],9:[function(require,module,exports){
2244 var $, SelectNodeHandler;
2245
2246 $ = jQuery;
2247
2248 SelectNodeHandler = (function() {
2249   function SelectNodeHandler(tree_widget) {
2250     this.tree_widget = tree_widget;
2251     this.clear();
2252   }
2253
2254   SelectNodeHandler.prototype.getSelectedNode = function() {
2255     var selected_nodes;
2256     selected_nodes = this.getSelectedNodes();
2257     if (selected_nodes.length) {
2258       return selected_nodes[0];
2259     } else {
2260       return false;
2261     }
2262   };
2263
2264   SelectNodeHandler.prototype.getSelectedNodes = function() {
2265     var id, node, selected_nodes;
2266     if (this.selected_single_node) {
2267       return [this.selected_single_node];
2268     } else {
2269       selected_nodes = [];
2270       for (id in this.selected_nodes) {
2271         node = this.tree_widget.getNodeById(id);
2272         if (node) {
2273           selected_nodes.push(node);
2274         }
2275       }
2276       return selected_nodes;
2277     }
2278   };
2279
2280   SelectNodeHandler.prototype.getSelectedNodesUnder = function(parent) {
2281     var id, node, selected_nodes;
2282     if (this.selected_single_node) {
2283       if (parent.isParentOf(this.selected_single_node)) {
2284         return [this.selected_single_node];
2285       } else {
2286         return [];
2287       }
2288     } else {
2289       selected_nodes = [];
2290       for (id in this.selected_nodes) {
2291         node = this.tree_widget.getNodeById(id);
2292         if (node && parent.isParentOf(node)) {
2293           selected_nodes.push(node);
2294         }
2295       }
2296       return selected_nodes;
2297     }
2298   };
2299
2300   SelectNodeHandler.prototype.isNodeSelected = function(node) {
2301     if (!node) {
2302       return false;
2303     } else if (node.id) {
2304       if (this.selected_nodes[node.id]) {
2305         return true;
2306       } else {
2307         return false;
2308       }
2309     } else if (this.selected_single_node) {
2310       return this.selected_single_node.element === node.element;
2311     } else {
2312       return false;
2313     }
2314   };
2315
2316   SelectNodeHandler.prototype.clear = function() {
2317     this.selected_nodes = {};
2318     return this.selected_single_node = null;
2319   };
2320
2321   SelectNodeHandler.prototype.removeFromSelection = function(node, include_children) {
2322     if (include_children == null) {
2323       include_children = false;
2324     }
2325     if (!node.id) {
2326       if (this.selected_single_node && node.element === this.selected_single_node.element) {
2327         return this.selected_single_node = null;
2328       }
2329     } else {
2330       delete this.selected_nodes[node.id];
2331       if (include_children) {
2332         return node.iterate((function(_this) {
2333           return function(n) {
2334             delete _this.selected_nodes[node.id];
2335             return true;
2336           };
2337         })(this));
2338       }
2339     }
2340   };
2341
2342   SelectNodeHandler.prototype.addToSelection = function(node) {
2343     if (node.id) {
2344       return this.selected_nodes[node.id] = true;
2345     } else {
2346       return this.selected_single_node = node;
2347     }
2348   };
2349
2350   return SelectNodeHandler;
2351
2352 })();
2353
2354 module.exports = SelectNodeHandler;
2355
2356 },{}],10:[function(require,module,exports){
2357
2358 /*
2359 Copyright 2013 Marco Braak
2360
2361 Licensed under the Apache License, Version 2.0 (the "License");
2362 you may not use this file except in compliance with the License.
2363 You may obtain a copy of the License at
2364
2365     http://www.apache.org/licenses/LICENSE-2.0
2366
2367 Unless required by applicable law or agreed to in writing, software
2368 distributed under the License is distributed on an "AS IS" BASIS,
2369 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2370 See the License for the specific language governing permissions and
2371 limitations under the License.
2372  */
2373 var $, SimpleWidget,
2374   slice = [].slice;
2375
2376 $ = jQuery;
2377
2378 SimpleWidget = (function() {
2379   SimpleWidget.prototype.defaults = {};
2380
2381   function SimpleWidget(el, options) {
2382     this.$el = $(el);
2383     this.options = $.extend({}, this.defaults, options);
2384   }
2385
2386   SimpleWidget.prototype.destroy = function() {
2387     return this._deinit();
2388   };
2389
2390   SimpleWidget.prototype._init = function() {
2391     return null;
2392   };
2393
2394   SimpleWidget.prototype._deinit = function() {
2395     return null;
2396   };
2397
2398   SimpleWidget.register = function(widget_class, widget_name) {
2399     var callFunction, createWidget, destroyWidget, getDataKey, getWidgetData;
2400     getDataKey = function() {
2401       return "simple_widget_" + widget_name;
2402     };
2403     getWidgetData = function(el, data_key) {
2404       var widget;
2405       widget = $.data(el, data_key);
2406       if (widget && (widget instanceof SimpleWidget)) {
2407         return widget;
2408       } else {
2409         return null;
2410       }
2411     };
2412     createWidget = function($el, options) {
2413       var data_key, el, existing_widget, i, len, widget;
2414       data_key = getDataKey();
2415       for (i = 0, len = $el.length; i < len; i++) {
2416         el = $el[i];
2417         existing_widget = getWidgetData(el, data_key);
2418         if (!existing_widget) {
2419           widget = new widget_class(el, options);
2420           if (!$.data(el, data_key)) {
2421             $.data(el, data_key, widget);
2422           }
2423           widget._init();
2424         }
2425       }
2426       return $el;
2427     };
2428     destroyWidget = function($el) {
2429       var data_key, el, i, len, results, widget;
2430       data_key = getDataKey();
2431       results = [];
2432       for (i = 0, len = $el.length; i < len; i++) {
2433         el = $el[i];
2434         widget = getWidgetData(el, data_key);
2435         if (widget) {
2436           widget.destroy();
2437         }
2438         results.push($.removeData(el, data_key));
2439       }
2440       return results;
2441     };
2442     callFunction = function($el, function_name, args) {
2443       var el, i, len, result, widget, widget_function;
2444       result = null;
2445       for (i = 0, len = $el.length; i < len; i++) {
2446         el = $el[i];
2447         widget = $.data(el, getDataKey());
2448         if (widget && (widget instanceof SimpleWidget)) {
2449           widget_function = widget[function_name];
2450           if (widget_function && (typeof widget_function === 'function')) {
2451             result = widget_function.apply(widget, args);
2452           }
2453         }
2454       }
2455       return result;
2456     };
2457     return $.fn[widget_name] = function() {
2458       var $el, args, argument1, function_name, options;
2459       argument1 = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
2460       $el = this;
2461       if (argument1 === void 0 || typeof argument1 === 'object') {
2462         options = argument1;
2463         return createWidget($el, options);
2464       } else if (typeof argument1 === 'string' && argument1[0] !== '_') {
2465         function_name = argument1;
2466         if (function_name === 'destroy') {
2467           return destroyWidget($el);
2468         } else if (function_name === 'get_widget_class') {
2469           return widget_class;
2470         } else {
2471           return callFunction($el, function_name, args);
2472         }
2473       }
2474     };
2475   };
2476
2477   return SimpleWidget;
2478
2479 })();
2480
2481 module.exports = SimpleWidget;
2482
2483 },{}],11:[function(require,module,exports){
2484 var $, BorderDropHint, DragAndDropHandler, DragElement, ElementsRenderer, FolderElement, GhostDropHint, HitAreasGenerator, JqTreeWidget, KeyHandler, MouseWidget, Node, NodeElement, Position, SaveStateHandler, ScrollHandler, SelectNodeHandler, SimpleWidget, __version__, drag_and_drop_handler, isFunction, node_module, ref, util_module,
2485   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; },
2486   hasProp = {}.hasOwnProperty;
2487
2488 __version__ = require('./version');
2489
2490 drag_and_drop_handler = require('./drag_and_drop_handler');
2491
2492 ElementsRenderer = require('./elements_renderer');
2493
2494 KeyHandler = require('./key_handler');
2495
2496 MouseWidget = require('./mouse.widget');
2497
2498 SaveStateHandler = require('./save_state_handler');
2499
2500 ScrollHandler = require('./scroll_handler');
2501
2502 SelectNodeHandler = require('./select_node_handler');
2503
2504 SimpleWidget = require('./simple.widget');
2505
2506 node_module = require('./node');
2507
2508 Node = node_module.Node;
2509
2510 Position = node_module.Position;
2511
2512 util_module = require('./util');
2513
2514 isFunction = util_module.isFunction;
2515
2516 ref = require('./node_element'), BorderDropHint = ref.BorderDropHint, FolderElement = ref.FolderElement, GhostDropHint = ref.GhostDropHint, NodeElement = ref.NodeElement;
2517
2518 DragAndDropHandler = drag_and_drop_handler.DragAndDropHandler, DragElement = drag_and_drop_handler.DragElement, HitAreasGenerator = drag_and_drop_handler.HitAreasGenerator;
2519
2520 $ = jQuery;
2521
2522 JqTreeWidget = (function(superClass) {
2523   extend(JqTreeWidget, superClass);
2524
2525   function JqTreeWidget() {
2526     return JqTreeWidget.__super__.constructor.apply(this, arguments);
2527   }
2528
2529   JqTreeWidget.prototype.BorderDropHint = BorderDropHint;
2530
2531   JqTreeWidget.prototype.DragElement = DragElement;
2532
2533   JqTreeWidget.prototype.DragAndDropHandler = DragAndDropHandler;
2534
2535   JqTreeWidget.prototype.ElementsRenderer = ElementsRenderer;
2536
2537   JqTreeWidget.prototype.GhostDropHint = GhostDropHint;
2538
2539   JqTreeWidget.prototype.HitAreasGenerator = HitAreasGenerator;
2540
2541   JqTreeWidget.prototype.Node = Node;
2542
2543   JqTreeWidget.prototype.SaveStateHandler = SaveStateHandler;
2544
2545   JqTreeWidget.prototype.ScrollHandler = ScrollHandler;
2546
2547   JqTreeWidget.prototype.SelectNodeHandler = SelectNodeHandler;
2548
2549   JqTreeWidget.prototype.defaults = {
2550     autoOpen: false,
2551     saveState: false,
2552     dragAndDrop: false,
2553     selectable: true,
2554     useContextMenu: true,
2555     onCanSelectNode: null,
2556     onSetStateFromStorage: null,
2557     onGetStateFromStorage: null,
2558     onCreateLi: null,
2559     onIsMoveHandle: null,
2560     onCanMove: null,
2561     onCanMoveTo: null,
2562     onLoadFailed: null,
2563     autoEscape: true,
2564     dataUrl: null,
2565     closedIcon: null,
2566     openedIcon: '&#x25bc;',
2567     slide: true,
2568     nodeClass: Node,
2569     dataFilter: null,
2570     keyboardSupport: true,
2571     openFolderDelay: 500,
2572     rtl: null,
2573     onDragMove: null,
2574     onDragStop: null,
2575     buttonLeft: true,
2576     onLoading: null
2577   };
2578
2579   JqTreeWidget.prototype.toggle = function(node, slide) {
2580     if (slide == null) {
2581       slide = null;
2582     }
2583     if (slide === null) {
2584       slide = this.options.slide;
2585     }
2586     if (node.is_open) {
2587       this.closeNode(node, slide);
2588     } else {
2589       this.openNode(node, slide);
2590     }
2591     return this.element;
2592   };
2593
2594   JqTreeWidget.prototype.getTree = function() {
2595     return this.tree;
2596   };
2597
2598   JqTreeWidget.prototype.selectNode = function(node) {
2599     this._selectNode(node, false);
2600     return this.element;
2601   };
2602
2603   JqTreeWidget.prototype._selectNode = function(node, must_toggle) {
2604     var canSelect, deselected_node, openParents, saveState;
2605     if (must_toggle == null) {
2606       must_toggle = false;
2607     }
2608     if (!this.select_node_handler) {
2609       return;
2610     }
2611     canSelect = (function(_this) {
2612       return function() {
2613         if (_this.options.onCanSelectNode) {
2614           return _this.options.selectable && _this.options.onCanSelectNode(node);
2615         } else {
2616           return _this.options.selectable;
2617         }
2618       };
2619     })(this);
2620     openParents = (function(_this) {
2621       return function() {
2622         var parent;
2623         parent = node.parent;
2624         if (parent && parent.parent && !parent.is_open) {
2625           return _this.openNode(parent, false);
2626         }
2627       };
2628     })(this);
2629     saveState = (function(_this) {
2630       return function() {
2631         if (_this.options.saveState) {
2632           return _this.save_state_handler.saveState();
2633         }
2634       };
2635     })(this);
2636     if (!node) {
2637       this._deselectCurrentNode();
2638       saveState();
2639       return;
2640     }
2641     if (!canSelect()) {
2642       return;
2643     }
2644     if (this.select_node_handler.isNodeSelected(node)) {
2645       if (must_toggle) {
2646         this._deselectCurrentNode();
2647         this._triggerEvent('tree.select', {
2648           node: null,
2649           previous_node: node
2650         });
2651       }
2652     } else {
2653       deselected_node = this.getSelectedNode();
2654       this._deselectCurrentNode();
2655       this.addToSelection(node);
2656       this._triggerEvent('tree.select', {
2657         node: node,
2658         deselected_node: deselected_node
2659       });
2660       openParents();
2661     }
2662     return saveState();
2663   };
2664
2665   JqTreeWidget.prototype.getSelectedNode = function() {
2666     if (this.select_node_handler) {
2667       return this.select_node_handler.getSelectedNode();
2668     } else {
2669       return null;
2670     }
2671   };
2672
2673   JqTreeWidget.prototype.toJson = function() {
2674     return JSON.stringify(this.tree.getData());
2675   };
2676
2677   JqTreeWidget.prototype.loadData = function(data, parent_node) {
2678     this._loadData(data, parent_node);
2679     return this.element;
2680   };
2681
2682
2683   /*
2684   signatures:
2685   - loadDataFromUrl(url, parent_node=null, on_finished=null)
2686       loadDataFromUrl('/my_data');
2687       loadDataFromUrl('/my_data', node1);
2688       loadDataFromUrl('/my_data', node1, function() { console.log('finished'); });
2689       loadDataFromUrl('/my_data', null, function() { console.log('finished'); });
2690   
2691   - loadDataFromUrl(parent_node=null, on_finished=null)
2692       loadDataFromUrl();
2693       loadDataFromUrl(node1);
2694       loadDataFromUrl(null, function() { console.log('finished'); });
2695       loadDataFromUrl(node1, function() { console.log('finished'); });
2696    */
2697
2698   JqTreeWidget.prototype.loadDataFromUrl = function(param1, param2, param3) {
2699     if ($.type(param1) === 'string') {
2700       this._loadDataFromUrl(param1, param2, param3);
2701     } else {
2702       this._loadDataFromUrl(null, param1, param2);
2703     }
2704     return this.element;
2705   };
2706
2707   JqTreeWidget.prototype.reload = function(on_finished) {
2708     this._loadDataFromUrl(null, null, on_finished);
2709     return this.element;
2710   };
2711
2712   JqTreeWidget.prototype._loadDataFromUrl = function(url_info, parent_node, on_finished) {
2713     var $el, addLoadingClass, handeLoadData, handleError, handleSuccess, loadDataFromUrlInfo, parseUrlInfo, removeLoadingClass;
2714     $el = null;
2715     addLoadingClass = (function(_this) {
2716       return function() {
2717         if (parent_node) {
2718           $el = $(parent_node.element);
2719         } else {
2720           $el = _this.element;
2721         }
2722         $el.addClass('jqtree-loading');
2723         return _this._notifyLoading(true, parent_node, $el);
2724       };
2725     })(this);
2726     removeLoadingClass = (function(_this) {
2727       return function() {
2728         if ($el) {
2729           $el.removeClass('jqtree-loading');
2730           return _this._notifyLoading(false, parent_node, $el);
2731         }
2732       };
2733     })(this);
2734     parseUrlInfo = function() {
2735       if ($.type(url_info) === 'string') {
2736         return {
2737           url: url_info
2738         };
2739       }
2740       if (!url_info.method) {
2741         url_info.method = 'get';
2742       }
2743       return url_info;
2744     };
2745     handeLoadData = (function(_this) {
2746       return function(data) {
2747         removeLoadingClass();
2748         _this._loadData(data, parent_node);
2749         if (on_finished && $.isFunction(on_finished)) {
2750           return on_finished();
2751         }
2752       };
2753     })(this);
2754     handleSuccess = (function(_this) {
2755       return function(response) {
2756         var data;
2757         if ($.isArray(response) || typeof response === 'object') {
2758           data = response;
2759         } else if (data != null) {
2760           data = $.parseJSON(response);
2761         } else {
2762           data = [];
2763         }
2764         if (_this.options.dataFilter) {
2765           data = _this.options.dataFilter(data);
2766         }
2767         return handeLoadData(data);
2768       };
2769     })(this);
2770     handleError = (function(_this) {
2771       return function(response) {
2772         removeLoadingClass();
2773         if (_this.options.onLoadFailed) {
2774           return _this.options.onLoadFailed(response);
2775         }
2776       };
2777     })(this);
2778     loadDataFromUrlInfo = function() {
2779       url_info = parseUrlInfo();
2780       return $.ajax($.extend({}, url_info, {
2781         method: url_info.method != null ? url_info.method.toUpperCase() : 'GET',
2782         cache: false,
2783         dataType: 'json',
2784         success: handleSuccess,
2785         error: handleError
2786       }));
2787     };
2788     if (!url_info) {
2789       url_info = this._getDataUrlInfo(parent_node);
2790     }
2791     addLoadingClass();
2792     if (!url_info) {
2793       removeLoadingClass();
2794     } else if ($.isArray(url_info)) {
2795       handeLoadData(url_info);
2796     } else {
2797       loadDataFromUrlInfo();
2798     }
2799   };
2800
2801   JqTreeWidget.prototype._loadData = function(data, parent_node) {
2802     var deselectNodes, loadSubtree;
2803     if (parent_node == null) {
2804       parent_node = null;
2805     }
2806     deselectNodes = (function(_this) {
2807       return function() {
2808         var i, len, n, selected_nodes_under_parent;
2809         if (_this.select_node_handler) {
2810           selected_nodes_under_parent = _this.select_node_handler.getSelectedNodesUnder(parent_node);
2811           for (i = 0, len = selected_nodes_under_parent.length; i < len; i++) {
2812             n = selected_nodes_under_parent[i];
2813             _this.select_node_handler.removeFromSelection(n);
2814           }
2815         }
2816         return null;
2817       };
2818     })(this);
2819     loadSubtree = (function(_this) {
2820       return function() {
2821         parent_node.loadFromData(data);
2822         parent_node.load_on_demand = false;
2823         parent_node.is_loading = false;
2824         return _this._refreshElements(parent_node);
2825       };
2826     })(this);
2827     if (!data) {
2828       return;
2829     }
2830     this._triggerEvent('tree.load_data', {
2831       tree_data: data
2832     });
2833     if (!parent_node) {
2834       this._initTree(data);
2835     } else {
2836       deselectNodes();
2837       loadSubtree();
2838     }
2839     if (this.isDragging()) {
2840       return this.dnd_handler.refresh();
2841     }
2842   };
2843
2844   JqTreeWidget.prototype.getNodeById = function(node_id) {
2845     return this.tree.getNodeById(node_id);
2846   };
2847
2848   JqTreeWidget.prototype.getNodeByName = function(name) {
2849     return this.tree.getNodeByName(name);
2850   };
2851
2852   JqTreeWidget.prototype.getNodesByProperty = function(key, value) {
2853     return this.tree.getNodesByProperty(key, value);
2854   };
2855
2856   JqTreeWidget.prototype.getNodeByHtmlElement = function(element) {
2857     return this._getNode($(element));
2858   };
2859
2860   JqTreeWidget.prototype.getNodeByCallback = function(callback) {
2861     return this.tree.getNodeByCallback(callback);
2862   };
2863
2864   JqTreeWidget.prototype.openNode = function(node, slide_param, on_finished_param) {
2865     var on_finished, parseParams, ref1, slide;
2866     if (slide_param == null) {
2867       slide_param = null;
2868     }
2869     if (on_finished_param == null) {
2870       on_finished_param = null;
2871     }
2872     parseParams = (function(_this) {
2873       return function() {
2874         var on_finished, slide;
2875         if (isFunction(slide_param)) {
2876           on_finished = slide_param;
2877           slide = null;
2878         } else {
2879           slide = slide_param;
2880           on_finished = on_finished_param;
2881         }
2882         if (slide === null) {
2883           slide = _this.options.slide;
2884         }
2885         return [slide, on_finished];
2886       };
2887     })(this);
2888     ref1 = parseParams(), slide = ref1[0], on_finished = ref1[1];
2889     if (node) {
2890       this._openNode(node, slide, on_finished);
2891     }
2892     return this.element;
2893   };
2894
2895   JqTreeWidget.prototype._openNode = function(node, slide, on_finished) {
2896     var doOpenNode, parent;
2897     if (slide == null) {
2898       slide = true;
2899     }
2900     doOpenNode = (function(_this) {
2901       return function(_node, _slide, _on_finished) {
2902         var folder_element;
2903         folder_element = new FolderElement(_node, _this);
2904         return folder_element.open(_on_finished, _slide);
2905       };
2906     })(this);
2907     if (node.isFolder()) {
2908       if (node.load_on_demand) {
2909         return this._loadFolderOnDemand(node, slide, on_finished);
2910       } else {
2911         parent = node.parent;
2912         while (parent) {
2913           if (parent.parent) {
2914             doOpenNode(parent, false, null);
2915           }
2916           parent = parent.parent;
2917         }
2918         doOpenNode(node, slide, on_finished);
2919         return this._saveState();
2920       }
2921     }
2922   };
2923
2924   JqTreeWidget.prototype._loadFolderOnDemand = function(node, slide, on_finished) {
2925     if (slide == null) {
2926       slide = true;
2927     }
2928     node.is_loading = true;
2929     return this._loadDataFromUrl(null, node, (function(_this) {
2930       return function() {
2931         return _this._openNode(node, slide, on_finished);
2932       };
2933     })(this));
2934   };
2935
2936   JqTreeWidget.prototype.closeNode = function(node, slide) {
2937     if (slide == null) {
2938       slide = null;
2939     }
2940     if (slide === null) {
2941       slide = this.options.slide;
2942     }
2943     if (node.isFolder()) {
2944       new FolderElement(node, this).close(slide);
2945       this._saveState();
2946     }
2947     return this.element;
2948   };
2949
2950   JqTreeWidget.prototype.isDragging = function() {
2951     if (this.dnd_handler) {
2952       return this.dnd_handler.is_dragging;
2953     } else {
2954       return false;
2955     }
2956   };
2957
2958   JqTreeWidget.prototype.refreshHitAreas = function() {
2959     this.dnd_handler.refresh();
2960     return this.element;
2961   };
2962
2963   JqTreeWidget.prototype.addNodeAfter = function(new_node_info, existing_node) {
2964     var new_node;
2965     new_node = existing_node.addAfter(new_node_info);
2966     this._refreshElements(existing_node.parent);
2967     return new_node;
2968   };
2969
2970   JqTreeWidget.prototype.addNodeBefore = function(new_node_info, existing_node) {
2971     var new_node;
2972     new_node = existing_node.addBefore(new_node_info);
2973     this._refreshElements(existing_node.parent);
2974     return new_node;
2975   };
2976
2977   JqTreeWidget.prototype.addParentNode = function(new_node_info, existing_node) {
2978     var new_node;
2979     new_node = existing_node.addParent(new_node_info);
2980     this._refreshElements(new_node.parent);
2981     return new_node;
2982   };
2983
2984   JqTreeWidget.prototype.removeNode = function(node) {
2985     var parent;
2986     parent = node.parent;
2987     if (parent) {
2988       this.select_node_handler.removeFromSelection(node, true);
2989       node.remove();
2990       this._refreshElements(parent);
2991     }
2992     return this.element;
2993   };
2994
2995   JqTreeWidget.prototype.appendNode = function(new_node_info, parent_node) {
2996     var node;
2997     parent_node = parent_node || this.tree;
2998     node = parent_node.append(new_node_info);
2999     this._refreshElements(parent_node);
3000     return node;
3001   };
3002
3003   JqTreeWidget.prototype.prependNode = function(new_node_info, parent_node) {
3004     var node;
3005     if (!parent_node) {
3006       parent_node = this.tree;
3007     }
3008     node = parent_node.prepend(new_node_info);
3009     this._refreshElements(parent_node);
3010     return node;
3011   };
3012
3013   JqTreeWidget.prototype.updateNode = function(node, data) {
3014     var id_is_changed;
3015     id_is_changed = data.id && data.id !== node.id;
3016     if (id_is_changed) {
3017       this.tree.removeNodeFromIndex(node);
3018     }
3019     node.setData(data);
3020     if (id_is_changed) {
3021       this.tree.addNodeToIndex(node);
3022     }
3023     if (typeof data === 'object' && data.children) {
3024       node.removeChildren();
3025       if (data.children.length) {
3026         node.loadFromData(data.children);
3027       }
3028     }
3029     this.renderer.renderFromNode(node);
3030     this._selectCurrentNode();
3031     return this.element;
3032   };
3033
3034   JqTreeWidget.prototype.moveNode = function(node, target_node, position) {
3035     var position_index;
3036     position_index = Position.nameToIndex(position);
3037     this.tree.moveNode(node, target_node, position_index);
3038     this._refreshElements();
3039     return this.element;
3040   };
3041
3042   JqTreeWidget.prototype.getStateFromStorage = function() {
3043     return this.save_state_handler.getStateFromStorage();
3044   };
3045
3046   JqTreeWidget.prototype.addToSelection = function(node) {
3047     if (node) {
3048       this.select_node_handler.addToSelection(node);
3049       this._getNodeElementForNode(node).select();
3050       this._saveState();
3051     }
3052     return this.element;
3053   };
3054
3055   JqTreeWidget.prototype.getSelectedNodes = function() {
3056     return this.select_node_handler.getSelectedNodes();
3057   };
3058
3059   JqTreeWidget.prototype.isNodeSelected = function(node) {
3060     return this.select_node_handler.isNodeSelected(node);
3061   };
3062
3063   JqTreeWidget.prototype.removeFromSelection = function(node) {
3064     this.select_node_handler.removeFromSelection(node);
3065     this._getNodeElementForNode(node).deselect();
3066     this._saveState();
3067     return this.element;
3068   };
3069
3070   JqTreeWidget.prototype.scrollToNode = function(node) {
3071     var $element, top;
3072     $element = $(node.element);
3073     top = $element.offset().top - this.$el.offset().top;
3074     this.scroll_handler.scrollTo(top);
3075     return this.element;
3076   };
3077
3078   JqTreeWidget.prototype.getState = function() {
3079     return this.save_state_handler.getState();
3080   };
3081
3082   JqTreeWidget.prototype.setState = function(state) {
3083     this.save_state_handler.setInitialState(state);
3084     this._refreshElements();
3085     return this.element;
3086   };
3087
3088   JqTreeWidget.prototype.setOption = function(option, value) {
3089     this.options[option] = value;
3090     return this.element;
3091   };
3092
3093   JqTreeWidget.prototype.moveDown = function() {
3094     if (this.key_handler) {
3095       this.key_handler.moveDown();
3096     }
3097     return this.element;
3098   };
3099
3100   JqTreeWidget.prototype.moveUp = function() {
3101     if (this.key_handler) {
3102       this.key_handler.moveUp();
3103     }
3104     return this.element;
3105   };
3106
3107   JqTreeWidget.prototype.getVersion = function() {
3108     return __version__;
3109   };
3110
3111   JqTreeWidget.prototype._init = function() {
3112     JqTreeWidget.__super__._init.call(this);
3113     this.element = this.$el;
3114     this.mouse_delay = 300;
3115     this.is_initialized = false;
3116     this.options.rtl = this._getRtlOption();
3117     if (!this.options.closedIcon) {
3118       this.options.closedIcon = this._getDefaultClosedIcon();
3119     }
3120     this.renderer = new ElementsRenderer(this);
3121     if (SaveStateHandler != null) {
3122       this.save_state_handler = new SaveStateHandler(this);
3123     } else {
3124       this.options.saveState = false;
3125     }
3126     if (SelectNodeHandler != null) {
3127       this.select_node_handler = new SelectNodeHandler(this);
3128     }
3129     if (DragAndDropHandler != null) {
3130       this.dnd_handler = new DragAndDropHandler(this);
3131     } else {
3132       this.options.dragAndDrop = false;
3133     }
3134     if (ScrollHandler != null) {
3135       this.scroll_handler = new ScrollHandler(this);
3136     }
3137     if ((KeyHandler != null) && (SelectNodeHandler != null)) {
3138       this.key_handler = new KeyHandler(this);
3139     }
3140     this._initData();
3141     this.element.click($.proxy(this._click, this));
3142     this.element.dblclick($.proxy(this._dblclick, this));
3143     if (this.options.useContextMenu) {
3144       return this.element.bind('contextmenu', $.proxy(this._contextmenu, this));
3145     }
3146   };
3147
3148   JqTreeWidget.prototype._deinit = function() {
3149     this.element.empty();
3150     this.element.unbind();
3151     if (this.key_handler) {
3152       this.key_handler.deinit();
3153     }
3154     this.tree = null;
3155     return JqTreeWidget.__super__._deinit.call(this);
3156   };
3157
3158   JqTreeWidget.prototype._initData = function() {
3159     var data_url;
3160     if (this.options.data) {
3161       return this._loadData(this.options.data);
3162     } else {
3163       data_url = this._getDataUrlInfo();
3164       if (data_url) {
3165         return this._loadDataFromUrl();
3166       } else {
3167         return this._loadData([]);
3168       }
3169     }
3170   };
3171
3172   JqTreeWidget.prototype._getDataUrlInfo = function(node) {
3173     var data_url, getUrlFromString;
3174     data_url = this.options.dataUrl || this.element.data('url');
3175     getUrlFromString = (function(_this) {
3176       return function() {
3177         var data, selected_node_id, url_info;
3178         url_info = {
3179           url: data_url
3180         };
3181         if (node && node.id) {
3182           data = {
3183             node: node.id
3184           };
3185           url_info['data'] = data;
3186         } else {
3187           selected_node_id = _this._getNodeIdToBeSelected();
3188           if (selected_node_id) {
3189             data = {
3190               selected_node: selected_node_id
3191             };
3192             url_info['data'] = data;
3193           }
3194         }
3195         return url_info;
3196       };
3197     })(this);
3198     if ($.isFunction(data_url)) {
3199       return data_url(node);
3200     } else if ($.type(data_url) === 'string') {
3201       return getUrlFromString();
3202     } else {
3203       return data_url;
3204     }
3205   };
3206
3207   JqTreeWidget.prototype._getNodeIdToBeSelected = function() {
3208     if (this.options.saveState) {
3209       return this.save_state_handler.getNodeIdToBeSelected();
3210     } else {
3211       return null;
3212     }
3213   };
3214
3215   JqTreeWidget.prototype._initTree = function(data) {
3216     var doInit, must_load_on_demand;
3217     doInit = (function(_this) {
3218       return function() {
3219         if (!_this.is_initialized) {
3220           _this.is_initialized = true;
3221           return _this._triggerEvent('tree.init');
3222         }
3223       };
3224     })(this);
3225     this.tree = new this.options.nodeClass(null, true, this.options.nodeClass);
3226     if (this.select_node_handler) {
3227       this.select_node_handler.clear();
3228     }
3229     this.tree.loadFromData(data);
3230     must_load_on_demand = this._setInitialState();
3231     this._refreshElements();
3232     if (!must_load_on_demand) {
3233       return doInit();
3234     } else {
3235       return this._setInitialStateOnDemand(doInit);
3236     }
3237   };
3238
3239   JqTreeWidget.prototype._setInitialState = function() {
3240     var autoOpenNodes, is_restored, must_load_on_demand, ref1, restoreState;
3241     restoreState = (function(_this) {
3242       return function() {
3243         var must_load_on_demand, state;
3244         if (!(_this.options.saveState && _this.save_state_handler)) {
3245           return [false, false];
3246         } else {
3247           state = _this.save_state_handler.getStateFromStorage();
3248           if (!state) {
3249             return [false, false];
3250           } else {
3251             must_load_on_demand = _this.save_state_handler.setInitialState(state);
3252             return [true, must_load_on_demand];
3253           }
3254         }
3255       };
3256     })(this);
3257     autoOpenNodes = (function(_this) {
3258       return function() {
3259         var max_level, must_load_on_demand;
3260         if (_this.options.autoOpen === false) {
3261           return false;
3262         }
3263         max_level = _this._getAutoOpenMaxLevel();
3264         must_load_on_demand = false;
3265         _this.tree.iterate(function(node, level) {
3266           if (node.load_on_demand) {
3267             must_load_on_demand = true;
3268             return false;
3269           } else if (!node.hasChildren()) {
3270             return false;
3271           } else {
3272             node.is_open = true;
3273             return level !== max_level;
3274           }
3275         });
3276         return must_load_on_demand;
3277       };
3278     })(this);
3279     ref1 = restoreState(), is_restored = ref1[0], must_load_on_demand = ref1[1];
3280     if (!is_restored) {
3281       must_load_on_demand = autoOpenNodes();
3282     }
3283     return must_load_on_demand;
3284   };
3285
3286   JqTreeWidget.prototype._setInitialStateOnDemand = function(cb_finished) {
3287     var autoOpenNodes, restoreState;
3288     restoreState = (function(_this) {
3289       return function() {
3290         var state;
3291         if (!(_this.options.saveState && _this.save_state_handler)) {
3292           return false;
3293         } else {
3294           state = _this.save_state_handler.getStateFromStorage();
3295           if (!state) {
3296             return false;
3297           } else {
3298             _this.save_state_handler.setInitialStateOnDemand(state, cb_finished);
3299             return true;
3300           }
3301         }
3302       };
3303     })(this);
3304     autoOpenNodes = (function(_this) {
3305       return function() {
3306         var loadAndOpenNode, loading_count, max_level, openNodes;
3307         max_level = _this._getAutoOpenMaxLevel();
3308         loading_count = 0;
3309         loadAndOpenNode = function(node) {
3310           loading_count += 1;
3311           return _this._openNode(node, false, function() {
3312             loading_count -= 1;
3313             return openNodes();
3314           });
3315         };
3316         openNodes = function() {
3317           _this.tree.iterate(function(node, level) {
3318             if (node.load_on_demand) {
3319               if (!node.is_loading) {
3320                 loadAndOpenNode(node);
3321               }
3322               return false;
3323             } else {
3324               _this._openNode(node, false);
3325               return level !== max_level;
3326             }
3327           });
3328           if (loading_count === 0) {
3329             return cb_finished();
3330           }
3331         };
3332         return openNodes();
3333       };
3334     })(this);
3335     if (!restoreState()) {
3336       return autoOpenNodes();
3337     }
3338   };
3339
3340   JqTreeWidget.prototype._getAutoOpenMaxLevel = function() {
3341     if (this.options.autoOpen === true) {
3342       return -1;
3343     } else {
3344       return parseInt(this.options.autoOpen);
3345     }
3346   };
3347
3348
3349   /*
3350   Redraw the tree or part of the tree.
3351    * from_node: redraw this subtree
3352    */
3353
3354   JqTreeWidget.prototype._refreshElements = function(from_node) {
3355     if (from_node == null) {
3356       from_node = null;
3357     }
3358     this.renderer.render(from_node);
3359     return this._triggerEvent('tree.refresh');
3360   };
3361
3362   JqTreeWidget.prototype._click = function(e) {
3363     var click_target, event, node;
3364     click_target = this._getClickTarget(e.target);
3365     if (click_target) {
3366       if (click_target.type === 'button') {
3367         this.toggle(click_target.node, this.options.slide);
3368         e.preventDefault();
3369         return e.stopPropagation();
3370       } else if (click_target.type === 'label') {
3371         node = click_target.node;
3372         event = this._triggerEvent('tree.click', {
3373           node: node,
3374           click_event: e
3375         });
3376         if (!event.isDefaultPrevented()) {
3377           return this._selectNode(node, true);
3378         }
3379       }
3380     }
3381   };
3382
3383   JqTreeWidget.prototype._dblclick = function(e) {
3384     var click_target;
3385     click_target = this._getClickTarget(e.target);
3386     if (click_target && click_target.type === 'label') {
3387       return this._triggerEvent('tree.dblclick', {
3388         node: click_target.node,
3389         click_event: e
3390       });
3391     }
3392   };
3393
3394   JqTreeWidget.prototype._getClickTarget = function(element) {
3395     var $button, $el, $target, node;
3396     $target = $(element);
3397     $button = $target.closest('.jqtree-toggler');
3398     if ($button.length) {
3399       node = this._getNode($button);
3400       if (node) {
3401         return {
3402           type: 'button',
3403           node: node
3404         };
3405       }
3406     } else {
3407       $el = $target.closest('.jqtree-element');
3408       if ($el.length) {
3409         node = this._getNode($el);
3410         if (node) {
3411           return {
3412             type: 'label',
3413             node: node
3414           };
3415         }
3416       }
3417     }
3418     return null;
3419   };
3420
3421   JqTreeWidget.prototype._getNode = function($element) {
3422     var $li;
3423     $li = $element.closest('li.jqtree_common');
3424     if ($li.length === 0) {
3425       return null;
3426     } else {
3427       return $li.data('node');
3428     }
3429   };
3430
3431   JqTreeWidget.prototype._getNodeElementForNode = function(node) {
3432     if (node.isFolder()) {
3433       return new FolderElement(node, this);
3434     } else {
3435       return new NodeElement(node, this);
3436     }
3437   };
3438
3439   JqTreeWidget.prototype._getNodeElement = function($element) {
3440     var node;
3441     node = this._getNode($element);
3442     if (node) {
3443       return this._getNodeElementForNode(node);
3444     } else {
3445       return null;
3446     }
3447   };
3448
3449   JqTreeWidget.prototype._contextmenu = function(e) {
3450     var $div, node;
3451     $div = $(e.target).closest('ul.jqtree-tree .jqtree-element');
3452     if ($div.length) {
3453       node = this._getNode($div);
3454       if (node) {
3455         e.preventDefault();
3456         e.stopPropagation();
3457         this._triggerEvent('tree.contextmenu', {
3458           node: node,
3459           click_event: e
3460         });
3461         return false;
3462       }
3463     }
3464   };
3465
3466   JqTreeWidget.prototype._saveState = function() {
3467     if (this.options.saveState) {
3468       return this.save_state_handler.saveState();
3469     }
3470   };
3471
3472   JqTreeWidget.prototype._mouseCapture = function(position_info) {
3473     if (this.options.dragAndDrop) {
3474       return this.dnd_handler.mouseCapture(position_info);
3475     } else {
3476       return false;
3477     }
3478   };
3479
3480   JqTreeWidget.prototype._mouseStart = function(position_info) {
3481     if (this.options.dragAndDrop) {
3482       return this.dnd_handler.mouseStart(position_info);
3483     } else {
3484       return false;
3485     }
3486   };
3487
3488   JqTreeWidget.prototype._mouseDrag = function(position_info) {
3489     var result;
3490     if (this.options.dragAndDrop) {
3491       result = this.dnd_handler.mouseDrag(position_info);
3492       if (this.scroll_handler) {
3493         this.scroll_handler.checkScrolling();
3494       }
3495       return result;
3496     } else {
3497       return false;
3498     }
3499   };
3500
3501   JqTreeWidget.prototype._mouseStop = function(position_info) {
3502     if (this.options.dragAndDrop) {
3503       return this.dnd_handler.mouseStop(position_info);
3504     } else {
3505       return false;
3506     }
3507   };
3508
3509   JqTreeWidget.prototype._triggerEvent = function(event_name, values) {
3510     var event;
3511     event = $.Event(event_name);
3512     $.extend(event, values);
3513     this.element.trigger(event);
3514     return event;
3515   };
3516
3517   JqTreeWidget.prototype.testGenerateHitAreas = function(moving_node) {
3518     this.dnd_handler.current_item = this._getNodeElementForNode(moving_node);
3519     this.dnd_handler.generateHitAreas();
3520     return this.dnd_handler.hit_areas;
3521   };
3522
3523   JqTreeWidget.prototype._selectCurrentNode = function() {
3524     var node, node_element;
3525     node = this.getSelectedNode();
3526     if (node) {
3527       node_element = this._getNodeElementForNode(node);
3528       if (node_element) {
3529         return node_element.select();
3530       }
3531     }
3532   };
3533
3534   JqTreeWidget.prototype._deselectCurrentNode = function() {
3535     var node;
3536     node = this.getSelectedNode();
3537     if (node) {
3538       return this.removeFromSelection(node);
3539     }
3540   };
3541
3542   JqTreeWidget.prototype._getDefaultClosedIcon = function() {
3543     if (this.options.rtl) {
3544       return '&#x25c0;';
3545     } else {
3546       return '&#x25ba;';
3547     }
3548   };
3549
3550   JqTreeWidget.prototype._getRtlOption = function() {
3551     var data_rtl;
3552     if (this.options.rtl !== null) {
3553       return this.options.rtl;
3554     } else {
3555       data_rtl = this.element.data('rtl');
3556       if ((data_rtl != null) && data_rtl !== false) {
3557         return true;
3558       } else {
3559         return false;
3560       }
3561     }
3562   };
3563
3564   JqTreeWidget.prototype._notifyLoading = function(is_loading, node, $el) {
3565     if (this.options.onLoading) {
3566       return this.options.onLoading(is_loading, node, $el);
3567     }
3568   };
3569
3570   return JqTreeWidget;
3571
3572 })(MouseWidget);
3573
3574 JqTreeWidget.getModule = function(name) {
3575   var modules;
3576   modules = {
3577     'node': node_module,
3578     'util': util_module,
3579     'drag_and_drop_handler': drag_and_drop_handler
3580   };
3581   return modules[name];
3582 };
3583
3584 SimpleWidget.register(JqTreeWidget, 'tree');
3585
3586 },{"./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){
3587 var _indexOf, getBoolString, html_escape, indexOf, isFunction, isInt;
3588
3589 _indexOf = function(array, item) {
3590   var i, j, len, value;
3591   for (i = j = 0, len = array.length; j < len; i = ++j) {
3592     value = array[i];
3593     if (value === item) {
3594       return i;
3595     }
3596   }
3597   return -1;
3598 };
3599
3600 indexOf = function(array, item) {
3601   if (array.indexOf) {
3602     return array.indexOf(item);
3603   } else {
3604     return _indexOf(array, item);
3605   }
3606 };
3607
3608 isInt = function(n) {
3609   return typeof n === 'number' && n % 1 === 0;
3610 };
3611
3612 isFunction = function(v) {
3613   return typeof v === 'function';
3614 };
3615
3616 html_escape = function(string) {
3617   return ('' + string).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g, '&#x2F;');
3618 };
3619
3620 getBoolString = function(value) {
3621   if (value) {
3622     return 'true';
3623   } else {
3624     return 'false';
3625   }
3626 };
3627
3628 module.exports = {
3629   _indexOf: _indexOf,
3630   getBoolString: getBoolString,
3631   html_escape: html_escape,
3632   indexOf: indexOf,
3633   isInt: isInt,
3634   isFunction: isFunction
3635 };
3636
3637 },{}],13:[function(require,module,exports){
3638 module.exports = '1.3.7';
3639
3640 },{}]},{},[11]);