Browse Source

evt.to in onAdd, onSort, onUpdate

pull/1051/head
Joey Becker 8 years ago
parent
commit
ee7b8a71e2
  1. 5
      README.md
  2. 28
      Sortable.js
  3. 2
      Sortable.min.js

5
README.md

@ -128,6 +128,7 @@ var sortable = new Sortable(el, {
// Element is dropped into the list from another list
onAdd: function (/**Event*/evt) {
var itemEl = evt.item; // dragged HTMLElement
evt.to; // target list
evt.from; // previous list
// + indexes from onEnd
},
@ -140,12 +141,12 @@ var sortable = new Sortable(el, {
// Called by any change to the list (add / update / remove)
onSort: function (/**Event*/evt) {
// same properties as onUpdate
// same properties as onAdd
},
// Element is removed from the list into another list
onRemove: function (/**Event*/evt) {
// same properties as onUpdate
// same properties as onAdd
},
// Attempt to drag a filtered element

28
Sortable.js

@ -341,7 +341,7 @@
// Check filter
if (typeof filter === 'function') {
if (filter.call(this, evt, target, this)) {
_dispatchEvent(_this, originalTarget, 'filter', target, el, startIndex);
_dispatchEvent(_this, originalTarget, 'filter', target, el, el, startIndex);
preventOnFilter && evt.preventDefault();
return; // cancel dnd
}
@ -351,7 +351,7 @@
criteria = _closest(originalTarget, criteria.trim(), el);
if (criteria) {
_dispatchEvent(_this, criteria, 'filter', target, el, startIndex);
_dispatchEvent(_this, criteria, 'filter', target, el, el, startIndex);
return true;
}
});
@ -408,7 +408,7 @@
_this._triggerDragStart(evt, touch);
// Drag start event
_dispatchEvent(_this, rootEl, 'choose', dragEl, rootEl, oldIndex);
_dispatchEvent(_this, rootEl, 'choose', dragEl, rootEl, rootEl, oldIndex);
};
// Disable "draggable"
@ -499,7 +499,7 @@
Sortable.active = this;
// Drag start event
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, oldIndex);
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, rootEl, oldIndex);
} else {
this._nulling();
}
@ -889,7 +889,7 @@
_toggleClass(dragEl, this.options.chosenClass, false);
// Drag stop event
_dispatchEvent(this, rootEl, 'unchoose', dragEl, rootEl, oldIndex);
_dispatchEvent(this, rootEl, 'unchoose', dragEl, parentEl, rootEl, oldIndex);
if (rootEl !== parentEl) {
newIndex = _index(dragEl, options.draggable);
@ -897,14 +897,14 @@
if (newIndex >= 0) {
// Add event
_dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(null, parentEl, 'add', dragEl, parentEl, rootEl, oldIndex, newIndex);
// Remove event
_dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'remove', dragEl, parentEl, rootEl, oldIndex, newIndex);
// drag from one list and drop into another
_dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(null, parentEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
}
}
else {
@ -917,8 +917,8 @@
if (newIndex >= 0) {
// drag & drop within the same list
_dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'update', dragEl, parentEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
}
}
}
@ -929,7 +929,7 @@
newIndex = oldIndex;
}
_dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'end', dragEl, parentEl, rootEl, oldIndex, newIndex);
// Save sorting
this.save();
@ -1222,7 +1222,7 @@
function _dispatchEvent(sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) {
function _dispatchEvent(sortable, rootEl, name, targetEl, toEl, fromEl, startIndex, newIndex) {
sortable = (sortable || rootEl[expando]);
var evt = document.createEvent('Event'),
@ -1231,7 +1231,7 @@
evt.initEvent(name, true, true);
evt.to = rootEl;
evt.to = toEl || rootEl;
evt.from = fromEl || rootEl;
evt.item = targetEl || rootEl;
evt.clone = cloneEl;

2
Sortable.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save