Skip to content

Commit

Permalink
Merge branch 'visiongeist-fix-msPointerEvent-detection'
Browse files Browse the repository at this point in the history
  • Loading branch information
cubiq committed Jun 2, 2014
2 parents 74e4b09 + a7f19e5 commit 3b0cfde
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,10 @@ IScroll.prototype = {
}

if ( utils.hasPointer && !this.options.disablePointer ) {
eventType(this.wrapper, 'MSPointerDown', this);
eventType(target, 'MSPointerMove', this);
eventType(target, 'MSPointerCancel', this);
eventType(target, 'MSPointerUp', this);
eventType(this.wrapper, utils.prefixPointerEvent('pointerdown'), this);
eventType(target, utils.prefixPointerEvent('pointermove'), this);
eventType(target, utils.prefixPointerEvent('pointercancel'), this);
eventType(target, utils.prefixPointerEvent('pointerup'), this);
}

if ( utils.hasTouch && !this.options.disableTouch ) {
Expand Down
4 changes: 4 additions & 0 deletions src/default/handleEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
handleEvent: function (e) {
switch ( e.type ) {
case 'touchstart':
case 'pointerdown':
case 'MSPointerDown':
case 'mousedown':
this._start(e);
break;
case 'touchmove':
case 'pointermove':
case 'MSPointerMove':
case 'mousemove':
this._move(e);
break;
case 'touchend':
case 'pointerup':
case 'MSPointerUp':
case 'mouseup':
case 'touchcancel':
case 'pointercancel':
case 'MSPointerCancel':
case 'mousecancel':
this._end(e);
Expand Down
18 changes: 11 additions & 7 deletions src/indicator/indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function Indicator (scroller, options) {
utils.addEvent(window, 'touchend', this);
}
if ( !this.options.disablePointer ) {
utils.addEvent(this.indicator, 'MSPointerDown', this);
utils.addEvent(window, 'MSPointerUp', this);
utils.addEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this);
utils.addEvent(window, utils.prefixPointerEvent('pointerup'), this);
}
if ( !this.options.disableMouse ) {
utils.addEvent(this.indicator, 'mousedown', this);
Expand All @@ -89,19 +89,23 @@ Indicator.prototype = {
handleEvent: function (e) {
switch ( e.type ) {
case 'touchstart':
case 'pointerdown':
case 'MSPointerDown':
case 'mousedown':
this._start(e);
break;
case 'touchmove':
case 'pointermove':
case 'MSPointerMove':
case 'mousemove':
this._move(e);
break;
case 'touchend':
case 'pointerup':
case 'MSPointerUp':
case 'mouseup':
case 'touchcancel':
case 'pointercancel':
case 'MSPointerCancel':
case 'mousecancel':
this._end(e);
Expand All @@ -112,15 +116,15 @@ Indicator.prototype = {
destroy: function () {
if ( this.options.interactive ) {
utils.removeEvent(this.indicator, 'touchstart', this);
utils.removeEvent(this.indicator, 'MSPointerDown', this);
utils.removeEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this);
utils.removeEvent(this.indicator, 'mousedown', this);

utils.removeEvent(window, 'touchmove', this);
utils.removeEvent(window, 'MSPointerMove', this);
utils.removeEvent(window, utils.prefixPointerEvent('pointermove'), this);
utils.removeEvent(window, 'mousemove', this);

utils.removeEvent(window, 'touchend', this);
utils.removeEvent(window, 'MSPointerUp', this);
utils.removeEvent(window, utils.prefixPointerEvent('pointerup'), this);
utils.removeEvent(window, 'mouseup', this);
}

Expand Down Expand Up @@ -148,7 +152,7 @@ Indicator.prototype = {
utils.addEvent(window, 'touchmove', this);
}
if ( !this.options.disablePointer ) {
utils.addEvent(window, 'MSPointerMove', this);
utils.addEvent(window, utils.prefixPointerEvent('pointermove'), this);
}
if ( !this.options.disableMouse ) {
utils.addEvent(window, 'mousemove', this);
Expand Down Expand Up @@ -197,7 +201,7 @@ Indicator.prototype = {
e.stopPropagation();

utils.removeEvent(window, 'touchmove', this);
utils.removeEvent(window, 'MSPointerMove', this);
utils.removeEvent(window, utils.prefixPointerEvent('pointermove'), this);
utils.removeEvent(window, 'mousemove', this);

if ( this.scroller.options.snap ) {
Expand Down
12 changes: 11 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ var utils = (function () {
el.removeEventListener(type, fn, !!capture);
};

me.prefixPointerEvent = function (pointerEvent) {
return window.MSPointerEvent ?
'MSPointer' + pointerEvent.charAt(9).toUpperCase() + pointerEvent.substr(10):
pointerEvent;
};

me.momentum = function (current, start, time, lowerMargin, wrapperSize, deceleration) {
var distance = current - start,
speed = Math.abs(distance) / time,
Expand Down Expand Up @@ -78,7 +84,7 @@ var utils = (function () {
hasTransform: _transform !== false,
hasPerspective: _prefixStyle('perspective') in _elementStyle,
hasTouch: 'ontouchstart' in window,
hasPointer: navigator.msPointerEnabled,
hasPointer: window.PointerEvent || window.MSPointerEvent, // IE10 is prefixed
hasTransition: _prefixStyle('transition') in _elementStyle
});

Expand Down Expand Up @@ -153,6 +159,10 @@ var utils = (function () {
mousemove: 2,
mouseup: 2,

pointerdown: 3,
pointermove: 3,
pointerup: 3,

MSPointerDown: 3,
MSPointerMove: 3,
MSPointerUp: 3
Expand Down
4 changes: 4 additions & 0 deletions src/zoom/handleEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
handleEvent: function (e) {
switch ( e.type ) {
case 'touchstart':
case 'pointerdown':
case 'MSPointerDown':
case 'mousedown':
this._start(e);
Expand All @@ -11,6 +12,7 @@
}
break;
case 'touchmove':
case 'pointermove':
case 'MSPointerMove':
case 'mousemove':
if ( this.options.zoom && e.touches && e.touches[1] ) {
Expand All @@ -20,9 +22,11 @@
this._move(e);
break;
case 'touchend':
case 'pointerup':
case 'MSPointerUp':
case 'mouseup':
case 'touchcancel':
case 'pointercancel':
case 'MSPointerCancel':
case 'mousecancel':
if ( this.scaled ) {
Expand Down

0 comments on commit 3b0cfde

Please sign in to comment.