From d24c4d3fee831cd4fdb539d2de528c8284eca151 Mon Sep 17 00:00:00 2001 From: Andreas Pircher Date: Sat, 22 Jun 2013 10:27:15 +0200 Subject: [PATCH 1/2] Allow hover behavior without changing css --- jquery.mjs.nestedSortable.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js index 72ed56b..9b20f33 100644 --- a/jquery.mjs.nestedSortable.js +++ b/jquery.mjs.nestedSortable.js @@ -14,7 +14,7 @@ (function($) { function isOverAxis( x, reference, size ) { - return ( x > reference ) && ( x < ( reference + size ) ); + return ( x >= reference ) && ( x < ( reference + size ) ); } $.widget("mjs.nestedSortable", $.extend({}, $.ui.sortable.prototype, { @@ -22,6 +22,7 @@ options: { doNotClear: false, expandOnHover: 700, + hoverCallback: null, isAllowed: function(placeholder, placeholderParent, originalItem) { return true; }, isTree: false, listType: 'ol', @@ -206,6 +207,12 @@ } } + // Allow hover behavior without switching css classes. + if (o.hoverCallback && o.expandOnHover && !this.hovering) { + var self = this, item = itemElement; + this.hovering = window.setTimeout(function () { o.hoverCallback.call(self, item); }, o.expandOnHover); + } + this.direction = intersection == 1 ? "down" : "up"; // mjs - rearrange the elements and reset timeouts and hovering state @@ -380,7 +387,7 @@ // mjs - this function is slightly modified 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 || this.options.hoverCallback ? .8 : .5; var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height*half), item.height), isOverTopHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top - (item.height*half), item.height), From 7eff66c9d501a3d66518b5a70f887dadfd87a857 Mon Sep 17 00:00:00 2001 From: Andreas Pircher Date: Sat, 22 Jun 2013 10:53:50 +0200 Subject: [PATCH 2/2] Refresh positions if hoverCallback returns true --- jquery.mjs.nestedSortable.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jquery.mjs.nestedSortable.js b/jquery.mjs.nestedSortable.js index 9b20f33..4bf09aa 100644 --- a/jquery.mjs.nestedSortable.js +++ b/jquery.mjs.nestedSortable.js @@ -210,7 +210,10 @@ // Allow hover behavior without switching css classes. if (o.hoverCallback && o.expandOnHover && !this.hovering) { var self = this, item = itemElement; - this.hovering = window.setTimeout(function () { o.hoverCallback.call(self, item); }, o.expandOnHover); + this.hovering = window.setTimeout(function () { + if (o.hoverCallback.call(self, item) === true) + self.refreshPositions(); + }, o.expandOnHover); } this.direction = intersection == 1 ? "down" : "up";