From 446627298d3df79111c13d73193dd70260aa5c48 Mon Sep 17 00:00:00 2001 From: sp-kilobug Date: Sun, 4 Oct 2015 20:09:52 +0200 Subject: [PATCH] "distance" option An attempt to implement the "distance" option (like http://api.jqueryui.com/sortable/#option-distance). This is useful when your sortable element is also clickable. This prevents the drag to begin due to a micro-movement when you click. --- Sortable.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sortable.js b/Sortable.js index d767780..d3b102e 100644 --- a/Sortable.js +++ b/Sortable.js @@ -323,6 +323,9 @@ nextEl = dragEl.nextSibling; activeGroup = options.group; + this._lastX = evt.clientX; + this._lastY = evt.clientY; + dragStartFn = function () { // Delayed drag has been triggered // we can re-enable the events: touchmove/mousemove @@ -463,6 +466,15 @@ _onTouchMove: function (/**TouchEvent*/evt) { + + if (this.options.distance && this.options.distance > 0) { + // sorting will not start until mouse is dragged at a minimum distance + // this is used to prevent unwanted move during a simple click on a sortable element + if (!Sortable.active && !(Math.abs(evt.clientX - this._lastX) > this.options.distance || Math.abs(evt.clientY - this._lastY) > this.options.distance)) { + return; + } + } + if (tapEvt) { // only set the status to dragging, when we are actually dragging if (!Sortable.active) {