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

Loading…
Cancel
Save