2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2017-02-14 16:14:40 -08:00
|
|
|
import {Inject, Injectable} from '@angular/core';
|
|
|
|
|
|
|
|
|
|
import {DOCUMENT} from '../dom_tokens';
|
|
|
|
|
|
2016-04-28 17:50:03 -07:00
|
|
|
import {EventManagerPlugin} from './event_manager';
|
2015-11-17 15:24:36 -08:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class DomEventsPlugin extends EventManagerPlugin {
|
2017-02-14 16:14:40 -08:00
|
|
|
constructor(@Inject(DOCUMENT) doc: any) { super(doc); }
|
|
|
|
|
|
2015-11-17 15:24:36 -08:00
|
|
|
// This plugin should come last in the list of plugins, because it accepts all
|
|
|
|
|
// events.
|
|
|
|
|
supports(eventName: string): boolean { return true; }
|
|
|
|
|
|
2016-01-25 14:47:25 -08:00
|
|
|
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
|
2016-11-03 10:23:09 -07:00
|
|
|
element.addEventListener(eventName, handler as any, false);
|
|
|
|
|
return () => element.removeEventListener(eventName, handler as any, false);
|
2015-11-17 15:24:36 -08:00
|
|
|
}
|
|
|
|
|
}
|