1 var $, BorderDropHint, FolderElement, GhostDropHint, NodeElement, Position, node,
2 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; },
3 hasProp = {}.hasOwnProperty;
5 node = require('./node');
7 Position = node.Position;
11 NodeElement = (function() {
12 function NodeElement(node, tree_widget) {
13 this.init(node, tree_widget);
16 NodeElement.prototype.init = function(node, tree_widget) {
18 this.tree_widget = tree_widget;
20 node.element = this.tree_widget.element;
22 return this.$element = $(node.element);
25 NodeElement.prototype.getUl = function() {
26 return this.$element.children('ul:first');
29 NodeElement.prototype.getSpan = function() {
30 return this.$element.children('.jqtree-element').find('span.jqtree-title');
33 NodeElement.prototype.getLi = function() {
37 NodeElement.prototype.addDropHint = function(position) {
38 if (position === Position.INSIDE) {
39 return new BorderDropHint(this.$element);
41 return new GhostDropHint(this.node, this.$element, position);
45 NodeElement.prototype.select = function() {
48 $li.addClass('jqtree-selected');
49 $li.attr('aria-selected', 'true');
50 $span = this.getSpan();
51 return $span.attr('tabindex', 0);
54 NodeElement.prototype.deselect = function() {
57 $li.removeClass('jqtree-selected');
58 $li.attr('aria-selected', 'false');
59 $span = this.getSpan();
60 return $span.attr('tabindex', -1);
67 FolderElement = (function(superClass) {
68 extend(FolderElement, superClass);
70 function FolderElement() {
71 return FolderElement.__super__.constructor.apply(this, arguments);
74 FolderElement.prototype.open = function(on_finished, slide) {
79 if (!this.node.is_open) {
80 this.node.is_open = true;
81 $button = this.getButton();
82 $button.removeClass('jqtree-closed');
84 $button.append(this.tree_widget.renderer.opened_icon_element.cloneNode(false));
85 doOpen = (function(_this) {
89 $li.removeClass('jqtree-closed');
90 $span = _this.getSpan();
91 $span.attr('aria-expanded', 'true');
93 on_finished(_this.node);
95 return _this.tree_widget._triggerEvent('tree.open', {
101 return this.getUl().slideDown('fast', doOpen);
109 FolderElement.prototype.close = function(slide) {
110 var $button, doClose;
114 if (this.node.is_open) {
115 this.node.is_open = false;
116 $button = this.getButton();
117 $button.addClass('jqtree-closed');
119 $button.append(this.tree_widget.renderer.closed_icon_element.cloneNode(false));
120 doClose = (function(_this) {
124 $li.addClass('jqtree-closed');
125 $span = _this.getSpan();
126 $span.attr('aria-expanded', 'false');
127 return _this.tree_widget._triggerEvent('tree.close', {
133 return this.getUl().slideUp('fast', doClose);
141 FolderElement.prototype.getButton = function() {
142 return this.$element.children('.jqtree-element').find('a.jqtree-toggler');
145 FolderElement.prototype.addDropHint = function(position) {
146 if (!this.node.is_open && position === Position.INSIDE) {
147 return new BorderDropHint(this.$element);
149 return new GhostDropHint(this.node, this.$element, position);
153 return FolderElement;
157 BorderDropHint = (function() {
158 function BorderDropHint($element) {
160 $div = $element.children('.jqtree-element');
161 width = $element.width() - 4;
162 this.$hint = $('<span class="jqtree-border"></span>');
163 $div.append(this.$hint);
166 height: $div.outerHeight() - 4
170 BorderDropHint.prototype.remove = function() {
171 return this.$hint.remove();
174 return BorderDropHint;
178 GhostDropHint = (function() {
179 function GhostDropHint(node, $element, position) {
180 this.$element = $element;
182 this.$ghost = $('<li class="jqtree_common jqtree-ghost"><span class="jqtree_common jqtree-circle"></span><span class="jqtree_common jqtree-line"></span></li>');
183 if (position === Position.AFTER) {
185 } else if (position === Position.BEFORE) {
187 } else if (position === Position.INSIDE) {
188 if (node.isFolder() && node.is_open) {
189 this.moveInsideOpenFolder();
196 GhostDropHint.prototype.remove = function() {
197 return this.$ghost.remove();
200 GhostDropHint.prototype.moveAfter = function() {
201 return this.$element.after(this.$ghost);
204 GhostDropHint.prototype.moveBefore = function() {
205 return this.$element.before(this.$ghost);
208 GhostDropHint.prototype.moveInsideOpenFolder = function() {
209 return $(this.node.children[0].element).before(this.$ghost);
212 GhostDropHint.prototype.moveInside = function() {
213 this.$element.after(this.$ghost);
214 return this.$ghost.addClass('jqtree-inside');
217 return GhostDropHint;
222 BorderDropHint: BorderDropHint,
223 FolderElement: FolderElement,
224 GhostDropHint: GhostDropHint,
225 NodeElement: NodeElement