-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.jquery.js
More file actions
36 lines (35 loc) · 805 Bytes
/
state.jquery.js
File metadata and controls
36 lines (35 loc) · 805 Bytes
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
/**
* CSS-Tabs Plugin State Management
* Spencer Watson [wattydev.com]
* https://github.com/WattyRev/CSS-Tabs
*/
$(function() {
var q = window.location.search.replace('?', '').split('&');
var tab;
for (i = 0; i < q.length; i++) {
var query = q[i];
if (query.split('=')[0] === 'tab') {
tab = query.split('=')[1];
}
}
$('#' + tab).attr('checked', 'checked');
$('input:radio').change(function() {
var radio = $(this);
if (!radio.parents('.tab-wrapper')) {
return;
}
var id = radio.attr('id');
var url = '';
if (tab){
url = location.href.replace("tab="+tab, "tab="+id);
} else {
if (q[0] !== '') {
url = location.href + '&tab='+id;
} else {
url = location.href + '?tab='+id;
}
}
tab = id;
history.pushState(null, null, url);
});
});