/* DBC / BIOTEN V4.0.0 shared interaction finish. */ (function () { 'use strict'; const root = document.documentElement; const body = document.body; if (!body || !body.classList.contains('v400-site')) return; const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; function centerCurrentLocalLink() { const selectors = [ '.about-anchor-nav', '.packaging-anchor', '.resources-page-nav', '.news-business-anchor', '.knowledge-anchor-nav', '.bioten-product-nav', '.pl-anchor-nav', '.v245-local-nav', '.vp-anchor-nav', '.dv2-local-nav__inner', '.dv23-journey-nav' ]; selectors.forEach(function (selector) { const nav = document.querySelector(selector); if (!nav || nav.scrollWidth <= nav.clientWidth + 4) return; const active = nav.querySelector('[aria-current], .is-active, a[href="' + window.location.hash + '"]'); if (!active) return; window.requestAnimationFrame(function () { active.scrollIntoView({ behavior: 'auto', block: 'nearest', inline: 'center' }); }); }); } function setupSectionReveal() { if (reduceMotion || !('IntersectionObserver' in window)) return; if (body.classList.contains('dbc-home-page') || body.classList.contains('dv24-page')) return; const sections = Array.from(document.querySelectorAll('main > section')).slice(1); if (!sections.length) return; root.classList.add('v400-motion-ready'); sections.forEach(function (section) { section.classList.add('v400-reveal'); }); const observer = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (!entry.isIntersecting) return; entry.target.classList.add('is-visible'); observer.unobserve(entry.target); }); }, { rootMargin: '0px 0px -8% 0px', threshold: 0.07 }); sections.forEach(function (section) { observer.observe(section); }); } function stopDecorativeAutoplayForReducedMotion() { if (!reduceMotion) return; document.querySelectorAll('[data-v311-gallery]').forEach(function (gallery) { const button = gallery.querySelector('[data-v311-action="toggle"]'); if (!button) return; const label = (button.getAttribute('aria-label') || '').toLowerCase(); if (label.includes('暂停') || label.includes('pause')) button.click(); }); } function wireHashNavigation() { window.addEventListener('hashchange', centerCurrentLocalLink, { passive: true }); document.addEventListener('click', function (event) { const link = event.target.closest('a[href^="#"]'); if (!link) return; window.setTimeout(centerCurrentLocalLink, 80); }); } function markExternalLinks() { document.querySelectorAll('a[href^="http"]').forEach(function (link) { try { const target = new URL(link.href, window.location.href); if (target.origin === window.location.origin) return; if (link.target === '_blank') { const rel = new Set((link.rel || '').split(/\s+/).filter(Boolean)); rel.add('noopener'); link.rel = Array.from(rel).join(' '); } } catch (_) { /* Invalid user-authored URL remains untouched for the QA script. */ } }); } function init() { centerCurrentLocalLink(); setupSectionReveal(); stopDecorativeAutoplayForReducedMotion(); wireHashNavigation(); markExternalLinks(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init, { once: true }); } else { init(); } })();