Skip to content

Commit

Permalink
Determine the correct target before onFilter
Browse files Browse the repository at this point in the history
Fix #156 and also returning correct indexes if a drag handle is present (#154).
  • Loading branch information
dandv committed Dec 8, 2014
1 parent a5f5e32 commit 4e69d1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var sortable = new Sortable(el, {
// same properties as onUpdate
},

// Attempt to drag a filtered element
onFilter: function (/**Event*/evt) {
var itemEl = evt.item; // HTMLElement receiving the `mousedown|tapstart` event.
}
Expand Down
22 changes: 11 additions & 11 deletions Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,23 @@
el = this.el,
filter = options.filter;

// get the index of the dragged element within its parent
startIndex = _index(target);

if (evt.type === 'mousedown' && evt.button !== 0 || options.disabled) {
return; // only left button or enabled
}

if (options.handle) {
target = _closest(target, options.handle, el);
}

target = _closest(target, options.draggable, el);

// get the index of the dragged element within its parent
startIndex = _index(target);

// Check filter
if (typeof filter === 'function') {
if (filter.call(this, target, this)) {
_dispatchEvent(el, 'filter', target);
_dispatchEvent(el, 'filter', target, undefined, startIndex);
return; // cancel dnd
}
}
Expand All @@ -186,17 +192,11 @@
});

if (filter.length) {
_dispatchEvent(el, 'filter', target);
_dispatchEvent(el, 'filter', target, undefined, startIndex);
return; // cancel dnd
}
}

if (options.handle) {
target = _closest(target, options.handle, el);
}

target = _closest(target, options.draggable, el);

// IE 9 Support
if (target && evt.type == 'selectstart') {
if (target.tagName != 'A' && target.tagName != 'IMG') {
Expand Down

0 comments on commit 4e69d1c

Please sign in to comment.