UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![npm downloads](https://img.shields.io/npm/dm/primeng.sv

161 lines (157 loc) 7.71 kB
import * as i0 from '@angular/core'; import { Component, ChangeDetectionStrategy, ViewEncapsulation, Input, NgModule } from '@angular/core'; import * as i1 from '@angular/common'; import { CommonModule } from '@angular/common'; import { trigger, state, style, transition, animate } from '@angular/animations'; import { DomHandler } from 'primeng/dom'; class ScrollTop { constructor(el, cd) { this.el = el; this.cd = cd; 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() { this.el.nativeElement.children[0].style.zIndex = DomHandler.generateZIndex(); } 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(); } } ScrollTop.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: ScrollTop, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); ScrollTop.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.4", type: ScrollTop, selector: "p-scrollTop", inputs: { styleClass: "styleClass", style: "style", target: "target", threshold: "threshold", icon: "icon", behavior: "behavior", showTransitionOptions: "showTransitionOptions", hideTransitionOptions: "hideTransitionOptions" }, ngImport: i0, template: ` <button *ngIf="visible" [@animation]="{value: 'open', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" (@animation.start)="onEnter()" [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}"], directives: [{ type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.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: "12.0.4", 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()" [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, styleUrls: ['./scrolltop.css'], animations: [ trigger('animation', [ state('void', style({ opacity: 0 })), state('open', style({ opacity: 1 })), transition('void => open', animate('{{showTransitionParams}}')), transition('open => void', animate('{{hideTransitionParams}}')), ]) ] }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, 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: "12.0.4", ngImport: i0, type: ScrollTopModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); ScrollTopModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: ScrollTopModule, declarations: [ScrollTop], imports: [CommonModule], exports: [ScrollTop] }); ScrollTopModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: ScrollTopModule, imports: [[CommonModule]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", 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.js.map