blob: 234901ab72eec2a43dc4857a09c73d4724c1ebcc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
(function($) {
'use strict';
// Animate tabs of tabbed code blocks
/**
* TabbedCodeBlock
* @param {String} elems
* @constructor
*/
var TabbedCodeBlock = function(elems) {
this.$tabbedCodeBlocs = $(elems);
};
TabbedCodeBlock.prototype = {
/**
* Run TabbedCodeBlock feature
* @return {void}
*/
run: function() {
var self = this;
self.$tabbedCodeBlocs.find('.tab').click(function() {
var $codeblock = $(this).parent().parent().parent();
var $tabsContent = $codeblock.find('.tabs-content').children('pre, .highlight');
// remove `active` css class on all tabs
$(this).siblings().removeClass('active');
// add `active` css class on the clicked tab
$(this).addClass('active');
// hide all tab contents
$tabsContent.hide();
// show only the right one
$tabsContent.eq($(this).index()).show();
});
}
};
$(document).ready(function() {
var tabbedCodeBlocks = new TabbedCodeBlock('.codeblock--tabbed');
tabbedCodeBlocks.run();
});
})(jQuery);
|