Browse Source

Merge pull request #49 from dapetcu21/master

IE10+ Touch support
pull/51/head
Lebedev Konstantin 11 years ago
parent
commit
4f0c057cd7
  1. 1
      .gitignore
  2. 44
      Sortable.js
  3. 3
      Sortable.min.js

1
.gitignore vendored

@ -1,2 +1,3 @@
node_modules
mock.png
.*.sw*

44
Sortable.js

@ -55,6 +55,11 @@
, slice = [].slice
, touchDragOverListeners = []
, pointerdown
, pointerup
, pointermove
, pointercancel
;
@ -92,6 +97,18 @@
}
}
// Detect IE10/IE11+
if (window.onpointerdown !== undefined) {
pointerdown = 'pointerdown';
pointerup = 'pointerup';
pointermove = 'pointermove';
pointercancel = 'pointercancel';
} else {
pointerdown = 'MSPointerDown';
pointerup = 'MSPointerUp';
pointermove = 'MSPointerMove';
pointercancel = 'MSPointerCancel';
}
// Bind events
_on(el, 'add', options.onAdd);
@ -104,6 +121,10 @@
_on(el, 'dragover', this._onDragOver);
_on(el, 'dragenter', this._onDragOver);
_on(el, pointerdown, this._onTapStart);
_css(el, 'touch-action', 'none');
_css(el, '-ms-touch-action', 'none');
touchDragOverListeners.push(this._onDragOver);
}
@ -118,7 +139,7 @@
},
_onTapStart: function (evt/**Event|TouchEvent*/){
_onTapStart: function (evt/**Event|TouchEvent|PointerEvent*/){
var
touch = evt.touches && evt.touches[0]
, target = (touch || evt).target
@ -158,7 +179,11 @@
this._onDragStart(tapEvt, true);
evt.preventDefault();
}
if (evt.type == 'pointerdown' || evt.type == 'MSPointerDown') {
this._onDragStart(tapEvt, true);
evt.preventDefault();
}
_on(this.el, 'dragstart', this._onDragStart);
_on(this.el, 'dragend', this._onDrop);
@ -211,7 +236,7 @@
},
_onTouchMove: function (evt/**TouchEvent*/){
_onTouchMove: function (evt/**TouchEvent|PointerEvent*/){
if( tapEvt ){
var
touch = evt.touches[0]
@ -221,6 +246,10 @@
touchEvt = touch;
_css(ghostEl, 'webkitTransform', 'translate3d('+dx+'px,'+dy+'px,0)');
_css(ghostEl, 'mozTransform', 'translate3d('+dx+'px,'+dy+'px,0)');
_css(ghostEl, 'msTransform', 'translate3d('+dx+'px,'+dy+'px,0)');
_css(ghostEl, 'transform', 'translate3d('+dx+'px,'+dy+'px,0)');
evt.preventDefault();
}
},
@ -263,6 +292,10 @@
// Bind touch events
_on(document, 'touchmove', this._onTouchMove);
_on(document, 'touchend', this._onDrop);
_on(document, 'touchcancel', this._onDrop);
_on(document, pointermove, this._onTouchMove);
_on(document, pointerup, this._onDrop);
_on(document, pointercancel, this._onDrop);
this._loopId = setInterval(this._emulateDragOver, 150);
}
@ -339,6 +372,10 @@
_off(document, 'touchmove', this._onTouchMove);
_off(document, 'touchend', this._onDrop);
_off(document, 'touchcancel', this._onDrop);
_off(document, pointermove, this._onTouchMove);
_off(document, pointerup, this._onDrop);
_off(document, pointercancel, this._onDrop);
if( evt ){
@ -393,6 +430,7 @@
_off(el, 'mousedown', this._onTapStart);
_off(el, 'touchstart', this._onTapStart);
_off(el, 'selectstart', this._onTapStart);
_off(el, pointerdown, this._onTapStart);
_off(el, 'dragover', this._onDragOver);
_off(el, 'dragenter', this._onDragOver);

3
Sortable.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save