Browse Source

#701: fixed oldIndex & selector == '>*'

pull/699/merge
RubaXa 9 years ago
parent
commit
31e6f0fab6
  1. 22
      Sortable.js

22
Sortable.js

@ -259,7 +259,8 @@
touch = evt.touches && evt.touches[0], touch = evt.touches && evt.touches[0],
target = (touch || evt).target, target = (touch || evt).target,
originalTarget = target, originalTarget = target,
filter = options.filter; filter = options.filter,
startIndex;
// Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group. // Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
if (dragEl) { if (dragEl) {
@ -281,12 +282,12 @@
} }
// Get the index of the dragged element within its parent // Get the index of the dragged element within its parent
oldIndex = _index(target, options.draggable); startIndex = _index(target, options.draggable);
// Check filter // Check filter
if (typeof filter === 'function') { if (typeof filter === 'function') {
if (filter.call(this, evt, target, this)) { if (filter.call(this, evt, target, this)) {
_dispatchEvent(_this, originalTarget, 'filter', target, el, oldIndex); _dispatchEvent(_this, originalTarget, 'filter', target, el, startIndex);
evt.preventDefault(); evt.preventDefault();
return; // cancel dnd return; // cancel dnd
} }
@ -296,7 +297,7 @@
criteria = _closest(originalTarget, criteria.trim(), el); criteria = _closest(originalTarget, criteria.trim(), el);
if (criteria) { if (criteria) {
_dispatchEvent(_this, criteria, 'filter', target, el, oldIndex); _dispatchEvent(_this, criteria, 'filter', target, el, startIndex);
return true; return true;
} }
}); });
@ -308,10 +309,10 @@
} }
// Prepare `dragstart` // Prepare `dragstart`
this._prepareDragStart(evt, touch, target); this._prepareDragStart(evt, touch, target, startIndex);
}, },
_prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) { _prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target, /** Number */startIndex) {
var _this = this, var _this = this,
el = _this.el, el = _this.el,
options = _this.options, options = _this.options,
@ -326,6 +327,7 @@
parentEl = dragEl.parentNode; parentEl = dragEl.parentNode;
nextEl = dragEl.nextSibling; nextEl = dragEl.nextSibling;
activeGroup = options.group; activeGroup = options.group;
oldIndex = startIndex;
this._lastX = (touch || evt).clientX; this._lastX = (touch || evt).clientX;
this._lastY = (touch || evt).clientY; this._lastY = (touch || evt).clientY;
@ -1006,10 +1008,7 @@
ctx = ctx || document; ctx = ctx || document;
do { do {
if ( if ((selector === '>*' && el.parentNode === ctx) || _matches(el, selector)) {
(selector === '>*' && el.parentNode === ctx)
|| _matches(el, selector)
) {
return el; return el;
} }
} }
@ -1195,8 +1194,7 @@
} }
while (el && (el = el.previousElementSibling)) { while (el && (el = el.previousElementSibling)) {
if (el.nodeName.toUpperCase() !== 'TEMPLATE' if ((el.nodeName.toUpperCase() !== 'TEMPLATE') && (selector === '>*' || _matches(el, selector))) {
&& _matches(el, selector)) {
index++; index++;
} }
} }

Loading…
Cancel
Save