admin.component.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { Component, OnInit, ViewChild, AfterViewInit } from "@angular/core";
  2. import {
  3. Location,
  4. LocationStrategy,
  5. PathLocationStrategy,
  6. PopStateEvent
  7. } from "@angular/common";
  8. import { filter, map } from "rxjs/operators";
  9. import { Subscription } from "rxjs/Subscription";
  10. //import { NavbarComponent } from '../../components/navbar/navbar.component';
  11. import { Router, NavigationEnd, NavigationStart } from "@angular/router";
  12. import * as $ from "jquery";
  13. @Component({
  14. selector: "app-admin",
  15. templateUrl: "./admin.component.html",
  16. styleUrls: ["./admin.component.scss"]
  17. })
  18. export class AdminComponent implements OnInit {
  19. private _router: Subscription;
  20. private lastPoppedUrl: string;
  21. private yScrollStack: number[] = [];
  22. constructor(public location: Location, private router: Router) {}
  23. ngOnInit() {
  24. const isWindows = navigator.platform.indexOf("Win") > -1 ? true : false;
  25. const elemMainPanel = <HTMLElement>document.querySelector(".main-panel");
  26. const elemSidebar = <HTMLElement>(
  27. document.querySelector(".sidebar .sidebar-wrapper")
  28. );
  29. this.location.subscribe((ev: PopStateEvent) => {
  30. this.lastPoppedUrl = ev.url;
  31. });
  32. this.router.events.subscribe((event: any) => {
  33. if (event instanceof NavigationStart) {
  34. if (event.url != this.lastPoppedUrl)
  35. this.yScrollStack.push(window.scrollY);
  36. } else if (event instanceof NavigationEnd) {
  37. if (event.url == this.lastPoppedUrl) {
  38. this.lastPoppedUrl = undefined;
  39. window.scrollTo(0, this.yScrollStack.pop());
  40. } else window.scrollTo(0, 0);
  41. }
  42. });
  43. this._router = this.router.events
  44. .pipe(filter(event => event instanceof NavigationEnd))
  45. .subscribe((event: NavigationEnd) => {
  46. elemMainPanel.scrollTop = 0;
  47. elemSidebar.scrollTop = 0;
  48. });
  49. const window_width = $(window).width();
  50. let $sidebar = $(".sidebar");
  51. let $sidebar_responsive = $("body > .navbar-collapse");
  52. let $sidebar_img_container = $sidebar.find(".sidebar-background");
  53. if (window_width > 767) {
  54. if ($(".fixed-plugin .dropdown").hasClass("show-dropdown")) {
  55. $(".fixed-plugin .dropdown").addClass("open");
  56. }
  57. }
  58. $(".fixed-plugin a").click(function(event) {
  59. // Alex if we click on switch, stop propagation of the event, so the dropdown will not be hide, otherwise we set the section active
  60. if ($(this).hasClass("switch-trigger")) {
  61. if (event.stopPropagation) {
  62. event.stopPropagation();
  63. } else if (window.event) {
  64. window.event.cancelBubble = true;
  65. }
  66. }
  67. });
  68. $(".fixed-plugin .badge").click(function() {
  69. let $full_page_background = $(".full-page-background");
  70. $(this)
  71. .siblings()
  72. .removeClass("active");
  73. $(this).addClass("active");
  74. var new_color = $(this).data("color");
  75. if ($sidebar.length !== 0) {
  76. $sidebar.attr("data-color", new_color);
  77. }
  78. if ($sidebar_responsive.length != 0) {
  79. $sidebar_responsive.attr("data-color", new_color);
  80. }
  81. });
  82. $(".fixed-plugin .img-holder").click(function() {
  83. let $full_page_background = $(".full-page-background");
  84. $(this)
  85. .parent("li")
  86. .siblings()
  87. .removeClass("active");
  88. $(this)
  89. .parent("li")
  90. .addClass("active");
  91. //var new_image = $(this).find("img").attr('src');
  92. if ($sidebar_img_container.length != 0) {
  93. $sidebar_img_container.fadeOut("fast", function() {
  94. //$sidebar_img_container.css('background-image','url("' + new_image + '")');
  95. $sidebar_img_container.fadeIn("fast");
  96. });
  97. }
  98. if ($full_page_background.length != 0) {
  99. $full_page_background.fadeOut("fast", function() {
  100. //$full_page_background.css('background-image','url("' + new_image + '")');
  101. $full_page_background.fadeIn("fast");
  102. });
  103. }
  104. if ($sidebar_responsive.length != 0) {
  105. //$sidebar_responsive.css('background-image','url("' + new_image + '")');
  106. }
  107. });
  108. }
  109. ngAfterViewInit() {
  110. this.runOnRouteChange();
  111. }
  112. isMaps(path) {
  113. var titlee = this.location.prepareExternalUrl(this.location.path());
  114. titlee = titlee.slice(1);
  115. if (path == titlee) {
  116. return false;
  117. } else {
  118. return true;
  119. }
  120. }
  121. runOnRouteChange(): void {
  122. if (window.matchMedia(`(min-width: 960px)`).matches && !this.isMac()) {
  123. const elemMainPanel = <HTMLElement>document.querySelector(".main-panel");
  124. }
  125. }
  126. isMac(): boolean {
  127. let bool = false;
  128. if (
  129. navigator.platform.toUpperCase().indexOf("MAC") >= 0 ||
  130. navigator.platform.toUpperCase().indexOf("IPAD") >= 0
  131. ) {
  132. bool = true;
  133. }
  134. return bool;
  135. }
  136. }