|
|
@ -63,11 +63,11 @@ |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @class Sortable |
|
|
|
* @class Sortable |
|
|
|
* @param {HTMLElement} el |
|
|
|
* @param {HTMLElement} el |
|
|
|
* @param {Object} [options] |
|
|
|
* @param {Object} [options] |
|
|
|
* @constructor |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function Sortable(el, options){ |
|
|
|
function Sortable(el, options){ |
|
|
|
this.el = el; // root element
|
|
|
|
this.el = el; // root element
|
|
|
@ -76,6 +76,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
// Defaults
|
|
|
|
// Defaults
|
|
|
|
options.group = options.group || Math.random(); |
|
|
|
options.group = options.group || Math.random(); |
|
|
|
|
|
|
|
options.store = options.store || null; |
|
|
|
options.handle = options.handle || 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.draggable = options.draggable || el.children[0] && el.children[0].nodeName || (/[uo]l/i.test(el.nodeName) ? 'li' : '*'); |
|
|
|
options.ghostClass = options.ghostClass || 'sortable-ghost'; |
|
|
|
options.ghostClass = options.ghostClass || 'sortable-ghost'; |
|
|
@ -131,10 +132,13 @@ |
|
|
|
_css(el, '-ms-touch-action', 'none'); |
|
|
|
_css(el, '-ms-touch-action', 'none'); |
|
|
|
|
|
|
|
|
|
|
|
touchDragOverListeners.push(this._onDragOver); |
|
|
|
touchDragOverListeners.push(this._onDragOver); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Restore sorting
|
|
|
|
|
|
|
|
options.store && this.sort(options.store.get(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sortable.prototype = { |
|
|
|
Sortable.prototype = /** @lends Sortable.prototype */ { |
|
|
|
constructor: Sortable, |
|
|
|
constructor: Sortable, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -406,6 +410,7 @@ |
|
|
|
// Update event
|
|
|
|
// Update event
|
|
|
|
dragEl.dispatchEvent(_createEvent('update', dragEl)); |
|
|
|
dragEl.dispatchEvent(_createEvent('update', dragEl)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dragEl.dispatchEvent(_createEvent('stop', dragEl)); |
|
|
|
dragEl.dispatchEvent(_createEvent('stop', dragEl)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -422,11 +427,58 @@ |
|
|
|
lastCSS = |
|
|
|
lastCSS = |
|
|
|
|
|
|
|
|
|
|
|
activeGroup = null; |
|
|
|
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: function (){ |
|
|
|
/** |
|
|
|
|
|
|
|
* Destroy |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
destroy: function () { |
|
|
|
var el = this.el, options = this.options; |
|
|
|
var el = this.el, options = this.options; |
|
|
|
|
|
|
|
|
|
|
|
_off(el, 'add', options.onAdd); |
|
|
|
_off(el, 'add', options.onAdd); |
|
|
@ -455,6 +507,7 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _bind(ctx, fn){ |
|
|
|
function _bind(ctx, fn){ |
|
|
|
var args = slice.call(arguments, 2); |
|
|
|
var args = slice.call(arguments, 2); |
|
|
|
return fn.bind ? fn.bind.apply(fn, [ctx].concat(args)) : function (){ |
|
|
|
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
|
|
|
|
// Export utils
|
|
|
|
Sortable.utils = { |
|
|
|
Sortable.utils = { |
|
|
@ -580,7 +650,8 @@ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sortable.version = '0.3.0'; |
|
|
|
Sortable.version = '0.4.0'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Export
|
|
|
|
// Export
|
|
|
|
return Sortable; |
|
|
|
return Sortable; |
|
|
|