|
|
@ -23,6 +23,7 @@ |
|
|
|
var |
|
|
|
var |
|
|
|
dragEl |
|
|
|
dragEl |
|
|
|
, ghostEl |
|
|
|
, ghostEl |
|
|
|
|
|
|
|
, cloneEl |
|
|
|
, rootEl |
|
|
|
, rootEl |
|
|
|
, nextEl |
|
|
|
, nextEl |
|
|
|
|
|
|
|
|
|
|
@ -74,9 +75,10 @@ |
|
|
|
this.options = options = (options || {}); |
|
|
|
this.options = options = (options || {}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Defaults
|
|
|
|
// Default options
|
|
|
|
var defaults = { |
|
|
|
var defaults = { |
|
|
|
group: Math.random(), |
|
|
|
group: Math.random(), |
|
|
|
|
|
|
|
sort: true, |
|
|
|
store: null, |
|
|
|
store: null, |
|
|
|
handle: null, |
|
|
|
handle: null, |
|
|
|
draggable: el.children[0] && el.children[0].nodeName || (/[uo]l/i.test(el.nodeName) ? 'li' : '*'), |
|
|
|
draggable: el.children[0] && el.children[0].nodeName || (/[uo]l/i.test(el.nodeName) ? 'li' : '*'), |
|
|
@ -86,12 +88,24 @@ |
|
|
|
animation: 0 |
|
|
|
animation: 0 |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set default options
|
|
|
|
// Set default options
|
|
|
|
for (var name in defaults) { |
|
|
|
for (var name in defaults) { |
|
|
|
options[name] = options[name] || defaults[name]; |
|
|
|
options[name] = options[name] || defaults[name]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!options.group.name) { |
|
|
|
|
|
|
|
options.group = { name: options.group }; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
['pull', 'put'].forEach(function (key) { |
|
|
|
|
|
|
|
if (!(key in options.group)) { |
|
|
|
|
|
|
|
options.group[key] = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Define events
|
|
|
|
// Define events
|
|
|
|
_customEvents.forEach(function (name) { |
|
|
|
_customEvents.forEach(function (name) { |
|
|
|
options[name] = _bind(this, options[name] || noop); |
|
|
|
options[name] = _bind(this, options[name] || noop); |
|
|
@ -100,7 +114,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Export group name
|
|
|
|
// Export group name
|
|
|
|
el[expando] = options.group; |
|
|
|
el[expando] = options.group.name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Bind all private methods
|
|
|
|
// Bind all private methods
|
|
|
@ -187,6 +201,10 @@ |
|
|
|
nextEl = dragEl.nextSibling; |
|
|
|
nextEl = dragEl.nextSibling; |
|
|
|
activeGroup = this.options.group; |
|
|
|
activeGroup = this.options.group; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cloneEl = dragEl.cloneNode(true); |
|
|
|
|
|
|
|
_css(cloneEl, 'display', 'none'); |
|
|
|
|
|
|
|
rootEl.insertBefore(cloneEl, dragEl); |
|
|
|
|
|
|
|
|
|
|
|
dragEl.draggable = true; |
|
|
|
dragEl.draggable = true; |
|
|
|
|
|
|
|
|
|
|
|
// Disable "draggable"
|
|
|
|
// Disable "draggable"
|
|
|
@ -235,13 +253,13 @@ |
|
|
|
var |
|
|
|
var |
|
|
|
target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY) |
|
|
|
target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY) |
|
|
|
, parent = target |
|
|
|
, parent = target |
|
|
|
, group = this.options.group |
|
|
|
, groupName = this.options.group.name |
|
|
|
, i = touchDragOverListeners.length |
|
|
|
, i = touchDragOverListeners.length |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
if( parent ){ |
|
|
|
if( parent ){ |
|
|
|
do { |
|
|
|
do { |
|
|
|
if( parent[expando] === group ){ |
|
|
|
if( parent[expando] === groupName ){ |
|
|
|
while( i-- ){ |
|
|
|
while( i-- ){ |
|
|
|
touchDragOverListeners[i]({ |
|
|
|
touchDragOverListeners[i]({ |
|
|
|
clientX: touchEvt.clientX, |
|
|
|
clientX: touchEvt.clientX, |
|
|
@ -332,12 +350,32 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_onDragOver: function (evt/**Event*/){ |
|
|
|
_onDragOver: function (evt/**Event*/){ |
|
|
|
if( !_silent && (activeGroup === this.options.group) && (evt.rootEl === void 0 || evt.rootEl === this.el) ){ |
|
|
|
var el = this.el, |
|
|
|
var |
|
|
|
target, |
|
|
|
el = this.el |
|
|
|
dragRect, |
|
|
|
, target = _closest(evt.target, this.options.draggable, el) |
|
|
|
revert, |
|
|
|
, dragRect = dragEl.getBoundingClientRect() |
|
|
|
options = this.options, |
|
|
|
; |
|
|
|
group = options.group, |
|
|
|
|
|
|
|
isOwner = (activeGroup === group); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !_silent && |
|
|
|
|
|
|
|
(activeGroup.name === group.name) && |
|
|
|
|
|
|
|
(isOwner && (options.sort || (revert = !rootEl.contains(dragEl))) || group.put && activeGroup.pull) && |
|
|
|
|
|
|
|
(evt.rootEl === void 0 || evt.rootEl === this.el) |
|
|
|
|
|
|
|
){ |
|
|
|
|
|
|
|
target = _closest(evt.target, this.options.draggable, el); |
|
|
|
|
|
|
|
dragRect = dragEl.getBoundingClientRect(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((activeGroup.pull == 'clone') && (cloneEl.state !== isOwner)) { |
|
|
|
|
|
|
|
_css(cloneEl, 'display', isOwner ? 'none' : ''); |
|
|
|
|
|
|
|
!isOwner && cloneEl.state && rootEl.insertBefore(cloneEl, dragEl); |
|
|
|
|
|
|
|
cloneEl.state = isOwner; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (revert) { |
|
|
|
|
|
|
|
rootEl.insertBefore(dragEl, cloneEl); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( el.children.length === 0 || el.children[0] === ghostEl || (el === evt.target) && _ghostInBottom(el, evt) ){ |
|
|
|
if( el.children.length === 0 || el.children[0] === ghostEl || (el === evt.target) && _ghostInBottom(el, evt) ){ |
|
|
|
el.appendChild(dragEl); |
|
|
|
el.appendChild(dragEl); |
|
|
@ -459,6 +497,7 @@ |
|
|
|
dragEl = |
|
|
|
dragEl = |
|
|
|
ghostEl = |
|
|
|
ghostEl = |
|
|
|
nextEl = |
|
|
|
nextEl = |
|
|
|
|
|
|
|
cloneEl = |
|
|
|
|
|
|
|
|
|
|
|
tapEvt = |
|
|
|
tapEvt = |
|
|
|
touchEvt = |
|
|
|
touchEvt = |
|
|
|