From 40af728d53c8ed6ca41dead85ceb08d71b8a77fa Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 6 Apr 2015 00:00:55 +0300 Subject: [PATCH] #325: * changed the order of the methods (code style) --- Sortable.js | 156 ++++++++++++++++++++++++++-------------------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/Sortable.js b/Sortable.js index ea26139..a3b82fe 100644 --- a/Sortable.js +++ b/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 () {