{"version":3,"file":"primeng-scrolltop.js","sources":["../../src/app/components/scrolltop/scrolltop.ts","../../src/app/components/scrolltop/primeng-scrolltop.ts"],"sourcesContent":["import { NgModule, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, OnInit, OnDestroy, ElementRef, ChangeDetectorRef} from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { animate, state, style, transition, trigger } from '@angular/animations';\nimport { DomHandler } from 'primeng/dom';\n\n@Component({\n selector: 'p-scrollTop',\n template: `\n \n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n styleUrls: ['./scrolltop.css'],\n animations: [\n trigger('animation', [\n state('void', style({\n opacity: 0\n })),\n state('open', style({\n opacity: 1\n })),\n transition('void => open', animate('{{showTransitionParams}}')),\n transition('open => void', animate('{{hideTransitionParams}}')),\n ])\n ]\n})\nexport class ScrollTop implements OnInit, OnDestroy {\n\n @Input() styleClass: string;\n\n @Input() style: any;\n\n @Input() target: string = \"window\";\n \n @Input() threshold: number = 400;\n\n @Input() icon: string = \"pi pi-chevron-up\";\n\n @Input() behavior: string = \"smooth\";\n \n @Input() showTransitionOptions: string = '.15s';\n\n @Input() hideTransitionOptions: string = '.15s';\n\n scrollListener: any;\n \n visible: boolean = false;\n\n constructor(public el: ElementRef, private cd: ChangeDetectorRef) { }\n\n ngOnInit() {\n if (this.target === 'window')\n this.bindDocumentScrollListener();\n else if (this.target === 'parent')\n this.bindParentScrollListener();\n }\n\n onClick() {\n let scrollElement = this.target === 'window' ? window : this.el.nativeElement.parentElement;\n scrollElement.scroll({\n top: 0, \n behavior: this.behavior\n });\n }\n\n onEnter() {\n this.el.nativeElement.children[0].style.zIndex = DomHandler.generateZIndex();\n }\n\n checkVisibility(scrollY) {\n if (scrollY > this.threshold)\n this.visible = true;\n else\n this.visible = false;\n\n this.cd.markForCheck();\n }\n\n bindParentScrollListener() {\n this.scrollListener = () => {\n\n this.checkVisibility(this.el.nativeElement.parentElement.scrollTop);\n };\n \n this.el.nativeElement.parentElement.addEventListener('scroll', this.scrollListener);\n }\n\n bindDocumentScrollListener() {\n this.scrollListener = () => {\n this.checkVisibility(DomHandler.getWindowScrollTop());\n };\n \n window.addEventListener('scroll', this.scrollListener);\n }\n\n unbindParentScrollListener() {\n if (this.scrollListener) {\n this.el.nativeElement.parentElement.removeEventListener('scroll', this.scrollListener);\n this.scrollListener = null;\n }\n }\n\n unbindDocumentScrollListener() {\n if (this.scrollListener) {\n window.removeEventListener('scroll', this.scrollListener);\n this.scrollListener = null;\n }\n }\n\n containerClass() {\n return {\n 'p-scrolltop p-link p-component': true,\n 'p-scrolltop-sticky': this.target !== 'window'\n };\n }\n\n ngOnDestroy() {\n if (this.target === 'window')\n this.unbindDocumentScrollListener();\n else if (this.target === 'parent')\n this.unbindParentScrollListener();\n }\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [ScrollTop],\n declarations: [ScrollTop]\n})\nexport class ScrollTopModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;MA6Ba,SAAS;IAsBlB,YAAmB,EAAc,EAAU,EAAqB;QAA7C,OAAE,GAAF,EAAE,CAAY;QAAU,OAAE,GAAF,EAAE,CAAmB;QAhBvD,WAAM,GAAW,QAAQ,CAAC;QAE1B,cAAS,GAAW,GAAG,CAAC;QAExB,SAAI,GAAW,kBAAkB,CAAC;QAElC,aAAQ,GAAW,QAAQ,CAAC;QAE5B,0BAAqB,GAAW,MAAM,CAAC;QAEvC,0BAAqB,GAAW,MAAM,CAAC;QAIhD,YAAO,GAAY,KAAK,CAAC;KAE4C;IAErE,QAAQ;QACJ,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ;YACxB,IAAI,CAAC,0BAA0B,EAAE,CAAC;aACjC,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ;YAC7B,IAAI,CAAC,wBAAwB,EAAE,CAAC;KACvC;IAED,OAAO;QACH,IAAI,aAAa,GAAG,IAAI,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