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

184 lines (176 loc) 10.7 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/animations'), require('primeng/dom')) : typeof define === 'function' && define.amd ? define('primeng/scrolltop', ['exports', '@angular/core', '@angular/common', '@angular/animations', 'primeng/dom'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.primeng = global.primeng || {}, global.primeng.scrolltop = {}), global.ng.core, global.ng.common, global.ng.animations, global.primeng.dom)); }(this, (function (exports, i0, i1, animations, dom) { 'use strict'; function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n['default'] = e; return Object.freeze(n); } var i0__namespace = /*#__PURE__*/_interopNamespace(i0); var i1__namespace = /*#__PURE__*/_interopNamespace(i1); var ScrollTop = /** @class */ (function () { function ScrollTop(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; } ScrollTop.prototype.ngOnInit = function () { if (this.target === 'window') this.bindDocumentScrollListener(); else if (this.target === 'parent') this.bindParentScrollListener(); }; ScrollTop.prototype.onClick = function () { var scrollElement = this.target === 'window' ? window : this.el.nativeElement.parentElement; scrollElement.scroll({ top: 0, behavior: this.behavior }); }; ScrollTop.prototype.onEnter = function () { this.el.nativeElement.children[0].style.zIndex = dom.DomHandler.generateZIndex(); }; ScrollTop.prototype.checkVisibility = function (scrollY) { if (scrollY > this.threshold) this.visible = true; else this.visible = false; this.cd.markForCheck(); }; ScrollTop.prototype.bindParentScrollListener = function () { var _this = this; this.scrollListener = function () { _this.checkVisibility(_this.el.nativeElement.parentElement.scrollTop); }; this.el.nativeElement.parentElement.addEventListener('scroll', this.scrollListener); }; ScrollTop.prototype.bindDocumentScrollListener = function () { var _this = this; this.scrollListener = function () { _this.checkVisibility(dom.DomHandler.getWindowScrollTop()); }; window.addEventListener('scroll', this.scrollListener); }; ScrollTop.prototype.unbindParentScrollListener = function () { if (this.scrollListener) { this.el.nativeElement.parentElement.removeEventListener('scroll', this.scrollListener); this.scrollListener = null; } }; ScrollTop.prototype.unbindDocumentScrollListener = function () { if (this.scrollListener) { window.removeEventListener('scroll', this.scrollListener); this.scrollListener = null; } }; ScrollTop.prototype.containerClass = function () { return { 'p-scrolltop p-link p-component': true, 'p-scrolltop-sticky': this.target !== 'window' }; }; ScrollTop.prototype.ngOnDestroy = function () { if (this.target === 'window') this.unbindDocumentScrollListener(); else if (this.target === 'parent') this.unbindParentScrollListener(); }; return ScrollTop; }()); ScrollTop.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0__namespace, type: ScrollTop, deps: [{ token: i0__namespace.ElementRef }, { token: i0__namespace.ChangeDetectorRef }], target: i0__namespace.ɵɵFactoryTarget.Component }); ScrollTop.ɵcmp = i0__namespace.ɵɵ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__namespace, template: "\n <button *ngIf=\"visible\" [@animation]=\"{value: 'open', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}\" (@animation.start)=\"onEnter()\"\n [ngClass]=\"containerClass()\" (click)=\"onClick()\" [class]=\"styleClass\" [ngStyle]=\"style\" type=\"button\">\n <span [class]=\"icon\" [ngClass]=\"'p-scrolltop-icon'\"></span>\n </button>\n ", 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__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1__namespace.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1__namespace.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], animations: [ animations.trigger('animation', [ animations.state('void', animations.style({ opacity: 0 })), animations.state('open', animations.style({ opacity: 1 })), animations.transition('void => open', animations.animate('{{showTransitionParams}}')), animations.transition('open => void', animations.animate('{{hideTransitionParams}}')), ]) ], changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush, encapsulation: i0__namespace.ViewEncapsulation.None }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0__namespace, type: ScrollTop, decorators: [{ type: i0.Component, args: [{ selector: 'p-scrollTop', template: "\n <button *ngIf=\"visible\" [@animation]=\"{value: 'open', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}\" (@animation.start)=\"onEnter()\"\n [ngClass]=\"containerClass()\" (click)=\"onClick()\" [class]=\"styleClass\" [ngStyle]=\"style\" type=\"button\">\n <span [class]=\"icon\" [ngClass]=\"'p-scrolltop-icon'\"></span>\n </button>\n ", changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None, styleUrls: ['./scrolltop.css'], animations: [ animations.trigger('animation', [ animations.state('void', animations.style({ opacity: 0 })), animations.state('open', animations.style({ opacity: 1 })), animations.transition('void => open', animations.animate('{{showTransitionParams}}')), animations.transition('open => void', animations.animate('{{hideTransitionParams}}')), ]) ] }] }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }, { type: i0__namespace.ChangeDetectorRef }]; }, propDecorators: { styleClass: [{ type: i0.Input }], style: [{ type: i0.Input }], target: [{ type: i0.Input }], threshold: [{ type: i0.Input }], icon: [{ type: i0.Input }], behavior: [{ type: i0.Input }], showTransitionOptions: [{ type: i0.Input }], hideTransitionOptions: [{ type: i0.Input }] } }); var ScrollTopModule = /** @class */ (function () { function ScrollTopModule() { } return ScrollTopModule; }()); ScrollTopModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0__namespace, type: ScrollTopModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule }); ScrollTopModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0__namespace, type: ScrollTopModule, declarations: [ScrollTop], imports: [i1.CommonModule], exports: [ScrollTop] }); ScrollTopModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0__namespace, type: ScrollTopModule, imports: [[i1.CommonModule]] }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0__namespace, type: ScrollTopModule, decorators: [{ type: i0.NgModule, args: [{ imports: [i1.CommonModule], exports: [ScrollTop], declarations: [ScrollTop] }] }] }); /** * Generated bundle index. Do not edit. */ exports.ScrollTop = ScrollTop; exports.ScrollTopModule = ScrollTopModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=primeng-scrolltop.umd.js.map