diff --git a/Sortable.js b/Sortable.js index f4f30d4..1ab3ef4 100644 --- a/Sortable.js +++ b/Sortable.js @@ -52,10 +52,12 @@ var evt = document.createEvent('Event'); evt.initEvent(name, true, true); + evt.item = targetEl || 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); }, @@ -250,7 +252,8 @@ } - _dispatchEvent(dragEl, 'start', undefined, undefined, startIndex); + // Drag start event + _dispatchEvent(rootEl, 'start', dragEl, rootEl, startIndex); if (activeGroup.pull == 'clone') { @@ -514,24 +517,25 @@ if (!rootEl.contains(dragEl)) { // drag from one list and drop into another - _dispatchEvent(dragEl, 'sort', dragEl, dragEl.parentNode, startIndex, newIndex); - _dispatchEvent(rootEl, 'sort', dragEl, undefined, startIndex, newIndex); + _dispatchEvent(dragEl.parentNode, 'sort', dragEl, rootEl, startIndex, newIndex); + _dispatchEvent(rootEl, 'sort', dragEl, rootEl, startIndex, newIndex); // Add event _dispatchEvent(dragEl, 'add', dragEl, rootEl, startIndex, newIndex); // Remove event - _dispatchEvent(rootEl, 'remove', dragEl, undefined, startIndex, newIndex); + _dispatchEvent(rootEl, 'remove', dragEl, rootEl, startIndex, newIndex); } else if (dragEl.nextSibling !== nextEl) { // drag & drop within the same list - _dispatchEvent(dragEl, 'update', undefined, undefined, startIndex, newIndex); - _dispatchEvent(dragEl, 'sort', undefined, undefined, startIndex, newIndex); + _dispatchEvent(rootEl, 'update', dragEl, rootEl, startIndex, newIndex); + _dispatchEvent(rootEl, 'sort', dragEl, rootEl, startIndex, newIndex); cloneEl && cloneEl.parentNode.removeChild(cloneEl); } - _dispatchEvent(rootEl, 'end', undefined, undefined, startIndex, newIndex); + // Drag end event + _dispatchEvent(rootEl, 'end', dragEl, rootEl, startIndex, newIndex); } // Set NULL diff --git a/index.html b/index.html index c1dff70..405d749 100644 --- a/index.html +++ b/index.html @@ -289,11 +289,12 @@ var editableList = new Sortable(editable, { localStorage.setItem(sortable.options.group, order.join('|')); } }, - onAdd: function (evt){ console.log('onAdd.foo:', evt.item); }, - onUpdate: function (evt){ console.log('onUpdate.foo:', evt.item); }, - onRemove: function (evt){ console.log('onRemove.foo:', evt.item); }, - onStart:function(evt){ console.log('onStart.foo:',evt.item);}, - onEnd: function(evt){ console.log('onEnd.foo:', evt.item);} + onAdd: function (evt){ console.log('onAdd.foo:', [evt.item, evt.from]); }, + onUpdate: function (evt){ console.log('onUpdate.foo:', [evt.item, evt.from]); }, + onRemove: function (evt){ console.log('onRemove.foo:', [evt.item, evt.from]); }, + onStart:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);}, + onSort:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);}, + onEnd: function(evt){ console.log('onEnd.foo:', [evt.item, evt.from]);} });