|
29 | 29 | isTree: false, |
30 | 30 | branchClass: 'mjs-nestedSortable-branch', |
31 | 31 | leafClass: 'mjs-nestedSortable-leaf', |
32 | | - collapsedClass: 'mjs-nestedSortable-collapse', |
33 | | - expandedClass: 'mjs-nestedSortable-expand', |
34 | | - expandOnHover: 200, |
| 32 | + collapsedClass: 'mjs-nestedSortable-collapsed', |
| 33 | + expandedClass: 'mjs-nestedSortable-expanded', |
| 34 | + expandOnHover: 500, |
35 | 35 | startCollapsed: true |
36 | 36 | }, |
37 | 37 |
|
|
41 | 41 | if (!this.element.is(this.options.listType)) |
42 | 42 | throw new Error('nestedSortable: Please check that the listType option is set to your actual list type'); |
43 | 43 |
|
| 44 | + var self = this; |
44 | 45 | // this goes through any any any list item, but what if a list is present but is not part of the sortable? |
45 | 46 | this.element.find('li').each(function() { |
46 | 47 | var $li = $(this); |
47 | | - if ($li.children('ul').length) { |
48 | | - $li.addClass(this.options.branchClass); |
| 48 | + if ($li.children(self.options.listType).length) { |
| 49 | + $li.addClass(self.options.branchClass); |
49 | 50 | // expand/collapse class only if they have children |
50 | | - if (this.options.startCollapsed) $li.addClass(this.options.collapsedClass); |
51 | | - else $li.addClass(this.options.expandedClass); |
| 51 | + if (self.options.startCollapsed) $li.addClass(self.options.collapsedClass); |
| 52 | + else $li.addClass(self.options.expandedClass); |
52 | 53 | } else { |
53 | | - $li.addClass(this.options.leafClass); |
| 54 | + $li.addClass(self.options.leafClass); |
54 | 55 | } |
55 | 56 | }) |
56 | 57 |
|
| 58 | + if (this.options.isTree) this.options.tolerance = 'intersect'; |
| 59 | + |
57 | 60 | return $.ui.sortable.prototype._create.apply(this, arguments); |
58 | 61 | }, |
59 | 62 |
|
|
111 | 114 | //Regenerate the absolute position used for position checks |
112 | 115 | this.positionAbs = this._convertPositionTo("absolute"); |
113 | 116 |
|
114 | | - // Find the top offset before rearrangement, |
115 | | - var previousTopOffset = this.placeholder.offset().top; |
| 117 | + // Find the top offset before rearrangement, |
| 118 | + var previousTopOffset = this.placeholder.offset().top; |
116 | 119 |
|
117 | 120 | //Set the helper position |
118 | 121 | if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; |
119 | 122 | if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; |
120 | 123 |
|
| 124 | + this.hovering = this.hovering ? this.hovering : null; |
| 125 | + |
121 | 126 | //Rearrange |
122 | 127 | for (var i = this.items.length - 1; i >= 0; i--) { |
123 | 128 |
|
|
136 | 141 |
|
137 | 142 | // if the element has children and they are hidden, show them after some time |
138 | 143 | if ($(itemElement).hasClass(o.collapsedClass)) { |
139 | | - TOID = window.setTimeout(function() { $(itemElement).removeClass(o.collapsedClass).addClass(o.expandedClass) }, o.expandOnHover); |
| 144 | + if (!this.hovering) { |
| 145 | + this.hovering = window.setTimeout(function() { $(itemElement).removeClass(o.collapsedClass).addClass(o.expandedClass) }, o.expandOnHover); |
| 146 | + console.log('started '+this.hovering); |
| 147 | + } |
140 | 148 | } |
141 | 149 |
|
142 | 150 | this.direction = intersection == 1 ? "down" : "up"; |
143 | 151 |
|
144 | | - if ( (this.options.tolerance == "pointer" && !o.isTree) || this._intersectsWithSides(item)) { |
| 152 | + if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) { |
145 | 153 | $(itemElement).mouseleave(); |
146 | | - window.clearTimeout(TOID); |
| 154 | + this.hovering && window.clearTimeout(this.hovering);console.log('cleared '+this.hovering); |
| 155 | + this.hovering = null; |
147 | 156 | this._rearrange(event, item); |
148 | 157 | } else { |
149 | 158 | break; |
|
198 | 207 | if (parentItem != null && nextItem == null && |
199 | 208 | (o.rtl && (this.positionAbs.left + this.helper.outerWidth() > parentItem.offset().left + parentItem.outerWidth()) || |
200 | 209 | !o.rtl && (this.positionAbs.left < parentItem.offset().left))) { |
| 210 | + |
201 | 211 | parentItem.after(this.placeholder[0]); |
| 212 | + if (parentItem.children(o.listItem).children('li:visible:not(.ui-sortable-helper)').length < 1) { |
| 213 | + parentItem.removeClass(this.options.branchClass + ' ' + this.options.expandedClass) |
| 214 | + .addClass(this.options.leafClass); |
| 215 | + } |
202 | 216 | this._clearEmpty(parentItem[0]); |
203 | 217 | this._trigger("change", event, this._uiHash()); |
204 | 218 | } |
205 | 219 | // If the item is below a sibling and is moved to the right, make it a child of that sibling. |
206 | 220 | else if (previousItem != null && |
| 221 | + (previousItem.children(o.listType).length && previousItem.children(o.listType).is(':visible') || !previousItem.children(o.listType).length) && |
207 | 222 | (o.rtl && (this.positionAbs.left + this.helper.outerWidth() < previousItem.offset().left + previousItem.outerWidth() - o.tabSize) || |
208 | 223 | !o.rtl && (this.positionAbs.left > previousItem.offset().left + o.tabSize))) { |
209 | 224 |
|
210 | 225 | this._isAllowed(previousItem, level, level+childLevels+1); |
211 | 226 |
|
212 | 227 | if (!previousItem.children(o.listType).length) { |
213 | | - previousItem[0].removeClass(o.leafClass) |
| 228 | + previousItem.removeClass(o.leafClass) |
214 | 229 | .addClass(o.branchClass + ' ' + o.expandedClass) |
215 | | - .appendChild(newList); |
| 230 | + .append(newList); |
216 | 231 | } |
217 | 232 |
|
218 | 233 | // If this item is being moved from the top, add it to the top of the list. |
|
261 | 276 |
|
262 | 277 | } |
263 | 278 |
|
| 279 | + $.ui.sortable.prototype._mouseStop.apply(this, arguments); |
| 280 | + |
| 281 | + }, |
| 282 | + |
| 283 | + _clear: function(event, noPropagation) { |
| 284 | + |
| 285 | + $.ui.sortable.prototype._clear.apply(this, arguments); |
| 286 | + |
264 | 287 | // Clean last empty ul/ol |
265 | 288 | for (var i = this.items.length - 1; i >= 0; i--) { |
266 | 289 | var item = this.items[i].item[0]; |
267 | 290 | this._clearEmpty(item); |
268 | 291 | } |
269 | 292 |
|
270 | | - $.ui.sortable.prototype._mouseStop.apply(this, arguments); |
271 | | - |
272 | 293 | }, |
273 | 294 |
|
274 | 295 | serialize: function(options) { |
|
391 | 412 | _clearEmpty: function(item) { |
392 | 413 |
|
393 | 414 | var emptyList = $(item).children(this.options.listType); |
| 415 | + |
394 | 416 | if (emptyList.length && !emptyList.children().length) { |
395 | 417 | $(item).removeClass(this.options.branchClass + ' ' + this.options.expandedClass) |
396 | 418 | .addClass(this.options.leafClass); |
397 | 419 | emptyList.remove(); |
| 420 | + } else if (emptyList.length && emptyList.children().length && emptyList.is(':visible')) { |
| 421 | + $(item).removeClass(this.options.leafClass) |
| 422 | + .addClass(this.options.branchClass + ' ' + this.options.expandedClass); |
| 423 | + } else if (emptyList.length && emptyList.children().length && !emptyList.is(':visible')) { |
| 424 | + $(item).removeClass(this.options.leafClass) |
| 425 | + .addClass(this.options.branchClass + ' ' + this.options.collapsedClass); |
398 | 426 | } |
399 | 427 |
|
400 | 428 | }, |
|
0 commit comments