|
|
@ -77,11 +77,11 @@ |
|
|
|
options.ghostClass = options.ghostClass || 'sortable-ghost'; |
|
|
|
options.ghostClass = options.ghostClass || 'sortable-ghost'; |
|
|
|
options.ignore = options.ignore || 'a, img'; |
|
|
|
options.ignore = options.ignore || 'a, img'; |
|
|
|
|
|
|
|
|
|
|
|
options.onAdd = _bind(this, options.onAdd || noop); |
|
|
|
|
|
|
|
options.onUpdate = _bind(this, options.onUpdate || noop); |
|
|
|
// Define events
|
|
|
|
options.onRemove = _bind(this, options.onRemove || noop); |
|
|
|
'onAdd onUpdate onRemove onStart onEnd'.split(' ').forEach(function (name) { |
|
|
|
options.onStart = _bind(this, options.onStart || noop); |
|
|
|
options[name] = _bind(this, options[name] || noop); |
|
|
|
options.onEnd = _bind(this, options.onEnd || noop); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Export group name
|
|
|
|
// Export group name
|
|
|
@ -149,10 +149,16 @@ |
|
|
|
|
|
|
|
|
|
|
|
if( target && !dragEl && (target.parentNode === el) ){ |
|
|
|
if( target && !dragEl && (target.parentNode === el) ){ |
|
|
|
tapEvt = evt; |
|
|
|
tapEvt = evt; |
|
|
|
target.draggable = true; |
|
|
|
|
|
|
|
|
|
|
|
rootEl = this.el; |
|
|
|
|
|
|
|
dragEl = target; |
|
|
|
|
|
|
|
nextEl = dragEl.nextSibling; |
|
|
|
|
|
|
|
activeGroup = this.options.group; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dragEl.draggable = true; |
|
|
|
|
|
|
|
|
|
|
|
// Disable "draggable"
|
|
|
|
// Disable "draggable"
|
|
|
|
Array.prototype.forEach.call(options.ignore.split(','), function (criteria) { |
|
|
|
options.ignore.split(',').forEach(function (criteria) { |
|
|
|
_find(target, criteria.trim(), _disableDraggable); |
|
|
|
_find(target, criteria.trim(), _disableDraggable); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -163,10 +169,14 @@ |
|
|
|
, clientX: touch.clientX |
|
|
|
, clientX: touch.clientX |
|
|
|
, clientY: touch.clientY |
|
|
|
, clientY: touch.clientY |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
this._onDragStart(tapEvt, true); |
|
|
|
this._onDragStart(tapEvt, true); |
|
|
|
evt.preventDefault(); |
|
|
|
evt.preventDefault(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_on(document, 'mouseup', this._onDrop); |
|
|
|
|
|
|
|
_on(document, 'touchend', this._onDrop); |
|
|
|
|
|
|
|
_on(document, 'touchcancel', this._onDrop); |
|
|
|
|
|
|
|
|
|
|
|
_on(this.el, 'dragstart', this._onDragStart); |
|
|
|
_on(this.el, 'dragstart', this._onDragStart); |
|
|
|
_on(this.el, 'dragend', this._onDrop); |
|
|
|
_on(this.el, 'dragend', this._onDrop); |
|
|
@ -180,10 +190,12 @@ |
|
|
|
window.getSelection().removeAllRanges() |
|
|
|
window.getSelection().removeAllRanges() |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (err){ } |
|
|
|
} catch (err){ } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dragEl.dispatchEvent(_createEvent('start', dragEl)); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_emulateDragOver: function (){ |
|
|
|
_emulateDragOver: function (){ |
|
|
|
if( touchEvt ){ |
|
|
|
if( touchEvt ){ |
|
|
|
_css(ghostEl, 'display', 'none'); |
|
|
|
_css(ghostEl, 'display', 'none'); |
|
|
@ -241,24 +253,18 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_onDragStart: function (evt/**Event*/, isTouch/**Boolean*/){ |
|
|
|
_onDragStart: function (evt/**Event*/, isTouch/**Boolean*/){ |
|
|
|
var |
|
|
|
var dataTransfer = evt.dataTransfer; |
|
|
|
target = evt.target |
|
|
|
|
|
|
|
, dataTransfer = evt.dataTransfer |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rootEl = this.el; |
|
|
|
this._offUpEvents(); |
|
|
|
dragEl = target; |
|
|
|
|
|
|
|
nextEl = target.nextSibling; |
|
|
|
|
|
|
|
activeGroup = this.options.group; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( isTouch ){ |
|
|
|
if( isTouch ){ |
|
|
|
var |
|
|
|
var |
|
|
|
rect = target.getBoundingClientRect() |
|
|
|
rect = dragEl.getBoundingClientRect() |
|
|
|
, css = _css(target) |
|
|
|
, css = _css(dragEl) |
|
|
|
, ghostRect |
|
|
|
, ghostRect |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
ghostEl = target.cloneNode(true); |
|
|
|
ghostEl = dragEl.cloneNode(true); |
|
|
|
|
|
|
|
|
|
|
|
_css(ghostEl, 'top', rect.top - parseInt(css.marginTop, 10)); |
|
|
|
_css(ghostEl, 'top', rect.top - parseInt(css.marginTop, 10)); |
|
|
|
_css(ghostEl, 'left', rect.left - parseInt(css.marginLeft, 10)); |
|
|
|
_css(ghostEl, 'left', rect.left - parseInt(css.marginLeft, 10)); |
|
|
@ -284,12 +290,11 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
dataTransfer.effectAllowed = 'move'; |
|
|
|
dataTransfer.effectAllowed = 'move'; |
|
|
|
dataTransfer.setData('Text', target.textContent); |
|
|
|
dataTransfer.setData('Text', dragEl.textContent); |
|
|
|
|
|
|
|
|
|
|
|
_on(document, 'drop', this._onDrop); |
|
|
|
_on(document, 'drop', this._onDrop); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dragEl.dispatchEvent(_createEvent('start', dragEl)); |
|
|
|
|
|
|
|
setTimeout(this._applyEffects); |
|
|
|
setTimeout(this._applyEffects); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -342,6 +347,12 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_offUpEvents: function () { |
|
|
|
|
|
|
|
_off(document, 'mouseup', this._onDrop); |
|
|
|
|
|
|
|
_off(document, 'touchmove', this._onTouchMove); |
|
|
|
|
|
|
|
_off(document, 'touchend', this._onDrop); |
|
|
|
|
|
|
|
_off(document, 'touchcancel', this._onDrop); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
_onDrop: function (evt/**Event*/){ |
|
|
|
_onDrop: function (evt/**Event*/){ |
|
|
|
clearInterval(this._loopId); |
|
|
|
clearInterval(this._loopId); |
|
|
@ -354,10 +365,7 @@ |
|
|
|
_off(this.el, 'dragstart', this._onDragStart); |
|
|
|
_off(this.el, 'dragstart', this._onDragStart); |
|
|
|
_off(this.el, 'selectstart', this._onTapStart); |
|
|
|
_off(this.el, 'selectstart', this._onTapStart); |
|
|
|
|
|
|
|
|
|
|
|
_off(document, 'touchmove', this._onTouchMove); |
|
|
|
this._offUpEvents(); |
|
|
|
_off(document, 'touchend', this._onDrop); |
|
|
|
|
|
|
|
_off(document, 'touchcancel', this._onDrop); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( evt ){ |
|
|
|
if( evt ){ |
|
|
|
evt.preventDefault(); |
|
|
|
evt.preventDefault(); |
|
|
|