Browse Source

* upd

gh-pages
Lebedev Konstantin 8 years ago
parent
commit
2e3c09096a
  1. 140
      Sortable.js
  2. 4
      Sortable.min.js

140
Sortable.js

@ -13,10 +13,6 @@
else if (typeof module != "undefined" && typeof module.exports != "undefined") { else if (typeof module != "undefined" && typeof module.exports != "undefined") {
module.exports = factory(); module.exports = factory();
} }
else if (typeof Package !== "undefined") {
//noinspection JSUnresolvedVariable
Sortable = factory(); // export for Meteor.js
}
else { else {
/* jshint sub:true */ /* jshint sub:true */
window["Sortable"] = factory(); window["Sortable"] = factory();
@ -60,7 +56,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(),
@ -71,7 +68,7 @@
$ = win.jQuery || win.Zepto, $ = win.jQuery || win.Zepto,
Polymer = win.Polymer, Polymer = win.Polymer,
captureMode = {capture: false, passive: false}, captureMode = false,
supportDraggable = !!('draggable' in document.createElement('div')), supportDraggable = !!('draggable' in document.createElement('div')),
supportCssPointerEvents = (function (el) { supportCssPointerEvents = (function (el) {
@ -89,6 +86,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) {
@ -210,13 +208,13 @@
group.name = originalGroup.name; group.name = originalGroup.name;
group.checkPull = toFn(originalGroup.pull, true); group.checkPull = toFn(originalGroup.pull, true);
group.checkPut = toFn(originalGroup.put); group.checkPut = toFn(originalGroup.put);
group.revertClone = originalGroup.revertClone;
options.group = group; options.group = group;
} }
; ;
/** /**
* @class Sortable * @class Sortable
* @param {HTMLElement} el * @param {HTMLElement} el
@ -234,7 +232,6 @@
// Export instance // Export instance
el[expando] = this; el[expando] = this;
// Default options // Default options
var defaults = { var defaults = {
group: Math.random(), group: Math.random(),
@ -317,6 +314,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;
@ -387,7 +387,7 @@
dragEl = target; dragEl = target;
parentEl = dragEl.parentNode; parentEl = dragEl.parentNode;
nextEl = dragEl.nextSibling; nextEl = dragEl.nextSibling;
lastDownEl = target lastDownEl = target;
activeGroup = options.group; activeGroup = options.group;
oldIndex = startIndex; oldIndex = startIndex;
@ -423,6 +423,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
@ -440,9 +441,7 @@
dragStartFn(); dragStartFn();
} }
if (options.forceFallback) {
evt.preventDefault();
}
} }
}, },
@ -460,6 +459,7 @@
_triggerDragStart: function (/** Event */evt, /** Touch */touch) { _triggerDragStart: function (/** Event */evt, /** Touch */touch) {
touch = touch || (evt.pointerType == 'touch' ? evt : null); touch = touch || (evt.pointerType == 'touch' ? evt : null);
if (touch) { if (touch) {
// Touch device support // Touch device support
tapEvt = { tapEvt = {
@ -626,9 +626,15 @@
this._offUpEvents(); this._offUpEvents();
if (activeGroup.checkPull(this, this, dragEl, evt) == 'clone') { if (activeGroup.checkPull(this, this, dragEl, evt)) {
cloneEl = _clone(dragEl); cloneEl = _clone(dragEl);
cloneEl.draggable = false;
cloneEl.style['will-change'] = '';
_css(cloneEl, 'display', 'none'); _css(cloneEl, 'display', 'none');
_toggleClass(cloneEl, this.options.chosenClass, false);
rootEl.insertBefore(cloneEl, dragEl); rootEl.insertBefore(cloneEl, dragEl);
_dispatchEvent(this, rootEl, 'clone', dragEl); _dispatchEvent(this, rootEl, 'clone', dragEl);
} }
@ -672,6 +678,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) {
@ -679,6 +686,10 @@
!options.dragoverBubble && evt.stopPropagation(); !options.dragoverBubble && evt.stopPropagation();
} }
if (dragEl.animated) {
return;
}
moved = true; moved = true;
if (activeSortable && !options.disabled && if (activeSortable && !options.disabled &&
@ -686,7 +697,10 @@
? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list ? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list
: ( : (
putSortable === this || putSortable === this ||
activeGroup.checkPull(this, activeSortable, dragEl, evt) && group.checkPut(this, activeSortable, dragEl, evt) (
(activeSortable.lastPullMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) &&
group.checkPut(this, activeSortable, dragEl, evt)
)
) )
) && ) &&
(evt.rootEl === void 0 || evt.rootEl === this.el) // touch fallback (evt.rootEl === void 0 || evt.rootEl === this.el) // touch fallback
@ -700,10 +714,14 @@
target = _closest(evt.target, options.draggable, el); target = _closest(evt.target, options.draggable, el);
dragRect = dragEl.getBoundingClientRect(); dragRect = dragEl.getBoundingClientRect();
putSortable = this;
if (putSortable !== this) {
putSortable = this;
isMovingBetweenSortable = true;
}
if (revert) { if (revert) {
_cloneHide(true); _cloneHide(activeSortable, true);
parentEl = rootEl; // actualization parentEl = rootEl; // actualization
if (cloneEl || nextEl) { if (cloneEl || nextEl) {
@ -728,7 +746,7 @@
targetRect = target.getBoundingClientRect(); targetRect = target.getBoundingClientRect();
} }
_cloneHide(isOwner); _cloneHide(activeSortable, isOwner);
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt) !== false) { if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt) !== false) {
if (!dragEl.contains(el)) { if (!dragEl.contains(el)) {
@ -751,21 +769,21 @@
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) {
_silent = true; _silent = true;
setTimeout(_unsilent, 30); setTimeout(_unsilent, 30);
_cloneHide(isOwner); _cloneHide(activeSortable, isOwner);
if (moveVector === 1 || moveVector === -1) { if (moveVector === 1 || moveVector === -1) {
after = (moveVector === 1); after = (moveVector === 1);
@ -782,7 +800,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;
} }
@ -809,6 +827,10 @@
if (ms) { if (ms) {
var currentRect = target.getBoundingClientRect(); var currentRect = target.getBoundingClientRect();
if (prevRect.nodeType === 1) {
prevRect = prevRect.getBoundingClientRect();
}
_css(target, 'transition', 'none'); _css(target, 'transition', 'none');
_css(target, 'transform', 'translate3d(' _css(target, 'transform', 'translate3d('
+ (prevRect.left - currentRect.left) + 'px,' + (prevRect.left - currentRect.left) + 'px,'
@ -838,6 +860,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) {
@ -952,19 +975,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;
case 'dragover':
case 'dragenter':
if (dragEl) {
this._onDragOver(evt);
_globalDragOver(evt);
}
break;
if (type === 'dragover' || type === 'dragenter') { case 'selectstart':
if (dragEl) { evt.preventDefault();
this._onDragOver(evt); break;
_globalDragOver(evt);
}
}
else if (type === 'drop' || type === 'dragend') {
this._onDrop(evt);
} }
}, },
@ -1088,10 +1123,25 @@
}; };
function _cloneHide(state) { function _cloneHide(sortable, state) {
if (sortable.lastPullMode !== 'clone') {
state = true;
}
if (cloneEl && (cloneEl.state !== state)) { if (cloneEl && (cloneEl.state !== state)) {
_css(cloneEl, 'display', state ? 'none' : ''); _css(cloneEl, 'display', state ? 'none' : '');
!state && cloneEl.state && rootEl.insertBefore(cloneEl, dragEl);
if (!state) {
if (cloneEl.state) {
if (sortable.options.group.revertClone) {
rootEl.insertBefore(cloneEl, nextEl);
sortable._animate(dragEl, cloneEl);
} else {
rootEl.insertBefore(cloneEl, dragEl);
}
}
}
cloneEl.state = state; cloneEl.state = state;
} }
} }
@ -1144,8 +1194,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, ' ');
} }
} }
} }
@ -1368,6 +1418,26 @@
); );
} }
function _saveInputCheckedState(root) {
var inputs = root.getElementsByTagName('input');
var idx = inputs.length;
while (idx--) {
var el = inputs[idx];
el.checked && savedInputChecked.push(el);
}
}
try {
window.addEventListener('test', null, Object.defineProperty({}, 'passive', {
get: function () {
captureMode = {
capture: false,
passive: false
};
}
}));
} catch (err) {}
// Export utils // Export utils
Sortable.utils = { Sortable.utils = {
@ -1398,6 +1468,6 @@
// Export // Export
Sortable.version = '1.5.0-rc1'; Sortable.version = '1.5.0';
return Sortable; return Sortable;
}); });

4
Sortable.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save