-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmodern.js
More file actions
67 lines (53 loc) · 1.36 KB
/
modern.js
File metadata and controls
67 lines (53 loc) · 1.36 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(function() {
function hide_all_content() {
$('#content')
.children('h2')
.hide()
.next('div')
.hide();
}
function show_content(name) {
$('#' + name)
.show()
.next('div')
.show();
}
function show_only(name) {
hide_all_content();
show_content(name);
}
function location_id() {
// ''.substring(999999) returns ''
return location.hash.substring(1) || 'home';
}
function location_set_id(id) {
// we can navigate to '#anchor' URLs in the same way we can navigate to
// 'http://example.com/#full' URLs
location.assign(id);
}
// we'll show/hide content for local URLs,
// and allow other (e.g. GitHub) URLs to behave normally
$('#navbar a[href^=#]').click(function(e) {
var href = $(this).attr('href');
e.preventDefault();
location_set_id(href);
show_only(href.substring(1));
});
$('.share-button')
.attr('href', 'javascript:void(0)')
.click(function(e) {
e.preventDefault();
$('#share').toggle();
});
$('#share').hide();
show_only(location_id());
// ensure the correct content is shown when someone loads a page
// or presses the back/forward buttons
window.onpopstate = function() {
var pageName = location.hash.substring(1);
if (pageName.length === 0) {
pageName = 'home';
}
show_only(pageName);
};
})();