UNPKG

3.76 kBSource Map (JSON)View Raw
1{"version":3,"file":"primeng-defer.js","sources":["../../src/app/components/defer/defer.ts","../../src/app/components/defer/primeng-defer.ts"],"sourcesContent":["import {NgModule,Directive,ElementRef,AfterViewInit,OnDestroy,TemplateRef,EmbeddedViewRef,\n ViewContainerRef,Renderer2,EventEmitter,Output,ContentChild} from '@angular/core';\nimport {CommonModule} from '@angular/common';\n\n@Directive({\n selector: '[pDefer]'\n})\nexport class DeferredLoader implements AfterViewInit,OnDestroy {\n \n @Output() onLoad: EventEmitter<any> = new EventEmitter();\n \n @ContentChild(TemplateRef) template: TemplateRef<any>;\n \n documentScrollListener: Function;\n \n view: EmbeddedViewRef<any>;\n \n constructor(public el: ElementRef, public renderer: Renderer2, public viewContainer: ViewContainerRef) {}\n \n ngAfterViewInit() {\n if (this.shouldLoad()) {\n this.load();\n }\n \n if (!this.isLoaded()) {\n this.documentScrollListener = this.renderer.listen('window', 'scroll', () => {\n if (this.shouldLoad()) {\n this.load();\n this.documentScrollListener();\n this.documentScrollListener = null;\n }\n });\n }\n }\n \n shouldLoad(): boolean {\n if (this.isLoaded()) {\n return false;\n }\n else {\n let rect = this.el.nativeElement.getBoundingClientRect();\n let docElement = 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);\n this.onLoad.emit();\n }\n \n isLoaded() {\n return this.view != null;\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 * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;MAOa,cAAc;IAUvB,YAAmB,EAAc,EAAS,QAAmB,EAAS,aAA+B;QAAlF,OAAE,GAAF,EAAE,CAAY;QAAS,aAAQ,GAAR,QAAQ,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