aurelia-bootstrap
Version:
Bootstrap components written in Aurelia.
58 lines (44 loc) • 1.39 kB
JavaScript
import {children, bindable, bindingMode} from "aurelia-framework";
import {bootstrapOptions} from "../utils/bootstrap-options";
export class AubsTabsetCustomElement {
type = bootstrapOptions.tabsetType;
vertical = bootstrapOptions.tabsetVertical;
active = 0;
tabsClass = 'nav-tabs';
typeChanged(){
this.tabsClass = this.type === 'pills' ? 'nav-pills' : 'nav-tabs';
}
activeChanged(newValue){
if(!this.tabs || this.tabs.length == 0) {
return;
}
if(newValue > this.tabs.length){
this.active = 0;
return;
}
this.selectTab(this.tabs[this.active], true);
}
tabsChanged() {
for(let i = 0; i < this.tabs.length; i++){
let next = this.tabs[i];
next.index = i;
}
if(this.active >= this.tabs.length){
this.active = 0;
}
this.selectTab(this.tabs[this.active]);
}
selectTab(tab, force = false) {
if (tab.disabled && !force) {
return;
}
this.active = tab.index;
this.emitTabChanged();
}
emitTabChanged() {
for (let next of this.tabs) {
next.handleTabChanged(this.active);
}
}
}