Browse Source

#325: * changed the order of the methods (code style)

pull/346/head
RubaXa 10 years ago
parent
commit
40af728d53
  1. 156
      Sortable.js

156
Sortable.js

@ -252,54 +252,61 @@
Sortable.prototype = /** @lends Sortable.prototype */ { Sortable.prototype = /** @lends Sortable.prototype */ {
constructor: Sortable, constructor: Sortable,
_dragStarted: function () { _onTapStart: function (/** Event|TouchEvent */evt) {
if (rootEl && dragEl) { var el = this.el,
// Apply effect options = this.options,
_toggleClass(dragEl, this.options.ghostClass, true); type = evt.type,
touch = evt.touches && evt.touches[0],
target = (touch || evt).target,
originalTarget = target,
filter = options.filter;
Sortable.active = this;
// Drag start event if (type === 'mousedown' && evt.button !== 0 || options.disabled) {
_dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); return; // only left button or enabled
} }
},
_triggerDragStart: function (/** Touch */touch) { target = _closest(target, options.draggable, el);
if (touch) {
// Touch device support
tapEvt = {
target: dragEl,
clientX: touch.clientX,
clientY: touch.clientY
};
this._onDragStart(tapEvt, 'touch'); if (!target) {
} return;
else if (!supportDraggable) {
this._onDragStart(tapEvt, true);
} }
else {
_on(dragEl, 'dragend', this); // get the index of the dragged element within its parent
_on(rootEl, 'dragstart', this._onDragStart); oldIndex = _index(target);
// Check filter
if (typeof filter === 'function') {
if (filter.call(this, evt, target, this)) {
_dispatchEvent(originalTarget, 'filter', target, el, oldIndex);
evt.preventDefault();
return; // cancel dnd
}
} }
else if (filter) {
filter = filter.split(',').some(function (criteria) {
criteria = _closest(originalTarget, criteria.trim(), el);
try { if (criteria) {
if (document.selection) { _dispatchEvent(criteria, 'filter', target, el, oldIndex);
document.selection.empty(); return true;
} else { }
window.getSelection().removeAllRanges(); });
if (filter) {
evt.preventDefault();
return; // cancel dnd
} }
} catch (err) {
} }
},
_disableDelayedDrag: function () {
var ownerDocument = this.el.ownerDocument;
clearTimeout(this._dragStartTimer); if (options.handle && !_closest(originalTarget, options.handle, el)) {
return;
}
_off(ownerDocument, 'mousemove', this._disableDelayedDrag);
_off(ownerDocument, 'touchmove', this._disableDelayedDrag); // Prepare `dragstart`
this._prepareDragStart(evt, touch, target);
}, },
_prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) { _prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) {
@ -351,61 +358,54 @@
} }
}, },
_onTapStart: function (/** Event|TouchEvent */evt) { _disableDelayedDrag: function () {
var el = this.el, var ownerDocument = this.el.ownerDocument;
options = this.options,
type = evt.type,
touch = evt.touches && evt.touches[0],
target = (touch || evt).target,
originalTarget = target,
filter = options.filter;
clearTimeout(this._dragStartTimer);
if (type === 'mousedown' && evt.button !== 0 || options.disabled) { _off(ownerDocument, 'mousemove', this._disableDelayedDrag);
return; // only left button or enabled _off(ownerDocument, 'touchmove', this._disableDelayedDrag);
} },
target = _closest(target, options.draggable, el); _triggerDragStart: function (/** Touch */touch) {
if (touch) {
// Touch device support
tapEvt = {
target: dragEl,
clientX: touch.clientX,
clientY: touch.clientY
};
if (!target) { this._onDragStart(tapEvt, 'touch');
return;
} }
else if (!supportDraggable) {
// get the index of the dragged element within its parent this._onDragStart(tapEvt, true);
oldIndex = _index(target); }
else {
// Check filter _on(dragEl, 'dragend', this);
if (typeof filter === 'function') { _on(rootEl, 'dragstart', this._onDragStart);
if (filter.call(this, evt, target, this)) {
_dispatchEvent(originalTarget, 'filter', target, el, oldIndex);
evt.preventDefault();
return; // cancel dnd
}
} }
else if (filter) {
filter = filter.split(',').some(function (criteria) {
criteria = _closest(originalTarget, criteria.trim(), el);
if (criteria) {
_dispatchEvent(criteria, 'filter', target, el, oldIndex);
return true;
}
});
if (filter) { try {
evt.preventDefault(); if (document.selection) {
return; // cancel dnd document.selection.empty();
} else {
window.getSelection().removeAllRanges();
} }
} catch (err) {
} }
},
_dragStarted: function () {
if (rootEl && dragEl) {
// Apply effect
_toggleClass(dragEl, this.options.ghostClass, true);
if (options.handle && !_closest(originalTarget, options.handle, el)) { Sortable.active = this;
return;
}
// Prepare `dragstart` // Drag start event
this._prepareDragStart(evt, touch, target); _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex);
}
}, },
_emulateDragOver: function () { _emulateDragOver: function () {

Loading…
Cancel
Save