Browse Source

* upd

gh-pages
RubaXa 7 years ago
parent
commit
6b44e85549
  1. 77
      Sortable.js
  2. 4
      Sortable.min.js
  3. 2
      st/iframe/index.html

77
Sortable.js

@ -310,7 +310,7 @@
type = evt.type, type = evt.type,
touch = evt.touches && evt.touches[0], touch = evt.touches && evt.touches[0],
target = (touch || evt).target, target = (touch || evt).target,
originalTarget = evt.target.shadowRoot && evt.path[0] || target, originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0]) || target,
filter = options.filter, filter = options.filter,
startIndex; startIndex;
@ -322,7 +322,7 @@
return; return;
} }
if (type === 'mousedown' && evt.button !== 0 || options.disabled) { if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) {
return; // only left button or enabled return; // only left button or enabled
} }
@ -736,8 +736,13 @@
if ((el.children.length === 0) || (el.children[0] === ghostEl) || if ((el.children.length === 0) || (el.children[0] === ghostEl) ||
(el === evt.target) && (target = _ghostIsLast(el, evt)) (el === evt.target) && (_ghostIsLast(el, evt))
) { ) {
//assign target only if condition is true
if (el.children.length !== 0 && el.children[0] !== ghostEl && el === evt.target) {
target = el.lastElementChild;
}
if (target) { if (target) {
if (target.animated) { if (target.animated) {
return; return;
@ -775,34 +780,36 @@
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),
after = false after = false
; ;
if (moveVector !== false) { if (floating) {
_silent = true; var elTop = dragEl.offsetTop,
setTimeout(_unsilent, 30); tgTop = target.offsetTop;
_cloneHide(activeSortable, isOwner); if (elTop === tgTop) {
after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide;
}
else if (target.previousElementSibling === dragEl || dragEl.previousElementSibling === target) {
after = (evt.clientY - targetRect.top) / height > 0.5;
} else {
after = tgTop > elTop;
}
} else if (!isMovingBetweenSortable) {
after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
}
var moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, after);
if (moveVector !== false) {
if (moveVector === 1 || moveVector === -1) { if (moveVector === 1 || moveVector === -1) {
after = (moveVector === 1); after = (moveVector === 1);
} }
else if (floating) {
var elTop = dragEl.offsetTop,
tgTop = target.offsetTop;
if (elTop === tgTop) { _silent = true;
after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide; setTimeout(_unsilent, 30);
}
else if (target.previousElementSibling === dragEl || dragEl.previousElementSibling === target) { _cloneHide(activeSortable, isOwner);
after = (evt.clientY - targetRect.top) / height > 0.5;
} else {
after = tgTop > elTop;
}
} else if (!isMovingBetweenSortable) {
after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
}
if (!dragEl.contains(el)) { if (!dragEl.contains(el)) {
if (after && !nextSibling) { if (after && !nextSibling) {
@ -860,6 +867,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, 'pointercancel', this._onDrop);
_off(ownerDocument, 'selectstart', this); _off(ownerDocument, 'selectstart', this);
}, },
@ -887,7 +895,12 @@
!options.dropBubble && evt.stopPropagation(); !options.dropBubble && evt.stopPropagation();
} }
ghostEl && ghostEl.parentNode.removeChild(ghostEl); ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
if (rootEl === parentEl || Sortable.active.lastPullMode !== 'clone') {
// Remove clone
cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
}
if (dragEl) { if (dragEl) {
if (this.nativeDraggable) { if (this.nativeDraggable) {
@ -901,11 +914,13 @@
_toggleClass(dragEl, this.options.ghostClass, false); _toggleClass(dragEl, this.options.ghostClass, false);
_toggleClass(dragEl, this.options.chosenClass, false); _toggleClass(dragEl, this.options.chosenClass, false);
// Drag stop event
_dispatchEvent(this, rootEl, 'unchoose', dragEl, rootEl, oldIndex);
if (rootEl !== parentEl) { if (rootEl !== parentEl) {
newIndex = _index(dragEl, options.draggable); newIndex = _index(dragEl, options.draggable);
if (newIndex >= 0) { if (newIndex >= 0) {
// Add event // Add event
_dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex);
@ -918,9 +933,6 @@
} }
} }
else { else {
// Remove clone
cloneEl && cloneEl.parentNode.removeChild(cloneEl);
if (dragEl.nextSibling !== nextEl) { if (dragEl.nextSibling !== nextEl) {
// Get the index of the dragged element within its parent // Get the index of the dragged element within its parent
newIndex = _index(dragEl, options.draggable); newIndex = _index(dragEl, options.draggable);
@ -1269,7 +1281,7 @@
} }
function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvt) { function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvt, willInsertAfter) {
var evt, var evt,
sortable = fromEl[expando], sortable = fromEl[expando],
onMoveFn = sortable.options.onMove, onMoveFn = sortable.options.onMove,
@ -1284,6 +1296,7 @@
evt.draggedRect = dragRect; evt.draggedRect = dragRect;
evt.related = targetEl || toEl; evt.related = targetEl || toEl;
evt.relatedRect = targetRect || toEl.getBoundingClientRect(); evt.relatedRect = targetRect || toEl.getBoundingClientRect();
evt.willInsertAfter = willInsertAfter;
fromEl.dispatchEvent(evt); fromEl.dispatchEvent(evt);
@ -1312,10 +1325,8 @@
// 5 — min delta // 5 — min delta
// abs — нельзя добавлять, а то глюки при наведении сверху // abs — нельзя добавлять, а то глюки при наведении сверху
return ( return (evt.clientY - (rect.top + rect.height) > 5) ||
(evt.clientY - (rect.top + rect.height) > 5) || (evt.clientX - (rect.left + rect.width) > 5);
(evt.clientX - (rect.right + rect.width) > 5)
) && lastEl;
} }
@ -1475,6 +1486,6 @@
// Export // Export
Sortable.version = '1.5.0'; Sortable.version = '1.6.1';
return Sortable; return Sortable;
}); });

4
Sortable.min.js vendored

File diff suppressed because one or more lines are too long

2
st/iframe/index.html

@ -17,7 +17,7 @@
<!-- Simple List --> <!-- Simple List -->
<div id="simpleList" class="list-group"> <div id="simpleList" class="list-group">
<div class="list-group-item">This is <a href="http://rubaxa.github.io/Sortable/">Sortable</a></div> <div class="list-group-item">This is <a href="https://rubaxa.github.io/Sortable/">Sortable</a></div>
<div class="list-group-item">It works with Bootstrap...</div> <div class="list-group-item">It works with Bootstrap...</div>
<div class="list-group-item">...out of the box.</div> <div class="list-group-item">...out of the box.</div>
<div class="list-group-item">It has support for touch devices.</div> <div class="list-group-item">It has support for touch devices.</div>

Loading…
Cancel
Save