Browse Source

send insertAfter information in move hook

pull/1084/head
desmaisons_david 8 years ago
parent
commit
8451985bd8
  1. 101
      Sortable.js
  2. 3
      Sortable.min.js

101
Sortable.js

@ -67,7 +67,7 @@
$ = win.jQuery || win.Zepto, $ = win.jQuery || win.Zepto,
Polymer = win.Polymer, Polymer = win.Polymer,
captureMode = {capture: false, passive: false}, captureMode = { capture: false, passive: false },
supportDraggable = !!('draggable' in document.createElement('div')), supportDraggable = !!('draggable' in document.createElement('div')),
supportCssPointerEvents = (function (el) { supportCssPointerEvents = (function (el) {
@ -107,7 +107,7 @@
scrollOffsetX, scrollOffsetX,
scrollOffsetY scrollOffsetY
; ;
// Delect scrollEl // Delect scrollEl
if (scrollParentEl !== rootEl) { if (scrollParentEl !== rootEl) {
@ -158,7 +158,7 @@
scrollOffsetY = vy ? vy * speed : 0; scrollOffsetY = vy ? vy * speed : 0;
scrollOffsetX = vx ? vx * speed : 0; scrollOffsetX = vx ? vx * speed : 0;
if ('function' === typeof(scrollCustomFn)) { if ('function' === typeof (scrollCustomFn)) {
return scrollCustomFn.call(_this, scrollOffsetX, scrollOffsetY, evt); return scrollCustomFn.call(_this, scrollOffsetX, scrollOffsetY, evt);
} }
@ -200,7 +200,7 @@
var originalGroup = options.group; var originalGroup = options.group;
if (!originalGroup || typeof originalGroup != 'object') { if (!originalGroup || typeof originalGroup != 'object') {
originalGroup = {name: originalGroup}; originalGroup = { name: originalGroup };
} }
group.name = originalGroup.name; group.name = originalGroup.name;
@ -210,7 +210,7 @@
options.group = group; options.group = group;
} }
; ;
@ -261,7 +261,7 @@
fallbackClass: 'sortable-fallback', fallbackClass: 'sortable-fallback',
fallbackOnBody: false, fallbackOnBody: false,
fallbackTolerance: 0, fallbackTolerance: 0,
fallbackOffset: {x: 0, y: 0} fallbackOffset: { x: 0, y: 0 }
}; };
@ -384,7 +384,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;
@ -476,11 +476,11 @@
} }
try { try {
if (document.selection) { if (document.selection) {
// Timeout neccessary for IE9 // Timeout neccessary for IE9
setTimeout(function () { setTimeout(function () {
document.selection.empty(); document.selection.empty();
}); });
} else { } else {
window.getSelection().removeAllRanges(); window.getSelection().removeAllRanges();
} }
@ -552,7 +552,7 @@
_onTouchMove: function (/**TouchEvent*/evt) { _onTouchMove: function (/**TouchEvent*/evt) {
if (tapEvt) { if (tapEvt) {
var options = this.options, var options = this.options,
fallbackTolerance = options.fallbackTolerance, fallbackTolerance = options.fallbackTolerance,
fallbackOffset = options.fallbackOffset, fallbackOffset = options.fallbackOffset,
touch = evt.touches ? evt.touches[0] : evt, touch = evt.touches ? evt.touches[0] : evt,
@ -763,34 +763,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 after
; ;
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 {
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 {
after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
}
if (!dragEl.contains(el)) { if (!dragEl.contains(el)) {
if (after && !nextSibling) { if (after && !nextSibling) {
@ -941,30 +943,30 @@
this._nulling(); this._nulling();
}, },
_nulling: function() { _nulling: function () {
rootEl = rootEl =
dragEl = dragEl =
parentEl = parentEl =
ghostEl = ghostEl =
nextEl = nextEl =
cloneEl = cloneEl =
lastDownEl = lastDownEl =
scrollEl = scrollEl =
scrollParentEl = scrollParentEl =
tapEvt = tapEvt =
touchEvt = touchEvt =
moved = moved =
newIndex = newIndex =
lastEl = lastEl =
lastCSS = lastCSS =
putSortable = putSortable =
activeGroup = activeGroup =
Sortable.active = null; Sortable.active = null;
}, },
handleEvent: function (/**Event*/evt) { handleEvent: function (/**Event*/evt) {
@ -1247,7 +1249,7 @@
} }
function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvt) { function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvt, insertAfter) {
var evt, var evt,
sortable = fromEl[expando], sortable = fromEl[expando],
onMoveFn = sortable.options.onMove, onMoveFn = sortable.options.onMove,
@ -1262,6 +1264,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.insertAfter = insertAfter;
fromEl.dispatchEvent(evt); fromEl.dispatchEvent(evt);

3
Sortable.min.js vendored

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