1/** 2 * cbpFWTabs.js v1.0.0 3 * http://www.codrops.com 4 * 5 * Licensed under the MIT license. 6 * http://www.opensource.org/licenses/mit-license.php 7 * 8 * Copyright 2014, Codrops 9 * http://www.codrops.com 10 */ 11;( function( window ) { 12 13 'use strict'; 14 15 function extend( a, b ) { 16 for( var key in b ) { 17 if( b.hasOwnProperty( key ) ) { 18 a[key] = b[key]; 19 } 20 } 21 return a; 22 } 23 24 function CBPFWTabs( el, options ) { 25 this.el = el; 26 this.options = extend( {}, this.options ); 27 extend( this.options, options ); 28 this._init(); 29 } 30 31 CBPFWTabs.prototype.options = { 32 start : 0 33 }; 34 35 CBPFWTabs.prototype._init = function() { 36 // tabs elems 37 this.tabs = [].slice.call( this.el.querySelectorAll( 'nav > ul > li' ) ); 38 // content items 39 this.items = [].slice.call( this.el.querySelectorAll( '.content-wrap > section' ) ); 40 // current index 41 this.current = -1; 42 // show current content item 43 this._show(); 44 // init events 45 this._initEvents(); 46 }; 47 48 CBPFWTabs.prototype._initEvents = function() { 49 var self = this; 50 this.tabs.forEac
50h( function( tab, idx ) { 51 tab.addEventListener( 'click', function( ev ) { 52 ev.preventDefault(); 53 self._show( idx ); 54 } ); 55 } ); 56 }; 57 58 CBPFWTabs.prototype._show = function( idx ) { 59 if (undefined != idx) { 60 if( this.current >= 0 ) { 61 this.tabs[ this.current ].className = this.items[ this.current ].className = ''; 62 } 63 // change current 64 this.current = idx != undefined ? idx : this.options.start >= 0 && this.options.start < this.items.length ? this.options.start : 0; 65 this.tabs[ this.current ].className = 'tab-current'; 66 this.items[ this.current ].className = 'content-current'; 67 } 68 }; 69 70 // add to global namespace 71 window.CBPFWTabs = CBPFWTabs; 72 73})( window );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.