UNPKG

ng2-bs3-modal

Version:

Angular Boostrap 3 Modal Component

2 lines 10.9 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("@angular/common")):"function"==typeof define&&define.amd?define("ng2-bs3-modal",["exports","@angular/core","rxjs","rxjs/operators","@angular/common"],e):e(t["ng2-bs3-modal"]={},t.ng.core,t.rxjs,t.rxjs.operators,t.ng.common)}(this,function(t,i,s,n,e){"use strict";var r={Close:0,Dismiss:1,Backdrop:2,Keyboard:3,RouteChange:4,Destroy:5};r[r.Close]="Close",r[r.Dismiss]="Dismiss",r[r.Backdrop]="Backdrop",r[r.Keyboard]="Keyboard",r[r.RouteChange]="RouteChange",r[r.Destroy]="Destroy";var o=function(){function e(){}return e.isValidSize=function(t){return t&&(t===e.Small||t===e.Large)},e.Small="sm",e.Large="lg",e}(),a=function(){function t(){var e=this;this.modals=[],this.$body=jQuery(document.body),this.onBackdropClose$=s.fromEvent(this.$body,"click.ng2-bs3-modal").pipe(n.filter(function(t){return jQuery(t.target).is(".modal")}),n.map(function(){return r.Backdrop}),n.share()),this.onKeyboardClose$=s.fromEvent(this.$body,"keyup.ng2-bs3-modal").pipe(n.filter(function(t){return 27===t.which}),n.map(function(){return r.Keyboard}),n.share()),this.onModalStack$=s.fromEvent(this.$body,"show.bs.modal.ng2-bs3-modal").pipe(n.tap(function(){var t=1040+10*jQuery(".modal:visible").length;jQuery(e).css("z-index",t),setTimeout(function(){jQuery(".modal-backdrop").not(".modal-stack").css("z-index",t-1).addClass("modal-stack")},0)}),n.share())}return t.prototype.add=function(t){this.modals.push(t)},t.prototype.remove=function(t){var e=this.modals.indexOf(t);-1<e&&this.modals.splice(e,1)},t.prototype.focusNext=function(){var t=this.modals.filter(function(t){return t.visible});t.length&&(this.$body.addClass("modal-open"),t[t.length-1].focus())},t.prototype.dismissAll=function(){return Promise.all(this.modals.map(function(t){return t.dismiss()}))},t.decorators=[{type:i.Injectable}],t.ctorParameters=function(){return[]},t}();function l(t,e){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var n,i,s=o.call(t),r=[];try{for(;(void 0===e||0<e--)&&!(n=s.next()).done;)r.push(n.value)}catch(a){i={error:a}}finally{try{n&&!n.done&&(o=s["return"])&&o.call(s)}finally{if(i)throw i.error}}return r}var d="ng2-bs3-modal",u="shown.bs.modal."+d,p="bs.modal",c=function(){function t(t,e,o){var n=this;this.element=t,this.service=e,this.zone=o,this.overrideSize=null,this.onInternalClose$=new s.Subject,this.subscriptions=[],this.visible=!1,this.showing=!1,this.hiding=!1,this.animation=!0,this.backdrop=!0,this.keyboard=!0,this.onShow=new i.EventEmitter,this.onOpen=new i.EventEmitter,this.onHide=new i.EventEmitter,this.onClose=new i.EventEmitter,this.onDismiss=new i.EventEmitter,this.onLoaded=new i.EventEmitter,this.setVisible=function(t){return function(){n.visible=t,n.showing=!1,n.hiding=!1}},this.setOptions=function(t){var e=t.backdrop;"string"==typeof e&&"static"!==e&&(e=!0),t.backdrop!==undefined&&(n.options.backdrop=e),t.keyboard!==undefined&&(n.options.keyboard=t.keyboard)},this.service.add(this),this.init()}return Object.defineProperty(t.prototype,"options",{get:function(){return this.$modal||this.init(),this.$modal.data(p).options},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fadeClass",{get:function(){return this.animation},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"modalClass",{get:function(){return!0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"roleAttr",{get:function(){return"dialog"},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"tabindexAttr",{get:function(){return"-1"},enumerable:!0,configurable:!0}),t.prototype.ngOnInit=function(){this.wireUpEventEmitters()},t.prototype.ngAfterViewInit=function(){this.$dialog=this.$modal.find(".modal-dialog")},t.prototype.ngOnChanges=function(){this.setOptions({backdrop:this.backdrop,keyboard:this.keyboard})},t.prototype.ngOnDestroy=function(){return this.onInternalClose$.next(r.Destroy),this.destroy()},t.prototype.focus=function(){this.$modal.trigger("focus")},t.prototype.routerCanDeactivate=function(){return this.onInternalClose$.next(r.RouteChange),this.destroy()},t.prototype.open=function(t){return this.overrideSize=null,o.isValidSize(t)&&(this.overrideSize=t),this.show().toPromise()},t.prototype.close=function(t){var e=this;return this.onInternalClose$.next(r.Close),this.hide().pipe(n.tap(function(){return e.onClose.emit(t)})).toPromise().then(function(){return t})},t.prototype.dismiss=function(){return this.onInternalClose$.next(r.Dismiss),this.hide().toPromise()},t.prototype.getCssClasses=function(){var t=[];return this.isSmall()&&t.push("modal-sm"),this.isLarge()&&t.push("modal-lg"),this.cssClass&&t.push(this.cssClass),t.join(" ")},t.prototype.isSmall=function(){return this.overrideSize!==o.Large&&this.size===o.Small||this.overrideSize===o.Small},t.prototype.isLarge=function(){return this.overrideSize!==o.Small&&this.size===o.Large||this.overrideSize===o.Large},t.prototype.show=function(){var t=this;return this.visible&&!this.hiding?s.of(null):(this.showing=!0,s.Observable.create(function(e){t.onShown$.pipe(n.take(1)).subscribe(function(t){e.next(t),e.complete()}),t.transitionFix(),t.$modal.modal("show")}))},t.prototype.transitionFix=function(){var t=this;this.animation&&setTimeout(function(){t.$modal.trigger("focus").trigger(u)},jQuery.fn.modal.Constructor.TRANSITION_DURATION)},t.prototype.hide=function(){var t=this;return this.visible||this.showing?(this.hiding=!0,s.Observable.create(function(e){t.onHidden$.pipe(n.take(1)).subscribe(function(t){e.next(t),e.complete()}),t.$modal.modal("hide")})):s.of(null)},t.prototype.init=function(){var t=this;this.$modal=jQuery(this.element.nativeElement),this.$modal.appendTo(document.body),this.$modal.modal({show:!1}),this.onShowEvent$=s.fromEvent(this.$modal,"show.bs.modal.ng2-bs3-modal"),this.onShownEvent$=s.fromEvent(this.$modal,u),this.onHideEvent$=s.fromEvent(this.$modal,"hide.bs.modal.ng2-bs3-modal"),this.onHiddenEvent$=s.fromEvent(this.$modal,"hidden.bs.modal.ng2-bs3-modal"),this.onLoadedEvent$=s.fromEvent(this.$modal,"loaded.bs.modal.ng2-bs3-modal");var e,o=s.merge(this.onInternalClose$,this.service.onBackdropClose$,this.service.onKeyboardClose$);this.onHide$=s.zip(this.onHideEvent$,o).pipe(n.map(function(t){return{event:t[0],type:t[1]}})),this.onHidden$=s.zip(this.onHiddenEvent$,o).pipe(n.map(function(t){return t[1]}),n.tap(this.setVisible(!1)),n.tap(function(){return t.service.focusNext()}),n.share()),this.onShown$=this.onShownEvent$.pipe(n.tap(this.setVisible(!0)),n.share()),this.onDismiss$=this.onHidden$.pipe(n.filter(function(t){return t!==r.Close})),(e=this.subscriptions).push.apply(e,function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(l(arguments[e]));return t}([this.onShown$.subscribe(function(){}),this.onHidden$.subscribe(function(){}),this.service.onModalStack$.subscribe(function(){})]))},t.prototype.wireUpEventEmitters=function(){this.wireUpEventEmitter(this.onShow,this.onShowEvent$),this.wireUpEventEmitter(this.onOpen,this.onShown$),this.wireUpEventEmitter(this.onHide,this.onHide$),this.wireUpEventEmitter(this.onDismiss,this.onDismiss$),this.wireUpEventEmitter(this.onLoaded,this.onLoadedEvent$)},t.prototype.wireUpEventEmitter=function(e,t){var o=this;if(0!==e.observers.length){var n=t.subscribe(function(t){o.zone.run(function(){e.next(t)})});this.subscriptions.push(n)}},t.prototype.destroy=function(){var t=this;return this.hide().pipe(n.tap(function(){t.service.remove(t),t.subscriptions.forEach(function(t){return t.unsubscribe()}),t.subscriptions=[],t.$modal&&(t.$modal.data(p,null),t.$modal.remove(),t.$modal=null)})).toPromise()},t.decorators=[{type:i.Component,args:[{selector:"bs-modal",template:'\n <div class="modal-dialog" [ngClass]="getCssClasses()">\n <div class="modal-content">\n <ng-content></ng-content>\n </div>\n </div>\n '}]}],t.ctorParameters=function(){return[{type:i.ElementRef},{type:a},{type:i.NgZone}]},t.propDecorators={animation:[{type:i.Input}],backdrop:[{type:i.Input}],keyboard:[{type:i.Input}],size:[{type:i.Input}],cssClass:[{type:i.Input}],onShow:[{type:i.Output}],onOpen:[{type:i.Output}],onHide:[{type:i.Output}],onClose:[{type:i.Output}],onDismiss:[{type:i.Output}],onLoaded:[{type:i.Output}],fadeClass:[{type:i.HostBinding,args:["class.fade"]}],modalClass:[{type:i.HostBinding,args:["class.modal"]}],roleAttr:[{type:i.HostBinding,args:["attr.role"]}],tabindexAttr:[{type:i.HostBinding,args:["attr.tabindex"]}]},t}(),h=function(){function t(t){this.modal=t,this.showDismiss=!1}return t.decorators=[{type:i.Component,args:[{selector:"bs-modal-header",template:'\n <div class="modal-header">\n <button *ngIf="showDismiss" type="button" class="close" aria-label="Dismiss" (click)="modal.dismiss()">\n <span aria-hidden="true">&times;</span>\n </button>\n <ng-content></ng-content>\n </div>\n '}]}],t.ctorParameters=function(){return[{type:c}]},t.propDecorators={showDismiss:[{type:i.Input}]},t}(),m=function(){function t(){}return t.decorators=[{type:i.Component,args:[{selector:"bs-modal-body",template:'\n <div class="modal-body">\n <ng-content></ng-content>\n </div>\n '}]}],t}(),f=function(){function t(t){this.modal=t,this.showDefaultButtons=!1,this.dismissButtonLabel="Dismiss",this.closeButtonLabel="Close"}return t.decorators=[{type:i.Component,args:[{selector:"bs-modal-footer",template:'\n <div class="modal-footer">\n <ng-content></ng-content>\n <button *ngIf="showDefaultButtons" type="button" class="btn btn-default" (click)="modal.dismiss()">\n {{dismissButtonLabel}}\n </button>\n <button *ngIf="showDefaultButtons" type="button" class="btn btn-primary" (click)="modal.close()">\n {{closeButtonLabel}}\n </button>\n </div>\n '}]}],t.ctorParameters=function(){return[{type:c}]},t.propDecorators={showDefaultButtons:[{type:i.Input}],dismissButtonLabel:[{type:i.Input}],closeButtonLabel:[{type:i.Input}]},t}(),b=function(){function t(t,e){var o=this;this.el=t,(this.modal=e)&&this.modal.onOpen.subscribe(function(){o.el.nativeElement.focus()})}return t.decorators=[{type:i.Directive,args:[{selector:"[autofocus]"}]}],t.ctorParameters=function(){return[{type:i.ElementRef},{type:c,decorators:[{type:i.Optional}]}]},t}(),y=function(){function t(){}return t.decorators=[{type:i.NgModule,args:[{imports:[e.CommonModule],declarations:[c,h,m,f,b],providers:[a],exports:[c,h,m,f,b]}]}],t}();t.BsModalService=a,t.BsModalComponent=c,t.BsModalHeaderComponent=h,t.BsModalBodyComponent=m,t.BsModalFooterComponent=f,t.BsModalHideType=r,t.BsModalSize=o,t.BsModalModule=y,t.ɵa=b,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=ng2-bs3-modal.umd.min.js.map