2022-07-14 10:29:29 +02:00
|
|
|
import {AfterViewInit, Component, ElementRef, Input, OnDestroy, OnInit, ViewChild} from "@angular/core";
|
|
|
|
|
|
|
|
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">
|
2022-07-17 15:01:39 +02:00
|
|
|
<div id="page_content_header" #header [class.uk-blur-background]="headerSticky && isStickyActive"
|
|
|
|
[attr.uk-sticky]="(headerSticky && shouldSticky)?'media: @m':null" [attr.offset]="offset">
|
2022-07-13 19:25:19 +02:00
|
|
|
<div class="uk-container uk-container-large">
|
2022-04-09 15:18:30 +02:00
|
|
|
<div class="uk-padding-small uk-padding-remove-vertical">
|
|
|
|
<ng-content select="[header]"></ng-content>
|
2022-03-14 17:35:00 +01:00
|
|
|
</div>
|
2022-03-11 00:07:44 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-17 15:01:39 +02:00
|
|
|
<div id="page_content_actions" #actions [class.uk-blur-background]="!headerSticky && isStickyActive"
|
|
|
|
[attr.uk-sticky]="(!headerSticky && shouldSticky)?'media: @m':null" [attr.offset]="offset">
|
2022-07-13 19:25:19 +02:00
|
|
|
<div class="uk-container uk-container-large">
|
|
|
|
<div class="uk-padding-small uk-padding-remove-vertical">
|
|
|
|
<ng-content select="[actions]"></ng-content>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-28 00:21:55 +02:00
|
|
|
<div id="page_content_inner" class="uk-container uk-container-large">
|
2022-07-13 19:25:19 +02:00
|
|
|
<div class="uk-padding-small uk-padding-remove-vertical">
|
2022-03-28 00:21:55 +02:00
|
|
|
<ng-content select="[inner]"></ng-content>
|
|
|
|
</div>
|
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-30 19:47:47 +02:00
|
|
|
export class PageContentComponent implements OnInit, AfterViewInit, OnDestroy {
|
2022-07-13 19:25:19 +02:00
|
|
|
@Input()
|
|
|
|
public headerSticky: boolean = false;
|
2022-03-11 00:07:44 +01:00
|
|
|
public offset: number;
|
2022-03-30 19:47:47 +02:00
|
|
|
public shouldSticky: boolean = true;
|
2022-07-14 10:29:29 +02:00
|
|
|
@ViewChild('header') header: ElementRef;
|
|
|
|
@ViewChild('actions') actions: ElementRef;
|
|
|
|
public
|
2022-03-30 19:47:47 +02:00
|
|
|
private observer: IntersectionObserver;
|
2022-03-11 00:07:44 +01:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
2022-03-03 16:44:59 +01:00
|
|
|
ngOnInit() {
|
2022-03-30 19:47:47 +02:00
|
|
|
if (typeof document !== "undefined") {
|
2022-07-17 15:01:39 +02:00
|
|
|
this.offset = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--header-height'));
|
2022-03-11 00:07:44 +01:00
|
|
|
}
|
2022-03-14 17:35:00 +01:00
|
|
|
}
|
|
|
|
|
2022-07-14 10:29:29 +02:00
|
|
|
get isStickyActive() {
|
2022-07-17 23:46:58 +02:00
|
|
|
if(this.header && this.actions && this.shouldSticky) {
|
2022-07-14 10:29:29 +02:00
|
|
|
let sticky = (this.headerSticky)?this.header.nativeElement:this.actions.nativeElement;
|
|
|
|
return UIkit.sticky(sticky).isActive;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-30 19:47:47 +02:00
|
|
|
ngAfterViewInit() {
|
|
|
|
if(typeof document !== "undefined") {
|
|
|
|
let bottom = document.getElementById('bottom');
|
|
|
|
if(bottom) {
|
|
|
|
this.observer = new IntersectionObserver(entries => {
|
|
|
|
entries.forEach(entry => {
|
|
|
|
this.shouldSticky = !entry.isIntersecting;
|
|
|
|
})
|
|
|
|
});
|
|
|
|
this.observer.observe(bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 17:35:00 +01:00
|
|
|
ngOnDestroy() {
|
2022-03-30 19:47:47 +02:00
|
|
|
if(this.observer) {
|
|
|
|
this.observer.disconnect();
|
|
|
|
}
|
2022-03-14 17:35:00 +01:00
|
|
|
}
|
2020-11-01 16:41:02 +01:00
|
|
|
}
|