-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.js
264 lines (252 loc) · 8.95 KB
/
bundle.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// bundle.js created by bundlejs.sh v1.2.2 Sat Nov 9 07:42:55 EST 2024
// ./global.js
(function globaljs() {// Add a JS class so the CSS can take into account the new JS styles.
document.querySelector("body").classList.add("JS-Enabled");
})();
// ./assets/js/_utils/getContrast.js
(function assetsjsutilsgetContrastjs() {/**
* @function getContrast
* @description Get the contrasting color for any hex color
* Derived from work by Brian Suda, https://24ways.org/2010/calculating-color-contrast/
* @see https://gomakethings.com/dynamically-changing-the-text-color-based-on-background-color-contrast-with-vanilla-js/
* @param {string} inputHexColor A hexcolor value
* @return {string|undefined} The contrasting color (black or white), or
* undefined if the input is not a string.
* @since 10/14/21
* @version 1.0.1
* @author Alexander Burdiss
*/
window.getContrast = function (inputHexColor) {
if (typeof inputHexColor !== "string") {
return undefined;
}
let hexcolor = inputHexColor;
// If a leading # is provided, remove it
if (hexcolor.slice(0, 1) === "#") {
hexcolor = hexcolor.slice(1);
}
// If a three-character hexcode, make six-character
if (hexcolor.length === 3) {
hexcolor = hexcolor
.split("")
.map((hex) => hex + hex)
.join("");
}
// Convert to RGB value
let r = parseInt(hexcolor.substr(0, 2), 16);
let g = parseInt(hexcolor.substr(2, 2), 16);
let b = parseInt(hexcolor.substr(4, 2), 16);
// Get YIQ ratio
let yiq = (r * 299 + g * 587 + b * 114) / 1000;
// Check contrast
return yiq >= 128 ? "black" : "white";
};
})();
// ./assets/js/_utils/capitalize.js
(function assetsjsutilscapitalizejs() {/**
* @function capitalize
* @description Capitalizes the first letter of the string passed in.
* @param {string} inputString
* @returns {string}
* @author Alexander Burdiss
* @since 9/11/21
* @version 1.0.0
*/
window.capitalize = function (inputString) {
if (typeof inputString !== "string") {
return undefined;
}
const firstLetter = inputString[0];
const restOfString = inputString.slice(1);
return `${firstLetter.toUpperCase()}${restOfString}`;
};
})();
// ./assets/js/smoothScroll.js
(function assetsjssmoothScrolljs() {document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
document.querySelector(this.getAttribute("href")).scrollIntoView({
behavior: "smooth",
});
});
});
})();
// ./assets/js/header.js
(function assetsjsheaderjs() {// Populate Header Data
const headerNav = document.querySelector("header nav");
headerNav.innerHTML = `
<a href="/">Home</a>
<div class="navgroup" aria-expanded="false">
<button class="chevron" id="nav1">Get Informed</button>
<div class="subnav" id="subnav1">
<a href="/get-informed/">Overview</a>
<a href="/get-informed/books/">Books</a>
<a href="/get-informed/butchering">Butchering</a>
<a href="/get-informed/food-preservation">Food Preservation</a>
<a href="/get-informed/gardening/">Gardening</a>
<a href="/get-informed/guides/">How-To Guides</a>
<a href="/get-informed/recipes/">Recipes</a>
</div>
</div>
<a href="/get-trained/">Get Trained</a>
<div class="navgroup" aria-expanded="false">
<button class="chevron" id="nav3">Get Active</button>
<div class="subnav" id="subnav3">
<a href="/get-active/">Overview</a>
<a href="/get-active/activism/">Activism</a>
<a href="/get-active/churches/">Churches</a>
<a href="/get-active/community-events/">Community Events</a>
<a href="/get-active/memes/">Memes</a>
<a href="/get-active/small-group-resources/">Small Group Resources</a>
</div>
</div>
<a href="/about/">About</a>
`;
// Build dynamic navigation
const navButtons = document.querySelectorAll('[id^="nav"]');
const subnavButtons = document.querySelectorAll(".subnav");
/**
* Closes open navigation elements and removes event listeners from the body
* @author Alexander Burdiss
* @since 10/22/22
* @version 1.0.0
*/
function closeOpenNavigation(event) {
navButtons.forEach((button) => {
if (button.classList.contains("open")) {
button.parentElement.ariaExpanded = false;
button.classList.remove("open");
}
});
subnavButtons.forEach((button) => {
if (button.style.display === "block") {
button.style.display = "none";
}
});
if (document.body.onclick) {
document.body.onclick = undefined;
}
}
navButtons.forEach((button) => {
button.addEventListener("click", () => {
const number = button.id[button.id.length - 1];
const subnav = document.querySelector("#subnav" + number);
if (subnav.style.display === "block") {
button.parentElement.ariaExpanded = false;
button.classList.remove("open");
subnav.style.display = "none";
} else {
closeOpenNavigation();
button.parentElement.ariaExpanded = true;
button.classList.add("open");
subnav.style.display = "block";
setTimeout(() => (document.body.onclick = closeOpenNavigation), 0);
}
});
});
// Build hamburger navigation to replace static navigation (if JS enabled)
const closeButton = document.createElement("button");
closeButton.classList.add("hamburger");
closeButton.innerHTML = `
<span class="visually-hidden-accessibility">Open Menu</span>
<span class="first-span"></span>
<span class="second-span"></span>
<span class="third-span"></span>
`;
const headerContent = document.querySelector("header .inner-content");
closeButton.addEventListener("click", function () {
const header = document.querySelector("header");
const hamburgerMenu = document.querySelector(".hamburger");
const menuAccessibilityText = document.querySelector(
".hamburger .visually-hidden-accessibility"
);
const isOpen = hamburgerMenu.classList.contains("open");
if (isOpen) {
document.body.style.overflow = "visible";
hamburgerMenu.classList.remove("open");
header.classList.remove("mobile-menu-open");
menuAccessibilityText.innerText = "Open Menu";
} else {
document.body.style.overflow = "hidden";
hamburgerMenu.classList.add("open");
header.classList.add("mobile-menu-open");
menuAccessibilityText.innerText = "Close Menu";
}
});
// Close the menu when resized larger than mobile
window.addEventListener("resize", function (event) {
if (window.innerWidth >= 860) {
const header = document.querySelector("header");
const hamburgerMenu = document.querySelector(".hamburger");
const menuAccessibilityText = document.querySelector(
".hamburger .visually-hidden-accessibility"
);
document.body.style.overflow = "visible";
hamburgerMenu.classList.remove("open");
header.classList.remove("mobile-menu-open");
menuAccessibilityText.innerText = "Open Menu";
}
});
headerContent.appendChild(closeButton);
})();
// ./assets/js/breadcrumbs.js
(function assetsjsbreadcrumbsjs() {const main = document.querySelector("main");
const breadcrumbs = document.createElement("div");
breadcrumbs.classList.add("breadcrumbs");
let currentPath = window.location.pathname;
if (currentPath[0] == "/") {
currentPath = currentPath.slice(1);
}
// Remove trailing /
if (currentPath[currentPath.length - 1] == "/") {
currentPath = currentPath.slice(0, currentPath.length - 1);
}
const tempPathParts = currentPath.split("/");
// Remove current path from breadcrumbs
tempPathParts.pop();
tempPathParts.map((pathPart) => {
const humanReadable = pathPart.split("-").map(window.capitalize).join(" ");
const breadcrumb = document.createElement("a");
breadcrumb.innerText = humanReadable;
breadcrumb.href = "/" + currentPath.split(pathPart)[0] + pathPart;
breadcrumbs.appendChild(breadcrumb);
});
if (tempPathParts.length > 0) {
main.insertBefore(breadcrumbs, main.firstChild);
}
})();
// ./assets/js/footer.js
(function assetsjsfooterjs() {// Populate footer with links
const footer = document.querySelector('footer');
footer.innerHTML = `
<div class="inner-content">
<div class="left-container">
<h2><a href="/get-informed/">Get Informed</a></h2>
<a href="/get-informed/books/">Books</a>
<a href="/get-informed/butchering/">Butchering</a>
<a href="/get-informed/food-preservation">Food Preservation</a>
<a href="/get-informed/gardening/">Gardening</a>
<a href="/get-informed/guides/">How-To Guides</a>
<a href="/get-informed/recipes/">Recipes</a>
<h2><a href="/get-trained/">Get Trained</a></h2>
<h2><a href="/get-active/">Get Active</a></h2>
<a href="/get-active/activism/">Activism</a>
<a href="/get-active/churches/">Churches</a>
<a href="/get-active/community-events/">Community Events</a>
<a href="/get-active/memes/">Memes</a>
<a href="/get-active/small-group-resources/">Small Group Resources</a>
<h2><a href="/about/">About</a></h2>
</div>
<div>
<address>
<a href="mailto:info@shelbyready.com">info@shelbyready.com</a>
</address>
<p>
Website built and designed by
<a href="https://alexanderburdiss.com">Alexander Burdiss</a>
</p>
<a href="/privacy-policy/">Privacy Policy</a>
</div>
</div>
`;
})();