import {NgModule,Component,ElementRef,AfterViewInit,Input,Output,Renderer2} from '@angular/core'; import {CommonModule} from '@angular/common'; import {DomHandler} from '../dom/domhandler'; import {MenuItem} from '../common/menuitem'; import {Location} from '@angular/common'; import {RouterModule} from '@angular/router'; @Component({ selector: 'p-megaMenu', template: `
`, providers: [DomHandler] }) export class MegaMenu { @Input() model: MenuItem[]; @Input() style: any; @Input() styleClass: string; @Input() orientation: string = 'horizontal'; @Input() autoZIndex: boolean = true; @Input() baseZIndex: number = 0; activeItem: any; hideTimeout: any; constructor(public el: ElementRef, public domHandler: DomHandler, public renderer: Renderer2) {} onItemMouseEnter(event, item, menuitem: MenuItem) { if(menuitem.disabled) { return; } if(this.hideTimeout) { clearTimeout(this.hideTimeout); this.hideTimeout = null; } this.activeItem = item; if(menuitem.items) { let submenu = item.children[0].nextElementSibling; if (submenu) { if (this.autoZIndex) { submenu.style.zIndex = String(this.baseZIndex + (++DomHandler.zindex)); } if (this.orientation === 'horizontal') { submenu.style.top = this.domHandler.getOuterHeight(item.children[0]) + 'px'; submenu.style.left = '0px'; } else if (this.orientation === 'vertical') { submenu.style.top = '0px'; submenu.style.left = this.domHandler.getOuterWidth(item.children[0]) + 'px'; } } } } onItemMouseLeave(event, link) { this.hideTimeout = setTimeout(() => { this.activeItem = null; }, 1000); } itemClick(event, item: MenuItem) { 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: MenuItem) { let length = menuitem.items ? menuitem.items.length: 0; let columnClass; switch(length) { case 2: columnClass= 'ui-g-6'; break; case 3: columnClass= 'ui-g-4'; break; case 4: columnClass= 'ui-g-3'; break; case 6: columnClass= 'ui-g-2'; break; default: columnClass= 'ui-g-12'; break; } return columnClass; } } @NgModule({ imports: [CommonModule,RouterModule], exports: [MegaMenu,RouterModule], declarations: [MegaMenu] }) export class MegaMenuModule { }