cavallium-website/src/app/gui/navbar/navbar.component.ts

85 lines
2.4 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, HostListener, Input, ElementRef, ViewChild, AfterViewInit } from "@angular/core";
2019-04-12 20:20:38 +02:00
import { NavigationLink } from "src/app/symbols/NavigationLink";
import { ActivatedRoute, UrlSegment } from "@angular/router";
import { map } from "rxjs/operators";
import { CurrentDocumentService } from "src/app/services/current-document.service";
2019-04-12 00:16:56 +02:00
@Component({
2019-04-12 20:20:38 +02:00
selector: "app-navbar",
templateUrl: "./navbar.component.html",
styleUrls: ["./navbar.component.scss"]
2019-04-12 00:16:56 +02:00
})
export class NavbarComponent implements OnInit, AfterViewInit {
2019-04-12 00:16:56 +02:00
2019-04-12 20:20:38 +02:00
public navigationLinks: NavigationLink[] = [
{
text: "Cardboard bug",
2019-04-12 20:20:38 +02:00
address: "/article/software"
},
{
text: "Midi23D",
address: "/article/software/midi23d"
2019-04-12 20:20:38 +02:00
},
{
text: "Calculator",
address: "/article/calculator",
newtab: false
2019-04-12 20:20:38 +02:00
},
{
text: "Github",
address: "https://github.com/Cavallium/WarpPI",
external: true,
newtab: true
2019-04-12 20:20:38 +02:00
},
];
stickedOnTop = false;
overflowLogo = false;
overflowMax = false;
@ViewChild("navlogo") navLogo: ElementRef<HTMLElement>;
@ViewChild("navbuttons") navButtons: ElementRef<HTMLElement>;
2019-04-12 00:16:56 +02:00
constructor(private elRef: ElementRef<HTMLElement>, public currentDocument: CurrentDocumentService) { }
2019-04-12 20:20:38 +02:00
ngOnInit() {
// TODO: fare la parte dei percorsi preselezionati
2019-04-12 20:20:38 +02:00
}
2019-04-12 00:16:56 +02:00
ngAfterViewInit() {
setTimeout(() => {
this.updateSticked();
this.updateSize();
});
}
@Input()
public onParentScroll(event: Event) {
this.updateSticked();
}
private updateSticked() {
this.stickedOnTop = this.elRef.nativeElement.getBoundingClientRect().top <= 0;
}
private updateSize() {
if (this.overflowLogo === false
&& (this.navButtons.nativeElement.offsetWidth + this.navLogo.nativeElement.offsetWidth) > this.elRef.nativeElement.offsetWidth) {
this.overflowLogo = true;
} else if (this.overflowLogo === true
&& this.navButtons.nativeElement.offsetWidth + this.navLogo.nativeElement.offsetWidth < this.elRef.nativeElement.offsetWidth - 30) {
this.overflowLogo = false;
}
if (this.overflowMax === false
&& this.navButtons.nativeElement.offsetWidth > this.elRef.nativeElement.offsetWidth) {
this.overflowMax = true;
} else if (this.overflowMax === true
&& this.navButtons.nativeElement.offsetWidth < this.elRef.nativeElement.offsetWidth) {
this.overflowMax = false;
}
}
@HostListener("window:resize", ["$event"])
handleResize(event: Event) {
this.updateSize();
}
2019-04-12 00:16:56 +02:00
}