| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- "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 TieredMenuSub = /** @class */ (function () {
- function TieredMenuSub(tieredMenu, cf, renderer) {
- this.cf = cf;
- this.renderer = renderer;
- this.autoZIndex = true;
- this.baseZIndex = 0;
- this.tieredMenu = tieredMenu;
- }
- Object.defineProperty(TieredMenuSub.prototype, "parentActive", {
- get: function () {
- return this._parentActive;
- },
- set: function (value) {
- this._parentActive = value;
- if (!value) {
- this.activeItem = null;
- }
- },
- enumerable: true,
- configurable: true
- });
- TieredMenuSub.prototype.ngAfterViewInit = function () {
- if (this.root && !this.tieredMenu.popup) {
- this.bindDocumentClickListener();
- }
- };
- TieredMenuSub.prototype.onItemMouseEnter = function (event, item, menuitem) {
- if (this.tieredMenu.popup || (!this.root || this.activeItem)) {
- if (menuitem.disabled) {
- return;
- }
- this.activeItem = item;
- var nextElement = item.children[0].nextElementSibling;
- if (nextElement) {
- var sublist = nextElement.children[0];
- if (this.autoZIndex) {
- sublist.style.zIndex = String(this.baseZIndex + (++domhandler_1.DomHandler.zindex));
- }
- sublist.style.zIndex = String(++domhandler_1.DomHandler.zindex);
- sublist.style.top = '0px';
- sublist.style.left = domhandler_1.DomHandler.getOuterWidth(item.children[0]) + 'px';
- }
- }
- };
- TieredMenuSub.prototype.itemClick = function (event, item, menuitem) {
- if (menuitem.disabled) {
- event.preventDefault();
- return true;
- }
- if (!menuitem.url) {
- event.preventDefault();
- }
- if (menuitem.command) {
- menuitem.command({
- originalEvent: event,
- item: item
- });
- }
- if (this.root && !this.activeItem && !this.tieredMenu.popup) {
- this.activeItem = item;
- var nextElement = item.children[0].nextElementSibling;
- if (nextElement) {
- var sublist = nextElement.children[0];
- if (this.autoZIndex) {
- sublist.style.zIndex = String(this.baseZIndex + (++domhandler_1.DomHandler.zindex));
- }
- sublist.style.zIndex = String(++domhandler_1.DomHandler.zindex);
- sublist.style.top = '0px';
- sublist.style.left = domhandler_1.DomHandler.getOuterWidth(item.children[0]) + 'px';
- this.rootItemClick = true;
- }
- }
- if (!menuitem.items && this.tieredMenu.popup) {
- this.tieredMenu.hide();
- }
- };
- TieredMenuSub.prototype.listClick = function (event) {
- if (!this.rootItemClick) {
- this.activeItem = null;
- }
- };
- TieredMenuSub.prototype.bindDocumentClickListener = function () {
- var _this = this;
- if (!this.documentClickListener) {
- this.documentClickListener = this.renderer.listen('document', 'click', function () {
- if (!_this.rootItemClick) {
- _this.parentActive = false;
- _this.activeItem = null;
- }
- _this.rootItemClick = false;
- });
- }
- };
- TieredMenuSub.prototype.unbindDocumentClickListener = function () {
- if (this.documentClickListener) {
- this.documentClickListener();
- this.documentClickListener = null;
- }
- };
- TieredMenuSub.prototype.ngOnDestroy = function () {
- if (this.root && !this.tieredMenu.popup) {
- this.unbindDocumentClickListener();
- }
- };
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], TieredMenuSub.prototype, "item", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], TieredMenuSub.prototype, "root", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], TieredMenuSub.prototype, "autoZIndex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], TieredMenuSub.prototype, "baseZIndex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean),
- __metadata("design:paramtypes", [Object])
- ], TieredMenuSub.prototype, "parentActive", null);
- TieredMenuSub = __decorate([
- core_1.Component({
- selector: 'p-tieredMenuSub',
- template: "\n <ul [ngClass]=\"{'ui-widget-content ui-corner-all ui-shadow ui-submenu-list': !root}\" (click)=\"listClick($event)\">\n <ng-template ngFor let-child [ngForOf]=\"(root ? item : item.items)\">\n <li *ngIf=\"child.separator\" class=\"ui-menu-separator ui-widget-content\" [ngClass]=\"{'ui-helper-hidden': child.visible === false}\">\n <li *ngIf=\"!child.separator\" #listItem [ngClass]=\"{'ui-menuitem ui-widget ui-corner-all':true,'ui-menuitem-active':listItem==activeItem,'ui-helper-hidden': child.visible === false}\"\n [class]=\"child.styleClass\" [ngStyle]=\"child.style\"\n (mouseenter)=\"onItemMouseEnter($event, listItem, child)\">\n <a *ngIf=\"!child.routerLink\" [attr.href]=\"child.url\" class=\"ui-menuitem-link ui-corner-all\" [attr.target]=\"child.target\" [attr.tabindex]=\"child.tabindex ? child.tabindex : '0'\" [attr.title]=\"child.title\" [attr.id]=\"child.id\" \n [ngClass]=\"{'ui-state-disabled':child.disabled}\" (click)=\"itemClick($event, listItem, child)\">\n <span class=\"ui-menuitem-icon\" *ngIf=\"child.icon\" [ngClass]=\"child.icon\"></span>\n <span class=\"ui-menuitem-text\">{{child.label}}</span>\n <span class=\"ui-submenu-icon pi pi-fw pi-caret-right\" *ngIf=\"child.items\"></span>\n </a>\n <a *ngIf=\"child.routerLink\" [routerLink]=\"child.routerLink\" [queryParams]=\"child.queryParams\" [routerLinkActive]=\"'ui-state-active'\" [attr.tabindex]=\"child.tabindex ? child.tabindex : '0'\"\n [routerLinkActiveOptions]=\"child.routerLinkActiveOptions||{exact:false}\"\n class=\"ui-menuitem-link ui-corner-all\" [attr.target]=\"child.target\" [attr.title]=\"child.title\" [attr.id]=\"child.id\"\n [ngClass]=\"{'ui-state-disabled':child.disabled}\" (click)=\"itemClick($event, listItem, child)\">\n \n <span class=\"ui-menuitem-icon\" *ngIf=\"child.icon\" [ngClass]=\"child.icon\"></span>\n <span class=\"ui-menuitem-text\">{{child.label}}</span>\n <span class=\"ui-submenu-icon pi pi-fw pi-caret-right\" *ngIf=\"child.items\"></span>\n </a>\n <p-tieredMenuSub class=\"ui-submenu\" [item]=\"child\" *ngIf=\"child.items\" [baseZIndex]=\"baseZIndex\" [parentActive]=\"listItem==activeItem\" [autoZIndex]=\"autoZIndex\"></p-tieredMenuSub>\n </li>\n </ng-template>\n </ul>\n "
- }),
- __param(0, core_1.Inject(core_1.forwardRef(function () { return TieredMenu; }))),
- __metadata("design:paramtypes", [Object, core_1.ChangeDetectorRef, core_1.Renderer2])
- ], TieredMenuSub);
- return TieredMenuSub;
- }());
- exports.TieredMenuSub = TieredMenuSub;
- var TieredMenu = /** @class */ (function () {
- function TieredMenu(el, renderer) {
- this.el = el;
- this.renderer = renderer;
- this.autoZIndex = true;
- this.baseZIndex = 0;
- this.showTransitionOptions = '225ms ease-out';
- this.hideTransitionOptions = '195ms ease-in';
- }
- TieredMenu.prototype.toggle = function (event) {
- if (this.visible)
- this.hide();
- else
- this.show(event);
- this.preventDocumentDefault = true;
- };
- TieredMenu.prototype.show = function (event) {
- this.target = event.currentTarget;
- this.visible = true;
- this.parentActive = true;
- this.preventDocumentDefault = true;
- };
- TieredMenu.prototype.onOverlayAnimationStart = function (event) {
- switch (event.toState) {
- case 'visible':
- if (this.popup) {
- this.container = event.element;
- this.moveOnTop();
- this.appendOverlay();
- domhandler_1.DomHandler.absolutePosition(this.container, this.target);
- this.bindDocumentClickListener();
- this.bindDocumentResizeListener();
- }
- break;
- case 'void':
- this.onOverlayHide();
- break;
- }
- };
- TieredMenu.prototype.appendOverlay = function () {
- if (this.appendTo) {
- if (this.appendTo === 'body')
- document.body.appendChild(this.container);
- else
- domhandler_1.DomHandler.appendChild(this.container, this.appendTo);
- }
- };
- TieredMenu.prototype.restoreOverlayAppend = function () {
- if (this.container && this.appendTo) {
- this.el.nativeElement.appendChild(this.container);
- }
- };
- TieredMenu.prototype.moveOnTop = function () {
- if (this.autoZIndex) {
- this.container.style.zIndex = String(this.baseZIndex + (++domhandler_1.DomHandler.zindex));
- }
- };
- TieredMenu.prototype.hide = function () {
- this.visible = false;
- this.parentActive = false;
- };
- TieredMenu.prototype.onWindowResize = function () {
- this.hide();
- };
- TieredMenu.prototype.bindDocumentClickListener = function () {
- var _this = this;
- if (!this.documentClickListener) {
- this.documentClickListener = this.renderer.listen('document', 'click', function () {
- if (!_this.preventDocumentDefault && _this.popup) {
- _this.hide();
- }
- _this.preventDocumentDefault = false;
- });
- }
- };
- TieredMenu.prototype.unbindDocumentClickListener = function () {
- if (this.documentClickListener) {
- this.documentClickListener();
- this.documentClickListener = null;
- }
- };
- TieredMenu.prototype.bindDocumentResizeListener = function () {
- this.documentResizeListener = this.onWindowResize.bind(this);
- window.addEventListener('resize', this.documentResizeListener);
- };
- TieredMenu.prototype.unbindDocumentResizeListener = function () {
- if (this.documentResizeListener) {
- window.removeEventListener('resize', this.documentResizeListener);
- this.documentResizeListener = null;
- }
- };
- TieredMenu.prototype.onOverlayHide = function () {
- this.unbindDocumentClickListener();
- this.unbindDocumentResizeListener();
- this.preventDocumentDefault = false;
- this.target = null;
- };
- TieredMenu.prototype.ngOnDestroy = function () {
- if (this.popup) {
- this.restoreOverlayAppend();
- this.onOverlayHide();
- }
- };
- __decorate([
- core_1.Input(),
- __metadata("design:type", Array)
- ], TieredMenu.prototype, "model", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], TieredMenu.prototype, "popup", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], TieredMenu.prototype, "style", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], TieredMenu.prototype, "styleClass", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], TieredMenu.prototype, "appendTo", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], TieredMenu.prototype, "autoZIndex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], TieredMenu.prototype, "baseZIndex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], TieredMenu.prototype, "showTransitionOptions", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], TieredMenu.prototype, "hideTransitionOptions", void 0);
- TieredMenu = __decorate([
- core_1.Component({
- selector: 'p-tieredMenu',
- template: "\n <div [ngClass]=\"{'ui-tieredmenu ui-widget ui-widget-content ui-corner-all':true, 'ui-tieredmenu-dynamic ui-shadow':popup}\" [class]=\"styleClass\" [ngStyle]=\"style\"\n [@overlayAnimation]=\"{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}\" [@.disabled]=\"popup !== true\" (@overlayAnimation.start)=\"onOverlayAnimationStart($event)\" *ngIf=\"!popup || visible\">\n <p-tieredMenuSub [item]=\"model\" root=\"root\" [parentActive]=\"parentActive\" [baseZIndex]=\"baseZIndex\" [autoZIndex]=\"autoZIndex\"></p-tieredMenuSub>\n </div>\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])
- ], TieredMenu);
- return TieredMenu;
- }());
- exports.TieredMenu = TieredMenu;
- var TieredMenuModule = /** @class */ (function () {
- function TieredMenuModule() {
- }
- TieredMenuModule = __decorate([
- core_1.NgModule({
- imports: [common_1.CommonModule, router_1.RouterModule],
- exports: [TieredMenu, router_1.RouterModule],
- declarations: [TieredMenu, TieredMenuSub]
- })
- ], TieredMenuModule);
- return TieredMenuModule;
- }());
- exports.TieredMenuModule = TieredMenuModule;
- //# sourceMappingURL=tieredmenu.js.map
|