@progress/kendo-angular-common
Version:
Kendo UI for Angular - Utility Package
60 lines (59 loc) • 2.42 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
*/
var EventsOutsideAngularDirective = /** @class */ (function () {
function EventsOutsideAngularDirective(element, ngZone, renderer) {
this.element = element;
this.ngZone = ngZone;
this.renderer = renderer;
this.events = {};
}
EventsOutsideAngularDirective.prototype.ngOnInit = function () {
var _this = this;
if (!this.element || !this.element.nativeElement) {
return;
}
var events = this.events;
this.subscriptions = [];
this.ngZone.runOutsideAngular(function () {
for (var name_1 in events) {
if (events.hasOwnProperty(name_1)) {
_this.subscriptions.push(_this.renderer.listen(_this.element.nativeElement, name_1, _this.scope ? events[name_1].bind(_this.scope) : events[name_1]));
}
}
});
};
EventsOutsideAngularDirective.prototype.ngOnDestroy = function () {
if (this.subscriptions) {
for (var 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);
return EventsOutsideAngularDirective;
}());
export { EventsOutsideAngularDirective };