nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jqTree / lib / node_element.js
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;
4
5 node = require('./node');
6
7 Position = node.Position;
8
9 $ = jQuery;
10
11 NodeElement = (function() {
12   function NodeElement(node, tree_widget) {
13     this.init(node, tree_widget);
14   }
15
16   NodeElement.prototype.init = function(node, tree_widget) {
17     this.node = node;
18     this.tree_widget = tree_widget;
19     if (!node.element) {
20       node.element = this.tree_widget.element;
21     }
22     return this.$element = $(node.element);
23   };
24
25   NodeElement.prototype.getUl = function() {
26     return this.$element.children('ul:first');
27   };
28
29   NodeElement.prototype.getSpan = function() {
30     return this.$element.children('.jqtree-element').find('span.jqtree-title');
31   };
32
33   NodeElement.prototype.getLi = function() {
34     return this.$element;
35   };
36
37   NodeElement.prototype.addDropHint = function(position) {
38     if (position === Position.INSIDE) {
39       return new BorderDropHint(this.$element);
40     } else {
41       return new GhostDropHint(this.node, this.$element, position);
42     }
43   };
44
45   NodeElement.prototype.select = function() {
46     var $li, $span;
47     $li = this.getLi();
48     $li.addClass('jqtree-selected');
49     $li.attr('aria-selected', 'true');
50     $span = this.getSpan();
51     return $span.attr('tabindex', 0);
52   };
53
54   NodeElement.prototype.deselect = function() {
55     var $li, $span;
56     $li = this.getLi();
57     $li.removeClass('jqtree-selected');
58     $li.attr('aria-selected', 'false');
59     $span = this.getSpan();
60     return $span.attr('tabindex', -1);
61   };
62
63   return NodeElement;
64
65 })();
66
67 FolderElement = (function(superClass) {
68   extend(FolderElement, superClass);
69
70   function FolderElement() {
71     return FolderElement.__super__.constructor.apply(this, arguments);
72   }
73
74   FolderElement.prototype.open = function(on_finished, slide) {
75     var $button, doOpen;
76     if (slide == null) {
77       slide = true;
78     }
79     if (!this.node.is_open) {
80       this.node.is_open = true;
81       $button = this.getButton();
82       $button.removeClass('jqtree-closed');
83       $button.html('');
84       $button.append(this.tree_widget.renderer.opened_icon_element.cloneNode(false));
85       doOpen = (function(_this) {
86         return function() {
87           var $li, $span;
88           $li = _this.getLi();
89           $li.removeClass('jqtree-closed');
90           $span = _this.getSpan();
91           $span.attr('aria-expanded', 'true');
92           if (on_finished) {
93             on_finished(_this.node);
94           }
95           return _this.tree_widget._triggerEvent('tree.open', {
96             node: _this.node
97           });
98         };
99       })(this);
100       if (slide) {
101         return this.getUl().slideDown('fast', doOpen);
102       } else {
103         this.getUl().show();
104         return doOpen();
105       }
106     }
107   };
108
109   FolderElement.prototype.close = function(slide) {
110     var $button, doClose;
111     if (slide == null) {
112       slide = true;
113     }
114     if (this.node.is_open) {
115       this.node.is_open = false;
116       $button = this.getButton();
117       $button.addClass('jqtree-closed');
118       $button.html('');
119       $button.append(this.tree_widget.renderer.closed_icon_element.cloneNode(false));
120       doClose = (function(_this) {
121         return function() {
122           var $li, $span;
123           $li = _this.getLi();
124           $li.addClass('jqtree-closed');
125           $span = _this.getSpan();
126           $span.attr('aria-expanded', 'false');
127           return _this.tree_widget._triggerEvent('tree.close', {
128             node: _this.node
129           });
130         };
131       })(this);
132       if (slide) {
133         return this.getUl().slideUp('fast', doClose);
134       } else {
135         this.getUl().hide();
136         return doClose();
137       }
138     }
139   };
140
141   FolderElement.prototype.getButton = function() {
142     return this.$element.children('.jqtree-element').find('a.jqtree-toggler');
143   };
144
145   FolderElement.prototype.addDropHint = function(position) {
146     if (!this.node.is_open && position === Position.INSIDE) {
147       return new BorderDropHint(this.$element);
148     } else {
149       return new GhostDropHint(this.node, this.$element, position);
150     }
151   };
152
153   return FolderElement;
154
155 })(NodeElement);
156
157 BorderDropHint = (function() {
158   function BorderDropHint($element) {
159     var $div, width;
160     $div = $element.children('.jqtree-element');
161     width = $element.width() - 4;
162     this.$hint = $('<span class="jqtree-border"></span>');
163     $div.append(this.$hint);
164     this.$hint.css({
165       width: width,
166       height: $div.outerHeight() - 4
167     });
168   }
169
170   BorderDropHint.prototype.remove = function() {
171     return this.$hint.remove();
172   };
173
174   return BorderDropHint;
175
176 })();
177
178 GhostDropHint = (function() {
179   function GhostDropHint(node, $element, position) {
180     this.$element = $element;
181     this.node = node;
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) {
184       this.moveAfter();
185     } else if (position === Position.BEFORE) {
186       this.moveBefore();
187     } else if (position === Position.INSIDE) {
188       if (node.isFolder() && node.is_open) {
189         this.moveInsideOpenFolder();
190       } else {
191         this.moveInside();
192       }
193     }
194   }
195
196   GhostDropHint.prototype.remove = function() {
197     return this.$ghost.remove();
198   };
199
200   GhostDropHint.prototype.moveAfter = function() {
201     return this.$element.after(this.$ghost);
202   };
203
204   GhostDropHint.prototype.moveBefore = function() {
205     return this.$element.before(this.$ghost);
206   };
207
208   GhostDropHint.prototype.moveInsideOpenFolder = function() {
209     return $(this.node.children[0].element).before(this.$ghost);
210   };
211
212   GhostDropHint.prototype.moveInside = function() {
213     this.$element.after(this.$ghost);
214     return this.$ghost.addClass('jqtree-inside');
215   };
216
217   return GhostDropHint;
218
219 })();
220
221 module.exports = {
222   BorderDropHint: BorderDropHint,
223   FolderElement: FolderElement,
224   GhostDropHint: GhostDropHint,
225   NodeElement: NodeElement
226 };