UNPKG

12.9 kBJavaScriptView Raw
1!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common"],factory):factory((global.ng=global.ng||{},global.ng.ngxSmartModal={}),global.ng.core,global.ng.common)}(this,function(exports,core,common){"use strict";/**
2 * @license ngx-smart-modal
3 * MIT license
4 */
5var NgxSmartModalService=function(){function NgxSmartModalService(){this.modalStack=[]}return NgxSmartModalService.prototype.addModal=function(modalInstance,force){if(force){var i=this.modalStack.findIndex(function(o){return o.id===modalInstance.id});i>-1?this.modalStack[i].modal=modalInstance.modal:this.modalStack.push(modalInstance)}else this.modalStack.push(modalInstance)},NgxSmartModalService.prototype.getModal=function(id){return this.modalStack.filter(function(o){return o.id===id})[0].modal},NgxSmartModalService.prototype.get=function(id){return this.getModal(id)},NgxSmartModalService.prototype.open=function(id,force){void 0===force&&(force=!1);var instance=this.modalStack.find(function(o){return o.id===id});if(!instance)throw new Error("Modal not found");instance.modal.open(force)},NgxSmartModalService.prototype.close=function(id){var instance=this.modalStack.find(function(o){return o.id===id});if(!instance)throw new Error("Modal not found");instance.modal.close()},NgxSmartModalService.prototype.toggle=function(id,force){void 0===force&&(force=!1);var instance=this.modalStack.find(function(o){return o.id===id});if(!instance)throw new Error("Modal not found");instance.modal.toggle(force)},NgxSmartModalService.prototype.getModalStack=function(){return this.modalStack},NgxSmartModalService.prototype.getOpenedModals=function(){var modals=[];return this.modalStack.forEach(function(o){o.modal.visible&&modals.push(o)}),modals},NgxSmartModalService.prototype.getHigherIndex=function(){var index=[1041];return this.getModalStack().forEach(function(o){index.push(o.modal.layerPosition)}),Math.max.apply(Math,index)+1},NgxSmartModalService.prototype.getModalStackCount=function(){return this.modalStack.length},NgxSmartModalService.prototype.removeModal=function(id){var i=this.modalStack.findIndex(function(o){return o.id===id});i>-1&&this.modalStack.splice(i,1)},NgxSmartModalService.prototype.setModalData=function(data,id,force){return!!this.modalStack.find(function(o){return o.id===id})&&(this.getModal(id).setData(data,force),!0)},NgxSmartModalService.prototype.getModalData=function(id){return this.getModal(id).getData()},NgxSmartModalService.prototype.resetModalData=function(id){if(this.modalStack.find(function(o){return o.id===id})){var removed=this.getModal(id).getData();return this.getModal(id).removeData(),removed}return!1},NgxSmartModalService.prototype.closeLatestModal=function(){var me=this;clearTimeout(this.debouncer),this.debouncer=setTimeout(function(){var tmp;return me.getOpenedModals().forEach(function(m){m.modal.layerPosition>(tmp?tmp.modal.layerPosition:0)&&(tmp=m)}),!!tmp&&tmp.modal.close()},100)},NgxSmartModalService.decorators=[{type:core.Injectable}],NgxSmartModalService.ctorParameters=function(){return[]},NgxSmartModalService}(),NgxSmartModalComponent=function(){function NgxSmartModalComponent(_renderer,_changeDetectorRef,_ngxSmartModalService){this._renderer=_renderer,this._changeDetectorRef=_changeDetectorRef,this._ngxSmartModalService=_ngxSmartModalService,this.closable=!0,this.escapable=!0,this.dismissable=!0,this.identifier="",this.customClass="nsm-dialog-animation-fade",this.visible=!1,this.backdrop=!0,this.force=!0,this.hideDelay=500,this.autostart=!1,this.visibleChange=new core.EventEmitter,this.onClose=new core.EventEmitter,this.onCloseFinished=new core.EventEmitter,this.onDismiss=new core.EventEmitter,this.onDismissFinished=new core.EventEmitter,this.onAnyCloseEvent=new core.EventEmitter,this.onAnyCloseEventFinished=new core.EventEmitter,this.onOpen=new core.EventEmitter,this.onEscape=new core.EventEmitter,this.onDataAdded=new core.EventEmitter,this.onDataRemoved=new core.EventEmitter,this.layerPosition=1041,this.overlayVisible=!1,this.openedClass=!1,this._data=null}return NgxSmartModalComponent.prototype.ngOnInit=function(){if(!this.identifier||!this.identifier.length)throw new Error("identifier field isn’t set. Please set one before calling <ngx-smart-modal> in a template.");this.layerPosition+=this._ngxSmartModalService.getModalStackCount(),this._ngxSmartModalService.addModal({id:this.identifier,modal:this},this.force),this.autostart&&this._ngxSmartModalService.open(this.identifier)},NgxSmartModalComponent.prototype.ngOnDestroy=function(){this._ngxSmartModalService.removeModal(this.identifier)},NgxSmartModalComponent.prototype.open=function(top){var _this=this;top&&(this.layerPosition=this._ngxSmartModalService.getHigherIndex()),this._renderer.addClass(document.body,"dialog-open"),this.overlayVisible=!0,this.visible=!0,setTimeout(function(){_this.openedClass=!0,_this.target&&_this.targetPlacement(),_this._changeDetectorRef.markForCheck()}),this.onOpen.emit(this)},NgxSmartModalComponent.prototype.close=function(){var me=this;this.openedClass=!1,this.onClose.emit(this),this.onAnyCloseEvent.emit(this),this._ngxSmartModalService.getOpenedModals().length<2&&this._renderer.removeClass(document.body,"dialog-open"),setTimeout(function(){me.visibleChange.emit(me.visible),me.visible=!1,me.overlayVisible=!1,me._changeDetectorRef.markForCheck(),me.onCloseFinished.emit(me),me.onAnyCloseEventFinished.emit(me)},this.hideDelay)},NgxSmartModalComponent.prototype.dismiss=function(e){var me=this;this.dismissable&&e.target.classList.contains("overlay")&&(this.openedClass=!1,this.onDismiss.emit(this),this.onAnyCloseEvent.emit(this),this._ngxSmartModalService.getOpenedModals().length<2&&this._renderer.removeClass(document.body,"dialog-open"),setTimeout(function(){me.visible=!1,me.visibleChange.emit(me.visible),me.overlayVisible=!1,me._changeDetectorRef.markForCheck(),me.onDismissFinished.emit(me),me.onAnyCloseEventFinished.emit(me)},this.hideDelay))},NgxSmartModalComponent.prototype.toggle=function(top){this.visible?this.close():this.open(top)},NgxSmartModalComponent.prototype.addCustomClass=function(className){this.customClass.length?this.customClass+=" "+className:this.customClass=className},NgxSmartModalComponent.prototype.removeCustomClass=function(className){this.customClass=className?this.customClass.replace(className,"").trim():""},NgxSmartModalComponent.prototype.isVisible=function(){return this.visible},NgxSmartModalComponent.prototype.hasData=function(){return!!this._data},NgxSmartModalComponent.prototype.setData=function(data,force){var _this=this;(!this._data||this._data&&force)&&setTimeout(function(){_this._data=data,_this.onDataAdded.emit(_this._data)})},NgxSmartModalComponent.prototype.getData=function(){return this._data},NgxSmartModalComponent.prototype.removeData=function(){var _this=this;setTimeout(function(){_this._data=null,_this.onDataRemoved.emit(!0)})},NgxSmartModalComponent.prototype.escapeKeyboardEvent=function(event){if(27===event.keyCode&&this.visible){if(!this.escapable)return!1;this.onEscape.emit(this),this._ngxSmartModalService.closeLatestModal()}},NgxSmartModalComponent.prototype.targetPlacement=function(){if(this.nsmDialog&&this.nsmContent&&this.nsmOverlay&&this.target){var targetElementRect=document.querySelector(this.target).getBoundingClientRect(),bodyRect=this.nsmOverlay.nativeElement.getBoundingClientRect(),nsmContentRect=this.nsmContent.nativeElement.getBoundingClientRect(),nsmDialogRect=this.nsmDialog.nativeElement.getBoundingClientRect(),marginLeft=parseInt(getComputedStyle(this.nsmContent.nativeElement).marginLeft,10),marginTop=parseInt(getComputedStyle(this.nsmContent.nativeElement).marginTop,10),offsetTop=targetElementRect.top-nsmDialogRect.top-(nsmContentRect.height-targetElementRect.height)/2,offsetLeft=targetElementRect.left-nsmDialogRect.left-(nsmContentRect.width-targetElementRect.width)/2;offsetLeft+nsmDialogRect.left+nsmContentRect.width+2*marginLeft>bodyRect.width?offsetLeft=bodyRect.width-(nsmDialogRect.left+nsmContentRect.width)-2*marginLeft:offsetLeft+nsmDialogRect.left<0&&(offsetLeft=-nsmDialogRect.left),offsetTop+nsmDialogRect.top+nsmContentRect.height+marginTop>bodyRect.height&&(offsetTop=bodyRect.height-(nsmDialogRect.top+nsmContentRect.height)-marginTop),offsetTop<0&&(offsetTop=0),this._renderer.setStyle(this.nsmContent.nativeElement,"top",offsetTop+"px"),this._renderer.setStyle(this.nsmContent.nativeElement,"left",offsetLeft+"px")}},NgxSmartModalComponent.decorators=[{type:core.Component,args:[{selector:"ngx-smart-modal",template:'\n <div *ngIf="overlayVisible"\n [style.z-index]="visible ? layerPosition-1 : -1"\n [ngClass]="{\'transparent\':!backdrop, \'overlay\':true, \'nsm-overlay-open\':openedClass}"\n (click)="dismiss($event)" #nsmOverlay>\n <div [style.z-index]="visible ? layerPosition : -1"\n [ngClass]="[\'nsm-dialog\', customClass, openedClass ? \'nsm-dialog-open\': \'nsm-dialog-close\']" #nsmDialog>\n <div class="nsm-content" #nsmContent>\n <div class="nsm-body">\n <ng-content></ng-content>\n </div>\n <button type="button" *ngIf="closable" (click)="close()" aria-label="Close" class="nsm-dialog-btn-close">\n <img\n src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeD0iMHB4IiB5PSIwcHgiIHZpZXdCb3g9IjAgMCA1MTIgNTEyIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MTIgNTEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgd2lkdGg9IjE2cHgiIGhlaWdodD0iMTZweCI+CjxnPgoJPGc+CgkJPHBhdGggZD0iTTUwNS45NDMsNi4wNThjLTguMDc3LTguMDc3LTIxLjE3Mi04LjA3Ny0yOS4yNDksMEw2LjA1OCw0NzYuNjkzYy04LjA3Nyw4LjA3Ny04LjA3NywyMS4xNzIsMCwyOS4yNDkgICAgQzEwLjA5Niw1MDkuOTgyLDE1LjM5LDUxMiwyMC42ODMsNTEyYzUuMjkzLDAsMTAuNTg2LTIuMDE5LDE0LjYyNS02LjA1OUw1MDUuOTQzLDM1LjMwNiAgICBDNTE0LjAxOSwyNy4yMyw1MTQuMDE5LDE0LjEzNSw1MDUuOTQzLDYuMDU4eiIgZmlsbD0iIzAwMDAwMCIvPgoJPC9nPgo8L2c+CjxnPgoJPGc+CgkJPHBhdGggZD0iTTUwNS45NDIsNDc2LjY5NEwzNS4zMDYsNi4wNTljLTguMDc2LTguMDc3LTIxLjE3Mi04LjA3Ny0yOS4yNDgsMGMtOC4wNzcsOC4wNzYtOC4wNzcsMjEuMTcxLDAsMjkuMjQ4bDQ3MC42MzYsNDcwLjYzNiAgICBjNC4wMzgsNC4wMzksOS4zMzIsNi4wNTgsMTQuNjI1LDYuMDU4YzUuMjkzLDAsMTAuNTg3LTIuMDE5LDE0LjYyNC02LjA1N0M1MTQuMDE4LDQ5Ny44NjYsNTE0LjAxOCw0ODQuNzcxLDUwNS45NDIsNDc2LjY5NHoiIGZpbGw9IiMwMDAwMDAiLz4KCTwvZz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />\n </button>\n </div>\n </div>\n </div>\n '}]}],NgxSmartModalComponent.ctorParameters=function(){return[{type:core.Renderer2},{type:core.ChangeDetectorRef},{type:NgxSmartModalService}]},NgxSmartModalComponent.propDecorators={closable:[{type:core.Input}],escapable:[{type:core.Input}],dismissable:[{type:core.Input}],identifier:[{type:core.Input}],customClass:[{type:core.Input}],visible:[{type:core.Input}],backdrop:[{type:core.Input}],force:[{type:core.Input}],hideDelay:[{type:core.Input}],autostart:[{type:core.Input}],target:[{type:core.Input}],visibleChange:[{type:core.Output}],onClose:[{type:core.Output}],onCloseFinished:[{type:core.Output}],onDismiss:[{type:core.Output}],onDismissFinished:[{type:core.Output}],onAnyCloseEvent:[{type:core.Output}],onAnyCloseEventFinished:[{type:core.Output}],onOpen:[{type:core.Output}],onEscape:[{type:core.Output}],onDataAdded:[{type:core.Output}],onDataRemoved:[{type:core.Output}],nsmContent:[{type:core.ViewChild,args:["nsmContent"]}],nsmDialog:[{type:core.ViewChild,args:["nsmDialog"]}],nsmOverlay:[{type:core.ViewChild,args:["nsmOverlay"]}],escapeKeyboardEvent:[{type:core.HostListener,args:["document:keyup",["$event"]]}],targetPlacement:[{type:core.HostListener,args:["window:resize"]}]},NgxSmartModalComponent}(),NgxSmartModalModule=function(){function NgxSmartModalModule(){}return NgxSmartModalModule.forRoot=function(){return{ngModule:NgxSmartModalModule,providers:[NgxSmartModalService]}},NgxSmartModalModule.forChild=function(){return{ngModule:NgxSmartModalModule,providers:[NgxSmartModalService]}},NgxSmartModalModule.decorators=[{type:core.NgModule,args:[{declarations:[NgxSmartModalComponent],exports:[NgxSmartModalComponent],imports:[common.CommonModule]}]}],NgxSmartModalModule.ctorParameters=function(){return[]},NgxSmartModalModule}();exports.NgxSmartModalService=NgxSmartModalService,exports.NgxSmartModalComponent=NgxSmartModalComponent,exports.NgxSmartModalModule=NgxSmartModalModule,Object.defineProperty(exports,"__esModule",{value:!0})});
\No newline at end of file