-
Notifications
You must be signed in to change notification settings - Fork 0
/
tab.js
40 lines (32 loc) · 913 Bytes
/
tab.js
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
(function($){
'use strict';
var $tabContent, $tabLink, $iconElement;
function tabInit( opts ) {
var options = $.extend(tabOptions, opts);
$tabLink = $( options.link );
$tabContent = $( options.content );
$iconElement = $tabLink.find('.icon');
$tabLink.on('click', clickHandler );
showElement( options.current );
}
function animateIcon() {
var addClassName = ( $iconElement.hasClass('sz-icon-arrow-right') ) ? 'sz-icon-arrow-down' : 'sz-icon-arrow-right';
$iconElement.removeClass('sz-icon-arrow-right sz-icon-arrow-down').addClass(addClassName);
}
function showElement(elId) {
animateIcon();
$tabContent.addClass('hide');
if (elId) { $(elId).removeClass('hide'); }
}
function clickHandler() {
showElement( $(this).data('element') );
}
var tabOptions = {
current : null,
content : '.tab-content',
link : '.tab-link'
};
window.myFancyTab = {
init : tabInit
};
})( jQuery );