UNPKG

8.21 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-bootstrap/tabs",["exports","@angular/core","@angular/common"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["ngx-bootstrap"]=e["ngx-bootstrap"]||{},e["ngx-bootstrap"].tabs={}),e.ng.core,e.ng.common)}(this,(function(e,t,s){"use strict";var i=function(){function e(e){this.viewRef=e}return Object.defineProperty(e.prototype,"ngTransclude",{get:function(){return this._ngTransclude},set:function(e){this._ngTransclude=e,e&&this.viewRef.createEmbeddedView(e)},enumerable:!1,configurable:!0}),e}();i.decorators=[{type:t.Directive,args:[{selector:"[ngTransclude]"}]}],i.ctorParameters=function(){return[{type:t.ViewContainerRef}]},i.propDecorators={ngTransclude:[{type:t.Input}]};var a=function(){this.type="tabs",this.isKeysAllowed=!0,this.ariaLabel="Tabs"};a.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new a},token:a,providedIn:"root"}),a.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}];var n=function(){function e(e,t,s){this.renderer=t,this.elementRef=s,this.clazz=!0,this.tabs=[],this.classMap={},this.ariaLabel="Tabs",this.isDestroyed=!1,this._vertical=!1,this._justified=!1,this._type="tabs",this._isKeysAllowed=!0,Object.assign(this,e)}return Object.defineProperty(e.prototype,"vertical",{get:function(){return this._vertical},set:function(e){this._vertical=e,this.setClassMap()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"justified",{get:function(){return this._justified},set:function(e){this._justified=e,this.setClassMap()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return this._type},set:function(e){this._type=e,this.setClassMap()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isKeysAllowed",{get:function(){return this._isKeysAllowed},set:function(e){this._isKeysAllowed=e},enumerable:!1,configurable:!0}),e.prototype.ngOnDestroy=function(){this.isDestroyed=!0},e.prototype.addTab=function(e){this.tabs.push(e),e.active=1===this.tabs.length&&!e.active},e.prototype.removeTab=function(e,t){void 0===t&&(t={reselect:!0,emit:!0});var s=this.tabs.indexOf(e);if(-1!==s&&!this.isDestroyed){if(t.reselect&&e.active&&this.hasAvailableTabs(s)){var i=this.getClosestTabIndex(s);this.tabs[i].active=!0}t.emit&&e.removed.emit(e),this.tabs.splice(s,1),e.elementRef.nativeElement.parentNode&&this.renderer.removeChild(e.elementRef.nativeElement.parentNode,e.elementRef.nativeElement)}},e.prototype.keyNavActions=function(e,t){if(this.isKeysAllowed){var s=Array.from(this.elementRef.nativeElement.querySelectorAll(".nav-link"));if(13===e.keyCode||"Enter"===e.key||32===e.keyCode||"Space"===e.key)return e.preventDefault(),void s[t%s.length].click();if(39!==e.keyCode&&"RightArrow"!==e.key)if(37!==e.keyCode&&"LeftArrow"!==e.key)if(36!==e.keyCode&&"Home"!==e.key)if(35!==e.keyCode&&"End"!==e.key){if((46===e.keyCode||"Delete"===e.key)&&this.tabs[t].removable){if(this.removeTab(this.tabs[t]),s[t+1])return void s[(t+1)%s.length].focus();s[s.length-1]&&s[0].focus()}}else{e.preventDefault();var i=void 0;r=1,o=t;do{o-r<0?(i=s[o=s.length-1],r=0):i=s[o-r],r++}while(i.classList.contains("disabled"));i.focus()}else{e.preventDefault();var a=void 0;r=0;do{a=s[r%s.length],r++}while(a.classList.contains("disabled"));a.focus()}else{var n=void 0,r=1,o=t;do{o-r<0?(n=s[o=s.length-1],r=0):n=s[o-r],r++}while(n.classList.contains("disabled"));n.focus()}else{var l=void 0,r=1;do{l=s[(t+r)%s.length],r++}while(l.classList.contains("disabled"));l.focus()}}},e.prototype.getClosestTabIndex=function(e){var t=this.tabs.length;if(!t)return-1;for(var s=1;s<=t;s+=1){var i=e-s,a=e+s;if(this.tabs[i]&&!this.tabs[i].disabled)return i;if(this.tabs[a]&&!this.tabs[a].disabled)return a}return-1},e.prototype.hasAvailableTabs=function(e){var t=this.tabs.length;if(!t)return!1;for(var s=0;s<t;s+=1)if(!this.tabs[s].disabled&&s!==e)return!0;return!1},e.prototype.setClassMap=function(){var e;this.classMap=((e={"nav-stacked":this.vertical,"flex-column":this.vertical,"nav-justified":this.justified})["nav-"+this.type]=!0,e)},e}();n.decorators=[{type:t.Component,args:[{selector:"tabset",template:'<ul class="nav" [ngClass]="classMap"\n (click)="$event.preventDefault()"\n [attr.aria-label]="ariaLabel"\n role="tablist">\n <li *ngFor="let tabz of tabs; let i = index" [ngClass]="[\'nav-item\', tabz.customClass || \'\']"\n [class.active]="tabz.active" [class.disabled]="tabz.disabled" (keydown)="keyNavActions($event, i)">\n <a href="javascript:void(0);" class="nav-link" role="tab"\n [attr.aria-controls]="tabz.id ? tabz.id : \'\'"\n [attr.aria-selected]="!!tabz.active"\n [attr.id]="tabz.id ? tabz.id + \'-link\' : \'\'"\n [class.active]="tabz.active" [class.disabled]="tabz.disabled"\n (click)="tabz.active = true">\n <span [ngTransclude]="tabz.headingRef">{{ tabz.heading }}</span>\n <span *ngIf="tabz.removable" (click)="$event.preventDefault(); removeTab(tabz);" class="bs-remove-tab"> &#10060;</span>\n </a>\n </li>\n</ul>\n<div class="tab-content">\n <ng-content></ng-content>\n</div>\n',styles:[":host .nav-tabs .nav-item.disabled a.disabled{cursor:default}"]}]}],n.ctorParameters=function(){return[{type:a},{type:t.Renderer2},{type:t.ElementRef}]},n.propDecorators={vertical:[{type:t.Input}],justified:[{type:t.Input}],type:[{type:t.Input}],clazz:[{type:t.HostBinding,args:["class.tab-container"]}]};var r=function(){function e(e,s,i){this.elementRef=s,this.renderer=i,this.disabled=!1,this.removable=!1,this.selectTab=new t.EventEmitter,this.deselect=new t.EventEmitter,this.removed=new t.EventEmitter,this.addClass=!0,this.role="tabpanel",this._active=!1,this._customClass="",this.tabset=e,this.tabset.addTab(this)}return Object.defineProperty(e.prototype,"customClass",{get:function(){return this._customClass},set:function(e){var t=this;this.customClass&&this.customClass.split(" ").forEach((function(e){t.renderer.removeClass(t.elementRef.nativeElement,e)})),this._customClass=e?e.trim():"",this.customClass&&this.customClass.split(" ").forEach((function(e){t.renderer.addClass(t.elementRef.nativeElement,e)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"active",{get:function(){return this._active},set:function(e){var t=this;this._active!==e&&(this.disabled&&e||!e?this._active&&!e&&(this.deselect.emit(this),this._active=e):(this._active=e,this.selectTab.emit(this),this.tabset.tabs.forEach((function(e){e!==t&&(e.active=!1)}))))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ariaLabelledby",{get:function(){return this.id?this.id+"-link":""},enumerable:!1,configurable:!0}),e.prototype.ngOnInit=function(){this.removable=!!this.removable},e.prototype.ngOnDestroy=function(){this.tabset.removeTab(this,{reselect:!1,emit:!1})},e}();r.decorators=[{type:t.Directive,args:[{selector:"tab, [tab]",exportAs:"tab"}]}],r.ctorParameters=function(){return[{type:n},{type:t.ElementRef},{type:t.Renderer2}]},r.propDecorators={heading:[{type:t.Input}],id:[{type:t.HostBinding,args:["attr.id"]},{type:t.Input}],disabled:[{type:t.Input}],removable:[{type:t.Input}],customClass:[{type:t.Input}],active:[{type:t.HostBinding,args:["class.active"]},{type:t.Input}],selectTab:[{type:t.Output}],deselect:[{type:t.Output}],removed:[{type:t.Output}],addClass:[{type:t.HostBinding,args:["class.tab-pane"]}],role:[{type:t.HostBinding,args:["attr.role"]}],ariaLabelledby:[{type:t.HostBinding,args:["attr.aria-labelledby"]}]};var o=function(e,t){t.headingRef=e};o.decorators=[{type:t.Directive,args:[{selector:"[tabHeading]"}]}],o.ctorParameters=function(){return[{type:t.TemplateRef},{type:r}]};var l=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[]}},e}();l.decorators=[{type:t.NgModule,args:[{imports:[s.CommonModule],declarations:[i,r,n,o],exports:[r,n,o,i]}]}],e.NgTranscludeDirective=i,e.TabDirective=r,e.TabHeadingDirective=o,e.TabsModule=l,e.TabsetComponent=n,e.TabsetConfig=a,Object.defineProperty(e,"__esModule",{value:!0})}));
2//# sourceMappingURL=ngx-bootstrap-tabs.umd.min.js.map
\No newline at end of file