Browse Source

#325: PR refactoring: - _enableDragStart & revert lost fixes

pull/346/head
RubaXa 10 years ago
parent
commit
723bc1e605
  1. 103
      Sortable.js

103
Sortable.js

@ -252,7 +252,6 @@
Sortable.prototype = /** @lends Sortable.prototype */ { Sortable.prototype = /** @lends Sortable.prototype */ {
constructor: Sortable, constructor: Sortable,
_dragStarted: function () { _dragStarted: function () {
if (rootEl && dragEl) { if (rootEl && dragEl) {
// Apply effect // Apply effect
@ -265,21 +264,21 @@
} }
}, },
_triggerDragStart: function (evt, target, touch) { _triggerDragStart: function (/** Touch */touch) {
evt.preventDefault();
if (touch) { if (touch) {
// Touch device support // Touch device support
tapEvt = { tapEvt = {
target: target, target: dragEl,
clientX: touch.clientX, clientX: touch.clientX,
clientY: touch.clientY clientY: touch.clientY
}; };
this._onDragStart(tapEvt, 'touch'); this._onDragStart(tapEvt, 'touch');
} else if (!supportDraggable) { }
else if (!supportDraggable) {
this._onDragStart(tapEvt, true); this._onDragStart(tapEvt, true);
} else { }
else {
_on(dragEl, 'dragend', this); _on(dragEl, 'dragend', this);
_on(rootEl, 'dragstart', this._onDragStart); _on(rootEl, 'dragstart', this._onDragStart);
} }
@ -294,68 +293,73 @@
} }
}, },
_enableDragStart: function (dragEl, target) {
dragEl.draggable = true;
// Disable "draggable"
this.options.ignore.split(',').forEach(function (criteria) {
_find(target, criteria.trim(), _disableDraggable);
});
},
_disableDelayedDrag: function () { _disableDelayedDrag: function () {
clearTimeout(this.dragStartTimer); var ownerDocument = this.el.ownerDocument;
clearTimeout(this._dragStartTimer);
_off(document, 'mousemove', this._disableDelayedDrag); _off(ownerDocument, 'mousemove', this._disableDelayedDrag);
_off(document, 'touchmove', this._disableDelayedDrag); _off(ownerDocument, 'touchmove', this._disableDelayedDrag);
}, },
_prepareDragStart: function (evt, target, el, touch) { _prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) {
var _this = this; var _this = this,
el = _this.el,
options = _this.options,
ownerDocument = el.ownerDocument,
dragStartFn;
if (target && !dragEl && (target.parentNode === el)) { if (target && !dragEl && (target.parentNode === el)) {
tapEvt = evt; tapEvt = evt;
rootEl = this.el; rootEl = el;
dragEl = target; dragEl = target;
nextEl = dragEl.nextSibling; nextEl = dragEl.nextSibling;
activeGroup = this.options.group; activeGroup = options.group;
this.options.delay = this.options.delay || 1; dragStartFn = function () {
if (this.options.delay) { // Delayed drag has been triggered
_on(document, 'mouseup', this._onDrop); // we can re-enable the events: touchmove/mousemove
_on(document, 'touchend', this._onDrop); _this._disableDelayedDrag();
_on(document, 'touchcancel', this._onDrop);
// Make the element draggable
dragEl.draggable = true;
// Disable "draggable"
options.ignore.split(',').forEach(function (criteria) {
_find(dragEl, criteria.trim(), _disableDraggable);
});
// Bind the events: dragstart/dragend
_this._triggerDragStart(touch);
};
_on(ownerDocument, 'mouseup', _this._onDrop);
_on(ownerDocument, 'touchend', _this._onDrop);
_on(ownerDocument, 'touchcancel', _this._onDrop);
if (options.delay) {
// If the user moves the pointer before the delay has been reached: // If the user moves the pointer before the delay has been reached:
// disable the delayed drag // disable the delayed drag
_on(document, 'mousemove', this._disableDelayedDrag); _on(ownerDocument, 'mousemove', _this._disableDelayedDrag);
_on(document, 'touchmove', this._disableDelayedDrag); _on(ownerDocument, 'touchmove', _this._disableDelayedDrag);
this.dragStartTimer = setTimeout(function () { _this._dragStartTimer = setTimeout(dragStartFn, options.delay);
// Delayed drag has been triggered } else {
// we can re-enable the events: touchmove/mousemove dragStartFn();
_off(document, 'mousemove', _this._disableDelayedDrag);
_off(document, 'touchmove', _this._disableDelayedDrag);
// Make the element draggable
_this._enableDragStart(dragEl, target);
// Bind the events: dragstart/dragend
_this._triggerDragStart(evt, target, touch);
}, this.options.delay);
} }
} }
}, },
_onTapStart: function (/**Event|TouchEvent*/evt) { _onTapStart: function (/** Event|TouchEvent */evt) {
var type = evt.type, var el = this.el,
options = this.options,
type = evt.type,
touch = evt.touches && evt.touches[0], touch = evt.touches && evt.touches[0],
target = (touch || evt).target, target = (touch || evt).target,
originalTarget = target, originalTarget = target,
options = this.options, filter = options.filter;
filter = options.filter,
el = this.el,
ownerDocument = el.ownerDocument; // for correct working with/into iframe
if (type === 'mousedown' && evt.button !== 0 || options.disabled) { if (type === 'mousedown' && evt.button !== 0 || options.disabled) {
return; // only left button or enabled return; // only left button or enabled
@ -399,8 +403,9 @@
return; return;
} }
// Prepare `dragstart` // Prepare `dragstart`
this._prepareDragStart(evt, target, el, touch); this._prepareDragStart(evt, touch, target);
}, },
_emulateDragOver: function () { _emulateDragOver: function () {

Loading…
Cancel
Save