327 lines
14 KiB
JavaScript
327 lines
14 KiB
JavaScript
import { Component, ViewEncapsulation, Inject, forwardRef, Input, EventEmitter, ChangeDetectionStrategy, ElementRef, Renderer2, ChangeDetectorRef, Output, ViewChild, NgModule } from '@angular/core';
|
|
import { trigger, transition, style, animate } from '@angular/animations';
|
|
import { CommonModule } from '@angular/common';
|
|
import { DomHandler, ConnectedOverlayScrollHandler } from 'primeng/dom';
|
|
import { RouterModule } from '@angular/router';
|
|
|
|
class SlideMenuSub {
|
|
constructor(slideMenu) {
|
|
this.backLabel = 'Back';
|
|
this.easing = 'ease-out';
|
|
this.slideMenu = slideMenu;
|
|
}
|
|
itemClick(event, item, listitem) {
|
|
if (item.disabled) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
if (!item.url) {
|
|
event.preventDefault();
|
|
}
|
|
if (item.command) {
|
|
item.command({
|
|
originalEvent: event,
|
|
item: item
|
|
});
|
|
}
|
|
if (item.items && !this.slideMenu.animating) {
|
|
this.slideMenu.left -= this.slideMenu.menuWidth;
|
|
this.activeItem = listitem;
|
|
this.slideMenu.animating = true;
|
|
setTimeout(() => this.slideMenu.animating = false, this.effectDuration);
|
|
}
|
|
if (!item.items && this.slideMenu.popup) {
|
|
this.slideMenu.hide();
|
|
}
|
|
}
|
|
ngOnDestroy() {
|
|
this.activeItem = null;
|
|
}
|
|
}
|
|
SlideMenuSub.decorators = [
|
|
{ type: Component, args: [{
|
|
selector: 'p-slideMenuSub',
|
|
template: `
|
|
<ul [ngClass]="{'p-slidemenu-rootlist':root, 'p-submenu-list':!root, 'p-active-submenu': (-slideMenu.left == (index * menuWidth))}"
|
|
[style.width.px]="menuWidth" [style.left.px]="root ? slideMenu.left : slideMenu.menuWidth"
|
|
[style.transitionProperty]="root ? 'left' : 'none'" [style.transitionDuration]="effectDuration + 'ms'" [style.transitionTimingFunction]="easing">
|
|
<ng-template ngFor let-child [ngForOf]="(root ? item : item.items)">
|
|
<li *ngIf="child.separator" class="p-menu-separator" [ngClass]="{'p-hidden': child.visible === false}">
|
|
<li *ngIf="!child.separator" #listitem [ngClass]="{'p-menuitem':true,'p-menuitem-active':listitem==activeItem,'p-hidden': child.visible === false}"
|
|
[class]="child.styleClass" [ngStyle]="child.style">
|
|
<a *ngIf="!child.routerLink" [attr.href]="child.url" class="p-menuitem-link" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id"
|
|
[ngClass]="{'p-disabled':child.disabled}" [attr.tabindex]="child.disabled ? null : '0'"
|
|
(click)="itemClick($event, child, listitem)">
|
|
<span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span>
|
|
<span class="p-menuitem-text">{{child.label}}</span>
|
|
<span class="p-submenu-icon pi pi-fw pi-angle-right" *ngIf="child.items"></span>
|
|
</a>
|
|
<a *ngIf="child.routerLink" [routerLink]="child.routerLink" [queryParams]="child.queryParams" [routerLinkActive]="'p-menuitem-link-active'"
|
|
[routerLinkActiveOptions]="child.routerLinkActiveOptions||{exact:false}" [href]="child.url" class="p-menuitem-link"
|
|
[attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" [attr.tabindex]="child.disabled ? null : '0'"
|
|
[ngClass]="{'p-disabled':child.disabled}"
|
|
(click)="itemClick($event, child, listitem)"
|
|
[fragment]="child.fragment" [queryParamsHandling]="child.queryParamsHandling" [preserveFragment]="child.preserveFragment" [skipLocationChange]="child.skipLocationChange" [replaceUrl]="child.replaceUrl" [state]="child.state">
|
|
<span class="p-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span>
|
|
<span class="p-menuitem-text">{{child.label}}</span>
|
|
<span class="p-submenu-icon pi pi-fw pi-caret-right" *ngIf="child.items"></span>
|
|
</a>
|
|
<p-slideMenuSub class="p-submenu" [item]="child" [index]="index + 1" [menuWidth]="menuWidth" *ngIf="child.items"></p-slideMenuSub>
|
|
</li>
|
|
</ng-template>
|
|
</ul>
|
|
`,
|
|
encapsulation: ViewEncapsulation.None
|
|
},] }
|
|
];
|
|
SlideMenuSub.ctorParameters = () => [
|
|
{ type: undefined, decorators: [{ type: Inject, args: [forwardRef(() => SlideMenu),] }] }
|
|
];
|
|
SlideMenuSub.propDecorators = {
|
|
item: [{ type: Input }],
|
|
root: [{ type: Input }],
|
|
backLabel: [{ type: Input }],
|
|
menuWidth: [{ type: Input }],
|
|
effectDuration: [{ type: Input }],
|
|
easing: [{ type: Input }],
|
|
index: [{ type: Input }]
|
|
};
|
|
class SlideMenu {
|
|
constructor(el, renderer, cd) {
|
|
this.el = el;
|
|
this.renderer = renderer;
|
|
this.cd = cd;
|
|
this.menuWidth = 190;
|
|
this.viewportHeight = 180;
|
|
this.effectDuration = 250;
|
|
this.easing = 'ease-out';
|
|
this.backLabel = 'Back';
|
|
this.autoZIndex = true;
|
|
this.baseZIndex = 0;
|
|
this.showTransitionOptions = '.12s cubic-bezier(0, 0, 0.2, 1)';
|
|
this.hideTransitionOptions = '.1s linear';
|
|
this.onShow = new EventEmitter();
|
|
this.onHide = new EventEmitter();
|
|
this.left = 0;
|
|
this.animating = false;
|
|
}
|
|
ngAfterViewChecked() {
|
|
if (!this.viewportUpdated && !this.popup && this.containerViewChild) {
|
|
this.updateViewPort();
|
|
this.viewportUpdated = true;
|
|
}
|
|
}
|
|
set container(element) {
|
|
this.containerViewChild = element;
|
|
}
|
|
set backward(element) {
|
|
this.backwardViewChild = element;
|
|
}
|
|
set slideMenuContent(element) {
|
|
this.slideMenuContentViewChild = element;
|
|
}
|
|
updateViewPort() {
|
|
this.slideMenuContentViewChild.nativeElement.style.height = this.viewportHeight - DomHandler.getHiddenElementOuterHeight(this.backwardViewChild.nativeElement) + 'px';
|
|
}
|
|
toggle(event) {
|
|
if (this.visible)
|
|
this.hide();
|
|
else
|
|
this.show(event);
|
|
this.preventDocumentDefault = true;
|
|
}
|
|
show(event) {
|
|
this.target = event.currentTarget;
|
|
this.visible = true;
|
|
this.preventDocumentDefault = true;
|
|
this.cd.markForCheck();
|
|
}
|
|
onOverlayAnimationStart(event) {
|
|
switch (event.toState) {
|
|
case 'visible':
|
|
if (this.popup) {
|
|
this.updateViewPort();
|
|
this.moveOnTop();
|
|
this.onShow.emit({});
|
|
this.appendOverlay();
|
|
DomHandler.absolutePosition(this.containerViewChild.nativeElement, this.target);
|
|
this.bindDocumentClickListener();
|
|
this.bindDocumentResizeListener();
|
|
this.bindScrollListener();
|
|
}
|
|
break;
|
|
case 'void':
|
|
this.onOverlayHide();
|
|
this.onHide.emit({});
|
|
break;
|
|
}
|
|
}
|
|
appendOverlay() {
|
|
if (this.appendTo) {
|
|
if (this.appendTo === 'body')
|
|
document.body.appendChild(this.containerViewChild.nativeElement);
|
|
else
|
|
DomHandler.appendChild(this.containerViewChild.nativeElement, this.appendTo);
|
|
}
|
|
}
|
|
restoreOverlayAppend() {
|
|
if (this.container && this.appendTo) {
|
|
this.el.nativeElement.appendChild(this.containerViewChild.nativeElement);
|
|
}
|
|
}
|
|
moveOnTop() {
|
|
if (this.autoZIndex) {
|
|
this.containerViewChild.nativeElement.style.zIndex = String(this.baseZIndex + (++DomHandler.zindex));
|
|
}
|
|
}
|
|
hide() {
|
|
this.visible = false;
|
|
this.cd.markForCheck();
|
|
}
|
|
onWindowResize() {
|
|
this.hide();
|
|
}
|
|
onClick(event) {
|
|
this.preventDocumentDefault = true;
|
|
}
|
|
goBack() {
|
|
this.left += this.menuWidth;
|
|
}
|
|
bindDocumentClickListener() {
|
|
if (!this.documentClickListener) {
|
|
const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document';
|
|
this.documentClickListener = this.renderer.listen(documentTarget, 'click', () => {
|
|
if (!this.preventDocumentDefault) {
|
|
this.hide();
|
|
this.cd.detectChanges();
|
|
}
|
|
this.preventDocumentDefault = false;
|
|
});
|
|
}
|
|
}
|
|
unbindDocumentClickListener() {
|
|
if (this.documentClickListener) {
|
|
this.documentClickListener();
|
|
this.documentClickListener = null;
|
|
}
|
|
}
|
|
bindDocumentResizeListener() {
|
|
this.documentResizeListener = this.onWindowResize.bind(this);
|
|
window.addEventListener('resize', this.documentResizeListener);
|
|
}
|
|
unbindDocumentResizeListener() {
|
|
if (this.documentResizeListener) {
|
|
window.removeEventListener('resize', this.documentResizeListener);
|
|
this.documentResizeListener = null;
|
|
}
|
|
}
|
|
bindScrollListener() {
|
|
if (!this.scrollHandler) {
|
|
this.scrollHandler = new ConnectedOverlayScrollHandler(this.target, () => {
|
|
if (this.visible) {
|
|
this.hide();
|
|
}
|
|
});
|
|
}
|
|
this.scrollHandler.bindScrollListener();
|
|
}
|
|
unbindScrollListener() {
|
|
if (this.scrollHandler) {
|
|
this.scrollHandler.unbindScrollListener();
|
|
}
|
|
}
|
|
onOverlayHide() {
|
|
this.unbindDocumentClickListener();
|
|
this.unbindDocumentResizeListener();
|
|
this.unbindScrollListener();
|
|
this.preventDocumentDefault = false;
|
|
this.target = null;
|
|
this.left = 0;
|
|
}
|
|
ngOnDestroy() {
|
|
if (this.popup) {
|
|
if (this.scrollHandler) {
|
|
this.scrollHandler.destroy();
|
|
this.scrollHandler = null;
|
|
}
|
|
this.restoreOverlayAppend();
|
|
this.onOverlayHide();
|
|
}
|
|
}
|
|
}
|
|
SlideMenu.decorators = [
|
|
{ type: Component, args: [{
|
|
selector: 'p-slideMenu',
|
|
template: `
|
|
<div #container [ngClass]="{'p-slidemenu p-component':true, 'p-slidemenu-overlay':popup}"
|
|
[class]="styleClass" [ngStyle]="style" (click)="onClick($event)"
|
|
[@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" [@.disabled]="popup !== true" (@overlayAnimation.start)="onOverlayAnimationStart($event)" *ngIf="!popup || visible">
|
|
<div class="p-slidemenu-wrapper" [style.height]="left ? viewportHeight + 'px' : 'auto'">
|
|
<div #slideMenuContent class="p-slidemenu-content">
|
|
<p-slideMenuSub [item]="model" root="root" [index]="0" [menuWidth]="menuWidth" [effectDuration]="effectDuration" [easing]="easing"></p-slideMenuSub>
|
|
</div>
|
|
<div #backward class="p-slidemenu-backward" [style.display]="left ? 'block' : 'none'" (click)="goBack()">
|
|
<span class="p-slidemenu-backward-icon pi pi-fw pi-caret-left"></span><span>{{backLabel}}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`,
|
|
animations: [
|
|
trigger('overlayAnimation', [
|
|
transition(':enter', [
|
|
style({ opacity: 0, transform: 'scaleY(0.8)' }),
|
|
animate('{{showTransitionParams}}')
|
|
]),
|
|
transition(':leave', [
|
|
animate('{{hideTransitionParams}}', style({ opacity: 0 }))
|
|
])
|
|
])
|
|
],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
encapsulation: ViewEncapsulation.None,
|
|
styles: [".p-slidemenu{width:12.5rem}.p-slidemenu.p-slidemenu-overlay{position:absolute}.p-slidemenu ul{list-style:none;margin:0;padding:0}.p-slidemenu .p-slidemenu-rootlist{position:absolute;top:0}.p-slidemenu .p-submenu-list{display:none;position:absolute;top:0;width:12.5rem}.p-slidemenu .p-menuitem-link{-ms-flex-align:center;align-items:center;cursor:pointer;display:-ms-flexbox;display:flex;overflow:hidden;text-decoration:none}.p-slidemenu .p-menuitem-icon,.p-slidemenu .p-menuitem-text{vertical-align:middle}.p-slidemenu .p-menuitem{position:relative}.p-slidemenu .p-menuitem-link .p-submenu-icon{margin-left:auto}.p-slidemenu .p-slidemenu-wrapper{position:relative}.p-slidemenu .p-slidemenu-content{overflow-x:hidden;overflow-y:auto;position:relative}.p-slidemenu-backward{bottom:0;cursor:pointer;display:none;position:absolute;width:100%}.p-slidemenu-backward .p-slidemenu-backward-icon,.p-slidemenu-backward span{vertical-align:middle}.p-slidemenu .p-menuitem-active{position:static}.p-slidemenu .p-menuitem-active>.p-submenu>.p-submenu-list{display:block}.p-slidemenu .p-active-submenu>.p-menuitem-active>.p-submenu>.p-submenu-list,.p-slidemenu ul:not(.p-active-submenu)>.p-menuitem:not(.p-menuitem-active){display:none}.p-slidemenu .p-active-submenu>.p-menuitem-active~.p-menuitem{display:block}"]
|
|
},] }
|
|
];
|
|
SlideMenu.ctorParameters = () => [
|
|
{ type: ElementRef },
|
|
{ type: Renderer2 },
|
|
{ type: ChangeDetectorRef }
|
|
];
|
|
SlideMenu.propDecorators = {
|
|
model: [{ type: Input }],
|
|
popup: [{ type: Input }],
|
|
style: [{ type: Input }],
|
|
styleClass: [{ type: Input }],
|
|
menuWidth: [{ type: Input }],
|
|
viewportHeight: [{ type: Input }],
|
|
effectDuration: [{ type: Input }],
|
|
easing: [{ type: Input }],
|
|
backLabel: [{ type: Input }],
|
|
appendTo: [{ type: Input }],
|
|
autoZIndex: [{ type: Input }],
|
|
baseZIndex: [{ type: Input }],
|
|
showTransitionOptions: [{ type: Input }],
|
|
hideTransitionOptions: [{ type: Input }],
|
|
onShow: [{ type: Output }],
|
|
onHide: [{ type: Output }],
|
|
container: [{ type: ViewChild, args: ['container',] }],
|
|
backward: [{ type: ViewChild, args: ['backward',] }],
|
|
slideMenuContent: [{ type: ViewChild, args: ['slideMenuContent',] }]
|
|
};
|
|
class SlideMenuModule {
|
|
}
|
|
SlideMenuModule.decorators = [
|
|
{ type: NgModule, args: [{
|
|
imports: [CommonModule, RouterModule],
|
|
exports: [SlideMenu, RouterModule],
|
|
declarations: [SlideMenu, SlideMenuSub]
|
|
},] }
|
|
];
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { SlideMenu, SlideMenuModule, SlideMenuSub };
|
|
//# sourceMappingURL=primeng-slidemenu.js.map
|