Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ export default function AnimationStateManager() {
if (!this.options.animation) return;
let children = [].slice.call(this.el.children);

for (let i in children) {
if (css(children[i], 'display') === 'none' || children[i] === Sortable.ghost) continue;
children.forEach(child => {
if (css(child, 'display') === 'none' || child === Sortable.ghost) return;
animationStates.push({
target: children[i],
rect: getRect(children[i])
target: child,
rect: getRect(child)
});
let fromRect = getRect(children[i]);
let fromRect = getRect(child);

// If animating: compensate for current animation
if (children[i].thisAnimationDuration) {
let childMatrix = matrix(children[i], true);
if (child.thisAnimationDuration) {
let childMatrix = matrix(child, true);
if (childMatrix) {
fromRect.top -= childMatrix.f;
fromRect.left -= childMatrix.e;
}
}

children[i].fromRect = fromRect;
}
child.fromRect = fromRect;
});
},

addAnimationState(state) {
Expand All @@ -50,15 +50,14 @@ export default function AnimationStateManager() {
let animating = false,
animationTime = 0;

for (let i in animationStates) {
animationStates.forEach((animationState, i) => {
let time = 0,
animatingThis = false,
target = animationStates[i].target,
target = animationState.target,
fromRect = target.fromRect,
toRect = getRect(target),
prevFromRect = target.prevFromRect,
prevToRect = target.prevToRect,
animatingRect = animationStates[i].rect,
animatingRect = animationState.rect,
targetMatrix = matrix(target, true);


Expand Down Expand Up @@ -90,7 +89,7 @@ export default function AnimationStateManager() {
isScrolledPast(target, fromRect, 'right', 'left') ||
isScrolledPast(target, fromRect, 'left', 'right')
)
) continue;
) return;


if (target.thisAnimationDuration) {
Expand Down Expand Up @@ -137,7 +136,7 @@ export default function AnimationStateManager() {
}).bind({ animationStates, i: Number(i) }), time);
target.thisAnimationDuration = time;
}
}
});


clearTimeout(animationCallbackId);
Expand Down
77 changes: 39 additions & 38 deletions src/PluginManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,39 @@ export default {
pluginEvent(eventName, sortable, evt) {
this.eventCanceled = false;
const eventNameGlobal = eventName + 'Global';
for (let i in plugins) {
if (!sortable[plugins[i].pluginName]) continue;
// Fire global events if it exists in this sortable
if (
sortable[plugins[i].pluginName][eventNameGlobal]
) {
this.eventCanceled = !!sortable[plugins[i].pluginName][eventNameGlobal]({ sortable, ...evt });
}
plugins.forEach(plugin => {
if (sortable[plugin.pluginName]) {
// Fire global events if it exists in this sortable
if (
sortable[plugin.pluginName][eventNameGlobal]
) {
this.eventCanceled = !!sortable[plugin.pluginName][eventNameGlobal]({sortable, ...evt});
}

// Only fire plugin event if plugin is enabled in this sortable,
// and plugin has event defined
if (
sortable.options[plugins[i].pluginName] &&
sortable[plugins[i].pluginName][eventName]
) {
this.eventCanceled = this.eventCanceled || !!sortable[plugins[i].pluginName][eventName]({ sortable, ...evt });
// Only fire plugin event if plugin is enabled in this sortable,
// and plugin has event defined
if (
sortable.options[plugin.pluginName] &&
sortable[plugin.pluginName][eventName]
) {
this.eventCanceled = this.eventCanceled || !!sortable[plugin.pluginName][eventName]({sortable, ...evt});
}
}
}
});
},
initializePlugins(sortable, el, defaults) {
for (let i in plugins) {
const pluginName = plugins[i].pluginName;
if (!sortable.options[pluginName] && !plugins[i].initializeByDefault) continue;
plugins.forEach(plugin => {
const pluginName = plugin.pluginName;
if (sortable.options[pluginName] || plugin.initializeByDefault) {

let initialized = new plugins[i](sortable, el);
initialized.sortable = sortable;
sortable[pluginName] = initialized;
let initialized = new plugin(sortable, el);
initialized.sortable = sortable;
sortable[pluginName] = initialized;

// Add default options from plugin
Object.assign(defaults, initialized.options);
}
// Add default options from plugin
Object.assign(defaults, initialized.options);
}
});

for (let option in sortable.options) {
let modified = this.modifyOption(sortable, option, sortable.options[option]);
Expand All @@ -56,23 +58,22 @@ export default {
},
getEventOptions(name, sortable) {
let eventOptions = {};
for (let i in plugins) {
if (typeof(plugins[i].eventOptions) !== 'function') continue;
Object.assign(eventOptions, plugins[i].eventOptions.call(sortable, name));
}
plugins.forEach(plugin => {
if (typeof(plugin.eventOptions) === 'function') {
Object.assign(eventOptions, plugins[i].eventOptions.call(sortable, name));
}
});
return eventOptions;
},
modifyOption(sortable, name, value) {
let modifiedValue;
for (let i in plugins) {
return plugins.find(plugin => {
// Plugin must exist on the Sortable
if (!sortable[plugins[i].pluginName]) continue;

// If static option listener exists for this option, call in the context of the Sortable's instance of this plugin
if (plugins[i].optionListeners && typeof(plugins[i].optionListeners[name]) === 'function') {
modifiedValue = plugins[i].optionListeners[name].call(sortable[plugins[i].pluginName], value);
if (sortable[plugin.pluginName]) {
// If static option listener exists for this option, call in the context of the Sortable's instance of this plugin
if (plugin.optionListeners && typeof (plugin.optionListeners[name]) === 'function') {
return plugin.optionListeners[name].call(sortable[plugin.pluginName], value);
}
}
}
return modifiedValue;
});
}
};
27 changes: 13 additions & 14 deletions src/Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,18 @@ let dragEl,
* @return {HTMLElement} Element of the first found nearest Sortable
*/
_detectNearestEmptySortable = function(x, y) {
for (let i in sortables) {
if (lastChild(sortables[i])) continue;

let rect = getRect(sortables[i]),
threshold = sortables[i][expando].options.emptyInsertThreshold,
insideHorizontally = x >= (rect.left - threshold) && x <= (rect.right + threshold),
insideVertically = y >= (rect.top - threshold) && y <= (rect.bottom + threshold);

if (threshold && insideHorizontally && insideVertically) {
return sortables[i];
return sortables.find(sortable => {
if (!lastChild(sortable)) {
let rect = getRect(sortable),
threshold = sortables[i][expando].options.emptyInsertThreshold,
insideHorizontally = x >= (rect.left - threshold) && x <= (rect.right + threshold),
insideVertically = y >= (rect.top - threshold) && y <= (rect.bottom + threshold);

if (threshold && insideHorizontally && insideVertically) {
return true;
}
}
}
});
},

_prepareGroup = function (options) {
Expand Down Expand Up @@ -1883,15 +1883,14 @@ Sortable.utils = {
Sortable.mount = function(...plugins) {
if (plugins[0].constructor === Array) plugins = plugins[0];

for (let i in plugins) {
let plugin = plugins[i];
plugins.forEach(plugin => {
if (!plugin.prototype || !plugin.prototype.constructor) {
throw `Sortable: Mounted plugin must be a constructor function, not ${ {}.toString.call(el) }`;
}
if (plugin.utils) Sortable.utils = { ...Sortable.utils, ...plugin.utils };

PluginManager.mount(plugin);
}
});
};


Expand Down
10 changes: 4 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,14 @@ function scrollBy(el, x, y) {


function clone(el) {
let Polymer = window.Polymer;
let $ = window.jQuery || window.Zepto;
var Polymer = window.Polymer;
var $ = window.jQuery || window.Zepto;

if (Polymer && Polymer.dom) {
return Polymer.dom(el).cloneNode(true);
}
else if ($) {
} else if ($) {
return $(el).clone(true)[0];
}
else {
} else {
return el.cloneNode(true);
}
}
Expand Down