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") {
module.exports = factory();
}
else if (typeof Package !== "undefined") {
//noinspection JSUnresolvedVariable
Sortable = factory(); // export for Meteor.js
}
else {
/* jshint sub:true */
window["Sortable"] = factory();
@ -60,7 +56,8 @@
moved,
/** @const */
RSPACE = /\s+/g,
R_SPACE = /\s+/g,
R_FLOAT = /left|right|inline/,
expando = 'Sortable' + (new Date).getTime(),
@ -71,7 +68,7 @@
$ = win.jQuery || win.Zepto,
Polymer = win.Polymer,
captureMode = {capture: false, passive: false},
captureMode = false,
supportDraggable = !!('draggable' in document.createElement('div')),
supportCssPointerEvents = (function (el) {
@ -89,6 +86,7 @@
abs = Math.abs,
min = Math.min,
savedInputChecked = [],
touchDragOverListeners = [],
_autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) {
@ -210,13 +208,13 @@
group.name = originalGroup.name;
group.checkPull = toFn(originalGroup.pull, true);
group.checkPut = toFn(originalGroup.put);
group.revertClone = originalGroup.revertClone;
options.group = group;
}
;
/**
* @class Sortable
* @param {HTMLElement} el
@ -234,7 +232,6 @@
// Export instance
el[expando] = this;
// Default options
var defaults = {
group: Math.random(),
@ -317,6 +314,9 @@
filter = options.filter,
startIndex;
_saveInputCheckedState(el);
// Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
if (dragEl) {
return;
@ -387,7 +387,7 @@
dragEl = target;
parentEl = dragEl.parentNode;
nextEl = dragEl.nextSibling;
lastDownEl = target
lastDownEl = target;
activeGroup = options.group;
oldIndex = startIndex;
@ -423,6 +423,7 @@
_on(ownerDocument, 'touchend', _this._onDrop);
_on(ownerDocument, 'touchcancel', _this._onDrop);
_on(ownerDocument, 'pointercancel', _this._onDrop);
_on(ownerDocument, 'selectstart', _this);
if (options.delay) {
// If the user moves the pointer or let go the click or touch
@ -440,9 +441,7 @@
dragStartFn();
}
if (options.forceFallback) {
evt.preventDefault();
}
}
},
@ -460,6 +459,7 @@
_triggerDragStart: function (/** Event */evt, /** Touch */touch) {
touch = touch || (evt.pointerType == 'touch' ? evt : null);
if (touch) {
// Touch device support
tapEvt = {
@ -626,9 +626,15 @@
this._offUpEvents();
if (activeGroup.checkPull(this, this, dragEl, evt) == 'clone') {
if (activeGroup.checkPull(this, this, dragEl, evt)) {
cloneEl = _clone(dragEl);
cloneEl.draggable = false;
cloneEl.style['will-change'] = '';
_css(cloneEl, 'display', 'none');
_toggleClass(cloneEl, this.options.chosenClass, false);
rootEl.insertBefore(cloneEl, dragEl);
_dispatchEvent(this, rootEl, 'clone', dragEl);
}
@ -672,6 +678,7 @@
group = options.group,
activeSortable = Sortable.active,
isOwner = (activeGroup === group),
isMovingBetweenSortable = false,
canSort = options.sort;
if (evt.preventDefault !== void 0) {
@ -679,6 +686,10 @@
!options.dragoverBubble && evt.stopPropagation();
}
if (dragEl.animated) {
return;
}
moved = true;
if (activeSortable && !options.disabled &&
@ -686,7 +697,10 @@
? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list
: (
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
@ -700,10 +714,14 @@
target = _closest(evt.target, options.draggable, el);
dragRect = dragEl.getBoundingClientRect();
putSortable = this;
if (putSortable !== this) {
putSortable = this;
isMovingBetweenSortable = true;
}
if (revert) {
_cloneHide(true);
_cloneHide(activeSortable, true);
parentEl = rootEl; // actualization
if (cloneEl || nextEl) {
@ -728,7 +746,7 @@
targetRect = target.getBoundingClientRect();
}
_cloneHide(isOwner);
_cloneHide(activeSortable, isOwner);
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt) !== false) {
if (!dragEl.contains(el)) {
@ -751,21 +769,21 @@
var width = targetRect.right - targetRect.left,
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),
isWide = (target.offsetWidth > dragEl.offsetWidth),
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, evt),
after
after = false
;
if (moveVector !== false) {
_silent = true;
setTimeout(_unsilent, 30);
_cloneHide(isOwner);
_cloneHide(activeSortable, isOwner);
if (moveVector === 1 || moveVector === -1) {
after = (moveVector === 1);
@ -782,7 +800,7 @@
} else {
after = tgTop > elTop;
}
} else {
} else if (!isMovingBetweenSortable) {
after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
}
@ -809,6 +827,10 @@
if (ms) {
var currentRect = target.getBoundingClientRect();
if (prevRect.nodeType === 1) {
prevRect = prevRect.getBoundingClientRect();
}
_css(target, 'transition', 'none');
_css(target, 'transform', 'translate3d('
+ (prevRect.left - currentRect.left) + 'px,'
@ -838,6 +860,7 @@
_off(ownerDocument, 'touchend', this._onDrop);
_off(ownerDocument, 'pointerup', this._onDrop);
_off(ownerDocument, 'touchcancel', this._onDrop);
_off(ownerDocument, 'selectstart', this);
},
_onDrop: function (/**Event*/evt) {
@ -952,19 +975,31 @@
putSortable =
activeGroup =
Sortable.active = null;
savedInputChecked.forEach(function (el) {
el.checked = true;
});
savedInputChecked.length = 0;
},
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') {
if (dragEl) {
this._onDragOver(evt);
_globalDragOver(evt);
}
}
else if (type === 'drop' || type === 'dragend') {
this._onDrop(evt);
case 'selectstart':
evt.preventDefault();
break;
}
},
@ -1088,10 +1123,25 @@
};
function _cloneHide(state) {
function _cloneHide(sortable, state) {
if (sortable.lastPullMode !== 'clone') {
state = true;
}
if (cloneEl && (cloneEl.state !== state)) {
_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;
}
}
@ -1144,8 +1194,8 @@
el.classList[state ? 'add' : 'remove'](name);
}
else {
var className = (' ' + el.className + ' ').replace(RSPACE, ' ').replace(' ' + name + ' ', ' ');
el.className = (className + (state ? ' ' + name : '')).replace(RSPACE, ' ');
var className = (' ' + el.className + ' ').replace(R_SPACE, ' ').replace(' ' + name + ' ', ' ');
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
Sortable.utils = {
@ -1398,6 +1468,6 @@
// Export
Sortable.version = '1.5.0-rc1';
Sortable.version = '1.5.0';
return Sortable;
});

4
Sortable.min.js vendored

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