forked from CYD-poolen/cyd.liu.se
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
executable file
·72 lines (61 loc) · 1.87 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
$(document).ready(function(){
// Since no new elements are fetched via AJAX.
// Only traverse the DOM for these objects once.
var bigFat = $('#BigFatContainer');
var navigation = $('#Navigation');
var mobileHeader = $('#MobileHeader');
var indicator = $('#Indicator');
// Place the indicator in the right position at page load.
indicator.css({marginTop: getIndicatorPosition()});
// Set some settings in the localscroll plugin.
navigation.localScroll({duration:800, hash:true});
window.onhashchange = function(){
position = getIndicatorPosition();
indicator.animate({marginTop: position},function(){
// If a phone is viewing the page.
if(mobileHeader.css('display') != 'hidden'){
closeMenuOnMobile(400);
}
});
};
// Opening the menu on phones or small screens.
mobileHeader.click(function(){
if(bigFat.css('left') != '155px') {
openMenuOnMobile();
}
});
// Clicking anywhere but the menu when the menu
// is open closes the menu.
bigFat.click(closeMenuOnMobile);
mobileHeader.click(closeMenuOnMobile);
function openMenuOnMobile(time){
if(time == undefined)
time = 200;
bigFat.animate({left: '155px'}, time);
mobileHeader.animate({left: '155px'}, time);
}
function closeMenuOnMobile(time){
if(bigFat.css('left') == '155px'){
if(time == undefined)
time = 200;
bigFat.animate({left: '0px'}, time);
mobileHeader.animate({left: '0px'}, time);
}
}
});
function getIndicatorPosition(){
var offset = 0;
var page = location.pathname.split('/');
page = page[page.length - 2];
// If on a dated blog entry
if (!isNaN(page))
page = "";
// If we're at the index page.
if (page === "_site" || page === "")
offset = $('#Logo').position().top + 71;
else
offset = $('#' + page).position().top - 9;
if(window.innerHeight < 420)
offset -= 156;
return offset;
}