UNPKG

ngx-bootstrap

Version:
2 lines 6.8 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("ngx-bootstrap/utils"),require("ngx-bootstrap/positioning")):"function"==typeof define&&define.amd?define("ngx-bootstrap/component-loader",["exports","@angular/core","ngx-bootstrap/utils","ngx-bootstrap/positioning"],t):t((e["ngx-bootstrap"]=e["ngx-bootstrap"]||{},e["ngx-bootstrap"]["component-loader"]={}),e.ng.core,e.utils,e.positioning)}(this,function(e,h,s,t){"use strict";var n=function r(){},a=function c(e,t,n){this.nodes=e,this.viewRef=t,this.componentRef=n},i=function(){function e(e,t,n,i,o,s,r,c){this._viewContainerRef=e,this._renderer=t,this._elementRef=n,this._injector=i,this._componentFactoryResolver=o,this._ngZone=s,this._applicationRef=r,this._posService=c,this.onBeforeShow=new h.EventEmitter,this.onShown=new h.EventEmitter,this.onBeforeHide=new h.EventEmitter,this.onHidden=new h.EventEmitter,this._providers=[],this._isHiding=!1,this._listenOpts={},this._globalListener=Function.prototype}return Object.defineProperty(e.prototype,"isShown",{get:function(){return!this._isHiding&&!!this._componentRef},enumerable:!0,configurable:!0}),e.prototype.attach=function(e){return this._componentFactory=this._componentFactoryResolver.resolveComponentFactory(e),this},e.prototype.to=function(e){return this.container=e||this.container,this},e.prototype.position=function(e){return this.attachment=e.attachment||this.attachment,this._elementRef=e.target||this._elementRef,this},e.prototype.provide=function(e){return this._providers.push(e),this},e.prototype.show=function(e){if(void 0===e&&(e={}),this._subscribePositioning(),this._innerComponent=null,!this._componentRef){this.onBeforeShow.emit(),this._contentRef=this._getContentRef(e.content,e.context,e.initialState);var t=h.Injector.create({providers:this._providers,parent:this._injector});this._componentRef=this._componentFactory.create(t,this._contentRef.nodes),this._applicationRef.attachView(this._componentRef.hostView),this.instance=this._componentRef.instance,Object.assign(this._componentRef.instance,e),this.container instanceof h.ElementRef&&this.container.nativeElement.appendChild(this._componentRef.location.nativeElement),"body"===this.container&&"undefined"!=typeof document&&document.querySelector(this.container).appendChild(this._componentRef.location.nativeElement),!this.container&&this._elementRef&&this._elementRef.nativeElement.parentElement&&this._elementRef.nativeElement.parentElement.appendChild(this._componentRef.location.nativeElement),this._contentRef.componentRef&&(this._innerComponent=this._contentRef.componentRef.instance,this._contentRef.componentRef.changeDetectorRef.markForCheck(),this._contentRef.componentRef.changeDetectorRef.detectChanges()),this._componentRef.changeDetectorRef.markForCheck(),this._componentRef.changeDetectorRef.detectChanges(),this.onShown.emit(this._componentRef.instance)}return this._registerOutsideClick(),this._componentRef},e.prototype.hide=function(){if(!this._componentRef)return this;this.onBeforeHide.emit(this._componentRef.instance);var e=this._componentRef.location.nativeElement;return e.parentNode.removeChild(e),this._contentRef.componentRef&&this._contentRef.componentRef.destroy(),this._componentRef.destroy(),this._viewContainerRef&&this._contentRef.viewRef&&this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._contentRef.viewRef)),this._contentRef.viewRef&&this._contentRef.viewRef.destroy(),this._contentRef=null,this._componentRef=null,this._removeGlobalListener(),this.onHidden.emit(),this},e.prototype.toggle=function(){this.isShown?this.hide():this.show()},e.prototype.dispose=function(){this.isShown&&this.hide(),this._unsubscribePositioning(),this._unregisterListenersFn&&this._unregisterListenersFn()},e.prototype.listen=function(t){var n=this;this.triggers=t.triggers||this.triggers,this._listenOpts.outsideClick=t.outsideClick,t.target=t.target||this._elementRef.nativeElement;var i=this._listenOpts.hide=function(){return t.hide?t.hide():void n.hide()},o=this._listenOpts.show=function(e){t.show?t.show(e):n.show(e),e()};return this._unregisterListenersFn=s.listenToTriggersV2(this._renderer,{target:t.target,triggers:t.triggers,show:o,hide:i,toggle:function(e){n.isShown?i():o(e)}}),this},e.prototype._removeGlobalListener=function(){this._globalListener&&(this._globalListener(),this._globalListener=null)},e.prototype.attachInline=function(e,t){return this._inlineViewRef=e.createEmbeddedView(t),this},e.prototype._registerOutsideClick=function(){var e=this;if(this._componentRef&&this._componentRef.location&&this._listenOpts.outsideClick){var t=this._componentRef.location.nativeElement;setTimeout(function(){e._globalListener=s.registerOutsideClick(e._renderer,{targets:[t,e._elementRef.nativeElement],outsideClick:e._listenOpts.outsideClick,hide:function(){return e._listenOpts.hide()}})})}},e.prototype.getInnerComponent=function(){return this._innerComponent},e.prototype._subscribePositioning=function(){var e=this;!this._zoneSubscription&&this.attachment&&(this._zoneSubscription=this._ngZone.onStable.subscribe(function(){e._componentRef&&e._posService.position({element:e._componentRef.location,target:e._elementRef,attachment:e.attachment,appendToBody:"body"===e.container})}))},e.prototype._unsubscribePositioning=function(){this._zoneSubscription&&(this._zoneSubscription.unsubscribe(),this._zoneSubscription=null)},e.prototype._getContentRef=function(e,t,n){if(!e)return new a([]);if(e instanceof h.TemplateRef){if(this._viewContainerRef){var i=this._viewContainerRef.createEmbeddedView(e,t);return i.markForCheck(),new a([i.rootNodes],i)}var o=e.createEmbeddedView({});return this._applicationRef.attachView(o),new a([o.rootNodes],o)}if("function"!=typeof e)return new a([[this._renderer.createText(""+e)]]);var s=this._componentFactoryResolver.resolveComponentFactory(e),r=h.Injector.create({providers:this._providers,parent:this._injector}),c=s.create(r);return Object.assign(c.instance,n),this._applicationRef.attachView(c.hostView),new a([[c.location.nativeElement]],c.hostView,c)},e}(),o=function(){function e(e,t,n,i,o){this._componentFactoryResolver=e,this._ngZone=t,this._injector=n,this._posService=i,this._applicationRef=o}return e.prototype.createLoader=function(e,t,n){return new i(t,n,e,this._injector,this._componentFactoryResolver,this._ngZone,this._applicationRef,this._posService)},e.decorators=[{type:h.Injectable}],e.ctorParameters=function(){return[{type:h.ComponentFactoryResolver},{type:h.NgZone},{type:h.Injector},{type:t.PositioningService},{type:h.ApplicationRef}]},e}();e.BsComponentRef=n,e.ComponentLoader=i,e.ComponentLoaderFactory=o,e.ContentRef=a,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=ngx-bootstrap-component-loader.umd.min.js.map