Browse Source

* event.from

pull/168/head
RubaXa 10 years ago
parent
commit
6cb59900e2
  1. 22
      Sortable.js
  2. 11
      index.html

22
Sortable.js

@ -52,10 +52,12 @@
var evt = document.createEvent('Event'); var evt = document.createEvent('Event');
evt.initEvent(name, true, true); evt.initEvent(name, true, true);
evt.item = targetEl || rootEl; evt.item = targetEl || rootEl;
evt.from = fromEl || rootEl; evt.from = fromEl || rootEl;
if (startIndex !== undefined) evt.oldIndex = startIndex;
if (newIndex !== undefined) evt.newIndex = newIndex; evt.oldIndex = startIndex;
evt.newIndex = newIndex;
rootEl.dispatchEvent(evt); rootEl.dispatchEvent(evt);
}, },
@ -250,7 +252,8 @@
} }
_dispatchEvent(dragEl, 'start', undefined, undefined, startIndex); // Drag start event
_dispatchEvent(rootEl, 'start', dragEl, rootEl, startIndex);
if (activeGroup.pull == 'clone') { if (activeGroup.pull == 'clone') {
@ -514,24 +517,25 @@
if (!rootEl.contains(dragEl)) { if (!rootEl.contains(dragEl)) {
// drag from one list and drop into another // drag from one list and drop into another
_dispatchEvent(dragEl, 'sort', dragEl, dragEl.parentNode, startIndex, newIndex); _dispatchEvent(dragEl.parentNode, 'sort', dragEl, rootEl, startIndex, newIndex);
_dispatchEvent(rootEl, 'sort', dragEl, undefined, startIndex, newIndex); _dispatchEvent(rootEl, 'sort', dragEl, rootEl, startIndex, newIndex);
// Add event // Add event
_dispatchEvent(dragEl, 'add', dragEl, rootEl, startIndex, newIndex); _dispatchEvent(dragEl, 'add', dragEl, rootEl, startIndex, newIndex);
// Remove event // Remove event
_dispatchEvent(rootEl, 'remove', dragEl, undefined, startIndex, newIndex); _dispatchEvent(rootEl, 'remove', dragEl, rootEl, startIndex, newIndex);
} }
else if (dragEl.nextSibling !== nextEl) { else if (dragEl.nextSibling !== nextEl) {
// drag & drop within the same list // drag & drop within the same list
_dispatchEvent(dragEl, 'update', undefined, undefined, startIndex, newIndex); _dispatchEvent(rootEl, 'update', dragEl, rootEl, startIndex, newIndex);
_dispatchEvent(dragEl, 'sort', undefined, undefined, startIndex, newIndex); _dispatchEvent(rootEl, 'sort', dragEl, rootEl, startIndex, newIndex);
cloneEl && cloneEl.parentNode.removeChild(cloneEl); cloneEl && cloneEl.parentNode.removeChild(cloneEl);
} }
_dispatchEvent(rootEl, 'end', undefined, undefined, startIndex, newIndex); // Drag end event
_dispatchEvent(rootEl, 'end', dragEl, rootEl, startIndex, newIndex);
} }
// Set NULL // Set NULL

11
index.html

@ -289,11 +289,12 @@ var editableList = new Sortable(editable, {
localStorage.setItem(sortable.options.group, order.join('|')); localStorage.setItem(sortable.options.group, order.join('|'));
} }
}, },
onAdd: function (evt){ console.log('onAdd.foo:', evt.item); }, onAdd: function (evt){ console.log('onAdd.foo:', [evt.item, evt.from]); },
onUpdate: function (evt){ console.log('onUpdate.foo:', evt.item); }, onUpdate: function (evt){ console.log('onUpdate.foo:', [evt.item, evt.from]); },
onRemove: function (evt){ console.log('onRemove.foo:', evt.item); }, onRemove: function (evt){ console.log('onRemove.foo:', [evt.item, evt.from]); },
onStart:function(evt){ console.log('onStart.foo:',evt.item);}, onStart:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);},
onEnd: function(evt){ console.log('onEnd.foo:', evt.item);} onSort:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);},
onEnd: function(evt){ console.log('onEnd.foo:', [evt.item, evt.from]);}
}); });

Loading…
Cancel
Save