This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
/
navbar.component.ts
62 lines (53 loc) 路 1.76 KB
/
navbar.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {TocService} from '../../shared/services/toc-service';
import {InfoService} from '../../shared/services/info-service';
import {Subscription} from 'rxjs/Subscription';
import {RouteChangedEvent} from '../../shared/services/route-changed-event';
import * as octicons from 'octicons';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser'
import {forOwn} from 'lodash';
@Component({
selector: 'doc-navbar',
templateUrl: './navbar.component.html',
})
export class NavbarComponent implements OnInit, OnDestroy {
version: string;
subscription: Subscription;
navbar: any[] = [];
navbarOpen = false;
githubIcon: SafeHtml;
searchIcon: SafeHtml;
repoUrl: string;
isCollapsed = {};
constructor(
private tocService: TocService,
private infoService: InfoService,
private sanitizer: DomSanitizer,
private router: Router,
) {
}
ngOnInit() {
this.githubIcon = this.sanitizer.bypassSecurityTrustHtml(octicons['mark-github'].toSVG({fill: 'white'}));
this.searchIcon = this.sanitizer.bypassSecurityTrustHtml(octicons.search.toSVG({style: 'vertical-align:text-bottom;'}));
this.version = this.infoService.getVersion();
this.repoUrl = this.infoService.getRepoUrl();
this.navbar = this.tocService.getNavbarItems();
}
toggleNavbar() {
this.navbarOpen = !this.navbarOpen;
}
collapseNav(title) {
forOwn(this.isCollapsed, (v, k) => { this.isCollapsed[k] = false });
this.isCollapsed[title] = !this.isCollapsed[title];
}
search(q) {
if (q) {
this.router.navigate(['/api/search'], {queryParams: { q }});
this.navbarOpen = false;
}
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}