forked from mozilla/zamboni
/
homepage.js
49 lines (42 loc) · 1.56 KB
/
homepage.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
41
42
43
44
45
46
47
48
49
$(document).ready(function(){
if (!$(document.body).hasClass('home')) {
return;
}
$('#homepage .listing-header a').click(function(e) {
e.preventDefault();
update(this, true);
});
// Switch to the tab of the <a> given as `link`.
// Only call pushState if `push` is True.
function update(link, push) {
var target = $(link).attr('data-target');
// Change the list to show the right add-ons.
$('.addon-listing').attr('class', 'addon-listing addon-listing-' + target);
// Update the selected tab.
$('.listing-header .selected').removeClass('selected');
$('#' + target).addClass('selected').focus();
if (push && history.pushState) {
history.pushState({target: target}, document.title, link.href);
}
};
// If we already have a hash, switch to the tab.
if (location.hash) {
var selected = $('#homepage .listing-header ' + location.hash);
if (selected) {
selected.find('a').click().focus();
}
} else {
// Add the current page to the history so we can get back.
var selected = $('#homepage .listing-header .selected a')[0];
update(selected, true, true);
}
// Set up our history callback.
$(window).bind('popstate', function(ev) {
// We don't pushState here because we'd be stuck in this position.
var e = ev.originalEvent;
if (e.state && e.state.target) {
var a = $('#' + e.state.target + ' a')[0];
update(a, false);
}
});
});