Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #17 from azakus/ms
Browse files Browse the repository at this point in the history
Enable IE 10 support, use MSPointerEvents as source
  • Loading branch information
Steve Orvell committed Nov 1, 2012
2 parents e08c4b1 + 8e983c9 commit dd4a5cb
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/pointerevents.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions samples/paint/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
}
canvas {
-ms-touch-action: none;
touch-action: none;
background: lightgreen;
margin: 0 auto;
overflow: hidden;
Expand Down
2 changes: 2 additions & 0 deletions samples/simple/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
}
body {
overflow: auto;
-ms-touch-action: none;
touch-action: none;
}
#capture {
background-color: orange;
Expand Down
2 changes: 2 additions & 0 deletions samples/spaceship/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
body {
background-color: #000000;
margin: 0px;
-ms-touch-action: none;
touch-action: none;
}
canvas {
display:block;
Expand Down
2 changes: 2 additions & 0 deletions samples/tracker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
body {
background-color: #000000;
margin: 0px;
-ms-touch-action: none;
touch-action: none;
}
canvas {
background-color:#111133;
Expand Down
8 changes: 6 additions & 2 deletions src/PointerEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ function PointerEvent(inType, inDict) {
//
// {e}->{PointerEvent}->{MouseEvent}->{UIEvent}...
var e = document.createEvent('MouseEvent');
e.__proto__ = PointerEvent.prototype;
e.initPointerEvent(inType, inDict);
if (Object.__proto__) {
e.__proto__ = PointerEvent.prototype;
e.initPointerEvent(inType, inDict);
} else {
PointerEvent.prototype.initPointerEvent.call(e, inType, inDict);
}
return e;
};

Expand Down
57 changes: 55 additions & 2 deletions src/platform-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
findTarget: function(inEvent) {
// TODO (dfreedman): support shadow.elementFromPoint here, when available
return document.elementFromPoint(inEvent.clientX, inEvent.clientY);
return document.elementFromPoint(inEvent.clientX, inEvent.clientY) || document;
},
touchstart: function(inEvent) {
if (this.firstTouch === null) {
Expand Down Expand Up @@ -156,6 +156,53 @@
}
};

var msEvents = {
events: [
'MSPointerDown',
'MSPointerMove',
'MSPointerUp',
'MSPointerOut',
'MSPointerOver',
'MSPointerCancel'
],
POINTER_TYPES: [
'NOT USED',
'unavailable',
'touch',
'pen',
'mouse'
],
prepareEvent: function(inEvent) {
var e = dispatcher.cloneEvent(inEvent);
e.pointerType = this.POINTER_TYPES[inEvent.pointerType];
return e;
},
MSPointerDown: function(inEvent) {
var e = this.prepareEvent(inEvent);
dispatcher.down(e);
},
MSPointerMove: function(inEvent) {
var e = this.prepareEvent(inEvent);
dispatcher.move(e);
},
MSPointerUp: function(inEvent) {
var e = this.prepareEvent(inEvent);
dispatcher.up(e);
},
MSPointerOut: function(inEvent) {
var e = this.prepareEvent(inEvent);
dispatcher.out(e);
},
MSPointerOver: function(inEvent) {
var e = this.prepareEvent(inEvent);
dispatcher.over(e);
},
MSPointerCancel: function(inEvent) {
var e = this.prepareEvent(inEvent);
dispatcher.cancel(e);
}
}

// only activate if this platform does not have pointer events
if (window.navigator.pointerEnabled === undefined) {
// We fork the initialization of dispatcher event listeners here because
Expand All @@ -172,11 +219,17 @@
//
// Therefore we choose to only listen to native touch events if they exist.

if ('ontouchstart' in window) {
if (window.navigator.msPointerEnabled) {
dispatcher.registerSource('ms', msEvents);
if (window.navigator.msMaxTouchPoints !== undefined) {
Object.defineProperty(window.navigator, 'maxTouchPoints', {value: window.navigator.msMaxTouchPoints, enumerable: true});
}
} else if ('ontouchstart' in window) {
dispatcher.registerSource('touch', touchEvents);
} else {
dispatcher.registerSource('mouse', mouseEvents);
}

dispatcher.registerTarget(document);
Object.defineProperty(window.navigator, 'pointerEnabled', {value: true, enumerable: true});
}
Expand Down

0 comments on commit dd4a5cb

Please sign in to comment.