From 8ae82072d3ce942eb4079c7d68a10134bf37616e Mon Sep 17 00:00:00 2001 From: sp-kilobug Date: Sat, 27 Jun 2015 12:45:06 +0200 Subject: [PATCH] remove drag/drop handlers in forceFallback mode drag/drop handlers should be disabled in fallback mode to avoid unwanted behaviors --- Sortable.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/Sortable.js b/Sortable.js index a2477f6..cbd14a2 100644 --- a/Sortable.js +++ b/Sortable.js @@ -56,8 +56,6 @@ document = win.document, parseInt = win.parseInt, - supportDraggable = !!('draggable' in document.createElement('div')), - _silent = false, abs = Math.abs, @@ -190,6 +188,11 @@ !(name in options) && (options[name] = defaults[name]); } + if (options.forceFallback) { + this.nativeDragMode = false; + } else { + this.nativeDragMode = !!('draggable' in document.createElement('div')); + } var group = options.group; @@ -220,8 +223,10 @@ _on(el, 'mousedown', this._onTapStart); _on(el, 'touchstart', this._onTapStart); - _on(el, 'dragover', this); - _on(el, 'dragenter', this); + if (this.nativeDragMode) { + _on(el, 'dragover', this); + _on(el, 'dragenter', this); + } touchDragOverListeners.push(this._onDragOver); @@ -366,7 +371,7 @@ this._onDragStart(tapEvt, 'touch'); } - else if (!supportDraggable || this.options.forceFallback) { + else if (!this.nativeDragMode) { this._onDragStart(tapEvt, true); } else { @@ -521,7 +526,6 @@ _on(document, 'drop', this); setTimeout(this._dragStarted, 0); } - }, _onDragOver: function (/**Event*/evt) { @@ -684,9 +688,12 @@ clearTimeout(this._dragStartTimer); // Unbind events - _off(document, 'drop', this); _off(document, 'mousemove', this._onTouchMove); - _off(el, 'dragstart', this._onDragStart); + + if (this.nativeDragMode) { + _off(document, 'drop', this); + _off(el, 'dragstart', this._onDragStart); + } this._offUpEvents(); @@ -698,7 +705,9 @@ ghostEl && ghostEl.parentNode.removeChild(ghostEl); if (dragEl) { - _off(dragEl, 'dragend', this); + if (this.nativeDragMode) { + _off(dragEl, 'dragend', this); + } _disableDraggable(dragEl); _toggleClass(dragEl, this.options.ghostClass, false); @@ -873,8 +882,10 @@ _off(el, 'mousedown', this._onTapStart); _off(el, 'touchstart', this._onTapStart); - _off(el, 'dragover', this); - _off(el, 'dragenter', this); + if (this.nativeDragMode) { + _off(el, 'dragover', this); + _off(el, 'dragenter', this); + } // Remove draggable attributes Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {