65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import {AfterViewInit, Component, Input, OnDestroy, OnInit} from "@angular/core";
|
|
|
|
@Component({
|
|
selector: '[page-content]',
|
|
template: `
|
|
<div id="page_content">
|
|
<div id="page_content_header" [attr.uk-sticky]="(headerSticky && shouldSticky)?'media: @m':null" [attr.offset]="offset">
|
|
<div class="uk-container uk-container-large">
|
|
<div class="uk-padding-small uk-padding-remove-vertical">
|
|
<ng-content select="[header]"></ng-content>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="page_content_actions" [attr.uk-sticky]="(!headerSticky && shouldSticky)?'media: @m':null" [attr.offset]="offset">
|
|
<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>
|
|
<div id="page_content_inner" class="uk-container uk-container-large">
|
|
<div class="uk-padding-small uk-padding-remove-vertical">
|
|
<ng-content select="[inner]"></ng-content>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`,
|
|
})
|
|
export class PageContentComponent implements OnInit, AfterViewInit, OnDestroy {
|
|
@Input()
|
|
public headerSticky: boolean = false;
|
|
public offset: number;
|
|
public shouldSticky: boolean = true;
|
|
private observer: IntersectionObserver;
|
|
|
|
constructor() {
|
|
}
|
|
|
|
ngOnInit() {
|
|
if (typeof document !== "undefined") {
|
|
this.offset = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--structure-header-height'));
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
if(this.observer) {
|
|
this.observer.disconnect();
|
|
}
|
|
}
|
|
}
|