4 Copyright 2015 Marco Braak
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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
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;
23 node_module = require('./node');
25 util = require('./util');
27 Position = node_module.Position;
31 DragAndDropHandler = (function() {
32 function DragAndDropHandler(tree_widget) {
33 this.tree_widget = tree_widget;
34 this.hovered_area = null;
37 this.is_dragging = false;
38 this.current_item = null;
41 DragAndDropHandler.prototype.mouseCapture = function(position_info) {
42 var $element, node_element;
43 $element = $(position_info.target);
44 if (!this.mustCaptureElement($element)) {
47 if (this.tree_widget.options.onIsMoveHandle && !this.tree_widget.options.onIsMoveHandle($element)) {
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)) {
56 this.current_item = node_element;
57 return this.current_item !== null;
60 DragAndDropHandler.prototype.mouseStart = function(position_info) {
61 var node, node_name, offset;
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);
68 node_name = node.name;
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');
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();
85 if (this.hovered_area !== area) {
86 this.hovered_area = area;
87 if (this.mustOpenFolderTimer(area)) {
88 this.startOpenFolderTimer(area.node);
90 this.stopOpenFolderTimer();
92 this.updateDropHint();
96 this.removeDropHint();
97 this.stopOpenFolderTimer();
100 if (this.tree_widget.options.onDragMove != null) {
101 this.tree_widget.options.onDragMove(this.current_item.node, position_info.original_event);
107 DragAndDropHandler.prototype.mustCaptureElement = function($element) {
108 return !$element.is('input,select,textarea');
111 DragAndDropHandler.prototype.canMoveToArea = function(area) {
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);
123 DragAndDropHandler.prototype.mouseStop = function(position_info) {
125 this.moveItem(position_info);
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;
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);
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');
155 DragAndDropHandler.prototype.removeHitAreas = function() {
156 return this.hit_areas = [];
159 DragAndDropHandler.prototype.clear = function() {
160 this.drag_element.remove();
161 return this.drag_element = null;
164 DragAndDropHandler.prototype.removeDropHint = function() {
165 if (this.previous_ghost) {
166 return this.previous_ghost.remove();
170 DragAndDropHandler.prototype.removeHover = function() {
171 return this.hovered_area = null;
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();
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) {
187 high = this.hit_areas.length;
189 mid = (low + high) >> 1;
190 area = this.hit_areas[mid];
193 } else if (y > area.bottom) {
202 DragAndDropHandler.prototype.mustOpenFolderTimer = function(area) {
205 return node.isFolder() && !node.is_open && area.position === Position.INSIDE;
208 DragAndDropHandler.prototype.updateDropHint = function() {
210 if (!this.hovered_area) {
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);
218 DragAndDropHandler.prototype.startOpenFolderTimer = function(folder) {
220 openFolder = (function(_this) {
222 return _this.tree_widget._openNode(folder, _this.tree_widget.options.slide, function() {
224 return _this.updateDropHint();
228 this.stopOpenFolderTimer();
229 return this.open_folder_timer = setTimeout(openFolder, this.tree_widget.options.openFolderDelay);
232 DragAndDropHandler.prototype.stopOpenFolderTimer = function() {
233 if (this.open_folder_timer) {
234 clearTimeout(this.open_folder_timer);
235 return this.open_folder_timer = null;
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;
249 doMove = (function(_this) {
251 _this.tree_widget.tree.moveNode(moved_node, target_node, position);
252 _this.tree_widget.element.empty();
253 return _this.tree_widget._refreshElements();
256 event = this.tree_widget._triggerEvent('tree.move', {
258 moved_node: moved_node,
259 target_node: target_node,
260 position: Position.getName(position),
261 previous_parent: previous_parent,
263 original_event: position_info.original_event
266 if (!event.isDefaultPrevented()) {
272 DragAndDropHandler.prototype.getTreeDimensions = function() {
274 offset = this.tree_widget.element.offset();
278 right: offset.left + this.tree_widget.element.width(),
279 bottom: offset.top + this.tree_widget.element.height() + 16
283 return DragAndDropHandler;
287 VisibleNodeIterator = (function() {
288 function VisibleNodeIterator(tree) {
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();
300 $element = $(node.element);
301 if (!$element.is(':visible')) {
305 _this.handleFirstNode(node, $element);
306 is_first_node = false;
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;
315 _this.handleClosedFolder(node, next_node, $element);
318 if (must_iterate_inside) {
319 children_length = node.children.length;
321 for (i = j = 0, len = ref.length; j < len; i = ++j) {
323 if (i === (children_length - 1)) {
324 _iterateNode(node.children[i], null);
326 _iterateNode(node.children[i], node.children[i + 1]);
330 return _this.handleAfterOpenFolder(node, next_node, $element);
335 return _iterateNode(this.tree, null);
338 VisibleNodeIterator.prototype.handleNode = function(node, next_node, $element) {};
340 VisibleNodeIterator.prototype.handleOpenFolder = function(node, $element) {};
342 VisibleNodeIterator.prototype.handleClosedFolder = function(node, next_node, $element) {};
344 VisibleNodeIterator.prototype.handleAfterOpenFolder = function(node, next_node, $element) {};
346 VisibleNodeIterator.prototype.handleFirstNode = function(node, $element) {};
348 return VisibleNodeIterator;
352 HitAreasGenerator = (function(superClass) {
353 extend(HitAreasGenerator, superClass);
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;
361 HitAreasGenerator.prototype.generate = function() {
365 return this.generateHitAreas(this.positions);
368 HitAreasGenerator.prototype.getTop = function($element) {
369 return $element.offset().top;
372 HitAreasGenerator.prototype.addPosition = function(node, position, top) {
379 this.positions.push(area);
380 return this.last_top = top;
383 HitAreasGenerator.prototype.handleNode = function(node, next_node, $element) {
385 top = this.getTop($element);
386 if (node === this.current_node) {
387 this.addPosition(node, Position.NONE, top);
389 this.addPosition(node, Position.INSIDE, top);
391 if (next_node === this.current_node || node === this.current_node) {
392 return this.addPosition(node, Position.NONE, top);
394 return this.addPosition(node, Position.AFTER, top);
398 HitAreasGenerator.prototype.handleOpenFolder = function(node, $element) {
399 if (node === this.current_node) {
402 if (node.children[0] !== this.current_node) {
403 this.addPosition(node, Position.INSIDE, this.getTop($element));
408 HitAreasGenerator.prototype.handleClosedFolder = function(node, next_node, $element) {
410 top = this.getTop($element);
411 if (node === this.current_node) {
412 return this.addPosition(node, Position.NONE, top);
414 this.addPosition(node, Position.INSIDE, top);
415 if (next_node !== this.current_node) {
416 return this.addPosition(node, Position.AFTER, top);
421 HitAreasGenerator.prototype.handleFirstNode = function(node, $element) {
422 if (node !== this.current_node) {
423 return this.addPosition(node, Position.BEFORE, this.getTop($(node.element)));
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);
431 return this.addPosition(node, Position.AFTER, this.last_top);
435 HitAreasGenerator.prototype.generateHitAreas = function(positions) {
436 var group, hit_areas, j, len, position, previous_top;
440 for (j = 0, len = positions.length; j < len; j++) {
441 position = positions[j];
442 if (position.top !== previous_top && group.length) {
444 this.generateHitAreasForGroup(hit_areas, group, previous_top, position.top);
446 previous_top = position.top;
449 group.push(position);
451 this.generateHitAreasForGroup(hit_areas, group, previous_top, this.tree_bottom);
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);
461 while (i < position_count) {
462 position = positions_in_group[i];
465 bottom: area_top + area_height,
467 position: position.position
469 area_top += area_height;
475 return HitAreasGenerator;
477 })(VisibleNodeIterator);
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);
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
495 DragElement.prototype.remove = function() {
496 return this.$element.remove();
504 DragAndDropHandler: DragAndDropHandler,
505 DragElement: DragElement,
506 HitAreasGenerator: HitAreasGenerator
509 },{"./node":5,"./util":12}],2:[function(require,module,exports){
510 var $, ElementsRenderer, NodeElement, html_escape, node_element, util;
512 node_element = require('./node_element');
514 NodeElement = node_element.NodeElement;
516 util = require('./util');
518 html_escape = util.html_escape;
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);
529 ElementsRenderer.prototype.render = function(from_node) {
530 if (from_node && from_node.parent) {
531 return this.renderFromNode(from_node);
533 return this.renderFromRoot();
537 ElementsRenderer.prototype.renderFromRoot = function() {
539 $element = this.tree_widget.element;
541 return this.createDomElements($element[0], this.tree_widget.tree.children, true, true, 1);
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();
552 return this.createDomElements(li, node.children, false, false, node.getLevel() + 1);
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++) {
562 li = this.createLi(child, level);
564 this.attachNodeData(child, li);
565 if (child.hasChildren()) {
566 this.createDomElements(li, child.children, false, child.is_open, level + 1);
572 ElementsRenderer.prototype.attachNodeData = function(node, li) {
574 return $(li).data('node', node);
577 ElementsRenderer.prototype.createUl = function(is_root_node) {
578 var class_string, role, ul;
583 class_string = 'jqtree-tree';
585 if (this.tree_widget.options.rtl) {
586 class_string += ' jqtree-rtl';
589 ul = document.createElement('ul');
590 ul.className = "jqtree_common " + class_string;
591 ul.setAttribute('role', role);
595 ElementsRenderer.prototype.createLi = function(node, level) {
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);
601 li = this.createNodeLi(node, level, is_selected);
603 if (this.tree_widget.options.onCreateLi) {
604 this.tree_widget.options.onCreateLi(node, $(li));
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);
614 icon_element = this.opened_icon_element;
616 icon_element = this.closed_icon_element;
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');
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);
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);
640 ElementsRenderer.prototype.createNodeLi = function(node, level, is_selected) {
641 var class_string, div, is_folder, li, li_classes;
642 li_classes = ['jqtree_common'];
644 li_classes.push('jqtree-selected');
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');
654 div.appendChild(this.createTitleSpan(node.name, level, is_selected, node.is_open, is_folder = false));
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";
663 classes += " jqtree-title-folder";
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));
671 title_span.setAttribute('tabindex', 0);
673 title_span.innerHTML = this.escapeIfNecessary(node_name);
677 ElementsRenderer.prototype.getButtonClasses = function(node) {
679 classes = ['jqtree-toggler', 'jqtree_common'];
681 classes.push('jqtree-closed');
683 if (this.tree_widget.options.buttonLeft) {
684 classes.push('jqtree-toggler-left');
686 classes.push('jqtree-toggler-right');
688 return classes.join(' ');
691 ElementsRenderer.prototype.getFolderClasses = function(node, is_selected) {
693 classes = ['jqtree-folder'];
695 classes.push('jqtree-closed');
698 classes.push('jqtree-selected');
700 if (node.is_loading) {
701 classes.push('jqtree-loading');
703 return classes.join(' ');
706 ElementsRenderer.prototype.escapeIfNecessary = function(value) {
707 if (this.tree_widget.options.autoEscape) {
708 return html_escape(value);
714 ElementsRenderer.prototype.createButtonElement = function(value) {
716 if (typeof value === 'string') {
717 div = document.createElement('div');
718 div.innerHTML = value;
719 return document.createTextNode(div.innerHTML);
725 return ElementsRenderer;
729 module.exports = ElementsRenderer;
731 },{"./node_element":6,"./util":12}],3:[function(require,module,exports){
733 bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
737 KeyHandler = (function() {
738 var DOWN, LEFT, RIGHT, UP;
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));
756 KeyHandler.prototype.deinit = function() {
757 return $(document).unbind('keydown.jqtree');
760 KeyHandler.prototype.moveDown = function() {
762 node = this.tree_widget.getSelectedNode();
764 return this.selectNode(node.getNextNode());
770 KeyHandler.prototype.moveUp = function() {
772 node = this.tree_widget.getSelectedNode();
774 return this.selectNode(node.getPreviousNode());
780 KeyHandler.prototype.moveRight = function() {
782 node = this.tree_widget.getSelectedNode();
785 } else if (!node.isFolder()) {
789 return this.selectNode(node.getNextNode());
791 this.tree_widget.openNode(node);
797 KeyHandler.prototype.moveLeft = function() {
799 node = this.tree_widget.getSelectedNode();
802 } else if (node.isFolder() && node.is_open) {
803 this.tree_widget.closeNode(node);
806 return this.selectNode(node.getParent());
810 KeyHandler.prototype.handleKeyDown = function(e) {
812 if (!this.tree_widget.options.keyboardSupport) {
815 if ($(document.activeElement).is('textarea,input,select')) {
818 if (!this.tree_widget.getSelectedNode()) {
824 return this.moveDown();
826 return this.moveUp();
828 return this.moveRight();
830 return this.moveLeft();
835 KeyHandler.prototype.selectNode = function(node) {
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);
851 module.exports = KeyHandler;
853 },{}],4:[function(require,module,exports){
856 This widget does the same a the mouse widget in jqueryui.
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;
862 SimpleWidget = require('./simple.widget');
866 MouseWidget = (function(superClass) {
867 extend(MouseWidget, superClass);
869 function MouseWidget() {
870 return MouseWidget.__super__.constructor.apply(this, arguments);
873 MouseWidget.is_mouse_handled = false;
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;
885 MouseWidget.prototype._deinit = function() {
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');
894 MouseWidget.prototype._mouseDown = function(e) {
899 result = this._handleMouseDown(e, this._getPositionInfo(e));
906 MouseWidget.prototype._handleMouseDown = function(e, position_info) {
907 if (MouseWidget.is_mouse_handled) {
910 if (this.is_mouse_started) {
911 this._handleMouseUp(position_info);
913 this.mouse_down_info = position_info;
914 if (!this._mouseCapture(position_info)) {
917 this._handleStartMouse();
918 this.is_mouse_handled = true;
922 MouseWidget.prototype._handleStartMouse = function() {
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();
934 MouseWidget.prototype._startMouseDelayTimer = function() {
935 if (this._mouse_delay_timer) {
936 clearTimeout(this._mouse_delay_timer);
938 this._mouse_delay_timer = setTimeout((function(_this) {
940 return _this._is_mouse_delay_met = true;
942 })(this), this.mouse_delay);
943 return this._is_mouse_delay_met = false;
946 MouseWidget.prototype._mouseMove = function(e) {
947 return this._handleMouseMove(e, this._getPositionInfo(e));
950 MouseWidget.prototype._handleMouseMove = function(e, position_info) {
951 if (this.is_mouse_started) {
952 this._mouseDrag(position_info);
953 return e.preventDefault();
955 if (this.mouse_delay && !this._is_mouse_delay_met) {
958 this.is_mouse_started = this._mouseStart(this.mouse_down_info) !== false;
959 if (this.is_mouse_started) {
960 this._mouseDrag(position_info);
962 this._handleMouseUp(position_info);
964 return !this.is_mouse_started;
967 MouseWidget.prototype._getPositionInfo = function(e) {
976 MouseWidget.prototype._mouseUp = function(e) {
977 return this._handleMouseUp(this._getPositionInfo(e));
980 MouseWidget.prototype._handleMouseUp = function(position_info) {
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);
993 MouseWidget.prototype._mouseCapture = function(position_info) {
997 MouseWidget.prototype._mouseStart = function(position_info) {
1001 MouseWidget.prototype._mouseDrag = function(position_info) {
1005 MouseWidget.prototype._mouseStop = function(position_info) {
1009 MouseWidget.prototype.setMouseDelay = function(mouse_delay) {
1010 return this.mouse_delay = mouse_delay;
1013 MouseWidget.prototype._touchStart = function(e) {
1015 if (e.originalEvent.touches.length > 1) {
1018 touch = e.originalEvent.changedTouches[0];
1019 return this._handleMouseDown(e, this._getPositionInfo(touch));
1022 MouseWidget.prototype._touchMove = function(e) {
1024 if (e.originalEvent.touches.length > 1) {
1027 touch = e.originalEvent.changedTouches[0];
1028 return this._handleMouseMove(e, this._getPositionInfo(touch));
1031 MouseWidget.prototype._touchEnd = function(e) {
1033 if (e.originalEvent.touches.length > 1) {
1036 touch = e.originalEvent.changedTouches[0];
1037 return this._handleMouseUp(this._getPositionInfo(touch));
1044 module.exports = MouseWidget;
1046 },{"./simple.widget":10}],5:[function(require,module,exports){
1047 var $, Node, Position;
1052 getName: function(position) {
1053 return Position.strings[position - 1];
1055 nameToIndex: function(name) {
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) {
1066 Position.BEFORE = 1;
1070 Position.INSIDE = 3;
1074 Position.strings = ['before', 'after', 'inside', 'none'];
1076 Node = (function() {
1077 function Node(o, is_root, node_class) {
1078 if (is_root == null) {
1081 if (node_class == null) {
1089 this.id_mapping = {};
1091 this.node_class = node_class;
1095 Node.prototype.setData = function(o) {
1098 Set the data of this node.
1100 setData(string): set the name of the node
1101 setdata(object): set attributes of the node
1106 setData({ name: 'node1', id: 1});
1108 setData({ name: 'node2', id: 2, color: 'green'});
1110 * This is an internal function; it is not in the docs
1111 * Does not remove existing node values
1113 var key, setName, value;
1114 setName = (function(_this) {
1115 return function(name) {
1116 if (name !== null) {
1117 return _this.name = name;
1121 if (typeof o !== 'object') {
1126 if (key === 'label') {
1128 } else if (key !== 'children') {
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);
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);
1164 Create tree from data.
1166 Structure of data is:
1171 { label: 'child1' },
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++) {
1186 node = new this.tree.node_class(o);
1187 this.addChild(node);
1188 if (typeof o === 'object' && o.children) {
1189 node.loadFromData(o.children);
1204 Node.prototype.addChild = function(node) {
1205 this.children.push(node);
1206 return node._setParent(this);
1211 Add child at position. Index starts at 0.
1213 tree.addChildAtPosition(
1219 Node.prototype.addChildAtPosition = function(node, index) {
1220 this.children.splice(index, 0, node);
1221 return node._setParent(this);
1224 Node.prototype._setParent = function(parent) {
1225 this.parent = parent;
1226 this.tree = parent.tree;
1227 return this.tree.addNodeToIndex(this);
1232 Remove child. This also removes the children of the node.
1234 tree.removeChild(tree.children[0]);
1237 Node.prototype.removeChild = function(node) {
1238 node.removeChildren();
1239 return this._removeChild(node);
1242 Node.prototype._removeChild = function(node) {
1243 this.children.splice(this.getChildIndex(node), 1);
1244 return this.tree.removeNodeFromIndex(node);
1251 var index = getChildIndex(node);
1254 Node.prototype.getChildIndex = function(node) {
1255 return $.inArray(node, this.children);
1260 Does the tree have children?
1262 if (tree.hasChildren()) {
1267 Node.prototype.hasChildren = function() {
1268 return this.children.length !== 0;
1271 Node.prototype.isFolder = function() {
1272 return this.hasChildren() || this.load_on_demand;
1277 Iterate over all the nodes in the tree.
1279 Calls callback with (node, level).
1281 The callback must return true to continue the iteration on current node.
1284 function(node, level) {
1285 console.log(node.name);
1287 // stop iteration after level 2
1288 return (level <= 2);
1293 Node.prototype.iterate = function(callback) {
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++) {
1301 result = callback(child, level);
1302 if (result && child.hasChildren()) {
1303 _iterate(child, level + 1);
1315 Move node relative to another node.
1317 Argument position: Position.BEFORE, Position.AFTER or Position.Inside
1319 // move node1 after node2
1320 tree.moveNode(node1, node2, Position.AFTER);
1323 Node.prototype.moveNode = function(moved_node, target_node, position) {
1324 if (moved_node.isParentOf(target_node)) {
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);
1339 Get the tree as data.
1342 Node.prototype.getData = function(include_parent) {
1343 var getDataFromNodes;
1344 if (include_parent == null) {
1345 include_parent = false;
1347 getDataFromNodes = function(nodes) {
1348 var data, j, k, len, node, tmp_node, v;
1350 for (j = 0, len = nodes.length; j < len; j++) {
1355 if ((k !== 'parent' && k !== 'children' && k !== 'element' && k !== 'tree') && Object.prototype.hasOwnProperty.call(node, k)) {
1359 if (node.hasChildren()) {
1360 tmp_node.children = getDataFromNodes(node.children);
1362 data.push(tmp_node);
1366 if (include_parent) {
1367 return getDataFromNodes([this]);
1369 return getDataFromNodes(this.children);
1373 Node.prototype.getNodeByName = function(name) {
1374 return this.getNodeByCallback(function(node) {
1375 return node.name === name;
1379 Node.prototype.getNodeByCallback = function(callback) {
1382 this.iterate(function(node) {
1383 if (callback(node)) {
1393 Node.prototype.addAfter = function(node_info) {
1394 var child_index, node;
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);
1408 Node.prototype.addBefore = function(node_info) {
1409 var child_index, node;
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);
1423 Node.prototype.addParent = function(node_info) {
1424 var child, j, len, new_parent, original_parent, ref;
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++) {
1434 new_parent.addChild(child);
1436 original_parent.children = [];
1437 original_parent.addChild(new_parent);
1442 Node.prototype.remove = function() {
1444 this.parent.removeChild(this);
1445 return this.parent = null;
1449 Node.prototype.append = function(node_info) {
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);
1459 Node.prototype.prepend = function(node_info) {
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);
1469 Node.prototype.isParentOf = function(node) {
1471 parent = node.parent;
1473 if (parent === this) {
1476 parent = parent.parent;
1481 Node.prototype.getLevel = function() {
1485 while (node.parent) {
1492 Node.prototype.getNodeById = function(node_id) {
1493 return this.id_mapping[node_id];
1496 Node.prototype.addNodeToIndex = function(node) {
1497 if (node.id != null) {
1498 return this.id_mapping[node.id] = node;
1502 Node.prototype.removeNodeFromIndex = function(node) {
1503 if (node.id != null) {
1504 return delete this.id_mapping[node.id];
1508 Node.prototype.removeChildren = function() {
1509 this.iterate((function(_this) {
1510 return function(child) {
1511 _this.tree.removeNodeFromIndex(child);
1515 return this.children = [];
1518 Node.prototype.getPreviousSibling = function() {
1523 previous_index = this.parent.getChildIndex(this) - 1;
1524 if (previous_index >= 0) {
1525 return this.parent.children[previous_index];
1532 Node.prototype.getNextSibling = function() {
1537 next_index = this.parent.getChildIndex(this) + 1;
1538 if (next_index < this.parent.children.length) {
1539 return this.parent.children[next_index];
1546 Node.prototype.getNodesByProperty = function(key, value) {
1547 return this.filter(function(node) {
1548 return node[key] === value;
1552 Node.prototype.filter = function(f) {
1555 this.iterate(function(node) {
1564 Node.prototype.getNextNode = function(include_children) {
1566 if (include_children == null) {
1567 include_children = true;
1569 if (include_children && this.hasChildren() && this.is_open) {
1570 return this.children[0];
1575 next_sibling = this.getNextSibling();
1577 return next_sibling;
1579 return this.parent.getNextNode(false);
1585 Node.prototype.getPreviousNode = function() {
1586 var previous_sibling;
1590 previous_sibling = this.getPreviousSibling();
1591 if (previous_sibling) {
1592 if (!previous_sibling.hasChildren() || !previous_sibling.is_open) {
1593 return previous_sibling;
1595 return previous_sibling.getLastChild();
1598 return this.getParent();
1603 Node.prototype.getParent = function() {
1606 } else if (!this.parent.parent) {
1613 Node.prototype.getLastChild = function() {
1615 if (!this.hasChildren()) {
1618 last_child = this.children[this.children.length - 1];
1619 if (!last_child.hasChildren() || !last_child.is_open) {
1622 return last_child.getLastChild();
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;
1641 node = require('./node');
1643 Position = node.Position;
1647 NodeElement = (function() {
1648 function NodeElement(node, tree_widget) {
1649 this.init(node, tree_widget);
1652 NodeElement.prototype.init = function(node, tree_widget) {
1654 this.tree_widget = tree_widget;
1655 if (!node.element) {
1656 node.element = this.tree_widget.element;
1658 return this.$element = $(node.element);
1661 NodeElement.prototype.getUl = function() {
1662 return this.$element.children('ul:first');
1665 NodeElement.prototype.getSpan = function() {
1666 return this.$element.children('.jqtree-element').find('span.jqtree-title');
1669 NodeElement.prototype.getLi = function() {
1670 return this.$element;
1673 NodeElement.prototype.addDropHint = function(position) {
1674 if (position === Position.INSIDE) {
1675 return new BorderDropHint(this.$element);
1677 return new GhostDropHint(this.node, this.$element, position);
1681 NodeElement.prototype.select = function() {
1684 $li.addClass('jqtree-selected');
1685 $li.attr('aria-selected', 'true');
1686 $span = this.getSpan();
1687 return $span.attr('tabindex', 0);
1690 NodeElement.prototype.deselect = function() {
1693 $li.removeClass('jqtree-selected');
1694 $li.attr('aria-selected', 'false');
1695 $span = this.getSpan();
1696 return $span.attr('tabindex', -1);
1703 FolderElement = (function(superClass) {
1704 extend(FolderElement, superClass);
1706 function FolderElement() {
1707 return FolderElement.__super__.constructor.apply(this, arguments);
1710 FolderElement.prototype.open = function(on_finished, slide) {
1711 var $button, doOpen;
1712 if (slide == null) {
1715 if (!this.node.is_open) {
1716 this.node.is_open = true;
1717 $button = this.getButton();
1718 $button.removeClass('jqtree-closed');
1720 $button.append(this.tree_widget.renderer.opened_icon_element.cloneNode(false));
1721 doOpen = (function(_this) {
1724 $li = _this.getLi();
1725 $li.removeClass('jqtree-closed');
1726 $span = _this.getSpan();
1727 $span.attr('aria-expanded', 'true');
1731 return _this.tree_widget._triggerEvent('tree.open', {
1737 return this.getUl().slideDown('fast', doOpen);
1739 this.getUl().show();
1745 FolderElement.prototype.close = function(slide) {
1746 var $button, doClose;
1747 if (slide == null) {
1750 if (this.node.is_open) {
1751 this.node.is_open = false;
1752 $button = this.getButton();
1753 $button.addClass('jqtree-closed');
1755 $button.append(this.tree_widget.renderer.closed_icon_element.cloneNode(false));
1756 doClose = (function(_this) {
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', {
1769 return this.getUl().slideUp('fast', doClose);
1771 this.getUl().hide();
1777 FolderElement.prototype.getButton = function() {
1778 return this.$element.children('.jqtree-element').find('a.jqtree-toggler');
1781 FolderElement.prototype.addDropHint = function(position) {
1782 if (!this.node.is_open && position === Position.INSIDE) {
1783 return new BorderDropHint(this.$element);
1785 return new GhostDropHint(this.node, this.$element, position);
1789 return FolderElement;
1793 BorderDropHint = (function() {
1794 function BorderDropHint($element) {
1796 $div = $element.children('.jqtree-element');
1797 width = $element.width() - 4;
1798 this.$hint = $('<span class="jqtree-border"></span>');
1799 $div.append(this.$hint);
1802 height: $div.outerHeight() - 4
1806 BorderDropHint.prototype.remove = function() {
1807 return this.$hint.remove();
1810 return BorderDropHint;
1814 GhostDropHint = (function() {
1815 function GhostDropHint(node, $element, position) {
1816 this.$element = $element;
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) {
1821 } else if (position === Position.BEFORE) {
1823 } else if (position === Position.INSIDE) {
1824 if (node.isFolder() && node.is_open) {
1825 this.moveInsideOpenFolder();
1832 GhostDropHint.prototype.remove = function() {
1833 return this.$ghost.remove();
1836 GhostDropHint.prototype.moveAfter = function() {
1837 return this.$element.after(this.$ghost);
1840 GhostDropHint.prototype.moveBefore = function() {
1841 return this.$element.before(this.$ghost);
1844 GhostDropHint.prototype.moveInsideOpenFolder = function() {
1845 return $(this.node.children[0].element).before(this.$ghost);
1848 GhostDropHint.prototype.moveInside = function() {
1849 this.$element.after(this.$ghost);
1850 return this.$ghost.addClass('jqtree-inside');
1853 return GhostDropHint;
1858 BorderDropHint: BorderDropHint,
1859 FolderElement: FolderElement,
1860 GhostDropHint: GhostDropHint,
1861 NodeElement: NodeElement
1864 },{"./node":5}],7:[function(require,module,exports){
1865 var $, SaveStateHandler, indexOf, isInt, util;
1867 util = require('./util');
1869 indexOf = util.indexOf;
1875 SaveStateHandler = (function() {
1876 function SaveStateHandler(tree_widget) {
1877 this.tree_widget = tree_widget;
1880 SaveStateHandler.prototype.saveState = function() {
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, {
1895 SaveStateHandler.prototype.getStateFromStorage = function() {
1897 json_data = this._loadFromStorage();
1899 return this._parseState(json_data);
1905 SaveStateHandler.prototype._parseState = function(json_data) {
1907 state = $.parseJSON(json_data);
1908 if (state && state.selected_node && isInt(state.selected_node)) {
1909 state.selected_node = [state.selected_node];
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());
1927 SaveStateHandler.prototype.getState = function() {
1928 var getOpenNodeIds, getSelectedNodeIds;
1929 getOpenNodeIds = (function(_this) {
1933 _this.tree_widget.tree.iterate(function(node) {
1934 if (node.is_open && node.id && node.hasChildren()) {
1935 open_nodes.push(node.id);
1942 getSelectedNodeIds = (function(_this) {
1945 return (function() {
1946 var i, len, ref, results;
1947 ref = this.tree_widget.getSelectedNodes();
1949 for (i = 0, len = ref.length; i < len; i++) {
1958 open_nodes: getOpenNodeIds(),
1959 selected_node: getSelectedNodeIds()
1963 SaveStateHandler.prototype.setInitialState = function(state) {
1964 var must_load_on_demand;
1968 must_load_on_demand = this._openInitialNodes(state.open_nodes);
1969 this._selectInitialNodes(state.selected_node);
1970 return must_load_on_demand;
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);
1981 if (!node.load_on_demand) {
1982 node.is_open = true;
1984 must_load_on_demand = true;
1988 return must_load_on_demand;
1991 SaveStateHandler.prototype._selectInitialNodes = function(node_ids) {
1992 var i, len, node, node_id, select_count;
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);
1999 this.tree_widget.select_node_handler.addToSelection(node);
2002 return select_count !== 0;
2005 SaveStateHandler.prototype.setInitialStateOnDemand = function(state, cb_finished) {
2007 return this._setInitialStateOnDemand(state.open_nodes, state.selected_node, cb_finished);
2009 return cb_finished();
2013 SaveStateHandler.prototype._setInitialStateOnDemand = function(node_ids, selected_nodes, cb_finished) {
2014 var loadAndOpenNode, loading_count, openNodes;
2016 openNodes = (function(_this) {
2018 var i, len, new_nodes_ids, node, node_id;
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);
2024 new_nodes_ids.push(node_id);
2026 if (!node.is_loading) {
2027 if (node.load_on_demand) {
2028 loadAndOpenNode(node);
2030 _this.tree_widget._openNode(node, false);
2035 node_ids = new_nodes_ids;
2036 if (_this._selectInitialNodes(selected_nodes)) {
2037 _this.tree_widget._refreshElements();
2039 if (loading_count === 0) {
2040 return cb_finished();
2044 loadAndOpenNode = (function(_this) {
2045 return function(node) {
2047 return _this.tree_widget._openNode(node, false, function() {
2056 SaveStateHandler.prototype.getCookieName = function() {
2057 if (typeof this.tree_widget.options.saveState === 'string') {
2058 return this.tree_widget.options.saveState;
2064 SaveStateHandler.prototype.supportsLocalStorage = function() {
2066 testSupport = function() {
2068 if (typeof localStorage === "undefined" || localStorage === null) {
2072 key = '_storage_test';
2073 sessionStorage.setItem(key, true);
2074 sessionStorage.removeItem(key);
2082 if (this._supportsLocalStorage == null) {
2083 this._supportsLocalStorage = testSupport();
2085 return this._supportsLocalStorage;
2088 SaveStateHandler.prototype.getNodeIdToBeSelected = function() {
2090 state = this.getStateFromStorage();
2091 if (state && state.selected_node) {
2092 return state.selected_node[0];
2098 return SaveStateHandler;
2102 module.exports = SaveStateHandler;
2104 },{"./util":12}],8:[function(require,module,exports){
2105 var $, ScrollHandler;
2109 ScrollHandler = (function() {
2110 function ScrollHandler(tree_widget) {
2111 this.tree_widget = tree_widget;
2112 this.previous_top = -1;
2113 this.is_initialized = false;
2114 this._initScrollParent();
2117 ScrollHandler.prototype._initScrollParent = function() {
2118 var $scroll_parent, getParentWithOverflow, setDocumentAsScrollParent;
2119 getParentWithOverflow = (function(_this) {
2121 var css_values, el, hasOverFlow, i, len, ref;
2122 css_values = ['overflow', 'overflow-y'];
2123 hasOverFlow = function(el) {
2124 var css_value, i, len, ref;
2125 for (i = 0, len = css_values.length; i < len; i++) {
2126 css_value = css_values[i];
2127 if ((ref = $.css(el, css_value)) === 'auto' || ref === 'scroll') {
2133 if (hasOverFlow(_this.tree_widget.$el[0])) {
2134 return _this.tree_widget.$el;
2136 ref = _this.tree_widget.$el.parents();
2137 for (i = 0, len = ref.length; i < len; i++) {
2139 if (hasOverFlow(el)) {
2146 setDocumentAsScrollParent = (function(_this) {
2148 _this.scroll_parent_top = 0;
2149 return _this.$scroll_parent = null;
2152 if (this.tree_widget.$el.css('position') === 'fixed') {
2153 setDocumentAsScrollParent();
2155 $scroll_parent = getParentWithOverflow();
2156 if ($scroll_parent && $scroll_parent.length && $scroll_parent[0].tagName !== 'HTML') {
2157 this.$scroll_parent = $scroll_parent;
2158 this.scroll_parent_top = this.$scroll_parent.offset().top;
2160 setDocumentAsScrollParent();
2162 return this.is_initialized = true;
2165 ScrollHandler.prototype._ensureInit = function() {
2166 if (!this.is_initialized) {
2167 return this._initScrollParent();
2171 ScrollHandler.prototype.checkScrolling = function() {
2174 hovered_area = this.tree_widget.dnd_handler.hovered_area;
2175 if (hovered_area && hovered_area.top !== this.previous_top) {
2176 this.previous_top = hovered_area.top;
2177 if (this.$scroll_parent) {
2178 return this._handleScrollingWithScrollParent(hovered_area);
2180 return this._handleScrollingWithDocument(hovered_area);
2185 ScrollHandler.prototype._handleScrollingWithScrollParent = function(area) {
2186 var distance_bottom;
2187 distance_bottom = this.scroll_parent_top + this.$scroll_parent[0].offsetHeight - area.bottom;
2188 if (distance_bottom < 20) {
2189 this.$scroll_parent[0].scrollTop += 20;
2190 this.tree_widget.refreshHitAreas();
2191 return this.previous_top = -1;
2192 } else if ((area.top - this.scroll_parent_top) < 20) {
2193 this.$scroll_parent[0].scrollTop -= 20;
2194 this.tree_widget.refreshHitAreas();
2195 return this.previous_top = -1;
2199 ScrollHandler.prototype._handleScrollingWithDocument = function(area) {
2201 distance_top = area.top - $(document).scrollTop();
2202 if (distance_top < 20) {
2203 return $(document).scrollTop($(document).scrollTop() - 20);
2204 } else if ($(window).height() - (area.bottom - $(document).scrollTop()) < 20) {
2205 return $(document).scrollTop($(document).scrollTop() + 20);
2209 ScrollHandler.prototype.scrollTo = function(top) {
2212 if (this.$scroll_parent) {
2213 return this.$scroll_parent[0].scrollTop = top;
2215 tree_top = this.tree_widget.$el.offset().top;
2216 return $(document).scrollTop(top + tree_top);
2220 ScrollHandler.prototype.isScrolledIntoView = function(element) {
2221 var $element, element_bottom, element_top, view_bottom, view_top;
2223 $element = $(element);
2224 if (this.$scroll_parent) {
2226 view_bottom = this.$scroll_parent.height();
2227 element_top = $element.offset().top - this.scroll_parent_top;
2228 element_bottom = element_top + $element.height();
2230 view_top = $(window).scrollTop();
2231 view_bottom = view_top + $(window).height();
2232 element_top = $element.offset().top;
2233 element_bottom = element_top + $element.height();
2235 return (element_bottom <= view_bottom) && (element_top >= view_top);
2238 return ScrollHandler;
2242 module.exports = ScrollHandler;
2244 },{}],9:[function(require,module,exports){
2245 var $, SelectNodeHandler;
2249 SelectNodeHandler = (function() {
2250 function SelectNodeHandler(tree_widget) {
2251 this.tree_widget = tree_widget;
2255 SelectNodeHandler.prototype.getSelectedNode = function() {
2257 selected_nodes = this.getSelectedNodes();
2258 if (selected_nodes.length) {
2259 return selected_nodes[0];
2265 SelectNodeHandler.prototype.getSelectedNodes = function() {
2266 var id, node, selected_nodes;
2267 if (this.selected_single_node) {
2268 return [this.selected_single_node];
2270 selected_nodes = [];
2271 for (id in this.selected_nodes) {
2272 node = this.tree_widget.getNodeById(id);
2274 selected_nodes.push(node);
2277 return selected_nodes;
2281 SelectNodeHandler.prototype.getSelectedNodesUnder = function(parent) {
2282 var id, node, selected_nodes;
2283 if (this.selected_single_node) {
2284 if (parent.isParentOf(this.selected_single_node)) {
2285 return [this.selected_single_node];
2290 selected_nodes = [];
2291 for (id in this.selected_nodes) {
2292 node = this.tree_widget.getNodeById(id);
2293 if (node && parent.isParentOf(node)) {
2294 selected_nodes.push(node);
2297 return selected_nodes;
2301 SelectNodeHandler.prototype.isNodeSelected = function(node) {
2304 } else if (node.id) {
2305 if (this.selected_nodes[node.id]) {
2310 } else if (this.selected_single_node) {
2311 return this.selected_single_node.element === node.element;
2317 SelectNodeHandler.prototype.clear = function() {
2318 this.selected_nodes = {};
2319 return this.selected_single_node = null;
2322 SelectNodeHandler.prototype.removeFromSelection = function(node, include_children) {
2323 if (include_children == null) {
2324 include_children = false;
2327 if (this.selected_single_node && node.element === this.selected_single_node.element) {
2328 return this.selected_single_node = null;
2331 delete this.selected_nodes[node.id];
2332 if (include_children) {
2333 return node.iterate((function(_this) {
2334 return function(n) {
2335 delete _this.selected_nodes[node.id];
2343 SelectNodeHandler.prototype.addToSelection = function(node) {
2345 return this.selected_nodes[node.id] = true;
2347 return this.selected_single_node = node;
2351 return SelectNodeHandler;
2355 module.exports = SelectNodeHandler;
2357 },{}],10:[function(require,module,exports){
2360 Copyright 2013 Marco Braak
2362 Licensed under the Apache License, Version 2.0 (the "License");
2363 you may not use this file except in compliance with the License.
2364 You may obtain a copy of the License at
2366 http://www.apache.org/licenses/LICENSE-2.0
2368 Unless required by applicable law or agreed to in writing, software
2369 distributed under the License is distributed on an "AS IS" BASIS,
2370 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2371 See the License for the specific language governing permissions and
2372 limitations under the License.
2374 var $, SimpleWidget,
2379 SimpleWidget = (function() {
2380 SimpleWidget.prototype.defaults = {};
2382 function SimpleWidget(el, options) {
2384 this.options = $.extend({}, this.defaults, options);
2387 SimpleWidget.prototype.destroy = function() {
2388 return this._deinit();
2391 SimpleWidget.prototype._init = function() {
2395 SimpleWidget.prototype._deinit = function() {
2399 SimpleWidget.register = function(widget_class, widget_name) {
2400 var callFunction, createWidget, destroyWidget, getDataKey, getWidgetData;
2401 getDataKey = function() {
2402 return "simple_widget_" + widget_name;
2404 getWidgetData = function(el, data_key) {
2406 widget = $.data(el, data_key);
2407 if (widget && (widget instanceof SimpleWidget)) {
2413 createWidget = function($el, options) {
2414 var data_key, el, existing_widget, i, len, widget;
2415 data_key = getDataKey();
2416 for (i = 0, len = $el.length; i < len; i++) {
2418 existing_widget = getWidgetData(el, data_key);
2419 if (!existing_widget) {
2420 widget = new widget_class(el, options);
2421 if (!$.data(el, data_key)) {
2422 $.data(el, data_key, widget);
2429 destroyWidget = function($el) {
2430 var data_key, el, i, len, results, widget;
2431 data_key = getDataKey();
2433 for (i = 0, len = $el.length; i < len; i++) {
2435 widget = getWidgetData(el, data_key);
2439 results.push($.removeData(el, data_key));
2443 callFunction = function($el, function_name, args) {
2444 var el, i, len, result, widget, widget_function;
2446 for (i = 0, len = $el.length; i < len; i++) {
2448 widget = $.data(el, getDataKey());
2449 if (widget && (widget instanceof SimpleWidget)) {
2450 widget_function = widget[function_name];
2451 if (widget_function && (typeof widget_function === 'function')) {
2452 result = widget_function.apply(widget, args);
2458 return $.fn[widget_name] = function() {
2459 var $el, args, argument1, function_name, options;
2460 argument1 = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
2462 if (argument1 === void 0 || typeof argument1 === 'object') {
2463 options = argument1;
2464 return createWidget($el, options);
2465 } else if (typeof argument1 === 'string' && argument1[0] !== '_') {
2466 function_name = argument1;
2467 if (function_name === 'destroy') {
2468 return destroyWidget($el);
2469 } else if (function_name === 'get_widget_class') {
2470 return widget_class;
2472 return callFunction($el, function_name, args);
2478 return SimpleWidget;
2482 module.exports = SimpleWidget;
2484 },{}],11:[function(require,module,exports){
2485 var $, BorderDropHint, DragAndDropHandler, DragElement, ElementsRenderer, FolderElement, GhostDropHint, HitAreasGenerator, JqTreeWidget, KeyHandler, MouseWidget, Node, NodeElement, Position, SaveStateHandler, ScrollHandler, SelectNodeHandler, SimpleWidget, __version__, drag_and_drop_handler, node_module, ref, util_module,
2486 extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
2487 hasProp = {}.hasOwnProperty;
2489 __version__ = require('./version');
2491 drag_and_drop_handler = require('./drag_and_drop_handler');
2493 ElementsRenderer = require('./elements_renderer');
2495 KeyHandler = require('./key_handler');
2497 MouseWidget = require('./mouse.widget');
2499 SaveStateHandler = require('./save_state_handler');
2501 ScrollHandler = require('./scroll_handler');
2503 SelectNodeHandler = require('./select_node_handler');
2505 SimpleWidget = require('./simple.widget');
2507 node_module = require('./node');
2509 Node = node_module.Node;
2511 Position = node_module.Position;
2513 util_module = require('./util');
2515 ref = require('./node_element'), BorderDropHint = ref.BorderDropHint, FolderElement = ref.FolderElement, GhostDropHint = ref.GhostDropHint, NodeElement = ref.NodeElement;
2517 DragAndDropHandler = drag_and_drop_handler.DragAndDropHandler, DragElement = drag_and_drop_handler.DragElement, HitAreasGenerator = drag_and_drop_handler.HitAreasGenerator;
2521 JqTreeWidget = (function(superClass) {
2522 extend(JqTreeWidget, superClass);
2524 function JqTreeWidget() {
2525 return JqTreeWidget.__super__.constructor.apply(this, arguments);
2528 JqTreeWidget.prototype.BorderDropHint = BorderDropHint;
2530 JqTreeWidget.prototype.DragElement = DragElement;
2532 JqTreeWidget.prototype.DragAndDropHandler = DragAndDropHandler;
2534 JqTreeWidget.prototype.ElementsRenderer = ElementsRenderer;
2536 JqTreeWidget.prototype.GhostDropHint = GhostDropHint;
2538 JqTreeWidget.prototype.HitAreasGenerator = HitAreasGenerator;
2540 JqTreeWidget.prototype.Node = Node;
2542 JqTreeWidget.prototype.SaveStateHandler = SaveStateHandler;
2544 JqTreeWidget.prototype.ScrollHandler = ScrollHandler;
2546 JqTreeWidget.prototype.SelectNodeHandler = SelectNodeHandler;
2548 JqTreeWidget.prototype.defaults = {
2553 useContextMenu: true,
2554 onCanSelectNode: null,
2555 onSetStateFromStorage: null,
2556 onGetStateFromStorage: null,
2558 onIsMoveHandle: null,
2565 openedIcon: '▼',
2569 keyboardSupport: true,
2570 openFolderDelay: 500,
2578 JqTreeWidget.prototype.toggle = function(node, slide) {
2579 if (slide == null) {
2582 if (slide === null) {
2583 slide = this.options.slide;
2586 this.closeNode(node, slide);
2588 this.openNode(node, slide);
2590 return this.element;
2593 JqTreeWidget.prototype.getTree = function() {
2597 JqTreeWidget.prototype.selectNode = function(node) {
2598 this._selectNode(node, false);
2599 return this.element;
2602 JqTreeWidget.prototype._selectNode = function(node, must_toggle) {
2603 var canSelect, deselected_node, openParents, saveState;
2604 if (must_toggle == null) {
2605 must_toggle = false;
2607 if (!this.select_node_handler) {
2610 canSelect = (function(_this) {
2612 if (_this.options.onCanSelectNode) {
2613 return _this.options.selectable && _this.options.onCanSelectNode(node);
2615 return _this.options.selectable;
2619 openParents = (function(_this) {
2622 parent = node.parent;
2623 if (parent && parent.parent && !parent.is_open) {
2624 return _this.openNode(parent, false);
2628 saveState = (function(_this) {
2630 if (_this.options.saveState) {
2631 return _this.save_state_handler.saveState();
2636 this._deselectCurrentNode();
2643 if (this.select_node_handler.isNodeSelected(node)) {
2645 this._deselectCurrentNode();
2646 this._triggerEvent('tree.select', {
2652 deselected_node = this.getSelectedNode();
2653 this._deselectCurrentNode();
2654 this.addToSelection(node);
2655 this._triggerEvent('tree.select', {
2657 deselected_node: deselected_node
2664 JqTreeWidget.prototype.getSelectedNode = function() {
2665 if (this.select_node_handler) {
2666 return this.select_node_handler.getSelectedNode();
2672 JqTreeWidget.prototype.toJson = function() {
2673 return JSON.stringify(this.tree.getData());
2676 JqTreeWidget.prototype.loadData = function(data, parent_node) {
2677 this._loadData(data, parent_node);
2678 return this.element;
2684 - loadDataFromUrl(url, parent_node=null, on_finished=null)
2685 loadDataFromUrl('/my_data');
2686 loadDataFromUrl('/my_data', node1);
2687 loadDataFromUrl('/my_data', node1, function() { console.log('finished'); });
2688 loadDataFromUrl('/my_data', null, function() { console.log('finished'); });
2690 - loadDataFromUrl(parent_node=null, on_finished=null)
2692 loadDataFromUrl(node1);
2693 loadDataFromUrl(null, function() { console.log('finished'); });
2694 loadDataFromUrl(node1, function() { console.log('finished'); });
2697 JqTreeWidget.prototype.loadDataFromUrl = function(param1, param2, param3) {
2698 if ($.type(param1) === 'string') {
2699 this._loadDataFromUrl(param1, param2, param3);
2701 this._loadDataFromUrl(null, param1, param2);
2703 return this.element;
2706 JqTreeWidget.prototype.reload = function(on_finished) {
2707 this._loadDataFromUrl(null, null, on_finished);
2708 return this.element;
2711 JqTreeWidget.prototype._loadDataFromUrl = function(url_info, parent_node, on_finished) {
2712 var $el, addLoadingClass, handeLoadData, handleError, handleSuccess, loadDataFromUrlInfo, parseUrlInfo, removeLoadingClass;
2714 addLoadingClass = (function(_this) {
2717 $el = $(parent_node.element);
2719 $el = _this.element;
2721 $el.addClass('jqtree-loading');
2722 return _this._notifyLoading(true, parent_node, $el);
2725 removeLoadingClass = (function(_this) {
2728 $el.removeClass('jqtree-loading');
2729 return _this._notifyLoading(false, parent_node, $el);
2733 parseUrlInfo = function() {
2734 if ($.type(url_info) === 'string') {
2739 if (!url_info.method) {
2740 url_info.method = 'get';
2744 handeLoadData = (function(_this) {
2745 return function(data) {
2746 removeLoadingClass();
2747 _this._loadData(data, parent_node);
2748 if (on_finished && $.isFunction(on_finished)) {
2749 return on_finished();
2753 handleSuccess = (function(_this) {
2754 return function(response) {
2756 if ($.isArray(response) || typeof response === 'object') {
2758 } else if (data != null) {
2759 data = $.parseJSON(response);
2763 if (_this.options.dataFilter) {
2764 data = _this.options.dataFilter(data);
2766 return handeLoadData(data);
2769 handleError = (function(_this) {
2770 return function(response) {
2771 removeLoadingClass();
2772 if (_this.options.onLoadFailed) {
2773 return _this.options.onLoadFailed(response);
2777 loadDataFromUrlInfo = function() {
2778 url_info = parseUrlInfo();
2779 return $.ajax($.extend({}, url_info, {
2780 method: url_info.method != null ? url_info.method.toUpperCase() : 'GET',
2783 success: handleSuccess,
2788 url_info = this._getDataUrlInfo(parent_node);
2792 removeLoadingClass();
2793 } else if ($.isArray(url_info)) {
2794 handeLoadData(url_info);
2796 loadDataFromUrlInfo();
2800 JqTreeWidget.prototype._loadData = function(data, parent_node) {
2801 var deselectNodes, loadSubtree;
2802 if (parent_node == null) {
2805 deselectNodes = (function(_this) {
2807 var i, len, n, selected_nodes_under_parent;
2808 if (_this.select_node_handler) {
2809 selected_nodes_under_parent = _this.select_node_handler.getSelectedNodesUnder(parent_node);
2810 for (i = 0, len = selected_nodes_under_parent.length; i < len; i++) {
2811 n = selected_nodes_under_parent[i];
2812 _this.select_node_handler.removeFromSelection(n);
2818 loadSubtree = (function(_this) {
2820 parent_node.loadFromData(data);
2821 parent_node.load_on_demand = false;
2822 parent_node.is_loading = false;
2823 return _this._refreshElements(parent_node);
2829 this._triggerEvent('tree.load_data', {
2833 this._initTree(data);
2838 if (this.isDragging()) {
2839 return this.dnd_handler.refresh();
2843 JqTreeWidget.prototype.getNodeById = function(node_id) {
2844 return this.tree.getNodeById(node_id);
2847 JqTreeWidget.prototype.getNodeByName = function(name) {
2848 return this.tree.getNodeByName(name);
2851 JqTreeWidget.prototype.getNodesByProperty = function(key, value) {
2852 return this.tree.getNodesByProperty(key, value);
2855 JqTreeWidget.prototype.getNodeByHtmlElement = function(element) {
2856 return this._getNode($(element));
2859 JqTreeWidget.prototype.getNodeByCallback = function(callback) {
2860 return this.tree.getNodeByCallback(callback);
2863 JqTreeWidget.prototype.openNode = function(node, slide) {
2864 if (slide == null) {
2868 if (slide === null) {
2869 slide = this.options.slide;
2871 this._openNode(node, slide);
2873 return this.element;
2876 JqTreeWidget.prototype._openNode = function(node, slide, on_finished) {
2877 var doOpenNode, parent;
2878 if (slide == null) {
2881 doOpenNode = (function(_this) {
2882 return function(_node, _slide, _on_finished) {
2884 folder_element = new FolderElement(_node, _this);
2885 return folder_element.open(_on_finished, _slide);
2888 if (node.isFolder()) {
2889 if (node.load_on_demand) {
2890 return this._loadFolderOnDemand(node, slide, on_finished);
2892 parent = node.parent;
2894 if (parent.parent) {
2895 doOpenNode(parent, false, null);
2897 parent = parent.parent;
2899 doOpenNode(node, slide, on_finished);
2900 return this._saveState();
2905 JqTreeWidget.prototype._loadFolderOnDemand = function(node, slide, on_finished) {
2906 if (slide == null) {
2909 node.is_loading = true;
2910 return this._loadDataFromUrl(null, node, (function(_this) {
2912 return _this._openNode(node, slide, on_finished);
2917 JqTreeWidget.prototype.closeNode = function(node, slide) {
2918 if (slide == null) {
2921 if (slide === null) {
2922 slide = this.options.slide;
2924 if (node.isFolder()) {
2925 new FolderElement(node, this).close(slide);
2928 return this.element;
2931 JqTreeWidget.prototype.isDragging = function() {
2932 if (this.dnd_handler) {
2933 return this.dnd_handler.is_dragging;
2939 JqTreeWidget.prototype.refreshHitAreas = function() {
2940 this.dnd_handler.refresh();
2941 return this.element;
2944 JqTreeWidget.prototype.addNodeAfter = function(new_node_info, existing_node) {
2946 new_node = existing_node.addAfter(new_node_info);
2947 this._refreshElements(existing_node.parent);
2951 JqTreeWidget.prototype.addNodeBefore = function(new_node_info, existing_node) {
2953 new_node = existing_node.addBefore(new_node_info);
2954 this._refreshElements(existing_node.parent);
2958 JqTreeWidget.prototype.addParentNode = function(new_node_info, existing_node) {
2960 new_node = existing_node.addParent(new_node_info);
2961 this._refreshElements(new_node.parent);
2965 JqTreeWidget.prototype.removeNode = function(node) {
2967 parent = node.parent;
2969 this.select_node_handler.removeFromSelection(node, true);
2971 this._refreshElements(parent);
2973 return this.element;
2976 JqTreeWidget.prototype.appendNode = function(new_node_info, parent_node) {
2978 parent_node = parent_node || this.tree;
2979 node = parent_node.append(new_node_info);
2980 this._refreshElements(parent_node);
2984 JqTreeWidget.prototype.prependNode = function(new_node_info, parent_node) {
2987 parent_node = this.tree;
2989 node = parent_node.prepend(new_node_info);
2990 this._refreshElements(parent_node);
2994 JqTreeWidget.prototype.updateNode = function(node, data) {
2996 id_is_changed = data.id && data.id !== node.id;
2997 if (id_is_changed) {
2998 this.tree.removeNodeFromIndex(node);
3001 if (id_is_changed) {
3002 this.tree.addNodeToIndex(node);
3004 if (typeof data === 'object' && data.children) {
3005 node.removeChildren();
3006 if (data.children.length) {
3007 node.loadFromData(data.children);
3010 this.renderer.renderFromNode(node);
3011 this._selectCurrentNode();
3012 return this.element;
3015 JqTreeWidget.prototype.moveNode = function(node, target_node, position) {
3017 position_index = Position.nameToIndex(position);
3018 this.tree.moveNode(node, target_node, position_index);
3019 this._refreshElements();
3020 return this.element;
3023 JqTreeWidget.prototype.getStateFromStorage = function() {
3024 return this.save_state_handler.getStateFromStorage();
3027 JqTreeWidget.prototype.addToSelection = function(node) {
3029 this.select_node_handler.addToSelection(node);
3030 this._getNodeElementForNode(node).select();
3033 return this.element;
3036 JqTreeWidget.prototype.getSelectedNodes = function() {
3037 return this.select_node_handler.getSelectedNodes();
3040 JqTreeWidget.prototype.isNodeSelected = function(node) {
3041 return this.select_node_handler.isNodeSelected(node);
3044 JqTreeWidget.prototype.removeFromSelection = function(node) {
3045 this.select_node_handler.removeFromSelection(node);
3046 this._getNodeElementForNode(node).deselect();
3048 return this.element;
3051 JqTreeWidget.prototype.scrollToNode = function(node) {
3053 $element = $(node.element);
3054 top = $element.offset().top - this.$el.offset().top;
3055 this.scroll_handler.scrollTo(top);
3056 return this.element;
3059 JqTreeWidget.prototype.getState = function() {
3060 return this.save_state_handler.getState();
3063 JqTreeWidget.prototype.setState = function(state) {
3064 this.save_state_handler.setInitialState(state);
3065 this._refreshElements();
3066 return this.element;
3069 JqTreeWidget.prototype.setOption = function(option, value) {
3070 this.options[option] = value;
3071 return this.element;
3074 JqTreeWidget.prototype.moveDown = function() {
3075 if (this.key_handler) {
3076 this.key_handler.moveDown();
3078 return this.element;
3081 JqTreeWidget.prototype.moveUp = function() {
3082 if (this.key_handler) {
3083 this.key_handler.moveUp();
3085 return this.element;
3088 JqTreeWidget.prototype.getVersion = function() {
3092 JqTreeWidget.prototype._init = function() {
3093 JqTreeWidget.__super__._init.call(this);
3094 this.element = this.$el;
3095 this.mouse_delay = 300;
3096 this.is_initialized = false;
3097 this.options.rtl = this._getRtlOption();
3098 if (!this.options.closedIcon) {
3099 this.options.closedIcon = this._getDefaultClosedIcon();
3101 this.renderer = new ElementsRenderer(this);
3102 if (SaveStateHandler != null) {
3103 this.save_state_handler = new SaveStateHandler(this);
3105 this.options.saveState = false;
3107 if (SelectNodeHandler != null) {
3108 this.select_node_handler = new SelectNodeHandler(this);
3110 if (DragAndDropHandler != null) {
3111 this.dnd_handler = new DragAndDropHandler(this);
3113 this.options.dragAndDrop = false;
3115 if (ScrollHandler != null) {
3116 this.scroll_handler = new ScrollHandler(this);
3118 if ((KeyHandler != null) && (SelectNodeHandler != null)) {
3119 this.key_handler = new KeyHandler(this);
3122 this.element.click($.proxy(this._click, this));
3123 this.element.dblclick($.proxy(this._dblclick, this));
3124 if (this.options.useContextMenu) {
3125 return this.element.bind('contextmenu', $.proxy(this._contextmenu, this));
3129 JqTreeWidget.prototype._deinit = function() {
3130 this.element.empty();
3131 this.element.unbind();
3132 if (this.key_handler) {
3133 this.key_handler.deinit();
3136 return JqTreeWidget.__super__._deinit.call(this);
3139 JqTreeWidget.prototype._initData = function() {
3141 if (this.options.data) {
3142 return this._loadData(this.options.data);
3144 data_url = this._getDataUrlInfo();
3146 return this._loadDataFromUrl();
3148 return this._loadData([]);
3153 JqTreeWidget.prototype._getDataUrlInfo = function(node) {
3154 var data_url, getUrlFromString;
3155 data_url = this.options.dataUrl || this.element.data('url');
3156 getUrlFromString = (function(_this) {
3158 var data, selected_node_id, url_info;
3162 if (node && node.id) {
3166 url_info['data'] = data;
3168 selected_node_id = _this._getNodeIdToBeSelected();
3169 if (selected_node_id) {
3171 selected_node: selected_node_id
3173 url_info['data'] = data;
3179 if ($.isFunction(data_url)) {
3180 return data_url(node);
3181 } else if ($.type(data_url) === 'string') {
3182 return getUrlFromString();
3188 JqTreeWidget.prototype._getNodeIdToBeSelected = function() {
3189 if (this.options.saveState) {
3190 return this.save_state_handler.getNodeIdToBeSelected();
3196 JqTreeWidget.prototype._initTree = function(data) {
3197 var doInit, must_load_on_demand;
3198 doInit = (function(_this) {
3200 if (!_this.is_initialized) {
3201 _this.is_initialized = true;
3202 return _this._triggerEvent('tree.init');
3206 this.tree = new this.options.nodeClass(null, true, this.options.nodeClass);
3207 if (this.select_node_handler) {
3208 this.select_node_handler.clear();
3210 this.tree.loadFromData(data);
3211 must_load_on_demand = this._setInitialState();
3212 this._refreshElements();
3213 if (!must_load_on_demand) {
3216 return this._setInitialStateOnDemand(doInit);
3220 JqTreeWidget.prototype._setInitialState = function() {
3221 var autoOpenNodes, is_restored, must_load_on_demand, ref1, restoreState;
3222 restoreState = (function(_this) {
3224 var must_load_on_demand, state;
3225 if (!(_this.options.saveState && _this.save_state_handler)) {
3226 return [false, false];
3228 state = _this.save_state_handler.getStateFromStorage();
3230 return [false, false];
3232 must_load_on_demand = _this.save_state_handler.setInitialState(state);
3233 return [true, must_load_on_demand];
3238 autoOpenNodes = (function(_this) {
3240 var max_level, must_load_on_demand;
3241 if (_this.options.autoOpen === false) {
3244 max_level = _this._getAutoOpenMaxLevel();
3245 must_load_on_demand = false;
3246 _this.tree.iterate(function(node, level) {
3247 if (node.load_on_demand) {
3248 must_load_on_demand = true;
3250 } else if (!node.hasChildren()) {
3253 node.is_open = true;
3254 return level !== max_level;
3257 return must_load_on_demand;
3260 ref1 = restoreState(), is_restored = ref1[0], must_load_on_demand = ref1[1];
3262 must_load_on_demand = autoOpenNodes();
3264 return must_load_on_demand;
3267 JqTreeWidget.prototype._setInitialStateOnDemand = function(cb_finished) {
3268 var autoOpenNodes, restoreState;
3269 restoreState = (function(_this) {
3272 if (!(_this.options.saveState && _this.save_state_handler)) {
3275 state = _this.save_state_handler.getStateFromStorage();
3279 _this.save_state_handler.setInitialStateOnDemand(state, cb_finished);
3285 autoOpenNodes = (function(_this) {
3287 var loadAndOpenNode, loading_count, max_level, openNodes;
3288 max_level = _this._getAutoOpenMaxLevel();
3290 loadAndOpenNode = function(node) {
3292 return _this._openNode(node, false, function() {
3297 openNodes = function() {
3298 _this.tree.iterate(function(node, level) {
3299 if (node.load_on_demand) {
3300 if (!node.is_loading) {
3301 loadAndOpenNode(node);
3305 _this._openNode(node, false);
3306 return level !== max_level;
3309 if (loading_count === 0) {
3310 return cb_finished();
3316 if (!restoreState()) {
3317 return autoOpenNodes();
3321 JqTreeWidget.prototype._getAutoOpenMaxLevel = function() {
3322 if (this.options.autoOpen === true) {
3325 return parseInt(this.options.autoOpen);
3331 Redraw the tree or part of the tree.
3332 * from_node: redraw this subtree
3335 JqTreeWidget.prototype._refreshElements = function(from_node) {
3336 if (from_node == null) {
3339 this.renderer.render(from_node);
3340 return this._triggerEvent('tree.refresh');
3343 JqTreeWidget.prototype._click = function(e) {
3344 var click_target, event, node;
3345 click_target = this._getClickTarget(e.target);
3347 if (click_target.type === 'button') {
3348 this.toggle(click_target.node, this.options.slide);
3350 return e.stopPropagation();
3351 } else if (click_target.type === 'label') {
3352 node = click_target.node;
3353 event = this._triggerEvent('tree.click', {
3357 if (!event.isDefaultPrevented()) {
3358 return this._selectNode(node, true);
3364 JqTreeWidget.prototype._dblclick = function(e) {
3366 click_target = this._getClickTarget(e.target);
3367 if (click_target && click_target.type === 'label') {
3368 return this._triggerEvent('tree.dblclick', {
3369 node: click_target.node,
3375 JqTreeWidget.prototype._getClickTarget = function(element) {
3376 var $button, $el, $target, node;
3377 $target = $(element);
3378 $button = $target.closest('.jqtree-toggler');
3379 if ($button.length) {
3380 node = this._getNode($button);
3388 $el = $target.closest('.jqtree-element');
3390 node = this._getNode($el);
3402 JqTreeWidget.prototype._getNode = function($element) {
3404 $li = $element.closest('li.jqtree_common');
3405 if ($li.length === 0) {
3408 return $li.data('node');
3412 JqTreeWidget.prototype._getNodeElementForNode = function(node) {
3413 if (node.isFolder()) {
3414 return new FolderElement(node, this);
3416 return new NodeElement(node, this);
3420 JqTreeWidget.prototype._getNodeElement = function($element) {
3422 node = this._getNode($element);
3424 return this._getNodeElementForNode(node);
3430 JqTreeWidget.prototype._contextmenu = function(e) {
3432 $div = $(e.target).closest('ul.jqtree-tree .jqtree-element');
3434 node = this._getNode($div);
3437 e.stopPropagation();
3438 this._triggerEvent('tree.contextmenu', {
3447 JqTreeWidget.prototype._saveState = function() {
3448 if (this.options.saveState) {
3449 return this.save_state_handler.saveState();
3453 JqTreeWidget.prototype._mouseCapture = function(position_info) {
3454 if (this.options.dragAndDrop) {
3455 return this.dnd_handler.mouseCapture(position_info);
3461 JqTreeWidget.prototype._mouseStart = function(position_info) {
3462 if (this.options.dragAndDrop) {
3463 return this.dnd_handler.mouseStart(position_info);
3469 JqTreeWidget.prototype._mouseDrag = function(position_info) {
3471 if (this.options.dragAndDrop) {
3472 result = this.dnd_handler.mouseDrag(position_info);
3473 if (this.scroll_handler) {
3474 this.scroll_handler.checkScrolling();
3482 JqTreeWidget.prototype._mouseStop = function(position_info) {
3483 if (this.options.dragAndDrop) {
3484 return this.dnd_handler.mouseStop(position_info);
3490 JqTreeWidget.prototype._triggerEvent = function(event_name, values) {
3492 event = $.Event(event_name);
3493 $.extend(event, values);
3494 this.element.trigger(event);
3498 JqTreeWidget.prototype.testGenerateHitAreas = function(moving_node) {
3499 this.dnd_handler.current_item = this._getNodeElementForNode(moving_node);
3500 this.dnd_handler.generateHitAreas();
3501 return this.dnd_handler.hit_areas;
3504 JqTreeWidget.prototype._selectCurrentNode = function() {
3505 var node, node_element;
3506 node = this.getSelectedNode();
3508 node_element = this._getNodeElementForNode(node);
3510 return node_element.select();
3515 JqTreeWidget.prototype._deselectCurrentNode = function() {
3517 node = this.getSelectedNode();
3519 return this.removeFromSelection(node);
3523 JqTreeWidget.prototype._getDefaultClosedIcon = function() {
3524 if (this.options.rtl) {
3531 JqTreeWidget.prototype._getRtlOption = function() {
3533 if (this.options.rtl !== null) {
3534 return this.options.rtl;
3536 data_rtl = this.element.data('rtl');
3537 if ((data_rtl != null) && data_rtl !== false) {
3545 JqTreeWidget.prototype._notifyLoading = function(is_loading, node, $el) {
3546 if (this.options.onLoading) {
3547 return this.options.onLoading(is_loading, node, $el);
3551 return JqTreeWidget;
3555 JqTreeWidget.getModule = function(name) {
3558 'node': node_module,
3559 'util': util_module,
3560 'drag_and_drop_handler': drag_and_drop_handler
3562 return modules[name];
3565 SimpleWidget.register(JqTreeWidget, 'tree');
3567 },{"./drag_and_drop_handler":1,"./elements_renderer":2,"./key_handler":3,"./mouse.widget":4,"./node":5,"./node_element":6,"./save_state_handler":7,"./scroll_handler":8,"./select_node_handler":9,"./simple.widget":10,"./util":12,"./version":13}],12:[function(require,module,exports){
3568 var _indexOf, getBoolString, html_escape, indexOf, isInt;
3570 _indexOf = function(array, item) {
3571 var i, j, len, value;
3572 for (i = j = 0, len = array.length; j < len; i = ++j) {
3574 if (value === item) {
3581 indexOf = function(array, item) {
3582 if (array.indexOf) {
3583 return array.indexOf(item);
3585 return _indexOf(array, item);
3589 isInt = function(n) {
3590 return typeof n === 'number' && n % 1 === 0;
3593 html_escape = function(string) {
3594 return ('' + string).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g, '/');
3597 getBoolString = function(value) {
3607 getBoolString: getBoolString,
3608 html_escape: html_escape,
3613 },{}],13:[function(require,module,exports){
3614 module.exports = '1.3.6';