2022-08-29 13:57:05 +02:00
|
|
|
import {
|
|
|
|
AfterViewInit,
|
|
|
|
ChangeDetectorRef,
|
|
|
|
Component,
|
|
|
|
ElementRef,
|
|
|
|
Input,
|
|
|
|
OnDestroy,
|
|
|
|
OnInit,
|
|
|
|
ViewChild
|
|
|
|
} from "@angular/core";
|
2022-08-04 14:29:08 +02:00
|
|
|
import {LayoutService} from "../sidebar/layout.service";
|
2022-08-29 13:57:05 +02:00
|
|
|
import {Subscription} from "rxjs";
|
2022-07-14 10:29:29 +02:00
|
|
|
|
|
|
|
declare var UIkit;
|
2022-08-29 13:57:05 +02:00
|
|
|
declare var ResizeObserver;
|
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-08-29 13:57:05 +02:00
|
|
|
<div id="page_content_sticky_footer" #sticky_footer class="uk-blur-background"
|
|
|
|
[attr.uk-sticky]="'bottom: true;'" [attr.offset]="footer_offset">
|
|
|
|
<div class="uk-container uk-container-large">
|
|
|
|
<div class="uk-padding-small uk-padding-remove-vertical">
|
|
|
|
<ng-content select="[sticky_footer]"></ng-content>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-25 10:16:01 +02:00
|
|
|
<div id="page_content_header" #header class="uk-blur-background"
|
2022-08-29 13:57:05 +02:00
|
|
|
[attr.uk-sticky]="(headerSticky && shouldSticky)?'media: @m':null" [attr.offset]="offset"
|
|
|
|
[attr.style]="'margin-top: '+(footer_height? '-'+footer_height+'px': '0')">
|
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-25 10:16:01 +02:00
|
|
|
<div id="page_content_actions" #actions class="uk-blur-background"
|
2022-07-17 15:01:39 +02:00
|
|
|
[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>
|
2022-08-29 13:57:05 +02:00
|
|
|
<div id="page_content_footer" #footer>
|
|
|
|
<div class="uk-container uk-container-large">
|
|
|
|
<div class="uk-padding-small uk-padding-remove-vertical">
|
|
|
|
<ng-content select="[footer]"></ng-content>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</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;
|
2022-08-29 13:57:05 +02:00
|
|
|
public footer_offset: number = 0;
|
|
|
|
public footer_height: number = 0;
|
|
|
|
@ViewChild("sticky_footer") sticky_footer;
|
|
|
|
subscriptions = [];
|
2022-08-30 12:11:32 +02:00
|
|
|
|
2022-08-29 13:57:05 +02:00
|
|
|
constructor(private layoutService: LayoutService, private cdr: ChangeDetectorRef) {
|
2022-03-11 00:07:44 +01:00
|
|
|
}
|
|
|
|
|
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-08-30 12:11:32 +02:00
|
|
|
if (this.header && this.actions && this.shouldSticky) {
|
|
|
|
let sticky = this.headerSticky ? this.header.nativeElement : this.actions.nativeElement;
|
2022-07-14 10:29:29 +02:00
|
|
|
return UIkit.sticky(sticky).isActive;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-30 19:47:47 +02:00
|
|
|
ngAfterViewInit() {
|
2022-08-30 12:11:32 +02:00
|
|
|
if (typeof document !== "undefined") {
|
2022-09-20 10:01:51 +02:00
|
|
|
// TODO make it smooth
|
|
|
|
// this.observeBottom();
|
2022-08-30 12:11:32 +02:00
|
|
|
this.observeHeader();
|
|
|
|
this.observeStickyFooter();
|
2022-03-30 19:47:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 17:35:00 +01:00
|
|
|
ngOnDestroy() {
|
2022-08-29 13:57:05 +02:00
|
|
|
this.subscriptions.forEach(subscription => {
|
2022-08-30 12:11:32 +02:00
|
|
|
if (subscription instanceof (ResizeObserver || IntersectionObserver)) {
|
2022-08-29 13:57:05 +02:00
|
|
|
subscription.disconnect();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-08-30 12:11:32 +02:00
|
|
|
|
2022-08-29 13:57:05 +02:00
|
|
|
ngAfterContentChecked() {
|
2022-08-30 12:11:32 +02:00
|
|
|
if (this.sticky_footer && typeof document !== 'undefined') {
|
2022-08-29 13:57:05 +02:00
|
|
|
this.footer_offset = this.calcStickyFooterOffset(this.sticky_footer.nativeElement);
|
|
|
|
}
|
|
|
|
}
|
2022-08-30 12:11:32 +02:00
|
|
|
|
|
|
|
private observeBottom() {
|
|
|
|
let bottom = document.getElementById('bottom');
|
|
|
|
if (bottom) {
|
|
|
|
let bottomObs = new IntersectionObserver(entries => {
|
|
|
|
entries.forEach(entry => {
|
|
|
|
this.shouldSticky = !entry.isIntersecting;
|
|
|
|
})
|
|
|
|
});
|
|
|
|
this.subscriptions.push(bottomObs);
|
|
|
|
bottomObs.observe(bottom);
|
|
|
|
}
|
2022-08-29 13:57:05 +02:00
|
|
|
}
|
2022-08-30 12:11:32 +02:00
|
|
|
|
|
|
|
private observeHeader() {
|
|
|
|
if (this.header) {
|
|
|
|
let headerObs = new IntersectionObserver(entries => {
|
|
|
|
entries.forEach(entry => {
|
2022-08-31 12:15:49 +02:00
|
|
|
if(entry.boundingClientRect.height > 0) {
|
|
|
|
this.layoutService.setReplaceHeader(!entry.isIntersecting);
|
|
|
|
}
|
2022-08-30 12:11:32 +02:00
|
|
|
})
|
2022-08-31 12:15:49 +02:00
|
|
|
});
|
2022-08-30 12:11:32 +02:00
|
|
|
this.subscriptions.push(headerObs);
|
|
|
|
headerObs.observe(this.header.nativeElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private observeStickyFooter() {
|
|
|
|
if (this.sticky_footer) {
|
|
|
|
let resizeObs = new ResizeObserver(entries => {
|
|
|
|
entries.forEach(entry => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.footer_offset = this.calcStickyFooterOffset(entry.target);
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
this.subscriptions.push(resizeObs);
|
|
|
|
resizeObs.observe(this.sticky_footer.nativeElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-29 13:57:05 +02:00
|
|
|
calcStickyFooterOffset(element) {
|
|
|
|
this.footer_height = element.offsetHeight;
|
2022-08-30 12:11:32 +02:00
|
|
|
return window.innerHeight - this.footer_height;
|
2022-03-14 17:35:00 +01:00
|
|
|
}
|
2020-11-01 16:41:02 +01:00
|
|
|
}
|