diff --git a/public/themes/dist_static/static/css/news.css b/public/themes/dist_static/static/css/news.css index f351102..d3f5b33 100644 --- a/public/themes/dist_static/static/css/news.css +++ b/public/themes/dist_static/static/css/news.css @@ -43,7 +43,7 @@ font-size: var(--font-18); font-weight: 400; line-height: var(--font-24); - cursor: default; + cursor: pointer; } .n-tabs__item.is-active { background: var(--color-primary); @@ -81,15 +81,21 @@ } .n-featured { - display: grid; - grid-template-columns: minmax(0, 45rem) minmax(0, 1fr); - gap: 3rem; - align-items: center; + position: relative; padding: 3rem; margin-bottom: 5rem; border-radius: 2.5rem; background: rgba(175, 181, 185, 0.15); } +.n-featured__swiper { + overflow: hidden; +} +.n-featured__slide { + display: grid; + grid-template-columns: minmax(0, 45rem) minmax(0, 1fr); + gap: 3rem; + align-items: center; +} .n-featured__media { min-width: 0; border-radius: 2rem; @@ -130,8 +136,14 @@ font-family: "MiSans VF", "PingFang SC", sans-serif; font-size: var(--font-28); font-weight: 500; - line-height: var(--font-37); + line-height: var(--font-36); transition: color var(--duration-fast) var(--easing); + min-height: 4.5rem; + display: -webkit-box; + -webkit-line-clamp: 2; + line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; } .n-featured__desc { margin: 0; @@ -140,6 +152,12 @@ font-size: var(--font-18); font-weight: 400; line-height: var(--font-28); + min-height: 5.25rem; + display: -webkit-box; + -webkit-line-clamp: 3; + line-clamp: 3; + -webkit-box-orient: vertical; + overflow: hidden; } .n-featured__foot { display: flex; @@ -148,13 +166,15 @@ gap: 1.5rem; margin-top: auto; padding-top: 2rem; + padding-right: 8rem; border-top: 1px solid rgb(223, 224, 226); transition: border-color var(--duration-fast) var(--easing); } .n-featured__nav { - display: flex; - align-items: center; - gap: 1rem; + position: absolute; + right: 3rem; + bottom: 3rem; + z-index: 2; } .n-featured:hover { cursor: pointer; @@ -169,33 +189,6 @@ border-top-color: var(--color-primary); } -.n-nav-btn { - display: inline-flex; - align-items: center; - justify-content: center; - width: 3rem; - height: 3rem; - padding: 0; - border: 1px solid rgba(46, 53, 58, 0.1); - border-radius: 1rem; - background: transparent; - cursor: default; -} -.n-nav-btn img { - display: block; - width: 0.875rem; - height: auto; - transform: scaleX(-1); - filter: grayscale(1) opacity(0.45); -} -.n-nav-btn--active { - border-color: var(--color-primary); -} -.n-nav-btn--active img { - transform: none; - filter: none; -} - .n-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); @@ -330,12 +323,15 @@ font-size: 16Px; } .n-featured { - grid-template-columns: 1fr; gap: 32Px; padding: 32Px; margin-bottom: 56Px; border-radius: 24Px; } + .n-featured__slide { + grid-template-columns: 1fr; + gap: 32Px; + } .n-featured__media { border-radius: 20Px; } @@ -356,6 +352,11 @@ .n-featured__foot { margin-top: 24Px; padding-top: 24Px; + padding-right: 112Px; + } + .n-featured__nav { + right: 32Px; + bottom: 32Px; } .n-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); @@ -408,6 +409,9 @@ margin-bottom: 40Px; border-radius: 16Px; } + .n-featured__slide { + gap: 20Px; + } .n-featured__media { border-radius: 12Px; } @@ -420,27 +424,20 @@ .n-featured__title { font-size: 20Px; line-height: 28Px; + min-height: 56Px; } .n-featured__desc { font-size: 14Px; line-height: 22Px; - display: -webkit-box; - -webkit-line-clamp: 4; - line-clamp: 4; - -webkit-box-orient: vertical; - overflow: hidden; + min-height: 66Px; } .n-featured__foot { margin-top: 16Px; - padding-top: 16Px; + min-height: 3rem; } .n-featured__nav { - gap: 12Px; - } - .n-nav-btn { - width: 40Px; - height: 40Px; - border-radius: 12Px; + right: 20Px; + bottom: 10Px; } .n-grid { grid-template-columns: 1fr; diff --git a/public/themes/dist_static/static/js/news2.js b/public/themes/dist_static/static/js/news2.js index b600feb..9d9c90d 100644 --- a/public/themes/dist_static/static/js/news2.js +++ b/public/themes/dist_static/static/js/news2.js @@ -1,4 +1,11 @@ //#region js/news.js +var NEWS_CATEGORY_PARAM = "cat"; +var NEWS_CATEGORIES = [ + "all", + "insight", + "company", + "event" +]; function setActiveNav() { const pageNav = document.querySelector("[data-nav]")?.getAttribute("data-nav"); if (!pageNav) return; @@ -20,16 +27,94 @@ function newsDetailBackToggle() { else back.removeAttribute("tabindex"); }, { threshold: 1 }).observe(pager); } +var featuredSwiper = null; +function getCategoryFromQuery() { + const cat = new URLSearchParams(window.location.search).get(NEWS_CATEGORY_PARAM); + if (!cat || cat === "all") return "all"; + return NEWS_CATEGORIES.includes(cat) ? cat : "all"; +} +function setCategoryInUrl(cat) { + const url = new URL(window.location.href); + if (!cat || cat === "all") url.searchParams.delete(NEWS_CATEGORY_PARAM); + else url.searchParams.set(NEWS_CATEGORY_PARAM, cat); + window.history.replaceState(null, "", url); +} +function activateTab(cat) { + document.querySelectorAll(".n-tabs__item").forEach((btn) => { + const isActive = (btn.dataset.cat || "all") === cat; + btn.classList.toggle("is-active", isActive); + btn.setAttribute("aria-selected", isActive ? "true" : "false"); + }); +} +function filterNews(cat) { + const isMatch = (itemCat) => cat === "all" || itemCat === cat; + document.querySelectorAll(".n-featured__slide[data-category]").forEach((slide) => { + slide.hidden = !isMatch(slide.dataset.category); + }); + document.querySelectorAll(".n-card[data-category]").forEach((card) => { + card.hidden = !isMatch(card.dataset.category); + }); + const featured = document.querySelector(".n-featured"); + if (!featured) return; + featured.hidden = featured.querySelectorAll(".n-featured__slide:not([hidden])").length === 0; +} +function updateFeaturedSwiper() { + const root = document.querySelector(".n-featured"); + const el = root?.querySelector(".n-featured__swiper"); + if (!el || !window.Swiper) return; + if (featuredSwiper) { + featuredSwiper.destroy(true, true); + featuredSwiper = null; + } + if (!root || root.hidden) return; + const slideCount = el.querySelectorAll(".swiper-wrapper > .swiper-slide:not([hidden])").length; + if (slideCount <= 1) return; + featuredSwiper = new window.Swiper(el, { + effect: "fade", + fadeEffect: { crossFade: true }, + loop: slideCount > 1, + speed: 500, + observer: true, + observeParents: true, + watchOverflow: true, + navigation: { + prevEl: root.querySelector(".n-featured__nav .s-arrows__prev"), + nextEl: root.querySelector(".n-featured__nav .s-arrows__next") + } + }); +} +function applyCategory(cat) { + activateTab(cat); + filterNews(cat); + updateFeaturedSwiper(); +} +function initNewsTabs() { + const tabs = document.querySelector(".n-tabs"); + if (!tabs) return; + applyCategory(getCategoryFromQuery()); + tabs.addEventListener("click", (event) => { + const btn = event.target.closest(".n-tabs__item"); + if (!btn) return; + const cat = btn.dataset.cat || "all"; + setCategoryInUrl(cat); + applyCategory(cat); + }); + window.addEventListener("popstate", () => { + applyCategory(getCategoryFromQuery()); + }); +} 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"); + const $root = $(this); + const href = $root.hasClass("n-featured") ? $root.find(".swiper-slide-active a[href]").attr("href") : $root.find("a[href]").first().attr("href"); if (href) window.location.href = href; }); } $(function() { setActiveNav(); newsDetailBackToggle(); + initNewsTabs(); newsCardClick(); }); //#endregion