2022-03-11 00:07:44 +01:00
|
|
|
import {Component, ElementRef, EventEmitter, HostListener, OnDestroy, OnInit, Output, ViewChild} from "@angular/core";
|
|
|
|
import {Subscription} from "rxjs";
|
|
|
|
|
|
|
|
declare var UIkit;
|
2020-11-01 16:41:02 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: '[page-content]',
|
|
|
|
template: `
|
2022-03-14 17:35:00 +01:00
|
|
|
<div id="page_content">
|
|
|
|
<div id="header">
|
2022-03-16 14:10:35 +01:00
|
|
|
<div id="page_content_header" uk-sticky="media: @m" [attr.offset]="offset">
|
|
|
|
<div #header class="uk-container uk-container-large uk-padding-remove-vertical">
|
2022-03-14 17:35:00 +01:00
|
|
|
<ng-content select="[header]"></ng-content>
|
|
|
|
</div>
|
2022-03-11 00:07:44 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-17 12:28:25 +01:00
|
|
|
<div id="page_content_inner" class="uk-section uk-padding-remove-top uk-container uk-container-large">
|
2022-03-11 00:07:44 +01:00
|
|
|
<ng-content select="[inner]"></ng-content>
|
2022-03-03 16:44:59 +01:00
|
|
|
</div>
|
2020-11-01 16:41:02 +01:00
|
|
|
</div>
|
2022-03-14 17:35:00 +01:00
|
|
|
`,
|
2020-11-01 16:41:02 +01:00
|
|
|
})
|
2022-03-11 00:07:44 +01:00
|
|
|
export class PageContentComponent implements OnInit, OnDestroy {
|
|
|
|
public offset: number;
|
|
|
|
public sticky: boolean = false;
|
|
|
|
@Output()
|
|
|
|
public stickyEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
|
|
|
@ViewChild("header") public header: ElementRef;
|
2022-03-14 17:35:00 +01:00
|
|
|
private current;
|
2022-03-11 00:07:44 +01:00
|
|
|
private subscriptions: any[] = [];
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
2022-03-03 16:44:59 +01:00
|
|
|
ngOnInit() {
|
2022-03-11 00:07:44 +01:00
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
this.current = window.pageYOffset;
|
2022-03-16 14:10:35 +01:00
|
|
|
this.initSticky();
|
2022-03-11 00:07:44 +01:00
|
|
|
}
|
2022-03-14 17:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
initSticky() {
|
|
|
|
this.clear();
|
2022-03-16 14:10:35 +01:00
|
|
|
this.subscriptions.push(UIkit.util.on(document, 'active', '#sticky-menu', (): void => {
|
|
|
|
this.offset = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--structure-header-height'));
|
|
|
|
|
|
|
|
}));
|
|
|
|
this.subscriptions.push(UIkit.util.on(document, 'inactive', '#sticky-menu', (): void => {
|
|
|
|
this.offset = 0;
|
|
|
|
}));
|
2022-03-11 00:07:44 +01:00
|
|
|
this.subscriptions.push(UIkit.util.on(document, 'active', '#page_content_header', (): void => {
|
2022-03-14 17:35:00 +01:00
|
|
|
this.sticky = true;
|
|
|
|
this.stickyEmitter.emit(this.sticky);
|
2022-03-11 00:07:44 +01:00
|
|
|
}));
|
|
|
|
this.subscriptions.push(UIkit.util.on(document, 'inactive', '#page_content_header', (): void => {
|
|
|
|
this.sticky = false;
|
|
|
|
this.stickyEmitter.emit(this.sticky);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-03-14 17:35:00 +01:00
|
|
|
clear() {
|
2022-03-11 00:07:44 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
} else if (subscription instanceof Function) {
|
|
|
|
subscription();
|
|
|
|
}
|
|
|
|
});
|
2020-11-01 16:41:02 +01:00
|
|
|
}
|
2022-03-14 17:35:00 +01:00
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.clear();
|
|
|
|
}
|
2020-11-01 16:41:02 +01:00
|
|
|
}
|