@progress/kendo-angular-common
Version:
Kendo UI for Angular - Utility Package
62 lines (61 loc) • 2.52 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2020 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var core_1 = require("@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([
core_1.Input('kendoEventsOutsideAngular'),
tslib_1.__metadata("design:type", Object)
], EventsOutsideAngularDirective.prototype, "events", void 0);
tslib_1.__decorate([
core_1.Input(),
tslib_1.__metadata("design:type", Object)
], EventsOutsideAngularDirective.prototype, "scope", void 0);
EventsOutsideAngularDirective = tslib_1.__decorate([
core_1.Directive({
selector: '[kendoEventsOutsideAngular]'
}),
tslib_1.__metadata("design:paramtypes", [core_1.ElementRef,
core_1.NgZone,
core_1.Renderer2])
], EventsOutsideAngularDirective);
return EventsOutsideAngularDirective;
}());
exports.EventsOutsideAngularDirective = EventsOutsideAngularDirective;