-
Notifications
You must be signed in to change notification settings - Fork 768
/
main.js
113 lines (100 loc) · 2.97 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* Sets up Justified Gallery.
*/
if (!!$.prototype.justifiedGallery) {
var options = {
rowHeight: 140,
margins: 4,
lastRow: "justify"
};
$(".article-gallery").justifiedGallery(options);
}
$(document).ready(function() {
/**
* Shows the responsive navigation menu on mobile.
*/
$("#header > #nav > ul > .icon").click(function() {
$("#header > #nav > ul").toggleClass("responsive");
});
/**
* Controls the different versions of the menu in blog post articles
* for Desktop, tablet and mobile.
*/
if ($(".post").length) {
var menu = $("#menu");
var nav = $("#menu > #nav");
var menuIcon = $("#menu-icon, #menu-icon-tablet");
/**
* Display the menu on hi-res laptops and desktops.
*/
if ($(document).width() >= 1440) {
menu.show();
menuIcon.addClass("active");
}
/**
* Display the menu if the menu icon is clicked.
*/
menuIcon.click(function() {
if (menu.is(":hidden")) {
menu.show();
menuIcon.addClass("active");
} else {
menu.hide();
menuIcon.removeClass("active");
}
return false;
});
/**
* Add a scroll listener to the menu to hide/show the navigation links.
*/
if (menu.length) {
$(window).on("scroll", function() {
var topDistance = menu.offset().top;
// hide only the navigation links on desktop
if (!nav.is(":visible") && topDistance < 50) {
nav.show();
} else if (nav.is(":visible") && topDistance > 100) {
nav.hide();
}
// on tablet, hide the navigation icon as well and show a "scroll to top
// icon" instead
if ( ! $( "#menu-icon" ).is(":visible") && topDistance < 50 ) {
$("#menu-icon-tablet").show();
$("#top-icon-tablet").hide();
} else if (! $( "#menu-icon" ).is(":visible") && topDistance > 100) {
$("#menu-icon-tablet").hide();
$("#top-icon-tablet").show();
}
});
}
/**
* Show mobile navigation menu after scrolling upwards,
* hide it again after scrolling downwards.
*/
if ($( "#footer-post").length) {
var lastScrollTop = 0;
$(window).on("scroll", function() {
var topDistance = $(window).scrollTop();
if (topDistance > lastScrollTop){
// downscroll -> show menu
$("#footer-post").hide();
} else {
// upscroll -> hide menu
$("#footer-post").show();
}
lastScrollTop = topDistance;
// close all submenu"s on scroll
$("#nav-footer").hide();
$("#toc-footer").hide();
$("#share-footer").hide();
// show a "navigation" icon when close to the top of the page,
// otherwise show a "scroll to the top" icon
if (topDistance < 50) {
$("#actions-footer > #top").hide();
} else if (topDistance > 100) {
$("#actions-footer > #top").show();
}
});
}
}
});