Permalink
Browse files

fix pointercapture throws on IE 10

  • Loading branch information...
azakus committed May 1, 2013
1 parent 8ecb169 commit d338d9fc314961650c418101d4603b2a3a8c0302
Showing with 23 additions and 14 deletions.
  1. +17 −14 src/capture.js
  2. +6 −0 src/platform-events.js
View
@@ -8,25 +8,28 @@
var dispatcher = scope.dispatcher;
var n = window.navigator;
var s, r;
- var isDown = function(inId) {
- if (!dispatcher.pointermap.has(inId)) {
+ function assertDown(id) {
+ if (!dispatcher.pointermap.has(id)) {
throw new Error('InvalidPointerId');
}
- return true;
- };
+ }
if (n.msPointerEnabled) {
- s = Element.prototype.msSetPointerCapture;
- r = Element.prototype.msReleasePointerCapture;
+ s = function(pointerId) {
+ assertDown(pointerId);
+ this.msSetPointerCapture(pointerId);
+ };
+ r = function(pointerId) {
+ assertDown(pointerId);
+ this.msReleasePointerCapture(pointerId);
+ };
} else {
- s = function setPointerCapture(inPointerId) {
- if (isDown(inPointerId)) {
- dispatcher.setCapture(inPointerId, this);
- }
+ s = function setPointerCapture(pointerId) {
+ assertDown(pointerId);
+ dispatcher.setCapture(pointerId, this);
};
- r = function releasePointerCapture(inPointerId) {
- if (isDown(inPointerId)) {
- dispatcher.releaseCapture(inPointerId, this);
- }
+ r = function releasePointerCapture(pointerId) {
+ assertDown(pointerId);
+ dispatcher.releaseCapture(pointerId, this);
};
}
if (!Element.prototype.setPointerCapture) {
View
@@ -331,7 +331,11 @@
e.pointerType = this.POINTER_TYPES[inEvent.pointerType];
return e;
},
+ cleanup: function(id) {
+ pointermap.delete(id);
+ },
MSPointerDown: function(inEvent) {
+ pointermap.set(inEvent.pointerId, inEvent);
var e = this.prepareEvent(inEvent);
dispatcher.down(e);
},
@@ -342,6 +346,7 @@
MSPointerUp: function(inEvent) {
var e = this.prepareEvent(inEvent);
dispatcher.up(e);
+ this.cleanup(inEvent.pointerId);
},
MSPointerOut: function(inEvent) {
var e = this.prepareEvent(inEvent);
@@ -354,6 +359,7 @@
MSPointerCancel: function(inEvent) {
var e = this.prepareEvent(inEvent);
dispatcher.cancel(e);
+ this.cleanup(inEvent.pointerId);
},
MSLostPointerCapture: function(inEvent) {
var e = dispatcher.makeEvent('lostpointercapture', inEvent);

0 comments on commit d338d9f

Please sign in to comment.