"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var animations_1 = require("@angular/animations"); var common_1 = require("@angular/common"); var domhandler_1 = require("../dom/domhandler"); var router_1 = require("@angular/router"); var MenuItemContent = /** @class */ (function () { function MenuItemContent(menu) { this.menu = menu; } __decorate([ core_1.Input("pMenuItemContent"), __metadata("design:type", Object) ], MenuItemContent.prototype, "item", void 0); MenuItemContent = __decorate([ core_1.Component({ selector: '[pMenuItemContent]', template: "\n \n \n {{item.label}}\n \n \n \n {{item.label}}\n \n " }), __param(0, core_1.Inject(core_1.forwardRef(function () { return Menu; }))), __metadata("design:paramtypes", [Menu]) ], MenuItemContent); return MenuItemContent; }()); exports.MenuItemContent = MenuItemContent; var Menu = /** @class */ (function () { function Menu(el, renderer) { this.el = el; this.renderer = renderer; this.autoZIndex = true; this.baseZIndex = 0; this.showTransitionOptions = '225ms ease-out'; this.hideTransitionOptions = '195ms ease-in'; this.onShow = new core_1.EventEmitter(); this.onHide = new core_1.EventEmitter(); } Menu.prototype.toggle = function (event) { if (this.visible) this.hide(); else this.show(event); this.preventDocumentDefault = true; }; Menu.prototype.show = function (event) { this.target = event.currentTarget; this.visible = true; this.preventDocumentDefault = true; }; Menu.prototype.onOverlayAnimationStart = function (event) { switch (event.toState) { case 'visible': if (this.popup) { this.container = event.element; this.moveOnTop(); this.onShow.emit({}); this.appendOverlay(); domhandler_1.DomHandler.absolutePosition(this.container, this.target); this.bindDocumentClickListener(); this.bindDocumentResizeListener(); } break; case 'void': this.onOverlayHide(); this.onHide.emit({}); break; } }; Menu.prototype.appendOverlay = function () { if (this.appendTo) { if (this.appendTo === 'body') document.body.appendChild(this.container); else domhandler_1.DomHandler.appendChild(this.container, this.appendTo); } }; Menu.prototype.restoreOverlayAppend = function () { if (this.container && this.appendTo) { this.el.nativeElement.appendChild(this.container); } }; Menu.prototype.moveOnTop = function () { if (this.autoZIndex) { this.container.style.zIndex = String(this.baseZIndex + (++domhandler_1.DomHandler.zindex)); } }; Menu.prototype.hide = function () { this.visible = false; }; Menu.prototype.onWindowResize = function () { this.hide(); }; Menu.prototype.itemClick = function (event, item) { if (item.disabled) { event.preventDefault(); return; } if (!item.url) { event.preventDefault(); } if (item.command) { item.command({ originalEvent: event, item: item }); } if (this.popup) { this.hide(); } }; Menu.prototype.bindDocumentClickListener = function () { var _this = this; if (!this.documentClickListener) { this.documentClickListener = this.renderer.listen('document', 'click', function () { if (!_this.preventDocumentDefault) { _this.hide(); } _this.preventDocumentDefault = false; }); } }; Menu.prototype.unbindDocumentClickListener = function () { if (this.documentClickListener) { this.documentClickListener(); this.documentClickListener = null; } }; Menu.prototype.bindDocumentResizeListener = function () { this.documentResizeListener = this.onWindowResize.bind(this); window.addEventListener('resize', this.documentResizeListener); }; Menu.prototype.unbindDocumentResizeListener = function () { if (this.documentResizeListener) { window.removeEventListener('resize', this.documentResizeListener); this.documentResizeListener = null; } }; Menu.prototype.onOverlayHide = function () { this.unbindDocumentClickListener(); this.unbindDocumentResizeListener(); this.preventDocumentDefault = false; this.target = null; }; Menu.prototype.ngOnDestroy = function () { if (this.popup) { this.restoreOverlayAppend(); this.onOverlayHide(); } }; Menu.prototype.hasSubMenu = function () { if (this.model) { for (var _i = 0, _a = this.model; _i < _a.length; _i++) { var item = _a[_i]; if (item.items) { return true; } } } return false; }; __decorate([ core_1.Input(), __metadata("design:type", Array) ], Menu.prototype, "model", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], Menu.prototype, "popup", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], Menu.prototype, "style", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Menu.prototype, "styleClass", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], Menu.prototype, "appendTo", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], Menu.prototype, "autoZIndex", void 0); __decorate([ core_1.Input(), __metadata("design:type", Number) ], Menu.prototype, "baseZIndex", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Menu.prototype, "showTransitionOptions", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Menu.prototype, "hideTransitionOptions", void 0); __decorate([ core_1.ViewChild('container'), __metadata("design:type", core_1.ElementRef) ], Menu.prototype, "containerViewChild", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], Menu.prototype, "onShow", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], Menu.prototype, "onHide", void 0); Menu = __decorate([ core_1.Component({ selector: 'p-menu', template: "\n
\n \n
\n ", animations: [ animations_1.trigger('overlayAnimation', [ animations_1.state('void', animations_1.style({ transform: 'translateY(5%)', opacity: 0 })), animations_1.state('visible', animations_1.style({ transform: 'translateY(0)', opacity: 1 })), animations_1.transition('void => visible', animations_1.animate('{{showTransitionParams}}')), animations_1.transition('visible => void', animations_1.animate('{{hideTransitionParams}}')) ]) ] }), __metadata("design:paramtypes", [core_1.ElementRef, core_1.Renderer2]) ], Menu); return Menu; }()); exports.Menu = Menu; var MenuModule = /** @class */ (function () { function MenuModule() { } MenuModule = __decorate([ core_1.NgModule({ imports: [common_1.CommonModule, router_1.RouterModule], exports: [Menu, router_1.RouterModule], declarations: [Menu, MenuItemContent] }) ], MenuModule); return MenuModule; }()); exports.MenuModule = MenuModule; //# sourceMappingURL=menu.js.map