ngx-bootstrap
Version:
Native Angular Bootstrap Components
2 lines • 7.38 kB
JavaScript
!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=e||self)["ngx-bootstrap"]=e["ngx-bootstrap"]||{},e["ngx-bootstrap"]["component-loader"]={}),e.ng.core,e.utils,e.positioning)}(this,(function(e,t,n,i){"use strict";var o=function(){};var s=function(e,t,n){this.nodes=e,this.viewRef=t,this.componentRef=n};var r=function(){function e(e,n,i,o,s,r,c,h){this._viewContainerRef=e,this._renderer=n,this._elementRef=i,this._injector=o,this._componentFactoryResolver=s,this._ngZone=r,this._applicationRef=c,this._posService=h,this.onBeforeShow=new t.EventEmitter,this.onShown=new t.EventEmitter,this.onBeforeHide=new t.EventEmitter,this.onHidden=new t.EventEmitter,this._providers=[],this._isHiding=!1,this.containerDefaultSelector="body",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 n=t.Injector.create({providers:this._providers,parent:this._injector});if(this._componentRef=this._componentFactory.create(n,this._contentRef.nodes),this._applicationRef.attachView(this._componentRef.hostView),this.instance=this._componentRef.instance,Object.assign(this._componentRef.instance,e),this.container instanceof t.ElementRef&&this.container.nativeElement.appendChild(this._componentRef.location.nativeElement),"string"==typeof this.container&&"undefined"!=typeof document)(document.querySelector(this.container)||document.querySelector(this.containerDefaultSelector)).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(e.id?{id:e.id}:this._componentRef.instance)}return this._registerOutsideClick(),this._componentRef},e.prototype.hide=function(e){if(!this._componentRef)return this;this._posService.deletePositionElement(this._componentRef.location),this.onBeforeHide.emit(this._componentRef.instance);var t=this._componentRef.location.nativeElement;return t.parentNode.removeChild(t),this._contentRef.componentRef&&this._contentRef.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(e?{id:e}:null),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(e){var t=this;this.triggers=e.triggers||this.triggers,this._listenOpts.outsideClick=e.outsideClick,this._listenOpts.outsideEsc=e.outsideEsc,e.target=e.target||this._elementRef.nativeElement;var i=this._listenOpts.hide=function(){return e.hide?e.hide():void t.hide()},o=this._listenOpts.show=function(n){e.show?e.show(n):t.show(n),n()};return this._unregisterListenersFn=n.listenToTriggersV2(this._renderer,{target:e.target,triggers:e.triggers,show:o,hide:i,toggle:function(e){t.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){if(this._listenOpts.outsideClick){var t=this._componentRef.location.nativeElement;setTimeout((function(){e._globalListener=n.registerOutsideClick(e._renderer,{targets:[t,e._elementRef.nativeElement],outsideClick:e._listenOpts.outsideClick,hide:function(){return e._listenOpts.hide()}})}))}if(this._listenOpts.outsideEsc){var i=this._componentRef.location.nativeElement;this._globalListener=n.registerEscClick(this._renderer,{targets:[i,this._elementRef.nativeElement],outsideEsc:this._listenOpts.outsideEsc,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.onShown.subscribe((function(){e._posService.position({element:e._componentRef.location,target:e._elementRef,attachment:e.attachment,appendToBody:"body"===e.container})})),this._zoneSubscription=this._ngZone.onStable.subscribe((function(){e._componentRef&&e._posService.calcPosition()})))},e.prototype._unsubscribePositioning=function(){this._zoneSubscription&&(this._zoneSubscription.unsubscribe(),this._zoneSubscription=null)},e.prototype._getContentRef=function(e,n,i){if(!e)return new s([]);if(e instanceof t.TemplateRef){if(this._viewContainerRef){var o=this._viewContainerRef.createEmbeddedView(e,n);return o.markForCheck(),new s([o.rootNodes],o)}var r=e.createEmbeddedView({});return this._applicationRef.attachView(r),new s([r.rootNodes],r)}if("function"==typeof e){var c=this._componentFactoryResolver.resolveComponentFactory(e),h=t.Injector.create({providers:this._providers,parent:this._injector}),a=c.create(h);return Object.assign(a.instance,i),this._applicationRef.attachView(a.hostView),new s([[a.location.nativeElement]],a.hostView,a)}return new s([[this._renderer.createText(""+e)]])},e}();var c=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 r(t,n,e,this._injector,this._componentFactoryResolver,this._ngZone,this._applicationRef,this._posService)},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:t.ComponentFactoryResolver},{type:t.NgZone},{type:t.Injector},{type:i.PositioningService},{type:t.ApplicationRef}]},e}();e.BsComponentRef=o,e.ComponentLoader=r,e.ComponentLoaderFactory=c,e.ContentRef=s,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-bootstrap-component-loader.umd.min.js.map