;( function( window ) { 'use strict'; function extend( a, b ) { for( var key in b ) { if( b.hasownproperty( key ) ) { a[key] = b[key]; } } return a; } function cbpfwtabs( el, options ) { this.el = el; this.options = extend( {}, this.options ); extend( this.options, options ); this._init(); } cbpfwtabs.prototype.options = { start : 0 }; cbpfwtabs.prototype._init = function() { // tabs elems this.tabs = [].slice.call( this.el.queryselectorall( 'nav > ul > li' ) ); // content items this.items = [].slice.call( this.el.queryselectorall( '.content-wrap > section' ) ); // current index this.current = -1; // show current content item this._show(); // init events this._initevents(); }; cbpfwtabs.prototype._initevents = function() { var self = this; this.tabs.foreach( function( tab, idx ) { tab.addeventlistener( 'click', function( ev ) { ev.preventdefault(); self._show( idx ); } ); } ); }; cbpfwtabs.prototype._show = function( idx ) { if( this.current >= 0 ) { this.tabs[ this.current ].classname = this.items[ this.current ].classname = ''; } // change current this.current = idx != undefined ? idx : this.options.start >= 0 && this.options.start < this.items.length ? this.options.start : 0; this.tabs[ this.current ].classname = 'tab-current'; this.items[ this.current ].classname = 'content-current'; }; // add to global namespace window.cbpfwtabs = cbpfwtabs; })( window );