Browse Source

Merge branch 'master' into leave-enter

leave-enter
Lebedev Konstantin 8 years ago
parent
commit
787a02323c
  1. 65
      Sortable.js
  2. 2
      Sortable.min.js
  3. 3
      package.json

65
Sortable.js

@ -57,7 +57,8 @@
moved, moved,
/** @const */ /** @const */
RSPACE = /\s+/g, R_SPACE = /\s+/g,
R_FLOAT = /left|right|inline/,
expando = 'Sortable' + (new Date).getTime(), expando = 'Sortable' + (new Date).getTime(),
@ -86,6 +87,7 @@
abs = Math.abs, abs = Math.abs,
min = Math.min, min = Math.min,
savedInputChecked = [],
touchDragOverListeners = [], touchDragOverListeners = [],
_autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) { _autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) {
@ -214,7 +216,6 @@
; ;
/** /**
* @class Sortable * @class Sortable
* @param {HTMLElement} el * @param {HTMLElement} el
@ -314,6 +315,9 @@
filter = options.filter, filter = options.filter,
startIndex; startIndex;
_saveInputCheckedState(el);
// 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) {
return; return;
@ -420,6 +424,7 @@
_on(ownerDocument, 'touchend', _this._onDrop); _on(ownerDocument, 'touchend', _this._onDrop);
_on(ownerDocument, 'touchcancel', _this._onDrop); _on(ownerDocument, 'touchcancel', _this._onDrop);
_on(ownerDocument, 'pointercancel', _this._onDrop); _on(ownerDocument, 'pointercancel', _this._onDrop);
_on(ownerDocument, 'selectstart', _this);
if (options.delay) { if (options.delay) {
// If the user moves the pointer or let go the click or touch // If the user moves the pointer or let go the click or touch
@ -437,9 +442,7 @@
dragStartFn(); dragStartFn();
} }
if (options.forceFallback) {
evt.preventDefault();
}
} }
}, },
@ -678,6 +681,7 @@
group = options.group, group = options.group,
activeSortable = Sortable.active, activeSortable = Sortable.active,
isOwner = (activeGroup === group), isOwner = (activeGroup === group),
isMovingBetweenSortable = false,
canSort = options.sort; canSort = options.sort;
if (evt.preventDefault !== void 0) { if (evt.preventDefault !== void 0) {
@ -685,6 +689,10 @@
!options.dragoverBubble && evt.stopPropagation(); !options.dragoverBubble && evt.stopPropagation();
} }
if (dragEl.animated) {
return;
}
moved = true; moved = true;
if (lastOver !== this) { if (lastOver !== this) {
@ -715,7 +723,11 @@
target = _closest(evt.target, options.draggable, el); target = _closest(evt.target, options.draggable, el);
dragRect = dragEl.getBoundingClientRect(); dragRect = dragEl.getBoundingClientRect();
if (putSortable !== this) {
putSortable = this; putSortable = this;
isMovingBetweenSortable = true;
}
if (revert) { if (revert) {
_cloneHide(activeSortable, true); _cloneHide(activeSortable, true);
@ -766,14 +778,14 @@
var width = targetRect.right - targetRect.left, var width = targetRect.right - targetRect.left,
height = targetRect.bottom - targetRect.top, height = targetRect.bottom - targetRect.top,
floating = /left|right|inline/.test(lastCSS.cssFloat + lastCSS.display) floating = R_FLOAT.test(lastCSS.cssFloat + lastCSS.display)
|| (lastParentCSS.display == 'flex' && lastParentCSS['flex-direction'].indexOf('row') === 0), || (lastParentCSS.display == 'flex' && lastParentCSS['flex-direction'].indexOf('row') === 0),
isWide = (target.offsetWidth > dragEl.offsetWidth), isWide = (target.offsetWidth > dragEl.offsetWidth),
isLong = (target.offsetHeight > dragEl.offsetHeight), isLong = (target.offsetHeight > dragEl.offsetHeight),
halfway = (floating ? (evt.clientX - targetRect.left) / width : (evt.clientY - targetRect.top) / height) > 0.5, halfway = (floating ? (evt.clientX - targetRect.left) / width : (evt.clientY - targetRect.top) / height) > 0.5,
nextSibling = target.nextElementSibling, nextSibling = target.nextElementSibling,
moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt), moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt),
after after = false
; ;
if (moveVector !== false) { if (moveVector !== false) {
@ -797,7 +809,7 @@
} else { } else {
after = tgTop > elTop; after = tgTop > elTop;
} }
} else { } else if (!isMovingBetweenSortable) {
after = (nextSibling !== dragEl) && !isLong || halfway && isLong; after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
} }
@ -857,6 +869,7 @@
_off(ownerDocument, 'touchend', this._onDrop); _off(ownerDocument, 'touchend', this._onDrop);
_off(ownerDocument, 'pointerup', this._onDrop); _off(ownerDocument, 'pointerup', this._onDrop);
_off(ownerDocument, 'touchcancel', this._onDrop); _off(ownerDocument, 'touchcancel', this._onDrop);
_off(ownerDocument, 'selectstart', this);
}, },
_onDrop: function (/**Event*/evt) { _onDrop: function (/**Event*/evt) {
@ -972,19 +985,31 @@
putSortable = putSortable =
activeGroup = activeGroup =
Sortable.active = null; Sortable.active = null;
savedInputChecked.forEach(function (el) {
el.checked = true;
});
savedInputChecked.length = 0;
}, },
handleEvent: function (/**Event*/evt) { handleEvent: function (/**Event*/evt) {
var type = evt.type; switch (evt.type) {
case 'drop':
case 'dragend':
this._onDrop(evt);
break;
if (type === 'dragover' || type === 'dragenter') { case 'dragover':
case 'dragenter':
if (dragEl) { if (dragEl) {
this._onDragOver(evt); this._onDragOver(evt);
_globalDragOver(evt); _globalDragOver(evt);
} }
} break;
else if (type === 'drop' || type === 'dragend') {
this._onDrop(evt); case 'selectstart':
evt.preventDefault();
break;
} }
}, },
@ -1179,8 +1204,8 @@
el.classList[state ? 'add' : 'remove'](name); el.classList[state ? 'add' : 'remove'](name);
} }
else { else {
var className = (' ' + el.className + ' ').replace(RSPACE, ' ').replace(' ' + name + ' ', ' '); var className = (' ' + el.className + ' ').replace(R_SPACE, ' ').replace(' ' + name + ' ', ' ');
el.className = (className + (state ? ' ' + name : '')).replace(RSPACE, ' '); el.className = (className + (state ? ' ' + name : '')).replace(R_SPACE, ' ');
} }
} }
} }
@ -1403,6 +1428,16 @@
); );
} }
function _saveInputCheckedState(root) {
var inputs = root.getElementsByTagName('input');
var idx = inputs.length;
while (idx--) {
var el = inputs[idx];
el.checked && savedInputChecked.push(el);
}
}
try { try {
window.addEventListener('test', null, Object.defineProperty({}, 'passive', { window.addEventListener('test', null, Object.defineProperty({}, 'passive', {
get: function () { get: function () {

2
Sortable.min.js vendored

File diff suppressed because one or more lines are too long

3
package.json

@ -11,7 +11,8 @@
"description": "Minimalist JavaScript library for reorderable drag-and-drop lists on modern browsers and touch devices. No jQuery. Supports AngularJS and any CSS library, e.g. Bootstrap.", "description": "Minimalist JavaScript library for reorderable drag-and-drop lists on modern browsers and touch devices. No jQuery. Supports AngularJS and any CSS library, e.g. Bootstrap.",
"main": "Sortable.js", "main": "Sortable.js",
"scripts": { "scripts": {
"test": "grunt" "test": "grunt",
"prepublish": "grunt"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

Loading…
Cancel
Save