-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
98 lines (85 loc) · 2.75 KB
/
app.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
/* --- NAVBAR FUNCTIONS ---*/
function getNavbarElements() {
var navbar, navbar_btn, body_pad;
navbar = document.querySelector(".navbar");
navbar_btn = document.querySelector(".navbar_collapse_button button");
body_pad = document.querySelector(".body-padding");
return [navbar, navbar_btn, body_pad];
}
function foldNavbar(navbarStyle = "display:none") {
var navbar, navbar_btn, body_pad;
[navbar, navbar_btn, body_pad] = getNavbarElements();
navbar_btn.textContent = ">";
navbar_btn.style = "margin-left:0px";
navbar_btn.style = "display:inline-block";
navbar.style = navbarStyle;
}
function unfoldNavbar(navbarStyle = "display:block") {
var navbar, navbar_btn, body_pad;
[navbar, navbar_btn, body_pad] = getNavbarElements();
navbar_btn.textContent = "<";
navbar_btn.style = "margin-left:250px";
navbar.style = navbarStyle;
}
function adjustScreen(orientation = "") {
// REVIEW Feel like there would be better way to handle the logic
var navbar, navbar_btn, body_pad;
[navbar, navbar_btn, body_pad] = getNavbarElements();
// Portrait mode with nav_bar clicks
if (orientation === "") {
body_pad.style = "padding-left: 5%";
navbar_btn.style = "display:inline-block";
// Unfold navigation bar
if (navbar_btn.textContent === ">") {
("unfold in side no orient");
unfoldNavbar();
}
// Fold navigation bar
else {
("fold in side no orient");
foldNavbar();
}
}
// Portrait mode just by resizing
else if (orientation === "Port") {
("Port");
body_pad.style = "padding-left: 5%";
foldNavbar();
}
// Landscape mode just by resizing
else {
("Land");
body_pad.style = "padding-left: 23%";
foldNavbar("display:block");
}
}
// Get orientation of the screen
function getOrientation() {
var orientation = window.innerWidth >= window.innerHeight ? "Land" : "Port";
if (window.innerHeight <= 600 && window.innerWidth <= 800) {
orientation = "Port";
}
return orientation;
}
/* --- LISTENERS ---- */
// Listener resizing
window.onresize = function() {
var orientation;
orientation = getOrientation();
adjustScreen(orientation);
};
// Listener: button to fold/unfold navbar
document
.querySelector(".navbar_collapse_button button")
.addEventListener("click", function() {
adjustScreen();
});
// Listener: navbar content
document.querySelector(".navbar_content").addEventListener("click", function() {
var orient, navbar, navbar_btn, body_pad;
[navbar, navbar_btn, body_pad] = getNavbarElements();
orient = getOrientation();
if (orient === "Port") {
foldNavbar();
}
});