PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.6.9
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.6.9
8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 8.5.2 8.5.0 All 532 releases
chatbot / js / cbpFWTabs.js

cbpFWTabs.js in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 8.6.9, at js/cbpFWTabs.js

79 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.forEach( 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( this.current >= 0 ) {
60 this.tabs[ this.current ].className = '';
61 if( this.items[ this.current ] ) {
62 this.items[ this.current ].className = '';
63 }
64 }
65 // change current
66 this.current = idx != undefined ? idx : this.options.start >= 0 && this.options.start < this.items.length ? this.options.start : 0;
67 this.tabs[ this.current ].className = 'tab-current';
68 var sectionSelector = this.tabs[ this.current ].getAttribute( 'data-section' );
69 var section = sectionSelector ? this.el.querySelector( sectionSelector ) : this.items[ this.current ];
70 if( section ) {
71 section.className = 'content-current';
72 }
73 };
74
75 // add to global namespace
76 window.CBPFWTabs = CBPFWTabs;
77
78 })( window );
79