{"version":3,"sources":["../../src/app/components/defer/defer.ts"],"names":["DeferredLoader","el","renderer","viewContainer","this","onLoad","EventEmitter","prototype","ngAfterViewInit","_this","shouldLoad","load","isLoaded","documentScrollListener","listen","rect","nativeElement","getBoundingClientRect","document","documentElement","clientHeight","top","view","createEmbeddedView","template","emit","ngOnDestroy","Directive","args","selector","ElementRef","Renderer2","ViewContainerRef","Output","ContentChild","TemplateRef","NgModule","imports","CommonModule","exports","declarations"],"mappings":"gaAiBI,SAAAA,EAAmBC,EAAuBC,EAA4BC,GAAnDC,KAAAH,GAAAA,EAAuBG,KAAAF,SAAAA,EAA4BE,KAAAD,cAAAA,EAR5DC,KAAAC,OAA4B,IAAIC,EAAAA,oBAU1CN,EAAAO,UAAAC,gBAAA,WAAA,IAAAC,EAAAL,KACQA,KAAKM,cACLN,KAAKO,OAGJP,KAAKQ,aACNR,KAAKS,uBAAyBT,KAAKF,SAASY,OAAO,SAAU,UAAU,WAC/DL,EAAKC,eACLD,EAAKE,OACLF,EAAKI,yBACLJ,EAAKI,uBAAyB,WAM9Cb,EAAAO,UAAAG,WAAA,WACI,GAAIN,KAAKQ,WACL,OAAO,EAGP,IAAIG,EAAOX,KAAKH,GAAGe,cAAcC,wBAIjC,OAHiBC,SAASC,gBACCC,cAENL,EAAKM,KAIlCrB,EAAAO,UAAAI,KAAA,WACIP,KAAKkB,KAAOlB,KAAKD,cAAcoB,mBAAmBnB,KAAKoB,UACvDpB,KAAKC,OAAOoB,QAGhBzB,EAAAO,UAAAK,SAAA,WACI,OAAoB,MAAbR,KAAKkB,MAGhBtB,EAAAO,UAAAmB,YAAA,WACItB,KAAKkB,KAAO,KAERlB,KAAKS,wBACLT,KAAKS,mDAzDhBc,EAAAA,UAASC,KAAA,CAAC,CACPC,SAAU,wDALaC,EAAAA,kBACFC,EAAAA,iBAAjBC,EAAAA,oDAQHC,EAAAA,yBAEAC,EAAAA,aAAYN,KAAA,CAACO,EAAAA,sBA4DlB,iCALCC,EAAAA,SAAQR,KAAA,CAAC,CACNS,QAAS,CAACC,EAAAA,cACVC,QAAS,CAACvC,GACVwC,aAAc,CAACxC","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 = new EventEmitter();\n \n @ContentChild(TemplateRef) template: TemplateRef;\n \n documentScrollListener: Function;\n \n view: EmbeddedViewRef;\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 { }"]}