Refactored layout service
This commit is contained in:
parent
71888a54e5
commit
104b40f85a
@ -21,7 +21,7 @@ import { AppLayoutComponent } from "./layout/app.layout.component";
|
|||||||
{ path: 'landing', loadChildren: () => import('./demo/components/landing/landing.module').then(m => m.LandingModule) },
|
{ path: 'landing', loadChildren: () => import('./demo/components/landing/landing.module').then(m => m.LandingModule) },
|
||||||
{ path: 'pages/notfound', component: NotfoundComponent },
|
{ path: 'pages/notfound', component: NotfoundComponent },
|
||||||
{ path: '**', redirectTo: 'pages/notfound' },
|
{ path: '**', redirectTo: 'pages/notfound' },
|
||||||
], { scrollPositionRestoration: 'enabled', anchorScrolling: 'enabled' })
|
], { scrollPositionRestoration: 'enabled', anchorScrolling: 'enabled', onSameUrlNavigation: 'reload' })
|
||||||
],
|
],
|
||||||
exports: [RouterModule]
|
exports: [RouterModule]
|
||||||
})
|
})
|
||||||
|
@ -30,41 +30,53 @@ export class AppLayoutComponent implements OnDestroy {
|
|||||||
|| event.target.classList.contains('p-trigger') || event.target.parentNode.classList.contains('p-trigger'));
|
|| event.target.classList.contains('p-trigger') || event.target.parentNode.classList.contains('p-trigger'));
|
||||||
|
|
||||||
if (isOutsideClicked) {
|
if (isOutsideClicked) {
|
||||||
this.layoutService.state.overlayMenuActive = false;
|
this.hideMenu();
|
||||||
this.layoutService.state.staticMenuMobileActive = false;
|
|
||||||
this.layoutService.state.menuHoverActive = false;
|
|
||||||
this.menuService.reset();
|
|
||||||
this.menuOutsideClickListener();
|
|
||||||
this.menuOutsideClickListener = null;
|
|
||||||
this.unblockBodyScroll();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (this.layoutService.state.staticMenuMobileActive) {
|
|
||||||
this.blockBodyScroll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.profileMenuOutsideClickListener) {
|
if (!this.profileMenuOutsideClickListener) {
|
||||||
this.profileMenuOutsideClickListener = this.renderer.listen('document', 'click', event => {
|
this.profileMenuOutsideClickListener = this.renderer.listen('document', 'click', event => {
|
||||||
const shouldCloseProfileMenu = !(this.appTopbar.menu.nativeElement.isSameNode(event.target) || event.target.classList.contains('p-trigger') || event.target.parentNode.classList.contains('p-trigger'));
|
const isOutsideClicked = !(this.appTopbar.menu.nativeElement.isSameNode(event.target) || this.appTopbar.menu.nativeElement.contains(event.target)
|
||||||
|
|| event.target.classList.contains('p-trigger') || event.target.parentNode.classList.contains('p-trigger'));
|
||||||
|
|
||||||
if (shouldCloseProfileMenu) {
|
if (isOutsideClicked) {
|
||||||
this.layoutService.state.profileSidebarVisible = false;
|
this.hideProfileMenu();
|
||||||
this.profileMenuOutsideClickListener();
|
|
||||||
this.profileMenuOutsideClickListener = null;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.layoutService.state.staticMenuMobileActive) {
|
||||||
|
this.blockBodyScroll();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
this.unblockBodyScroll();
|
this.hideMenu();
|
||||||
|
this.hideProfileMenu();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hideMenu() {
|
||||||
|
this.layoutService.state.overlayMenuActive = false;
|
||||||
|
this.layoutService.state.staticMenuMobileActive = false;
|
||||||
|
this.layoutService.state.menuHoverActive = false;
|
||||||
|
if (this.menuOutsideClickListener) {
|
||||||
|
this.menuOutsideClickListener();
|
||||||
|
this.menuOutsideClickListener = null;
|
||||||
|
}
|
||||||
|
this.unblockBodyScroll();
|
||||||
|
}
|
||||||
|
|
||||||
|
hideProfileMenu() {
|
||||||
|
this.layoutService.state.profileSidebarVisible = false;
|
||||||
|
if (this.profileMenuOutsideClickListener) {
|
||||||
|
this.profileMenuOutsideClickListener();
|
||||||
|
this.profileMenuOutsideClickListener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
blockBodyScroll(): void {
|
blockBodyScroll(): void {
|
||||||
if (document.body.classList) {
|
if (document.body.classList) {
|
||||||
document.body.classList.add('blocked-scroll');
|
document.body.classList.add('blocked-scroll');
|
||||||
|
@ -48,12 +48,6 @@ import { LayoutService } from './service/app.layout.service';
|
|||||||
state('expanded', style({
|
state('expanded', style({
|
||||||
height: '*'
|
height: '*'
|
||||||
})),
|
})),
|
||||||
state('hidden', style({
|
|
||||||
display: 'none'
|
|
||||||
})),
|
|
||||||
state('visible', style({
|
|
||||||
display: 'block'
|
|
||||||
})),
|
|
||||||
transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
|
transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
@ -133,24 +127,12 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
|
|||||||
// toggle active state
|
// toggle active state
|
||||||
if (this.item.items) {
|
if (this.item.items) {
|
||||||
this.active = !this.active;
|
this.active = !this.active;
|
||||||
|
|
||||||
if (this.root && this.active) {
|
|
||||||
this.layoutService.onOverlaySubmenuOpen();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (this.layoutService.isMobile()) {
|
|
||||||
this.layoutService.state.staticMenuMobileActive = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.menuService.onMenuStateChange({ key: this.key });
|
this.menuService.onMenuStateChange({ key: this.key });
|
||||||
}
|
}
|
||||||
|
|
||||||
get submenuAnimation() {
|
get submenuAnimation() {
|
||||||
if (this.layoutService.isDesktop() && this.layoutService.isSlim())
|
|
||||||
return this.active ? 'visible' : 'hidden';
|
|
||||||
else
|
|
||||||
return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
|
return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,15 +17,13 @@
|
|||||||
<i class="pi pi-calendar"></i>
|
<i class="pi pi-calendar"></i>
|
||||||
<span>Calendar</span>
|
<span>Calendar</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button class="p-link layout-topbar-button">
|
|
||||||
<i class="pi pi-cog"></i>
|
|
||||||
<span>Settings</span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="p-link layout-topbar-button">
|
<button class="p-link layout-topbar-button">
|
||||||
<i class="pi pi-user"></i>
|
<i class="pi pi-user"></i>
|
||||||
<span>Profile</span>
|
<span>Profile</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button class="p-link layout-topbar-button" [routerLink]="'/documentation'">
|
||||||
|
<i class="pi pi-cog"></i>
|
||||||
|
<span>Settings</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
@ -36,9 +36,6 @@ export class AppConfigComponent {
|
|||||||
|
|
||||||
set menuMode(_val: string) {
|
set menuMode(_val: string) {
|
||||||
this.layoutService.config.menuMode = _val;
|
this.layoutService.config.menuMode = _val;
|
||||||
if (this.layoutService.isSlim()) {
|
|
||||||
this.menuService.reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get inputStyle(): string {
|
get inputStyle(): string {
|
||||||
|
@ -93,10 +93,6 @@ export class LayoutService {
|
|||||||
return window.innerWidth > 991;
|
return window.innerWidth > 991;
|
||||||
}
|
}
|
||||||
|
|
||||||
isSlim() {
|
|
||||||
return this.config.menuMode === 'slim';
|
|
||||||
}
|
|
||||||
|
|
||||||
isMobile() {
|
isMobile() {
|
||||||
return !this.isDesktop();
|
return !this.isDesktop();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user