-
Notifications
You must be signed in to change notification settings - Fork 0
/
navbar.js
96 lines (82 loc) · 2.73 KB
/
navbar.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
"use strict";
(function() {
window.addEventListener('load', init);
function init() {
// setTimeout(populateNavBar, 100);
populateNavBar();
id('hamburger-mobile').addEventListener('click', toggleHamburger);
}
function populateNavBar() {
let navbarContent = `
<header id="nav-menu">
<nav class="navbar">
<a id="logo" href="/">
<span id="logo-text">Pu Thavikulwat</span>
<!-- <img id="logo-img" src="img/pu_logo.png"> -->
</a>
<ul class="nav-links">
<div class="menu">
<li><a href="/#case-stdy">Case Studies</a></li>
<li><a href="/#coding-projects">Coding</a></li>
<li><a href="/about">About Me</a></li>
</div>
</ul>
</nav>
<div class="navbar-mobile-container">
<nav class="navbar-top-mobile">
<a href="/">
<img id="logo-img-mobile" src="img/pu_logo.png" alt="Pu Thavi Logo">
</a>
<img id="hamburger-mobile" src="img/hamburger_menu.svg" alt="Hamburger Menu">
</nav>
<nav class="navbar-mobile">
<ul>
<li><a href="/">Case Studies</a></li>
<li><a href="/">Coding</a></li>
<li><a href="/about">About Me</a></li>
</ul>
</nav>
</div>
</header>
`;
id('nav-placeholder').insertAdjacentHTML('afterbegin', navbarContent);
}
/**
* If the browser is Safari, apply color changes because Safari is hella buggy
* and work won't with backdrop-filter
*/
function detectSafari() {
let safariColor = 'white';
// Check if the browser is Safari
let isSafari = window.safari !== undefined;
let isIphone = /(iPhone)/i.test(navigator.userAgent);
// Add the 'safari-background' class to the container if it's Safari
if (isSafari && isIphone) {
document.documentElement.style.setProperty('--navbar-background-color', safariColor);
}
}
function toggleHamburger() {
let style2 = window.getComputedStyle(qs('.navbar-mobile'));
if (style2.display === 'none') {
qs('.navbar-mobile').style.display = 'block';
} else {
qs('.navbar-mobile').style.display = 'none';
}
}
/**
* Returns the element that has the ID attribute with the specified value.
* @param {string} id - element ID
* @return {object} DOM object associated with id.
*/
function id(id) {
return document.getElementById(id);
}
/**
* Returns the first element that matches the given CSS selector.
* @param {string} query - CSS query selector.
* @return {object[]} array of DOM objects matching the query.
*/
function qs(query) {
return document.querySelector(query);
}
})();