From aeb4e35a96199018c6e73fc54fef5883621b6fa6 Mon Sep 17 00:00:00 2001 From: Danny Raetzsch Date: Tue, 3 Feb 2015 15:07:47 -0600 Subject: [PATCH 1/6] Fix protectRoot logic --- jquery.mjs.nestedSortable.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js index d98edc8..05729cc 100644 --- a/jquery.mjs.nestedSortable.js +++ b/jquery.mjs.nestedSortable.js @@ -467,9 +467,8 @@ // mjs - if the item is moved to the left, send it one level up // but only if it's at the bottom of the list - if (parentItem != null && - nextItem == null && - o.protectRoot && parentItem[0].parentNode !== this.element[0] && + if (parentItem && !nextItem && + !(o.protectRoot && parentItem[0].parentNode === this.element[0]) && ( o.rtl && ( @@ -479,6 +478,7 @@ ) || !o.rtl && (this.positionAbs.left < parentItem.offset().left) ) + ) { parentItem.after(this.placeholder[0]); @@ -494,9 +494,10 @@ this._clearEmpty(parentItem[0]); this._trigger("change", event, this._uiHash()); + // mjs - if the item is below a sibling and is moved to the right, // make it a child of that sibling - } else if (previousItem != null && + } else if (previousItem && !previousItem.hasClass(o.disableNestingClass) && ( previousItem.children(o.listType).length && From 64c87b4efd5f77b143a62a52f6ff33275ee5f4ad Mon Sep 17 00:00:00 2001 From: Danny Raetzsch Date: Tue, 3 Feb 2015 15:28:31 -0600 Subject: [PATCH 2/6] Fix bad selector --- jquery.mjs.nestedSortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js index 05729cc..7c989c0 100644 --- a/jquery.mjs.nestedSortable.js +++ b/jquery.mjs.nestedSortable.js @@ -484,7 +484,7 @@ parentItem.after(this.placeholder[0]); helperIsNotSibling = !parentItem .children(o.listItem) - .children("li:visible:not(.ui-sortable-helper") + .children("li:visible:not(.ui-sortable-helper)") .length; if (o.isTree && helperIsNotSibling) { parentItem From d479d4b30e274c463a295c657b7c80d64d136cdc Mon Sep 17 00:00:00 2001 From: Danny Raetzsch Date: Tue, 3 Feb 2015 15:33:42 -0600 Subject: [PATCH 3/6] Pull expandItem anon function from loop --- jquery.mjs.nestedSortable.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js index 7c989c0..96932aa 100644 --- a/jquery.mjs.nestedSortable.js +++ b/jquery.mjs.nestedSortable.js @@ -264,6 +264,17 @@ childLevels = this._getChildLevels(this.helper); newList = document.createElement(o.listType); + var expandItem = function() { + return window.setTimeout(function() { + $(itemElement) + .removeClass(o.collapsedClass) + .addClass(o.expandedClass); + + self.refreshPositions(); + self._trigger("expand", event, self._uiHash()); + }, o.expandOnHover); + }; + //Rearrange for (i = this.items.length - 1; i >= 0; i--) { @@ -334,14 +345,7 @@ if (o.isTree && $(itemElement).hasClass(o.collapsedClass) && o.expandOnHover) { if (!this.hovering) { $(itemElement).addClass(o.hoveringClass); - this.hovering = window.setTimeout(function() { - $(itemElement) - .removeClass(o.collapsedClass) - .addClass(o.expandedClass); - - self.refreshPositions(); - self._trigger("expand", event, self._uiHash()); - }, o.expandOnHover); + this.hovering = expandItem(); } } From 2e43a4da01db439b2d58e97c20d1b52425ff4ccb Mon Sep 17 00:00:00 2001 From: Danny Raetzsch Date: Tue, 3 Feb 2015 15:35:01 -0600 Subject: [PATCH 4/6] Misc lint --- jquery.mjs.nestedSortable.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js index 96932aa..e73218a 100644 --- a/jquery.mjs.nestedSortable.js +++ b/jquery.mjs.nestedSortable.js @@ -424,7 +424,7 @@ } }.call(this)); - if (previousItem != null) { + if (previousItem) { while ( previousItem[0].nodeName.toLowerCase() !== "li" || previousItem[0].className.indexOf(o.disabledClass) !== -1 || @@ -451,7 +451,7 @@ } }.call(this)); - if (nextItem != null) { + if (nextItem) { while ( nextItem[0].nodeName.toLowerCase() !== "li" || nextItem[0].className.indexOf(o.disabledClass) !== -1 || @@ -600,7 +600,7 @@ // to make it easier to hover over a collapsed element and have it expand _intersectsWithSides: function(item) { - var half = this.options.isTree ? .8 : .5, + var half = this.options.isTree ? 0.8 : 0.5, isOverBottomHalf = isOverAxis( this.positionAbs.top + this.offset.click.top, item.top + (item.height * half), From 9032970b3beb99ff4af7ae03ac49faf0388a89e2 Mon Sep 17 00:00:00 2001 From: Danny Raetzsch Date: Tue, 3 Feb 2015 15:35:34 -0600 Subject: [PATCH 5/6] Remove some legacy code --- jquery.mjs.nestedSortable.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js index e73218a..3e71f4c 100644 --- a/jquery.mjs.nestedSortable.js +++ b/jquery.mjs.nestedSortable.js @@ -391,10 +391,6 @@ $(itemElement).children(o.listType); } - if (a[0] !== undefined) { - this._rearrange(event, null, a); - } - } else { this._rearrange(event, item); } From b2290041c231d7ac5c6ee55cdadf937a3e3c8865 Mon Sep 17 00:00:00 2001 From: Danny Raetzsch Date: Tue, 3 Feb 2015 11:50:39 -0600 Subject: [PATCH 6/6] Add placeholderContent option --- jquery.mjs.nestedSortable.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js index 3e71f4c..809392a 100644 --- a/jquery.mjs.nestedSortable.js +++ b/jquery.mjs.nestedSortable.js @@ -115,6 +115,14 @@ return $.ui.sortable.prototype._destroy.apply(this, arguments); }, + _createPlaceholder: function() { + var ret = $.ui.sortable.prototype._createPlaceholder.apply(this, arguments); + if (this.options.placeholderContent) { + this.placeholder.html(this.options.placeholderContent); + } + return ret; + }, + _mouseDrag: function(event) { var i, item,