You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
8.4 KiB
177 lines
8.4 KiB
import * as i0 from '@angular/core';
|
|
import { Component, ChangeDetectionStrategy, ViewEncapsulation, Input, NgModule } from '@angular/core';
|
|
import * as i2 from '@angular/common';
|
|
import { CommonModule } from '@angular/common';
|
|
import { trigger, state, style, transition, animate } from '@angular/animations';
|
|
import { DomHandler } from 'primeng/dom';
|
|
import { ZIndexUtils } from 'primeng/utils';
|
|
import * as i1 from 'primeng/api';
|
|
|
|
class ScrollTop {
|
|
constructor(el, cd, config) {
|
|
this.el = el;
|
|
this.cd = cd;
|
|
this.config = config;
|
|
this.target = "window";
|
|
this.threshold = 400;
|
|
this.icon = "pi pi-chevron-up";
|
|
this.behavior = "smooth";
|
|
this.showTransitionOptions = '.15s';
|
|
this.hideTransitionOptions = '.15s';
|
|
this.visible = false;
|
|
}
|
|
ngOnInit() {
|
|
if (this.target === 'window')
|
|
this.bindDocumentScrollListener();
|
|
else if (this.target === 'parent')
|
|
this.bindParentScrollListener();
|
|
}
|
|
onClick() {
|
|
let scrollElement = this.target === 'window' ? window : this.el.nativeElement.parentElement;
|
|
scrollElement.scroll({
|
|
top: 0,
|
|
behavior: this.behavior
|
|
});
|
|
}
|
|
onEnter(event) {
|
|
switch (event.toState) {
|
|
case 'open':
|
|
this.overlay = event.element;
|
|
ZIndexUtils.set('overlay', this.overlay, this.config.zIndex.overlay);
|
|
break;
|
|
case 'void':
|
|
this.overlay = null;
|
|
break;
|
|
}
|
|
}
|
|
onLeave(event) {
|
|
switch (event.toState) {
|
|
case 'void':
|
|
ZIndexUtils.clear(event.element);
|
|
break;
|
|
}
|
|
}
|
|
checkVisibility(scrollY) {
|
|
if (scrollY > this.threshold)
|
|
this.visible = true;
|
|
else
|
|
this.visible = false;
|
|
this.cd.markForCheck();
|
|
}
|
|
bindParentScrollListener() {
|
|
this.scrollListener = () => {
|
|
this.checkVisibility(this.el.nativeElement.parentElement.scrollTop);
|
|
};
|
|
this.el.nativeElement.parentElement.addEventListener('scroll', this.scrollListener);
|
|
}
|
|
bindDocumentScrollListener() {
|
|
this.scrollListener = () => {
|
|
this.checkVisibility(DomHandler.getWindowScrollTop());
|
|
};
|
|
window.addEventListener('scroll', this.scrollListener);
|
|
}
|
|
unbindParentScrollListener() {
|
|
if (this.scrollListener) {
|
|
this.el.nativeElement.parentElement.removeEventListener('scroll', this.scrollListener);
|
|
this.scrollListener = null;
|
|
}
|
|
}
|
|
unbindDocumentScrollListener() {
|
|
if (this.scrollListener) {
|
|
window.removeEventListener('scroll', this.scrollListener);
|
|
this.scrollListener = null;
|
|
}
|
|
}
|
|
containerClass() {
|
|
return {
|
|
'p-scrolltop p-link p-component': true,
|
|
'p-scrolltop-sticky': this.target !== 'window'
|
|
};
|
|
}
|
|
ngOnDestroy() {
|
|
if (this.target === 'window')
|
|
this.unbindDocumentScrollListener();
|
|
else if (this.target === 'parent')
|
|
this.unbindParentScrollListener();
|
|
if (this.overlay) {
|
|
ZIndexUtils.clear(this.overlay);
|
|
this.overlay = null;
|
|
}
|
|
}
|
|
}
|
|
ScrollTop.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ScrollTop, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i1.PrimeNGConfig }], target: i0.ɵɵFactoryTarget.Component });
|
|
ScrollTop.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.3", type: ScrollTop, selector: "p-scrollTop", inputs: { styleClass: "styleClass", style: "style", target: "target", threshold: "threshold", icon: "icon", behavior: "behavior", showTransitionOptions: "showTransitionOptions", hideTransitionOptions: "hideTransitionOptions" }, host: { classAttribute: "p-element" }, ngImport: i0, template: `
|
|
<button *ngIf="visible" [@animation]="{value: 'open', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" (@animation.start)="onEnter($event)" (@animation.done)="onLeave($event)"
|
|
[ngClass]="containerClass()" (click)="onClick()" [class]="styleClass" [ngStyle]="style" type="button">
|
|
<span [class]="icon" [ngClass]="'p-scrolltop-icon'"></span>
|
|
</button>
|
|
`, isInline: true, styles: [".p-scrolltop{position:fixed;bottom:20px;right:20px;display:flex;align-items:center;justify-content:center}.p-scrolltop-sticky{position:sticky}.p-scrolltop-sticky.p-link{margin-left:auto}\n"], directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], animations: [
|
|
trigger('animation', [
|
|
state('void', style({
|
|
opacity: 0
|
|
})),
|
|
state('open', style({
|
|
opacity: 1
|
|
})),
|
|
transition('void => open', animate('{{showTransitionParams}}')),
|
|
transition('open => void', animate('{{hideTransitionParams}}')),
|
|
])
|
|
], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ScrollTop, decorators: [{
|
|
type: Component,
|
|
args: [{ selector: 'p-scrollTop', template: `
|
|
<button *ngIf="visible" [@animation]="{value: 'open', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" (@animation.start)="onEnter($event)" (@animation.done)="onLeave($event)"
|
|
[ngClass]="containerClass()" (click)="onClick()" [class]="styleClass" [ngStyle]="style" type="button">
|
|
<span [class]="icon" [ngClass]="'p-scrolltop-icon'"></span>
|
|
</button>
|
|
`, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, animations: [
|
|
trigger('animation', [
|
|
state('void', style({
|
|
opacity: 0
|
|
})),
|
|
state('open', style({
|
|
opacity: 1
|
|
})),
|
|
transition('void => open', animate('{{showTransitionParams}}')),
|
|
transition('open => void', animate('{{hideTransitionParams}}')),
|
|
])
|
|
], host: {
|
|
'class': 'p-element'
|
|
}, styles: [".p-scrolltop{position:fixed;bottom:20px;right:20px;display:flex;align-items:center;justify-content:center}.p-scrolltop-sticky{position:sticky}.p-scrolltop-sticky.p-link{margin-left:auto}\n"] }]
|
|
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: i1.PrimeNGConfig }]; }, propDecorators: { styleClass: [{
|
|
type: Input
|
|
}], style: [{
|
|
type: Input
|
|
}], target: [{
|
|
type: Input
|
|
}], threshold: [{
|
|
type: Input
|
|
}], icon: [{
|
|
type: Input
|
|
}], behavior: [{
|
|
type: Input
|
|
}], showTransitionOptions: [{
|
|
type: Input
|
|
}], hideTransitionOptions: [{
|
|
type: Input
|
|
}] } });
|
|
class ScrollTopModule {
|
|
}
|
|
ScrollTopModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ScrollTopModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
ScrollTopModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ScrollTopModule, declarations: [ScrollTop], imports: [CommonModule], exports: [ScrollTop] });
|
|
ScrollTopModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ScrollTopModule, imports: [[CommonModule]] });
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ScrollTopModule, decorators: [{
|
|
type: NgModule,
|
|
args: [{
|
|
imports: [CommonModule],
|
|
exports: [ScrollTop],
|
|
declarations: [ScrollTop]
|
|
}]
|
|
}] });
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { ScrollTop, ScrollTopModule };
|
|
//# sourceMappingURL=primeng-scrolltop.mjs.map
|