ngx-bootstrap
Version:
Angular Bootstrap
16 lines (14 loc) • 13.2 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs/operators"),require("ngx-bootstrap/component-loader"),require("ngx-bootstrap/utils"),require("@angular/animations"),require("@angular/common"),require("ngx-bootstrap/positioning")):"function"==typeof define&&define.amd?define("ngx-bootstrap/dropdown",["exports","@angular/core","rxjs/operators","ngx-bootstrap/component-loader","ngx-bootstrap/utils","@angular/animations","@angular/common","ngx-bootstrap/positioning"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["ngx-bootstrap"]=e["ngx-bootstrap"]||{},e["ngx-bootstrap"].dropdown={}),e.ng.core,e.rxjs.operators,e.componentLoader,e.utils,e.ng.animations,e.ng.common,e.positioning)}(this,(function(e,t,n,i,o,s,r,a){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */Object.create;function d(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],i=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}Object.create;var p=function(){this.autoClose=!0,this.insideClick=!1,this.isAnimated=!1};p.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new p},token:p,providedIn:"root"}),p.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}];var u=function(){var e=this;this.direction="down",this.autoClose=!0,this.insideClick=!1,this.isAnimated=!1,this.isOpenChange=new t.EventEmitter,this.isDisabledChange=new t.EventEmitter,this.toggleClick=new t.EventEmitter,this.dropdownMenu=new Promise((function(t){e.resolveDropdownMenu=t}))};u.decorators=[{type:t.Injectable}],u.ctorParameters=function(){return[]};var c=[s.style({height:0,overflow:"hidden"}),s.animate("220ms cubic-bezier(0, 0, 0.2, 1)",s.style({height:"*",overflow:"hidden"}))],l=function(){function e(e,t,n,i,s){var r=this;this._state=e,this.cd=t,this._renderer=n,this._element=i,this.isOpen=!1,this._factoryDropDownAnimation=s.build(c),this._subscription=e.isOpenChange.subscribe((function(e){r.isOpen=e;var t=r._element.nativeElement.querySelector(".dropdown-menu");r._renderer.addClass(r._element.nativeElement.querySelector("div"),"open"),t&&!o.isBs3()&&(r._renderer.addClass(t,"show"),t.classList.contains("dropdown-menu-right")&&(r._renderer.setStyle(t,"left","auto"),r._renderer.setStyle(t,"right","0")),"up"===r.direction&&(r._renderer.setStyle(t,"top","auto"),r._renderer.setStyle(t,"transform","translateY(-101%)"))),t&&r._state.isAnimated&&r._factoryDropDownAnimation.create(t).play(),r.cd.markForCheck(),r.cd.detectChanges()}))}return Object.defineProperty(e.prototype,"direction",{get:function(){return this._state.direction},enumerable:!1,configurable:!0}),e.prototype._contains=function(e){return this._element.nativeElement.contains(e)},e.prototype.ngOnDestroy=function(){this._subscription.unsubscribe()},e}();l.decorators=[{type:t.Component,args:[{selector:"bs-dropdown-container",changeDetection:t.ChangeDetectionStrategy.OnPush,host:{style:"display:block;position: absolute;z-index: 1040"},template:'\n <div [class.dropup]="direction === \'up\'"\n [ngClass]="{dropdown: direction === \'down\'}"\n [class.show]="isOpen"\n [class.open]="isOpen"><ng-content></ng-content>\n </div>\n '}]}],l.ctorParameters=function(){return[{type:u},{type:t.ChangeDetectorRef},{type:t.Renderer2},{type:t.ElementRef},{type:s.AnimationBuilder}]};var h=function(){function e(e,t,n,i,o,s,r){this._elementRef=e,this._renderer=t,this._viewContainerRef=n,this._cis=i,this._state=o,this._config=s,this.dropup=!1,this._isInlineOpen=!1,this._isDisabled=!1,this._subscriptions=[],this._isInited=!1,this._state.autoClose=this._config.autoClose,this._state.insideClick=this._config.insideClick,this._state.isAnimated=this._config.isAnimated,this._factoryDropDownAnimation=r.build(c),this._dropdown=this._cis.createLoader(this._elementRef,this._viewContainerRef,this._renderer).provide({provide:u,useValue:this._state}),this.onShown=this._dropdown.onShown,this.onHidden=this._dropdown.onHidden,this.isOpenChange=this._state.isOpenChange}return Object.defineProperty(e.prototype,"autoClose",{get:function(){return this._state.autoClose},set:function(e){this._state.autoClose=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isAnimated",{get:function(){return this._state.isAnimated},set:function(e){this._state.isAnimated=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"insideClick",{get:function(){return this._state.insideClick},set:function(e){this._state.insideClick=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDisabled",{get:function(){return this._isDisabled},set:function(e){this._isDisabled=e,this._state.isDisabledChange.emit(e),e&&this.hide()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isOpen",{get:function(){return this._showInline?this._isInlineOpen:this._dropdown.isShown},set:function(e){e?this.show():this.hide()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isBs4",{get:function(){return!o.isBs3()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_showInline",{get:function(){return!this.container},enumerable:!1,configurable:!0}),e.prototype.ngOnInit=function(){var e=this;this._isInited||(this._isInited=!0,this._dropdown.listen({outsideClick:!1,triggers:this.triggers,show:function(){return e.show()}}),this._subscriptions.push(this._state.toggleClick.subscribe((function(t){return e.toggle(t)}))),this._subscriptions.push(this._state.isDisabledChange.pipe(n.filter((function(e){return e}))).subscribe((function(){return e.hide()}))))},e.prototype.show=function(){var e=this;if(!this.isOpen&&!this.isDisabled)return this._showInline?(this._inlinedMenu||this._state.dropdownMenu.then((function(t){e._dropdown.attachInline(t.viewContainer,t.templateRef),e._inlinedMenu=e._dropdown._inlineViewRef,e.addBs4Polyfills(),e._inlinedMenu&&e._renderer.addClass(e._inlinedMenu.rootNodes[0].parentNode,"open"),e.playAnimation()})).catch(),this.addBs4Polyfills(),this._isInlineOpen=!0,this.onShown.emit(!0),this._state.isOpenChange.emit(!0),void this.playAnimation()):void this._state.dropdownMenu.then((function(t){var n=e.dropup||void 0!==e.dropup&&e.dropup;e._state.direction=n?"up":"down";var i=e.placement||(n?"top start":"bottom start");e._dropdown.attach(l).to(e.container).position({attachment:i}).show({content:t.templateRef,placement:i}),e._state.isOpenChange.emit(!0)})).catch()},e.prototype.hide=function(){this.isOpen&&(this._showInline?(this.removeShowClass(),this.removeDropupStyles(),this._isInlineOpen=!1,this.onHidden.emit(!0)):this._dropdown.hide(),this._state.isOpenChange.emit(!1))},e.prototype.toggle=function(e){return this.isOpen||!e?this.hide():this.show()},e.prototype._contains=function(e){return this._elementRef.nativeElement.contains(e.target)||this._dropdown.instance&&this._dropdown.instance._contains(e.target)},e.prototype.ngOnDestroy=function(){var e,t;try{for(var n=d(this._subscriptions),i=n.next();!i.done;i=n.next()){i.value.unsubscribe()}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}this._dropdown.dispose()},e.prototype.addBs4Polyfills=function(){o.isBs3()||(this.addShowClass(),this.checkRightAlignment(),this.addDropupStyles())},e.prototype.playAnimation=function(){var e=this;this._state.isAnimated&&this._inlinedMenu&&setTimeout((function(){e._inlinedMenu&&e._factoryDropDownAnimation.create(e._inlinedMenu.rootNodes[0]).play()}))},e.prototype.addShowClass=function(){this._inlinedMenu&&this._inlinedMenu.rootNodes[0]&&this._renderer.addClass(this._inlinedMenu.rootNodes[0],"show")},e.prototype.removeShowClass=function(){this._inlinedMenu&&this._inlinedMenu.rootNodes[0]&&this._renderer.removeClass(this._inlinedMenu.rootNodes[0],"show")},e.prototype.checkRightAlignment=function(){if(this._inlinedMenu&&this._inlinedMenu.rootNodes[0]){var e=this._inlinedMenu.rootNodes[0].classList.contains("dropdown-menu-right");this._renderer.setStyle(this._inlinedMenu.rootNodes[0],"left",e?"auto":"0"),this._renderer.setStyle(this._inlinedMenu.rootNodes[0],"right",e?"0":"auto")}},e.prototype.addDropupStyles=function(){this._inlinedMenu&&this._inlinedMenu.rootNodes[0]&&(this._renderer.setStyle(this._inlinedMenu.rootNodes[0],"top",this.dropup?"auto":"100%"),this._renderer.setStyle(this._inlinedMenu.rootNodes[0],"transform",this.dropup?"translateY(-101%)":"translateY(0)"),this._renderer.setStyle(this._inlinedMenu.rootNodes[0],"bottom","auto"))},e.prototype.removeDropupStyles=function(){this._inlinedMenu&&this._inlinedMenu.rootNodes[0]&&(this._renderer.removeStyle(this._inlinedMenu.rootNodes[0],"top"),this._renderer.removeStyle(this._inlinedMenu.rootNodes[0],"transform"),this._renderer.removeStyle(this._inlinedMenu.rootNodes[0],"bottom"))},e}();h.decorators=[{type:t.Directive,args:[{selector:"[bsDropdown], [dropdown]",exportAs:"bs-dropdown",providers:[u],host:{"[class.dropup]":"dropup","[class.open]":"isOpen","[class.show]":"isOpen && isBs4"}}]}],h.ctorParameters=function(){return[{type:t.ElementRef},{type:t.Renderer2},{type:t.ViewContainerRef},{type:i.ComponentLoaderFactory},{type:u},{type:p},{type:s.AnimationBuilder}]},h.propDecorators={placement:[{type:t.Input}],triggers:[{type:t.Input}],container:[{type:t.Input}],dropup:[{type:t.Input}],autoClose:[{type:t.Input}],isAnimated:[{type:t.Input}],insideClick:[{type:t.Input}],isDisabled:[{type:t.Input}],isOpen:[{type:t.Input}],isOpenChange:[{type:t.Output}],onShown:[{type:t.Output}],onHidden:[{type:t.Output}]};var _=function(e,t,n){e.resolveDropdownMenu({templateRef:n,viewContainer:t})};_.decorators=[{type:t.Directive,args:[{selector:"[bsDropdownMenu],[dropdownMenu]",exportAs:"bs-dropdown-menu"}]}],_.ctorParameters=function(){return[{type:u},{type:t.ViewContainerRef},{type:t.TemplateRef}]};var f=function(){function e(e,t,n,i,o){var s=this;this._changeDetectorRef=e,this._dropdown=t,this._element=n,this._renderer=i,this._state=o,this.isOpen=!1,this._subscriptions=[],this._subscriptions.push(this._state.isOpenChange.subscribe((function(e){s.isOpen=e,e?(s._documentClickListener=s._renderer.listen("document","click",(function(e){!s._state.autoClose||2===e.button||s._element.nativeElement.contains(e.target)||s._state.insideClick&&s._dropdown._contains(e)||(s._state.toggleClick.emit(!1),s._changeDetectorRef.detectChanges())})),s._escKeyUpListener=s._renderer.listen(s._element.nativeElement,"keyup.esc",(function(){s._state.autoClose&&(s._state.toggleClick.emit(!1),s._changeDetectorRef.detectChanges())}))):(s._documentClickListener&&s._documentClickListener(),s._escKeyUpListener&&s._escKeyUpListener())}))),this._subscriptions.push(this._state.isDisabledChange.subscribe((function(e){return s.isDisabled=e||void 0})))}return e.prototype.onClick=function(e){e.stopPropagation(),this.isDisabled||this._state.toggleClick.emit(!0)},e.prototype.ngOnDestroy=function(){var e,t;this._documentClickListener&&this._documentClickListener(),this._escKeyUpListener&&this._escKeyUpListener();try{for(var n=d(this._subscriptions),i=n.next();!i.done;i=n.next()){i.value.unsubscribe()}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();f.decorators=[{type:t.Directive,args:[{selector:"[bsDropdownToggle],[dropdownToggle]",exportAs:"bs-dropdown-toggle",host:{"[attr.aria-haspopup]":"true"}}]}],f.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:h},{type:t.ElementRef},{type:t.Renderer2},{type:u}]},f.propDecorators={isDisabled:[{type:t.HostBinding,args:["attr.disabled"]}],isOpen:[{type:t.HostBinding,args:["attr.aria-expanded"]}],onClick:[{type:t.HostListener,args:["click",["$event"]]}]};var y=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[i.ComponentLoaderFactory,a.PositioningService,u]}},e}();y.decorators=[{type:t.NgModule,args:[{imports:[r.CommonModule],declarations:[_,f,l,h],exports:[_,f,h],entryComponents:[l]}]}],e.BsDropdownConfig=p,e.BsDropdownContainerComponent=l,e.BsDropdownDirective=h,e.BsDropdownMenuDirective=_,e.BsDropdownModule=y,e.BsDropdownState=u,e.BsDropdownToggleDirective=f,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-bootstrap-dropdown.umd.min.js.map