diff --git a/README.md b/README.md index e340a3f..94d2e6c 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,12 @@ var sortable = new Sortable(el, { evt.newIndex; // element's new index within parent }, + // Element enters into sortable + onEnter: function (/**Event*/evt) {}, + + // Element leaves from sortable + onLeave: function (/**Event*/evt) {}, + // Element is dropped into the list from another list onAdd: function (/**Event*/evt) { var itemEl = evt.item; // dragged HTMLElement diff --git a/Sortable.js b/Sortable.js index b942ea6..794960b 100644 --- a/Sortable.js +++ b/Sortable.js @@ -33,6 +33,7 @@ rootEl, nextEl, lastDownEl, + lastOver, scrollEl, scrollParentEl, @@ -456,6 +457,7 @@ _triggerDragStart: function (/** Event */evt, /** Touch */touch) { touch = touch || (evt.pointerType == 'touch' ? evt : null); + if (touch) { // Touch device support tapEvt = { @@ -495,10 +497,12 @@ _toggleClass(dragEl, options.ghostClass, true); _toggleClass(dragEl, options.dragClass, false); + lastOver = this; Sortable.active = this; // Drag start event _dispatchEvent(this, rootEl, 'start', dragEl, rootEl, oldIndex); + _dispatchEvent(this, rootEl, 'enter', dragEl, rootEl, oldIndex); } else { this._nulling(); } @@ -683,6 +687,12 @@ moved = true; + if (lastOver !== this) { + _dispatchEvent(lastOver, lastOver.el, 'leave', dragEl); + _dispatchEvent(this, el, 'enter', dragEl, lastOver.el); + lastOver = this; + } + if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list @@ -945,6 +955,7 @@ nextEl = cloneEl = lastDownEl = + lastOver = scrollEl = scrollParentEl =