You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.2 KiB
35 lines
1.2 KiB
//#region js/news.js
|
|
function setActiveNav() {
|
|
const pageNav = document.querySelector("[data-nav]")?.getAttribute("data-nav");
|
|
if (!pageNav) return;
|
|
document.querySelectorAll(".site-header__nav a").forEach((link) => {
|
|
const active = link.textContent.trim().startsWith(pageNav);
|
|
link.classList.toggle("is-active", active);
|
|
});
|
|
}
|
|
function newsDetailBackToggle() {
|
|
const back = document.querySelector(".nd-back");
|
|
const pager = document.querySelector(".nd-pager");
|
|
if (!back || !pager) return;
|
|
if (window.innerWidth <= 576) return;
|
|
new IntersectionObserver(([entry]) => {
|
|
const fullyVisible = entry.isIntersecting && entry.intersectionRatio >= 1;
|
|
back.classList.toggle("is-hidden", fullyVisible);
|
|
back.setAttribute("aria-hidden", fullyVisible ? "true" : "false");
|
|
if (fullyVisible) back.setAttribute("tabindex", "-1");
|
|
else back.removeAttribute("tabindex");
|
|
}, { threshold: 1 }).observe(pager);
|
|
}
|
|
function newsCardClick() {
|
|
$(".n-card, .n-featured").on("click", function(event) {
|
|
if ($(event.target).closest("a, button").length) return;
|
|
const href = $(this).find("a[href]").attr("href");
|
|
if (href) window.location.href = href;
|
|
});
|
|
}
|
|
$(function() {
|
|
setActiveNav();
|
|
newsDetailBackToggle();
|
|
newsCardClick();
|
|
});
|
|
//#endregion
|