@progress/kendo-angular-common
Version:
Kendo UI for Angular - Utility Package
58 lines (57 loc) • 2.14 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2020 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import * as tslib_1 from "tslib";
import { Directive, ElementRef, Input, Renderer2, NgZone } from '@angular/core';
/* tslint:disable:no-input-rename */
/**
* @hidden
*/
let EventsOutsideAngularDirective = class EventsOutsideAngularDirective {
constructor(element, ngZone, renderer) {
this.element = element;
this.ngZone = ngZone;
this.renderer = renderer;
this.events = {};
}
ngOnInit() {
if (!this.element || !this.element.nativeElement) {
return;
}
const events = this.events;
this.subscriptions = [];
this.ngZone.runOutsideAngular(() => {
for (let name in events) {
if (events.hasOwnProperty(name)) {
this.subscriptions.push(this.renderer.listen(this.element.nativeElement, name, this.scope ? events[name].bind(this.scope) : events[name]));
}
}
});
}
ngOnDestroy() {
if (this.subscriptions) {
for (let idx = 0; idx < this.subscriptions.length; idx++) {
this.subscriptions[idx]();
}
this.subscriptions = null;
}
}
};
tslib_1.__decorate([
Input('kendoEventsOutsideAngular'),
tslib_1.__metadata("design:type", Object)
], EventsOutsideAngularDirective.prototype, "events", void 0);
tslib_1.__decorate([
Input(),
tslib_1.__metadata("design:type", Object)
], EventsOutsideAngularDirective.prototype, "scope", void 0);
EventsOutsideAngularDirective = tslib_1.__decorate([
Directive({
selector: '[kendoEventsOutsideAngular]'
}),
tslib_1.__metadata("design:paramtypes", [ElementRef,
NgZone,
Renderer2])
], EventsOutsideAngularDirective);
export { EventsOutsideAngularDirective };