diff --git a/src/app/top-bar/top-bar.component.html b/src/app/top-bar/top-bar.component.html index 328e2bd..cc518b7 100644 --- a/src/app/top-bar/top-bar.component.html +++ b/src/app/top-bar/top-bar.component.html @@ -1,14 +1,17 @@
-
+ \ No newline at end of file diff --git a/src/app/top-bar/top-bar.component.scss b/src/app/top-bar/top-bar.component.scss index 292901a..21852ef 100644 --- a/src/app/top-bar/top-bar.component.scss +++ b/src/app/top-bar/top-bar.component.scss @@ -37,6 +37,28 @@ header { color: #fff; } +.nav .nav-btn-drop:hover { + background-color: #264998; + color: #fff; +} + +#ulHiddenLinks li, +#ulHiddenLinks li a { + width: 100%; +} + +.nav-btn { + width: 3rem; + text-align: center; +} + +@media only screen and (max-width: 575px) { + .nav-btn { + width: 5rem; + text-align: center; + } +} + .yellow { background-color:rgb(243, 217, 115 ); } @@ -62,16 +84,6 @@ header { height: 100%; } -.hidden-button { - display: none; -} - -@media (max-width: 1199px) { - .hidden-button { - display: block; - } -} - .dropdown-item:active { background-color: gray; } @@ -84,4 +96,4 @@ header { .active-link { background-color: #264998; color: #fff!important; -} \ No newline at end of file +} diff --git a/src/app/top-bar/top-bar.component.ts b/src/app/top-bar/top-bar.component.ts index 1c3db2e..7327728 100644 --- a/src/app/top-bar/top-bar.component.ts +++ b/src/app/top-bar/top-bar.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, HostListener } from '@angular/core'; import { AuthenticationService } from '@app/core'; import { Router } from '@angular/router'; @@ -13,31 +13,98 @@ export class TopBarComponent implements OnInit { * top bar to be shown over all the other components */ constructor(public authService: AuthenticationService, - private router: Router) {} + private router: Router) { } - ngOnInit() { } + ngOnInit() { } - /** - * logout from account - */ + ngAfterViewInit() { + this.onResized(); + } + + @HostListener('window:resize', ['$event']) + onResize() { + this.onResized(); + } + + onResized() { + var btn = document.getElementById("nav-btn"); + var vlinks = document.getElementById("ulVisibleLinks"); + var vlinksChildren = vlinks.getElementsByTagName("li"); + var hlinks = document.getElementById("ulHiddenLinks"); + var hlinksChildren = hlinks.getElementsByTagName("li"); + + var numVisibleItems = 0; + var totalItems = vlinksChildren.length + hlinksChildren.length; + var totalSpace = document.getElementById("divVisibleLinks").clientWidth - 30; + var usedSpace = 0; + var remainingSpace = totalSpace - usedSpace; + + // get all links in one array + var initiallength = hlinksChildren.length; + for (var k = 0; k < initiallength; k++) { + vlinks.append(hlinksChildren[0]); + } + + // set visible links + for (var i = 0; i < vlinksChildren.length; i++) { + if (vlinksChildren[i].clientWidth < remainingSpace) { + usedSpace += vlinksChildren[i].clientWidth; + remainingSpace = totalSpace - usedSpace; + numVisibleItems++; + } else { + break; + } + } + + // set hidden links + for (var j = vlinksChildren.length - 1; j >= numVisibleItems; j--) { + hlinks.prepend(vlinksChildren[j]); + } + + // update height of dropdown menu + var divHiddenLinks = document.getElementById("divHiddenLinks"); + var newHeight = hlinksChildren.length * 60 + 20 + 'px'; + divHiddenLinks.style.height = newHeight; + + // if no items visible, add 'Menu' to button + if (numVisibleItems == 0) { + btn.innerText = "Menu"; + } else { + btn.innerText = ""; + } + + // if all items visible, hide the button + if (numVisibleItems == totalItems) { + btn.classList.add("d-none"); + divHiddenLinks.classList.add("d-none"); + } else { + btn.classList.remove("d-none"); + divHiddenLinks.classList.remove("d-none"); + } + } + + /** + * logout from account + */ logout() { this.authService.logout().subscribe( - (didlogout: Boolean) => { - if (didlogout) { - this.router.navigate(['/login']); - } - }, - (error: any) => { - console.log('logout error: ', error); - }); - } + (didlogout: Boolean) => { + if (didlogout) { + this.router.navigate(['/login']); + } + }, + (error: any) => { + console.log('logout error: ', error); + }); + } - /** - * go to home path on icon click - */ + /** + * go to home path on icon click + */ goToDashboard() { this.router.navigate(['/' + this.authService.homePath()], { replaceUrl: true }); } + }