Skip to content

Commit 7f589e0

Browse files
committed
fix(event): in IE, fix #1128, angular#589, pointer event will be transformed in IE
1 parent 9c96904 commit 7f589e0

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

lib/common/events.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,26 @@
1010
* @suppress {missingRequire}
1111
*/
1212

13-
import {ADD_EVENT_LISTENER_STR, attachOriginToPatched, FALSE_STR, ObjectGetPrototypeOf, REMOVE_EVENT_LISTENER_STR, TRUE_STR, ZONE_SYMBOL_PREFIX, zoneSymbol} from './utils';
13+
import {ADD_EVENT_LISTENER_STR, attachOriginToPatched, FALSE_STR, isIEOrEdge, ObjectGetPrototypeOf, REMOVE_EVENT_LISTENER_STR, TRUE_STR, ZONE_SYMBOL_PREFIX, zoneSymbol} from './utils';
1414

1515
/** @internal **/
1616
interface EventTaskData extends TaskData {
1717
// use global callback or not
1818
readonly useG?: boolean;
1919
}
2020

21+
const pointerEventsMap: {[key: string]: string} = {
22+
'pointercancel': 'MSPointerCancel',
23+
'pointerdown': 'MSPointerDown',
24+
'pointerenter': 'MSPointerEnter',
25+
'pointerhover': 'MSPointerHover',
26+
'pointerleave': 'MSPointerLeave',
27+
'pointermove': 'MSPointerMove',
28+
'pointerout': 'MSPointerOut',
29+
'pointerover': 'MSPointerOver',
30+
'pointerup': 'MSPointerUp'
31+
};
32+
2133
let passiveSupported = false;
2234

2335
if (typeof window !== 'undefined') {
@@ -122,7 +134,12 @@ export function patchEventTarget(
122134
// event.target is needed for Samsung TV and SourceBuffer
123135
// || global is needed https://github.com/angular/zone.js/issues/190
124136
const target: any = this || event.target || _global;
125-
const tasks = target[zoneSymbolEventNames[event.type][FALSE_STR]];
137+
let tasks = target[zoneSymbolEventNames[event.type][FALSE_STR]];
138+
if (!tasks && isIEOrEdge) {
139+
const pointerMappedEvent = pointerEventsMap[event.type];
140+
tasks =
141+
pointerMappedEvent ? target[zoneSymbolEventNames[pointerMappedEvent]][FALSE_STR] : tasks;
142+
}
126143
if (tasks) {
127144
// invoke all tasks which attached to current target with given event.type and capture = false
128145
// for performance concern, if task.length === 1, just invoke
@@ -154,7 +171,12 @@ export function patchEventTarget(
154171
// event.target is needed for Samsung TV and SourceBuffer
155172
// || global is needed https://github.com/angular/zone.js/issues/190
156173
const target: any = this || event.target || _global;
157-
const tasks = target[zoneSymbolEventNames[event.type][TRUE_STR]];
174+
let tasks = target[zoneSymbolEventNames[event.type][TRUE_STR]];
175+
if (!tasks && isIEOrEdge) {
176+
const pointerMappedEvent = pointerEventsMap[event.type];
177+
tasks =
178+
pointerMappedEvent ? target[zoneSymbolEventNames[pointerMappedEvent]][TRUE_STR] : tasks;
179+
}
158180
if (tasks) {
159181
// invoke all tasks which attached to current target with given event.type and capture = false
160182
// for performance concern, if task.length === 1, just invoke

test/browser/browser.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,5 +2662,44 @@ describe('Zone', function() {
26622662
});
26632663
}));
26642664
});
2665+
2666+
describe(
2667+
'pointer event in IE',
2668+
ifEnvSupports(
2669+
() => {
2670+
return getIEVersion() === 10;
2671+
},
2672+
() => {
2673+
const pointerEventsMap: {[key: string]: string} = {
2674+
'pointercancel': 'MSPointerCancel',
2675+
'pointerdown': 'MSPointerDown',
2676+
'pointerenter': 'MSPointerEnter',
2677+
'pointerhover': 'MSPointerHover',
2678+
'pointerleave': 'MSPointerLeave',
2679+
'pointermove': 'MSPointerMove',
2680+
'pointerout': 'MSPointerOut',
2681+
'pointerover': 'MSPointerOver',
2682+
'pointerup': 'MSPointerUp'
2683+
};
2684+
let div: HTMLDivElement;
2685+
beforeEach(() => {
2686+
div = document.createElement('div');
2687+
document.body.appendChild(div);
2688+
});
2689+
afterEach(() => {
2690+
document.body.removeChild(div);
2691+
});
2692+
Object.keys(pointerEventsMap).forEach(key => {
2693+
it(`${key} should be registered as ${pointerEventsMap[key]}`, (done: DoneFn) => {
2694+
div.addEventListener(key, (event: any) => {
2695+
expect(event.type).toEqual(pointerEventsMap[key]);
2696+
done();
2697+
});
2698+
const evt = document.createEvent('Event');
2699+
evt.initEvent(key, true, true);
2700+
div.dispatchEvent(evt);
2701+
});
2702+
});
2703+
}));
26652704
});
26662705
});

0 commit comments

Comments
 (0)