|
|
|
@ -63,11 +63,11 @@
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @class Sortable |
|
|
|
|
* @param {HTMLElement} el |
|
|
|
|
* @param {Object} [options] |
|
|
|
|
* @constructor |
|
|
|
|
*/ |
|
|
|
|
function Sortable(el, options){ |
|
|
|
|
this.el = el; // root element
|
|
|
|
@ -76,6 +76,7 @@
|
|
|
|
|
|
|
|
|
|
// Defaults
|
|
|
|
|
options.group = options.group || Math.random(); |
|
|
|
|
options.store = options.store || null; |
|
|
|
|
options.handle = options.handle || null; |
|
|
|
|
options.draggable = options.draggable || el.children[0] && el.children[0].nodeName || (/[uo]l/i.test(el.nodeName) ? 'li' : '*'); |
|
|
|
|
options.ghostClass = options.ghostClass || 'sortable-ghost'; |
|
|
|
@ -131,10 +132,13 @@
|
|
|
|
|
_css(el, '-ms-touch-action', 'none'); |
|
|
|
|
|
|
|
|
|
touchDragOverListeners.push(this._onDragOver); |
|
|
|
|
|
|
|
|
|
// Restore sorting
|
|
|
|
|
options.store && this.sort(options.store.get(this)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sortable.prototype = { |
|
|
|
|
Sortable.prototype = /** @lends Sortable.prototype */ { |
|
|
|
|
constructor: Sortable, |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -406,6 +410,7 @@
|
|
|
|
|
// Update event
|
|
|
|
|
dragEl.dispatchEvent(_createEvent('update', dragEl)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dragEl.dispatchEvent(_createEvent('stop', dragEl)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -422,10 +427,57 @@
|
|
|
|
|
lastCSS = |
|
|
|
|
|
|
|
|
|
activeGroup = null; |
|
|
|
|
|
|
|
|
|
// Save sorting
|
|
|
|
|
this.options.store && this.options.store.set(this); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Serializes the item into an array of string. |
|
|
|
|
* @returns {String[]} |
|
|
|
|
*/ |
|
|
|
|
toArray: function () { |
|
|
|
|
var order = [], |
|
|
|
|
el, |
|
|
|
|
children = this.el.children, |
|
|
|
|
i = 0, |
|
|
|
|
n = children.length |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
for (; i < n; i++) { |
|
|
|
|
el = children[i]; |
|
|
|
|
order.push(el.getAttribute('data-id') || _generateId(el)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return order; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sorts the elements according to the array. |
|
|
|
|
* @param {String[]} order order of the items |
|
|
|
|
*/ |
|
|
|
|
sort: function (order) { |
|
|
|
|
var items = {}, el = this.el; |
|
|
|
|
|
|
|
|
|
this.toArray().forEach(function (id, i) { |
|
|
|
|
items[id] = el.children[i]; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
order.forEach(function (id) { |
|
|
|
|
if (items[id]) { |
|
|
|
|
el.removeChild(items[id]); |
|
|
|
|
el.appendChild(items[id]); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Destroy |
|
|
|
|
*/ |
|
|
|
|
destroy: function () { |
|
|
|
|
var el = this.el, options = this.options; |
|
|
|
|
|
|
|
|
@ -455,6 +507,7 @@
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _bind(ctx, fn){ |
|
|
|
|
var args = slice.call(arguments, 2); |
|
|
|
|
return fn.bind ? fn.bind.apply(fn, [ctx].concat(args)) : function (){ |
|
|
|
@ -567,6 +620,23 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Generate id |
|
|
|
|
* @param {HTMLElement} el |
|
|
|
|
* @returns {String} |
|
|
|
|
* @private |
|
|
|
|
*/ |
|
|
|
|
function _generateId(el) { |
|
|
|
|
var str = el.innerHTML + el.className + el.src, |
|
|
|
|
i = str.length, |
|
|
|
|
sum = 0 |
|
|
|
|
; |
|
|
|
|
while (i--) { |
|
|
|
|
sum += str.charCodeAt(i); |
|
|
|
|
} |
|
|
|
|
return sum.toString(36); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Export utils
|
|
|
|
|
Sortable.utils = { |
|
|
|
@ -580,7 +650,8 @@
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sortable.version = '0.3.0'; |
|
|
|
|
Sortable.version = '0.4.0'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Export
|
|
|
|
|
return Sortable; |
|
|
|
|