This repository was archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcodetabs.js
More file actions
39 lines (35 loc) · 1.32 KB
/
codetabs.js
File metadata and controls
39 lines (35 loc) · 1.32 KB
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
require([
'jquery'
], function($) {
var setupPage = function(){
if(localStorage){
var lastSelected = localStorage.getItem('codetabs-selected');
if(lastSelected){
$('.codetabs').each(function(){
var $tabs = $(this);
var tabId = $tabs.find('.codetabs-header .tab')
.filter(function(){ return $(this).text() == lastSelected; })
.data('codetab');
if(typeof tabId !== 'undefined'){
setActiveTab($tabs,tabId);
}
});
}
}
};
var setActiveTab = function($tabs,tabId){
$tabs.find('.tab').removeClass('active');
$tabs.find('.tab[data-codetab="' + tabId + '"]').addClass('active');
};
$(document).on('click.plugin.codetabs', '.codetabs .codetabs-header .tab', function(e) {
var $btn = $(e.target);
var $tabs = $btn.parents('.codetabs');
var tabId = $btn.data('codetab');
setActiveTab($tabs,tabId);
if(localStorage){
localStorage.setItem('codetabs-selected',$btn.text());
}
});
gitbook.events.bind('start', setupPage);
gitbook.events.bind('page.change', setupPage);
});