2024-08-10 18:18:52 +00:00
|
|
|
// Bulma CSS fixes and features for nonshy.
|
2022-08-10 05:10:47 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
2022-08-27 03:38:17 +00:00
|
|
|
// Make all off-site hyperlinks open in a new tab.
|
|
|
|
(document.querySelectorAll("a") || []).forEach(node => {
|
|
|
|
let href = node.attributes.href;
|
|
|
|
if (href === undefined) return;
|
|
|
|
href = href.textContent;
|
|
|
|
if (href.indexOf("http:") === 0 || href.indexOf("https:") === 0) {
|
|
|
|
node.target = "_blank";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-08-23 05:19:42 +00:00
|
|
|
// If we are a PWA in standalone mode, clicking on-site links shows our custom loading spinner.
|
|
|
|
if (window.matchMedia('(display-mode: standalone)').matches) {
|
|
|
|
const spinner = document.querySelector("#nonshy-pwa-loader");
|
|
|
|
(document.querySelectorAll("a, form") || []).forEach(node => {
|
|
|
|
// Links: only on-site ones.
|
|
|
|
if (node.tagName === 'A' && node.target === '_blank') return;
|
|
|
|
|
|
|
|
// Show our spinner on click or submit.
|
|
|
|
node.addEventListener(node.tagName === 'A' ? 'click' : 'submit', () => {
|
|
|
|
spinner.style.display = "block";
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-22 04:24:36 +00:00
|
|
|
// Hamburger menu script.
|
2023-11-28 05:23:31 +00:00
|
|
|
(function () {
|
2022-08-22 04:24:36 +00:00
|
|
|
// Get all "navbar-burger" elements
|
|
|
|
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
|
2022-08-13 06:11:36 +00:00
|
|
|
|
2022-08-22 04:24:36 +00:00
|
|
|
// Add a click event on each of them
|
2023-11-28 05:23:31 +00:00
|
|
|
$navbarBurgers.forEach(el => {
|
2022-08-22 04:24:36 +00:00
|
|
|
el.addEventListener('click', () => {
|
2022-08-13 06:11:36 +00:00
|
|
|
|
2022-08-22 04:24:36 +00:00
|
|
|
// Get the target from the "data-target" attribute
|
|
|
|
const target = el.dataset.target;
|
|
|
|
const $target = document.getElementById(target);
|
2022-08-13 06:11:36 +00:00
|
|
|
|
2022-08-22 04:24:36 +00:00
|
|
|
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
|
|
|
|
el.classList.toggle('is-active');
|
|
|
|
$target.classList.toggle('is-active');
|
2022-08-13 06:11:36 +00:00
|
|
|
|
2022-08-22 04:24:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Allow the "More" drop-down to work on mobile (toggle is-active on click instead of requiring mouseover)
|
2023-11-28 05:23:31 +00:00
|
|
|
(function () {
|
2022-08-22 04:24:36 +00:00
|
|
|
const menu = document.querySelector("#navbar-more"),
|
|
|
|
userMenu = document.querySelector("#navbar-user"),
|
|
|
|
activeClass = "is-active";
|
|
|
|
|
|
|
|
if (!menu) return;
|
|
|
|
|
|
|
|
// Click the "More" menu to permanently toggle the menu.
|
|
|
|
menu.addEventListener("click", (e) => {
|
|
|
|
if (menu.classList.contains(activeClass)) {
|
|
|
|
menu.classList.remove(activeClass);
|
|
|
|
} else {
|
|
|
|
menu.classList.add(activeClass);
|
|
|
|
}
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Touching the user drop-down button toggles it.
|
2022-08-30 03:00:15 +00:00
|
|
|
if (userMenu !== null) {
|
|
|
|
userMenu.addEventListener("touchstart", (e) => {
|
|
|
|
// On mobile/tablet screens they had to hamburger menu their way here anyway, let it thru.
|
|
|
|
if (screen.width < 1024) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-26 02:58:43 +00:00
|
|
|
|
2022-08-30 03:00:15 +00:00
|
|
|
e.preventDefault();
|
|
|
|
if (userMenu.classList.contains(activeClass)) {
|
|
|
|
userMenu.classList.remove(activeClass);
|
|
|
|
} else {
|
|
|
|
userMenu.classList.add(activeClass);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-08-22 04:24:36 +00:00
|
|
|
|
|
|
|
// Touching a link from the user menu lets it click thru.
|
|
|
|
(document.querySelectorAll(".navbar-dropdown") || []).forEach(node => {
|
2023-11-28 05:23:31 +00:00
|
|
|
node.addEventListener("touchstart", (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2022-08-10 05:10:47 +00:00
|
|
|
});
|
2022-08-22 04:24:36 +00:00
|
|
|
|
|
|
|
// Clicking the rest of the body will close an active navbar-dropdown.
|
|
|
|
(document.addEventListener("click", (e) => {
|
|
|
|
(document.querySelectorAll(".navbar-dropdown.is-active, .navbar-item.is-active") || []).forEach(node => {
|
|
|
|
node.classList.remove(activeClass);
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
})();
|
2022-08-13 06:11:36 +00:00
|
|
|
|
2024-07-07 19:45:42 +00:00
|
|
|
// Dropdown menus.
|
|
|
|
(document.querySelectorAll(".dropdown") || []).forEach(node => {
|
2024-08-10 18:18:52 +00:00
|
|
|
// If this dropdown is near the bottom of the page, make it open upwards.
|
|
|
|
if (!node.classList.contains("is-up") && !node.classList.contains("is-right")) {
|
|
|
|
let offsetTop = node.offsetTop,
|
|
|
|
body = document.body,
|
|
|
|
html = document.documentElement,
|
|
|
|
pageHeight = Math.max(body.scrollHeight, body.offsetHeight,
|
|
|
|
html.clientHeight, html.scrollHeight, html.offsetHeight,
|
|
|
|
);
|
|
|
|
if (pageHeight - offsetTop < 450) {
|
|
|
|
node.classList.add("is-up");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-07 19:45:42 +00:00
|
|
|
const button = node.querySelector("button");
|
|
|
|
button.addEventListener("click", (e) => {
|
|
|
|
node.classList.toggle("is-active");
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2022-08-13 06:11:36 +00:00
|
|
|
// Common event handlers for bulma modals.
|
|
|
|
(document.querySelectorAll(".modal-background, .modal-close, .photo-modal") || []).forEach(node => {
|
|
|
|
const target = node.closest(".modal");
|
2023-11-28 05:23:31 +00:00
|
|
|
if (target.classList.contains("vue-managed") || target.classList.contains("nonshy-important-modal")) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-13 06:11:36 +00:00
|
|
|
node.addEventListener("click", () => {
|
|
|
|
target.classList.remove("is-active");
|
2022-08-22 04:24:36 +00:00
|
|
|
});
|
|
|
|
});
|
2022-09-08 04:18:54 +00:00
|
|
|
|
|
|
|
// Collapsible cards for mobile view (e.g. People Search filters box)
|
|
|
|
(document.querySelectorAll(".card.nonshy-collapsible-mobile") || []).forEach(node => {
|
|
|
|
const header = node.querySelector(".card-header"),
|
|
|
|
body = node.querySelector(".card-content"),
|
2024-02-29 04:49:16 +00:00
|
|
|
icon = header.querySelector("button.card-header-icon > .icon > i"),
|
|
|
|
always = node.classList.contains("nonshy-collapsible-always");
|
2022-09-08 04:18:54 +00:00
|
|
|
|
|
|
|
// Icon classes.
|
|
|
|
const iconExpanded = "fa-angle-up",
|
|
|
|
iconContracted = "fa-angle-down";
|
|
|
|
|
|
|
|
// If we are already on mobile, hide the body now.
|
2024-02-29 04:49:16 +00:00
|
|
|
if (screen.width <= 768 || always) {
|
2022-09-08 04:18:54 +00:00
|
|
|
body.style.display = "none";
|
|
|
|
if (icon !== null) {
|
|
|
|
icon.classList.remove(iconExpanded);
|
|
|
|
icon.classList.add(iconContracted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add click toggle handler to the header.
|
|
|
|
header.addEventListener("click", () => {
|
|
|
|
if (body.style.display === "none") {
|
|
|
|
body.style.display = "block";
|
|
|
|
if (icon !== null) {
|
|
|
|
icon.classList.remove(iconContracted);
|
|
|
|
icon.classList.add(iconExpanded);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
body.style.display = "none";
|
|
|
|
if (icon !== null) {
|
|
|
|
icon.classList.remove(iconExpanded);
|
|
|
|
icon.classList.add(iconContracted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-09-20 01:24:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Reveal all blurred images on click.
|
|
|
|
(document.querySelectorAll(".blurred-explicit") || []).forEach(node => {
|
|
|
|
node.addEventListener("click", e => {
|
2023-11-28 05:23:31 +00:00
|
|
|
if (node.classList.contains("blurred-explicit")) {
|
|
|
|
node.classList.remove("blurred-explicit");
|
|
|
|
if (node.tagName !== "VIDEO") {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2023-09-20 01:54:47 +00:00
|
|
|
}
|
2023-11-28 05:23:31 +00:00
|
|
|
}
|
2023-09-20 01:24:57 +00:00
|
|
|
});
|
2023-09-24 18:41:19 +00:00
|
|
|
|
|
|
|
// Video tag: autoplay is disabled when blurred, onClick doesn't fire,
|
|
|
|
// set the handler for onPlay.
|
|
|
|
node.addEventListener("play", e => {
|
2023-11-28 05:23:31 +00:00
|
|
|
if (node.classList.contains("blurred-explicit")) {
|
|
|
|
node.classList.remove("blurred-explicit");
|
|
|
|
}
|
2023-09-24 18:41:19 +00:00
|
|
|
});
|
2023-09-20 01:24:57 +00:00
|
|
|
});
|
2023-09-14 04:28:38 +00:00
|
|
|
});
|