Browse Source

#475: * merge 'dev' branch

bernerbits-dev
RubaXa 10 years ago
parent
commit
960d7da05b
  1. 23
      Sortable.js
  2. 2
      Sortable.min.js

23
Sortable.js

@ -25,6 +25,7 @@
"use strict"; "use strict";
var dragEl, var dragEl,
parentEl,
ghostEl, ghostEl,
cloneEl, cloneEl,
rootEl, rootEl,
@ -303,6 +304,7 @@
rootEl = el; rootEl = el;
dragEl = target; dragEl = target;
parentEl = target.parentNode;
nextEl = dragEl.nextSibling; nextEl = dragEl.nextSibling;
activeGroup = options.group; activeGroup = options.group;
@ -706,19 +708,20 @@
_disableDraggable(dragEl); _disableDraggable(dragEl);
_toggleClass(dragEl, this.options.ghostClass, false); _toggleClass(dragEl, this.options.ghostClass, false);
if (rootEl !== dragEl.parentNode) { if (rootEl !== parentEl) {
newIndex = _index(dragEl); newIndex = _index(dragEl);
if (newIndex != -1) {
// drag from one list and drop into another // drag from one list and drop into another
_dispatchEvent(null, dragEl.parentNode, 'sort', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
// Add event // Add event
_dispatchEvent(null, dragEl.parentNode, 'add', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex);
// Remove event // Remove event
_dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex);
} }
}
else { else {
// Remove clone // Remove clone
cloneEl && cloneEl.parentNode.removeChild(cloneEl); cloneEl && cloneEl.parentNode.removeChild(cloneEl);
@ -726,12 +729,13 @@
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); newIndex = _index(dragEl);
if (newIndex != -1) {
// drag & drop within the same list // drag & drop within the same list
_dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
} }
} }
}
if (Sortable.active) { if (Sortable.active) {
// Drag end event // Drag end event
@ -745,6 +749,7 @@
// Nulling // Nulling
rootEl = rootEl =
dragEl = dragEl =
parentEl =
ghostEl = ghostEl =
nextEl = nextEl =
cloneEl = cloneEl =
@ -1092,6 +1097,9 @@
* @private * @private
*/ */
function _index(/**HTMLElement*/el) { function _index(/**HTMLElement*/el) {
if (!el || !el.parentNode) {
return -1;
}
var index = 0; var index = 0;
while (el && (el = el.previousElementSibling)) { while (el && (el = el.previousElementSibling)) {
if (el.nodeName.toUpperCase() !== 'TEMPLATE') { if (el.nodeName.toUpperCase() !== 'TEMPLATE') {
@ -1152,9 +1160,6 @@
}; };
Sortable.version = '1.2.2';
/** /**
* Create sortable instance * Create sortable instance
* @param {HTMLElement} el * @param {HTMLElement} el
@ -1164,6 +1169,8 @@
return new Sortable(el, options); return new Sortable(el, options);
}; };
// Export // Export
Sortable.version = '1.2.2';
return Sortable; return Sortable;
}); });

2
Sortable.min.js vendored

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