/* DBC / BIOTEN V4.1.0 — restrained progressive enhancements. */ (function () { 'use strict'; if (window.__DBC_SITE_V410__) return; window.__DBC_SITE_V410__ = true; document.documentElement.classList.add('v410-js'); function initNewsroomIndex() { const page = document.querySelector('main[data-v410-news-index]'); if (!page) return; const anchorBar = page.querySelector('.news-business-anchor'); const anchors = anchorBar ? Array.from(anchorBar.querySelectorAll('a[href^="#"]')) : []; const panels = anchors .map(function (anchor) { const id = anchor.getAttribute('href').slice(1); return document.getElementById(id); }) .filter(Boolean); function setActive(id) { anchors.forEach(function (anchor) { const active = anchor.getAttribute('href') === '#' + id; anchor.classList.toggle('is-active', active); if (active) anchor.setAttribute('aria-current', 'location'); else anchor.removeAttribute('aria-current'); }); } anchors.forEach(function (anchor) { anchor.addEventListener('click', function () { setActive(anchor.getAttribute('href').slice(1)); }); }); if ('IntersectionObserver' in window && panels.length) { const observer = new IntersectionObserver(function (entries) { const visible = entries .filter(function (entry) { return entry.isIntersecting; }) .sort(function (a, b) { return b.intersectionRatio - a.intersectionRatio; }); if (visible[0]) setActive(visible[0].target.id); }, { rootMargin: '-28% 0px -58% 0px', threshold: [0, .08, .2] }); panels.forEach(function (panel) { observer.observe(panel); }); } const hashAliases = { 'featured-evidence': 'bioten-news', 'partnerships': 'casu-news', 'brand-ecosystem': 'antux-news', 'archive': 'dpu-news' }; const hash = window.location.hash.slice(1); const activeId = hashAliases[hash] || hash; if (panels.some(function (panel) { return panel.id === activeId; })) { setActive(activeId); } else if (panels[0]) { setActive(panels[0].id); } const archive = document.querySelector('#dpu-news .news-card-grid'); if (!archive) return; const cards = Array.from(archive.querySelectorAll('.news-event-card')); const initialCount = window.matchMedia('(max-width: 760px)').matches ? 8 : 12; if (cards.length <= initialCount) return; let expanded = false; const control = document.createElement('div'); control.className = 'v410-archive-control'; const button = document.createElement('button'); button.type = 'button'; button.setAttribute('aria-expanded', 'false'); button.setAttribute('aria-controls', 'dpu-news'); control.appendChild(button); archive.insertAdjacentElement('afterend', control); function renderArchive() { cards.forEach(function (card, index) { card.hidden = !expanded && index >= initialCount; }); button.setAttribute('aria-expanded', String(expanded)); button.textContent = expanded ? '收起历史归档' : '展开全部历史归档(' + cards.length + ')'; } button.addEventListener('click', function () { expanded = !expanded; renderArchive(); if (!expanded) { document.getElementById('dpu-news').scrollIntoView({ behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth', block: 'start' }); } }); renderArchive(); } function labelUnavailableLanguageControl() { document.querySelectorAll('[data-language-unavailable]').forEach(function (button) { button.setAttribute('aria-disabled', 'true'); button.setAttribute('title', '本页英文内容正在校对,当前提供完整中文版本'); button.setAttribute('aria-label', '本页英文内容正在校对,当前提供完整中文版本'); }); } function guardLocalPreviewForms() { if (window.location.protocol !== 'file:') return; document.querySelectorAll('form').forEach(function (form) { form.addEventListener('submit', function (event) { event.preventDefault(); event.stopImmediatePropagation(); const status = form.querySelector('[role="status"], .request-status, .form-status, [data-form-status], [data-request-status]'); const message = '当前为本地预览,页面内容可完整检查,但不会发送表单。正式部署后再进行真实提交。'; if (status) { status.hidden = false; status.textContent = message; } else { window.alert(message); } }, true); }); } initNewsroomIndex(); labelUnavailableLanguageControl(); guardLocalPreviewForms(); })();