UNPKG

ng2-events

Version:

Supercharge your Angular2+ event handling

57 lines (56 loc) 2.78 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.OutsideEventPlugin = void 0; var core_1 = require("@angular/core"); var event_manager_plugin_1 = require("../__util/event-manager-plugin"); var common_1 = require("@angular/common"); var i0 = require("@angular/core"); /** * Listen to events that are fired outside of the current element and its children * * Usage: * <div (outside.click)="close()"></div> * */ var OutsideEventPlugin = /** @class */ (function (_super) { __extends(OutsideEventPlugin, _super); function OutsideEventPlugin(doc) { return _super.call(this, doc) || this; } OutsideEventPlugin.prototype.supports = function (eventName) { return eventName.indexOf('outside.') === 0; }; OutsideEventPlugin.prototype.addEventListener = function (element, eventName, handler) { var realEventName = eventName.slice(8); return this.manager.addEventListener((element.ownerDocument || document), realEventName, function (e) { if (element !== e.target && !element.contains(e.target)) { handler(e); } }); }; OutsideEventPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.2", ngImport: i0, type: OutsideEventPlugin, deps: [{ token: common_1.DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); OutsideEventPlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.2", ngImport: i0, type: OutsideEventPlugin }); return OutsideEventPlugin; }(event_manager_plugin_1.MyEventManagerPlugin)); exports.OutsideEventPlugin = OutsideEventPlugin; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.2", ngImport: i0, type: OutsideEventPlugin, decorators: [{ type: core_1.Injectable }], ctorParameters: function () { return [{ type: undefined, decorators: [{ type: core_1.Inject, args: [common_1.DOCUMENT] }] }]; } });