Skip to content

Commit

Permalink
chore(event): expose listenEvent and eventOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Nov 29, 2016
1 parent bdf02d4 commit 0af494e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/util/ui-event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,28 @@ export const enum PointerEventType {
}

// Test via a getter in the options object to see if the passive property is accessed
var supportsPassive = false;
var supportsOptions = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassive = true;
supportsOptions = true;
}
});
window.addEventListener('test', null, opts);
} catch (e) { }


export function eventOptions(useCapture = false, usePassive = false): any {
if (supportsOptions && usePassive) {
return {
capture: useCapture,
passive: usePassive
};
}
return useCapture;
}


/**
* @private
*/
Expand Down Expand Up @@ -180,7 +192,7 @@ export class UIEventManager {
}
let zone = config.zone || this.zoneWrapped;
let opts;
if (supportsPassive) {
if (supportsOptions) {
opts = {};
if (config.passive === true) {
opts['passive'] = true;
Expand Down Expand Up @@ -231,7 +243,7 @@ export class UIEventManager {
}
}

function listenEvent(ele: any, eventName: string, zoneWrapped: boolean, option: any, callback: any): Function {
export function listenEvent(ele: any, eventName: string, zoneWrapped: boolean, option: any, callback: any): Function {
let rawEvent = (!zoneWrapped && '__zone_symbol__addEventListener' in ele);
if (rawEvent) {
ele.__zone_symbol__addEventListener(eventName, callback, option);
Expand Down

0 comments on commit 0af494e

Please sign in to comment.