Browse Source

#979: + enter/leave events

leave-enter
Lebedev Konstantin 8 years ago
parent
commit
c52203da3d
  1. 34
      Sortable.js

34
Sortable.js

@ -291,6 +291,7 @@
if (this.nativeDraggable) { if (this.nativeDraggable) {
_on(el, 'dragover', this); _on(el, 'dragover', this);
_on(el, 'dragenter', this); _on(el, 'dragenter', this);
_on(el, 'dragleave', this);
} }
touchDragOverListeners.push(this._onDragOver); touchDragOverListeners.push(this._onDragOver);
@ -505,7 +506,7 @@
// Drag start event // Drag start event
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, oldIndex); _dispatchEvent(this, rootEl, 'start', dragEl, rootEl, oldIndex);
_dispatchEvent(this, rootEl, 'enter', dragEl, rootEl, oldIndex); _dispatchEvent(this, rootEl, 'enter', dragEl);
} else { } else {
this._nulling(); this._nulling();
} }
@ -696,8 +697,7 @@
moved = true; moved = true;
if (lastOver !== this) { if (lastOver !== this) {
_dispatchEvent(lastOver, lastOver.el, 'leave', dragEl); _dispatchEvent(this, el, 'enter', dragEl, activeSortable.el);
_dispatchEvent(this, el, 'enter', dragEl, lastOver.el);
lastOver = this; lastOver = this;
} }
@ -953,8 +953,9 @@
// Save sorting // Save sorting
this.save(); this.save();
} }
}
_dispatchEvent(this, el, 'leave', dragEl, lastOver.el);
}
} }
this._nulling(); this._nulling();
@ -1001,12 +1002,29 @@
case 'dragover': case 'dragover':
case 'dragenter': case 'dragenter':
this.hasDragleave = false;
if (dragEl) { if (dragEl) {
this._onDragOver(evt); this._onDragOver(evt);
_globalDragOver(evt); _globalDragOver(evt);
} }
break; break;
case 'dragleave':
this.hasDragleave = true;
if (lastOver && !lastOver.dragleaveId) {
lastOver.dragleaveId = setTimeout(function () {
lastOver.dragleaveId = null;
if (lastOver.hasDragleave) {
_dispatchEvent(lastOver, lastOver.el, 'leave', dragEl);
lastOver = null;
}
}, 10);
}
break;
case 'selectstart': case 'selectstart':
evt.preventDefault(); evt.preventDefault();
break; break;
@ -1113,11 +1131,9 @@
_off(el, 'mousedown', this._onTapStart); _off(el, 'mousedown', this._onTapStart);
_off(el, 'touchstart', this._onTapStart); _off(el, 'touchstart', this._onTapStart);
_off(el, 'pointerdown', this._onTapStart); _off(el, 'pointerdown', this._onTapStart);
_off(el, 'dragover', this);
if (this.nativeDraggable) { _off(el, 'dragenter', this);
_off(el, 'dragover', this); _off(el, 'dragleave', this);
_off(el, 'dragenter', this);
}
// Remove draggable attributes // Remove draggable attributes
Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) { Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {

Loading…
Cancel
Save