Browse Source

"distance" option, touch

pull/590/head
sp-kilobug 9 years ago
parent
commit
918501cd57
  1. 23
      Sortable.js

23
Sortable.js

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

Loading…
Cancel
Save