您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

75 行
2.2KB

  1. import { Component, OnInit, ElementRef } from '@angular/core';
  2. import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common';
  3. @Component({
  4. selector: 'app-navbar',
  5. templateUrl: './navbar.component.html',
  6. styleUrls: ['./navbar.component.scss']
  7. })
  8. export class NavbarComponent implements OnInit {
  9. private toggleButton: any;
  10. private sidebarVisible: boolean;
  11. constructor(public location: Location, private element : ElementRef) {
  12. this.sidebarVisible = false;
  13. }
  14. ngOnInit() {
  15. const navbar: HTMLElement = this.element.nativeElement;
  16. this.toggleButton = navbar.getElementsByClassName('navbar-toggler')[0];
  17. }
  18. sidebarOpen() {
  19. const toggleButton = this.toggleButton;
  20. const html = document.getElementsByTagName('html')[0];
  21. // console.log(html);
  22. // console.log(toggleButton, 'toggle');
  23. setTimeout(function(){
  24. toggleButton.classList.add('toggled');
  25. }, 500);
  26. html.classList.add('nav-open');
  27. this.sidebarVisible = true;
  28. };
  29. sidebarClose() {
  30. const html = document.getElementsByTagName('html')[0];
  31. // console.log(html);
  32. this.toggleButton.classList.remove('toggled');
  33. this.sidebarVisible = false;
  34. html.classList.remove('nav-open');
  35. };
  36. sidebarToggle() {
  37. // const toggleButton = this.toggleButton;
  38. // const body = document.getElementsByTagName('body')[0];
  39. if (this.sidebarVisible === false) {
  40. this.sidebarOpen();
  41. } else {
  42. this.sidebarClose();
  43. }
  44. };
  45. isHome() {
  46. var titlee = this.location.prepareExternalUrl(this.location.path());
  47. if(titlee.charAt(0) === '#'){
  48. titlee = titlee.slice( 1 );
  49. }
  50. if( titlee === '/home' ) {
  51. return true;
  52. }
  53. else {
  54. return false;
  55. }
  56. }
  57. isDocumentation() {
  58. var titlee = this.location.prepareExternalUrl(this.location.path());
  59. if(titlee.charAt(0) === '#'){
  60. titlee = titlee.slice( 1 );
  61. }
  62. if( titlee === '/documentation' ) {
  63. return true;
  64. }
  65. else {
  66. return false;
  67. }
  68. }
  69. }