-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathadmin-layout.component.ts
More file actions
157 lines (131 loc) · 5.49 KB
/
admin-layout.component.ts
File metadata and controls
157 lines (131 loc) · 5.49 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { Location, LocationStrategy, PathLocationStrategy, PopStateEvent } from '@angular/common';
import { Router, NavigationEnd, NavigationStart } from '@angular/router';
import PerfectScrollbar from 'perfect-scrollbar';
import * as $ from "jquery";
import { filter, Subscription } from 'rxjs';
@Component({
selector: 'app-admin-layout',
templateUrl: './admin-layout.component.html',
styleUrls: ['./admin-layout.component.scss']
})
export class AdminLayoutComponent implements OnInit {
private _router: Subscription;
private lastPoppedUrl: string;
private yScrollStack: number[] = [];
constructor( public location: Location, private router: Router) {}
ngOnInit() {
const isWindows = navigator.userAgent.indexOf('Win') > -1 ? true : false;
if (isWindows && !document.getElementsByTagName('body')[0].classList.contains('sidebar-mini')) {
// if we are on windows OS we activate the perfectScrollbar function
document.getElementsByTagName('body')[0].classList.add('perfect-scrollbar-on');
} else {
document.getElementsByTagName('body')[0].classList.remove('perfect-scrollbar-off');
}
const elemMainPanel = <HTMLElement>document.querySelector('.main-panel');
const elemSidebar = <HTMLElement>document.querySelector('.sidebar .sidebar-wrapper');
this.location.subscribe((ev:PopStateEvent) => {
this.lastPoppedUrl = ev.url;
});
this.router.events.subscribe((event:any) => {
if (event instanceof NavigationStart) {
if (event.url != this.lastPoppedUrl)
this.yScrollStack.push(window.scrollY);
} else if (event instanceof NavigationEnd) {
if (event.url == this.lastPoppedUrl) {
this.lastPoppedUrl = undefined;
window.scrollTo(0, this.yScrollStack.pop());
} else
window.scrollTo(0, 0);
}
});
this._router = this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((event: NavigationEnd) => {
elemMainPanel.scrollTop = 0;
elemSidebar.scrollTop = 0;
});
if (window.matchMedia(`(min-width: 960px)`).matches && !this.isMac()) {
let ps = new PerfectScrollbar(elemMainPanel);
ps = new PerfectScrollbar(elemSidebar);
}
const window_width = $(window).width();
let $sidebar = $('.sidebar');
let $sidebar_responsive = $('body > .navbar-collapse');
let $sidebar_img_container = $sidebar.find('.sidebar-background');
if(window_width > 767){
if($('.fixed-plugin .dropdown').hasClass('show-dropdown')){
$('.fixed-plugin .dropdown').addClass('open');
}
}
$('.fixed-plugin a').click(function(event){
// Alex if we click on switch, stop propagation of the event, so the dropdown will not be hide, otherwise we set the section active
if($(this).hasClass('switch-trigger')){
if(event.stopPropagation){
event.stopPropagation();
}
else if(window.event){
window.event.cancelBubble = true;
}
}
});
$('.fixed-plugin .badge').click(function(){
let $full_page_background = $('.full-page-background');
$(this).siblings().removeClass('active');
$(this).addClass('active');
var new_color = $(this).data('color');
if($sidebar.length !== 0){
$sidebar.attr('data-color', new_color);
}
if($sidebar_responsive.length != 0){
$sidebar_responsive.attr('data-color',new_color);
}
});
$('.fixed-plugin .img-holder').click(function(){
let $full_page_background = $('.full-page-background');
$(this).parent('li').siblings().removeClass('active');
$(this).parent('li').addClass('active');
var new_image = $(this).find("img").attr('src');
if($sidebar_img_container.length !=0 ){
$sidebar_img_container.fadeOut('fast', function(){
$sidebar_img_container.css('background-image','url("' + new_image + '")');
$sidebar_img_container.fadeIn('fast');
});
}
if($full_page_background.length != 0){
$full_page_background.fadeOut('fast', function(){
$full_page_background.css('background-image','url("' + new_image + '")');
$full_page_background.fadeIn('fast');
});
}
if($sidebar_responsive.length != 0){
$sidebar_responsive.css('background-image','url("' + new_image + '")');
}
});
}
ngAfterViewInit() {
this.runOnRouteChange();
}
isMaps(path){
var titlee = this.location.prepareExternalUrl(this.location.path());
titlee = titlee.slice( 1 );
if(path == titlee){
return false;
}
else {
return true;
}
}
runOnRouteChange(): void {
if (window.matchMedia(`(min-width: 960px)`).matches && !this.isMac()) {
const elemMainPanel = <HTMLElement>document.querySelector('.main-panel');
const ps = new PerfectScrollbar(elemMainPanel);
ps.update();
}
}
isMac(): boolean {
let bool = false;
if (navigator.userAgent.toUpperCase().indexOf('MAC') >= 0 || navigator.userAgent.toUpperCase().indexOf('IPAD') >= 0) {
bool = true;
}
return bool;
}
}