232 lines
14 KiB
JavaScript
232 lines
14 KiB
JavaScript
import { Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, Renderer2, ChangeDetectorRef, Input, ContentChildren, NgModule } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { PrimeTemplate } from 'primeng/api';
|
|
import { RouterModule } from '@angular/router';
|
|
import { RippleModule } from 'primeng/ripple';
|
|
|
|
class MegaMenu {
|
|
constructor(el, renderer, cd) {
|
|
this.el = el;
|
|
this.renderer = renderer;
|
|
this.cd = cd;
|
|
this.orientation = 'horizontal';
|
|
this.autoZIndex = true;
|
|
this.baseZIndex = 0;
|
|
}
|
|
ngAfterContentInit() {
|
|
this.templates.forEach((item) => {
|
|
switch (item.getType()) {
|
|
case 'start':
|
|
this.startTemplate = item.template;
|
|
break;
|
|
case 'end':
|
|
this.endTemplate = item.template;
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
onCategoryMouseEnter(event, menuitem) {
|
|
if (menuitem.disabled) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
if (this.activeItem) {
|
|
this.activeItem = menuitem;
|
|
}
|
|
}
|
|
onCategoryClick(event, item) {
|
|
if (item.disabled) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
if (!item.url) {
|
|
event.preventDefault();
|
|
}
|
|
if (item.command) {
|
|
item.command({
|
|
originalEvent: event,
|
|
item: item
|
|
});
|
|
}
|
|
if (item.items) {
|
|
if (this.activeItem && this.activeItem === item) {
|
|
this.activeItem = null;
|
|
this.unbindDocumentClickListener();
|
|
}
|
|
else {
|
|
this.activeItem = item;
|
|
this.bindDocumentClickListener();
|
|
}
|
|
}
|
|
}
|
|
itemClick(event, item) {
|
|
if (item.disabled) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
if (!item.url) {
|
|
event.preventDefault();
|
|
}
|
|
if (item.command) {
|
|
item.command({
|
|
originalEvent: event,
|
|
item: item
|
|
});
|
|
}
|
|
this.activeItem = null;
|
|
}
|
|
getColumnClass(menuitem) {
|
|
let length = menuitem.items ? menuitem.items.length : 0;
|
|
let columnClass;
|
|
switch (length) {
|
|
case 2:
|
|
columnClass = 'p-megamenu-col-6';
|
|
break;
|
|
case 3:
|
|
columnClass = 'p-megamenu-col-4';
|
|
break;
|
|
case 4:
|
|
columnClass = 'p-megamenu-col-3';
|
|
break;
|
|
case 6:
|
|
columnClass = 'p-megamenu-col-2';
|
|
break;
|
|
default:
|
|
columnClass = 'p-megamenu-col-12';
|
|
break;
|
|
}
|
|
return columnClass;
|
|
}
|
|
bindDocumentClickListener() {
|
|
if (!this.documentClickListener) {
|
|
this.documentClickListener = (event) => {
|
|
if (this.el && !this.el.nativeElement.contains(event.target)) {
|
|
this.activeItem = null;
|
|
this.unbindDocumentClickListener();
|
|
this.cd.markForCheck();
|
|
}
|
|
};
|
|
document.addEventListener('click', this.documentClickListener);
|
|
}
|
|
}
|
|
unbindDocumentClickListener() {
|
|
if (this.documentClickListener) {
|
|
document.removeEventListener('click', this.documentClickListener);
|
|
this.documentClickListener = null;
|
|
}
|
|
}
|
|
}
|
|
MegaMenu.decorators = [
|
|
{ type: Component, args: [{
|
|
selector: 'p-megaMenu',
|
|
template: `
|
|
<div [class]="styleClass" [ngStyle]="style"
|
|
[ngClass]="{'p-megamenu p-component':true,'p-megamenu-horizontal': orientation == 'horizontal','p-megamenu-vertical': orientation == 'vertical'}">
|
|
<div class="p-megamenu-start" *ngIf="startTemplate">
|
|
<ng-container *ngTemplateOutlet="startTemplate"></ng-container>
|
|
</div>
|
|
<ul class="p-megamenu-root-list" role="menubar">
|
|
<ng-template ngFor let-category [ngForOf]="model">
|
|
<li *ngIf="category.separator" class="p-menu-separator" [ngClass]="{'p-hidden': category.visible === false}">
|
|
<li *ngIf="!category.separator" [ngClass]="{'p-menuitem':true,'p-menuitem-active':category==activeItem, 'p-hidden': category.visible === false}"
|
|
(mouseenter)="onCategoryMouseEnter($event, category)">
|
|
<a *ngIf="!category.routerLink" [href]="category.url||'#'" [attr.target]="category.target" [attr.title]="category.title" [attr.id]="category.id" (click)="onCategoryClick($event, category)" [attr.tabindex]="category.tabindex ? category.tabindex : '0'"
|
|
[ngClass]="{'p-menuitem-link':true,'p-disabled':category.disabled}" [ngStyle]="category.style" [class]="category.styleClass" pRipple>
|
|
<span class="p-menuitem-icon" *ngIf="category.icon" [ngClass]="category.icon"></span>
|
|
<span class="p-menuitem-text" *ngIf="category.escape !== false; else categoryHtmlLabel">{{category.label}}</span>
|
|
<ng-template #categoryHtmlLabel><span class="p-menuitem-text" [innerHTML]="category.label"></span></ng-template>
|
|
<span *ngIf="category.items" class="p-submenu-icon pi" [ngClass]="{'pi-angle-down':orientation=='horizontal','pi-angle-right':orientation=='vertical'}"></span>
|
|
</a>
|
|
<a *ngIf="category.routerLink" [routerLink]="category.routerLink" [queryParams]="category.queryParams" [routerLinkActive]="'p-menuitem-link-active'" [routerLinkActiveOptions]="category.routerLinkActiveOptions||{exact:false}" [attr.tabindex]="category.tabindex ? category.tabindex : '0'"
|
|
[attr.target]="category.target" [attr.title]="category.title" [attr.id]="category.id"
|
|
(click)="onCategoryClick($event, category)" [ngClass]="{'p-menuitem-link':true,'p-disabled':category.disabled}" [ngStyle]="category.style" [class]="category.styleClass"
|
|
[fragment]="category.fragment" [queryParamsHandling]="category.queryParamsHandling" [preserveFragment]="category.preserveFragment" [skipLocationChange]="category.skipLocationChange" [replaceUrl]="category.replaceUrl" [state]="category.state" pRipple>
|
|
<span class="p-menuitem-icon" *ngIf="category.icon" [ngClass]="category.icon"></span>
|
|
<span class="p-menuitem-text" *ngIf="category.escape !== false; else categoryHtmlRouteLabel">{{category.label}}</span>
|
|
<ng-template #categoryHtmlRouteLabel><span class="p-menuitem-text" [innerHTML]="category.label"></span></ng-template>
|
|
</a>
|
|
<div class="p-megamenu-panel" *ngIf="category.items">
|
|
<div class="p-megamenu-grid">
|
|
<ng-template ngFor let-column [ngForOf]="category.items">
|
|
<div [class]="getColumnClass(category)">
|
|
<ng-template ngFor let-submenu [ngForOf]="column">
|
|
<ul class="p-megamenu-submenu" role="menu">
|
|
<li class="p-megamenu-submenu-header">
|
|
<span *ngIf="submenu.escape !== false; else submenuHtmlLabel">{{submenu.label}}</span>
|
|
<ng-template #submenuHtmlLabel><span [innerHTML]="submenu.label"></span></ng-template>
|
|
</li>
|
|
<ng-template ngFor let-item [ngForOf]="submenu.items">
|
|
<li *ngIf="item.separator" class="p-menu-separator" [ngClass]="{'p-hidden': item.visible === false}" role="separator">
|
|
<li *ngIf="!item.separator" class="p-menuitem" [ngClass]="{'p-hidden': item.visible === false}" role="none">
|
|
<a *ngIf="!item.routerLink" role="menuitem" [href]="item.url||'#'" class="p-menuitem-link" [attr.target]="item.target" [attr.title]="item.title" [attr.id]="item.id" [attr.tabindex]="item.tabindex ? item.tabindex : '0'"
|
|
[ngClass]="{'p-disabled':item.disabled}" (click)="itemClick($event, item)" pRipple>
|
|
<span class="p-menuitem-icon" *ngIf="item.icon" [ngClass]="item.icon"></span>
|
|
<span class="p-menuitem-text" *ngIf="item.escape !== false; else htmlLabel">{{item.label}}</span>
|
|
<ng-template #htmlLabel><span class="p-menuitem-text" [innerHTML]="item.label"></span></ng-template>
|
|
</a>
|
|
<a *ngIf="item.routerLink" role="menuitem" [routerLink]="item.routerLink" [queryParams]="item.queryParams" [routerLinkActive]="'p-menuitem-link-active'" [attr.tabindex]="item.tabindex ? item.tabindex : '0'"
|
|
[routerLinkActiveOptions]="item.routerLinkActiveOptions||{exact:false}" class="p-menuitem-link"
|
|
[attr.target]="item.target" [attr.title]="item.title" [attr.id]="item.id"
|
|
[ngClass]="{'p-disabled':item.disabled}" (click)="itemClick($event, item)"
|
|
[fragment]="item.fragment" [queryParamsHandling]="item.queryParamsHandling" [preserveFragment]="item.preserveFragment" [skipLocationChange]="item.skipLocationChange" [replaceUrl]="item.replaceUrl" [state]="item.state" pRipple>
|
|
<span class="p-menuitem-icon" *ngIf="item.icon" [ngClass]="item.icon"></span>
|
|
<span class="p-menuitem-text" *ngIf="item.escape !== false; else htmlRouteLabel">{{item.label}}</span>
|
|
<ng-template #htmlRouteLabel><span class="p-menuitem-text" [innerHTML]="item.label"></span></ng-template>
|
|
</a>
|
|
</li>
|
|
</ng-template>
|
|
</ul>
|
|
</ng-template>
|
|
</div>
|
|
</ng-template>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
</ng-template>
|
|
<div class="p-megamenu-end" *ngIf="endTemplate; else legacy">
|
|
<ng-container *ngTemplateOutlet="endTemplate"></ng-container>
|
|
</div>
|
|
<ng-template #legacy>
|
|
<div class="p-megamenu-end">
|
|
<ng-content></ng-content>
|
|
</div>
|
|
</ng-template>
|
|
</ul>
|
|
</div>
|
|
`,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
encapsulation: ViewEncapsulation.None,
|
|
styles: [".p-megamenu-root-list{list-style:none;margin:0;padding:0}.p-megamenu-root-list>.p-menuitem{position:relative}.p-megamenu .p-menuitem-link{-ms-flex-align:center;align-items:center;cursor:pointer;display:-ms-flexbox;display:flex;overflow:hidden;position:relative;text-decoration:none}.p-megamenu .p-menuitem-text{line-height:1}.p-megamenu-panel{display:none;position:absolute;width:auto;z-index:1}.p-megamenu-root-list>.p-menuitem-active>.p-megamenu-panel{display:block}.p-megamenu-submenu{list-style:none;margin:0;padding:0}.p-megamenu-horizontal .p-megamenu-root-list{-ms-flex-align:center;-ms-flex-wrap:wrap;align-items:center;display:-ms-flexbox;display:flex;flex-wrap:wrap}.p-megamenu-vertical .p-megamenu-root-list{-ms-flex-direction:column;flex-direction:column}.p-megamenu-vertical .p-megamenu-root-list>.p-menuitem-active>.p-megamenu-panel{left:100%;top:0}.p-megamenu-vertical .p-megamenu-root-list>.p-menuitem>.p-menuitem-link>.p-submenu-icon{margin-left:auto}.p-megamenu-grid{display:-ms-flexbox;display:flex}.p-megamenu-col-2,.p-megamenu-col-3,.p-megamenu-col-4,.p-megamenu-col-6,.p-megamenu-col-12{-ms-flex:0 0 auto;flex:0 0 auto;padding:.5rem}.p-megamenu-col-2{width:16.6667%}.p-megamenu-col-3{width:25%}.p-megamenu-col-4{width:33.3333%}.p-megamenu-col-6{width:50%}.p-megamenu-col-12{width:100%}"]
|
|
},] }
|
|
];
|
|
MegaMenu.ctorParameters = () => [
|
|
{ type: ElementRef },
|
|
{ type: Renderer2 },
|
|
{ type: ChangeDetectorRef }
|
|
];
|
|
MegaMenu.propDecorators = {
|
|
model: [{ type: Input }],
|
|
style: [{ type: Input }],
|
|
styleClass: [{ type: Input }],
|
|
orientation: [{ type: Input }],
|
|
autoZIndex: [{ type: Input }],
|
|
baseZIndex: [{ type: Input }],
|
|
templates: [{ type: ContentChildren, args: [PrimeTemplate,] }]
|
|
};
|
|
class MegaMenuModule {
|
|
}
|
|
MegaMenuModule.decorators = [
|
|
{ type: NgModule, args: [{
|
|
imports: [CommonModule, RouterModule, RippleModule],
|
|
exports: [MegaMenu, RouterModule],
|
|
declarations: [MegaMenu]
|
|
},] }
|
|
];
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { MegaMenu, MegaMenuModule };
|
|
//# sourceMappingURL=primeng-megamenu.js.map
|