1 line
6.5 KiB
Plaintext
1 line
6.5 KiB
Plaintext
{"version":3,"file":"primeng-defer.mjs","sources":["../../src/app/components/defer/defer.ts","../../src/app/components/defer/primeng-defer.ts"],"sourcesContent":["import { CommonModule, DOCUMENT, isPlatformBrowser } from '@angular/common';\nimport { AfterViewInit, ChangeDetectorRef, ContentChild, Directive, ElementRef, EmbeddedViewRef, EventEmitter, Inject, NgModule, OnDestroy, Output, PLATFORM_ID, Renderer2, TemplateRef, ViewContainerRef } from '@angular/core';\nimport { Nullable } from 'primeng/ts-helpers';\n/**\n * Defer postpones the loading the content that is initially not in the viewport until it becomes visible on scroll.\n * @group Components\n */\n@Directive({\n selector: '[pDefer]',\n host: {\n class: 'p-element'\n }\n})\nexport class DeferredLoader implements AfterViewInit, OnDestroy {\n /**\n * Callback to invoke when deferred content is loaded.\n * @param {Event} event - Browser event.\n * @group Emits\n */\n @Output() onLoad: EventEmitter<Event> = new EventEmitter<Event>();\n\n @ContentChild(TemplateRef) template: TemplateRef<any> | undefined;\n\n documentScrollListener: Nullable<Function>;\n\n view: Nullable<EmbeddedViewRef<any>>;\n\n window: Window;\n\n constructor(@Inject(DOCUMENT) private document: Document, @Inject(PLATFORM_ID) private platformId: any, public el: ElementRef, public renderer: Renderer2, public viewContainer: ViewContainerRef, private cd: ChangeDetectorRef) {\n this.window = this.document.defaultView as Window;\n }\n\n ngAfterViewInit() {\n if (isPlatformBrowser(this.platformId)) {\n if (this.shouldLoad()) {\n this.load();\n }\n\n if (!this.isLoaded()) {\n this.documentScrollListener = this.renderer.listen(this.window, 'scroll', () => {\n if (this.shouldLoad()) {\n this.load();\n this.documentScrollListener && this.documentScrollListener();\n this.documentScrollListener = null;\n }\n });\n }\n }\n }\n\n shouldLoad(): boolean {\n if (this.isLoaded()) {\n return false;\n } else {\n let rect = this.el.nativeElement.getBoundingClientRect();\n let docElement = this.document.documentElement;\n let winHeight = docElement.clientHeight;\n\n return winHeight >= rect.top;\n }\n }\n\n load(): void {\n this.view = this.viewContainer.createEmbeddedView(this.template as TemplateRef<any>);\n this.onLoad.emit();\n this.cd.detectChanges();\n }\n\n isLoaded() {\n return this.view != null && isPlatformBrowser(this.platformId);\n }\n\n ngOnDestroy() {\n this.view = null;\n\n if (this.documentScrollListener) {\n this.documentScrollListener();\n }\n }\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [DeferredLoader],\n declarations: [DeferredLoader]\n})\nexport class DeferModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;AAGA;;;AAGG;MAOU,cAAc,CAAA;AAgBe,IAAA,QAAA,CAAA;AAAiD,IAAA,UAAA,CAAA;AAAwB,IAAA,EAAA,CAAA;AAAuB,IAAA,QAAA,CAAA;AAA4B,IAAA,aAAA,CAAA;AAAyC,IAAA,EAAA,CAAA;AAf3M;;;;AAIG;AACO,IAAA,MAAM,GAAwB,IAAI,YAAY,EAAS,CAAC;AAEvC,IAAA,QAAQ,CAA+B;AAElE,IAAA,sBAAsB,CAAqB;AAE3C,IAAA,IAAI,CAAiC;AAErC,IAAA,MAAM,CAAS;IAEf,WAAsC,CAAA,QAAkB,EAA+B,UAAe,EAAS,EAAc,EAAS,QAAmB,EAAS,aAA+B,EAAU,EAAqB,EAAA;QAA1L,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAU;QAA+B,IAAU,CAAA,UAAA,GAAV,UAAU,CAAK;QAAS,IAAE,CAAA,EAAA,GAAF,EAAE,CAAY;QAAS,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAW;QAAS,IAAa,CAAA,aAAA,GAAb,aAAa,CAAkB;QAAU,IAAE,CAAA,EAAA,GAAF,EAAE,CAAmB;QAC5N,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAqB,CAAC;KACrD;IAED,eAAe,GAAA;AACX,QAAA,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;AACpC,YAAA,IAAI,IAAI,CAAC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