diff --git a/Sortable.js b/Sortable.js index d3b102e..32143a8 100644 --- a/Sortable.js +++ b/Sortable.js @@ -323,8 +323,8 @@ nextEl = dragEl.nextSibling; activeGroup = options.group; - this._lastX = evt.clientX; - this._lastY = evt.clientY; + this._lastX = (touch||evt).clientX; + this._lastY = (touch||evt).clientY; dragStartFn = function () { // Delayed drag has been triggered @@ -466,16 +466,18 @@ _onTouchMove: function (/**TouchEvent*/evt) { + if (tapEvt) { - 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; + var touch = evt.touches ? evt.touches[0] : 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(touch.clientX - this._lastX) > this.options.distance || Math.abs(touch.clientY - this._lastY) > this.options.distance)) { + return; + } } - } - if (tapEvt) { // only set the status to dragging, when we are actually dragging if (!Sortable.active) { this._dragStarted(); @@ -484,8 +486,7 @@ // as well as creating the ghost element on the document body this._appendGhost(); - var touch = evt.touches ? evt.touches[0] : evt, - dx = touch.clientX - tapEvt.clientX, + var dx = touch.clientX - tapEvt.clientX, dy = touch.clientY - tapEvt.clientY, translate3d = evt.touches ? 'translate3d(' + dx + 'px,' + dy + 'px,0)' : 'translate(' + dx + 'px,' + dy + 'px)';