Skip to content

Commit

Permalink
Merge pull request #834 from joual/dev
Browse files Browse the repository at this point in the history
Add the original mouse event as parameter in onMove()
  • Loading branch information
RubaXa committed Jun 21, 2016
2 parents 3b1b116 + 6264428 commit 48f3a11
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -126,12 +126,13 @@ var sortable = new Sortable(el, {
},

// Event when you move an item in the list or between lists
onMove: function (/**Event*/evt) {
onMove: function (/**Event*/evt, /**Event*/originalEvent) {
// Example: http://jsbin.com/tuyafe/1/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // TextRectangle {left, top, right и bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // TextRectangle
originalEvent.clientY; // mouse position
// return false; — for cancel
},

Expand Down
8 changes: 4 additions & 4 deletions Sortable.js
Expand Up @@ -681,7 +681,7 @@

_cloneHide(isOwner);

if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect) !== false) {
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt) !== false) {
if (!dragEl.contains(el)) {
el.appendChild(dragEl);
parentEl = el; // actualization
Expand All @@ -708,7 +708,7 @@
isLong = (target.offsetHeight > dragEl.offsetHeight),
halfway = (floating ? (evt.clientX - targetRect.left) / width : (evt.clientY - targetRect.top) / height) > 0.5,
nextSibling = target.nextElementSibling,
moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect),
moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt),
after
;

Expand Down Expand Up @@ -1158,7 +1158,7 @@
}


function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect) {
function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvt) {
var evt,
sortable = fromEl[expando],
onMoveFn = sortable.options.onMove,
Expand All @@ -1177,7 +1177,7 @@
fromEl.dispatchEvent(evt);

if (onMoveFn) {
retVal = onMoveFn.call(sortable, evt);
retVal = onMoveFn.call(sortable, evt, originalEvt);
}

return retVal;
Expand Down

0 comments on commit 48f3a11

Please sign in to comment.