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) [![Discord](https://img.shields.io/discord/557940238991753

83 lines (79 loc) 2.37 kB
import { EventEmitter, Directive, ElementRef, Renderer2, ViewContainerRef, ChangeDetectorRef, Output, ContentChild, TemplateRef, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; class DeferredLoader { constructor(el, renderer, viewContainer, cd) { this.el = el; this.renderer = renderer; this.viewContainer = viewContainer; this.cd = cd; this.onLoad = new EventEmitter(); } ngAfterViewInit() { if (this.shouldLoad()) { this.load(); } if (!this.isLoaded()) { this.documentScrollListener = this.renderer.listen('window', 'scroll', () => { if (this.shouldLoad()) { this.load(); this.documentScrollListener(); this.documentScrollListener = null; } }); } } shouldLoad() { if (this.isLoaded()) { return false; } else { let rect = this.el.nativeElement.getBoundingClientRect(); let docElement = document.documentElement; let winHeight = docElement.clientHeight; return (winHeight >= rect.top); } } load() { this.view = this.viewContainer.createEmbeddedView(this.template); this.onLoad.emit(); this.cd.detectChanges(); } isLoaded() { return this.view != null; } ngOnDestroy() { this.view = null; if (this.documentScrollListener) { this.documentScrollListener(); } } } DeferredLoader.decorators = [ { type: Directive, args: [{ selector: '[pDefer]' },] } ]; DeferredLoader.ctorParameters = () => [ { type: ElementRef }, { type: Renderer2 }, { type: ViewContainerRef }, { type: ChangeDetectorRef } ]; DeferredLoader.propDecorators = { onLoad: [{ type: Output }], template: [{ type: ContentChild, args: [TemplateRef,] }] }; class DeferModule { } DeferModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule], exports: [DeferredLoader], declarations: [DeferredLoader] },] } ]; /** * Generated bundle index. Do not edit. */ export { DeferModule, DeferredLoader }; //# sourceMappingURL=primeng-defer.js.map