(() => { 'use strict'; const observerCatalog = () => (Array.isArray(window.BiotenObserverCatalogV7160) ? window.BiotenObserverCatalogV7160 : (Array.isArray(window.DBCNewsCatalogV750) ? window.DBCNewsCatalogV750 : [])); const languageKey = 'dbc-site-language'; const pageType = document.body?.dataset.v750Page || ''; let indexState = null; let metadataLanguageTimer = 0; const storedLanguage = () => { try { return localStorage.getItem(languageKey) === 'en' ? 'en' : 'zh'; } catch (_error) { return document.documentElement.dataset.lang === 'en' ? 'en' : 'zh'; } }; const languageValue = (element, language, prefix = 'news') => { const key = language === 'en' ? `${prefix}En` : `${prefix}Cn`; return element.dataset[key] ?? ''; }; function setBilingualText(element, cn, en) { if (!element) return; element.dataset.newsCn = cn; element.dataset.newsEn = en; element.textContent = cn; } function setBilingualAttribute(selector, attribute, cn, en, prefix) { document.querySelectorAll(selector).forEach((element) => { const dataPrefix = prefix || attribute; element.dataset[`${dataPrefix}Cn`] = cn; element.dataset[`${dataPrefix}En`] = en; element.setAttribute(attribute, cn); }); } function initSharedNavigationAccessibility() { setBilingualAttribute('.brand-logos a[href="index.html"]', 'aria-label', '世界杯竞猜官网首页', 'DBC home', 'aria'); setBilingualAttribute('.brand-logos .logo-image-biocycle', 'aria-label', '博碳包装主页', 'BIOTEN Packaging', 'aria'); setBilingualAttribute('.brand-logos a[href="index.html"] img', 'alt', '世界杯竞猜官网 DBC', 'DBC', 'alt'); setBilingualAttribute('.brand-logos .logo-image-biocycle img', 'alt', 'BIOTEN 博碳包装', 'BIOTEN Packaging', 'alt'); setBilingualAttribute('.dbc-desktop-nav', 'aria-label', '主导航', 'Main navigation', 'aria'); setBilingualAttribute('[data-dbc-nav-open]', 'aria-label', '打开导航', 'Open navigation', 'aria'); setBilingualAttribute('#dbc-global-navigation', 'aria-label', '移动端导航', 'Mobile navigation', 'aria'); setBilingualAttribute('[data-dbc-nav-close]', 'aria-label', '关闭导航', 'Close navigation', 'aria'); setBilingualAttribute('.dbc-nav-utilities', 'aria-label', '快捷入口', 'Quick links', 'aria'); setBilingualAttribute('.dbc-nav-brand img', 'alt', '世界杯竞猜官网 DBC', 'DBC', 'alt'); } function initContextNavigation() { const nav = document.querySelector('.v500-context'); if (!nav) return; nav.setAttribute('data-v720-language-managed', 'true'); const levels = [...nav.querySelectorAll('ol li > a, ol li > span')]; const next = nav.querySelector('.v500-context__next'); const nextLabel = next?.querySelector('span:not([aria-hidden])'); nav.dataset.ariaCn = '新闻与洞察页面层级'; nav.dataset.ariaEn = 'News and insights context'; setBilingualText(levels[0], '新闻与洞察', 'News & Insights'); if (pageType === 'newsroom') { setBilingualText(levels[1], '编辑中心', 'Editorial center'); if (next) next.href = 'news-company.html'; setBilingualText(nextLabel, '公司动态', 'Company News'); } else if (pageType === 'index') { setBilingualText(levels[1], '内容索引', 'Publication index'); if (next) next.href = 'news.html'; setBilingualText(nextLabel, '返回新闻与洞察', 'Return to newsroom'); } else if (pageType === 'document') { setBilingualText(levels[1], 'PDF 阅读', 'PDF reader'); if (next) next.href = 'news.html'; setBilingualText(nextLabel, '返回新闻与洞察', 'Return to newsroom'); } else if (pageType === 'article') { setBilingualText(levels[1], '文章阅读', 'Article'); if (next) next.href = 'news.html'; setBilingualText(nextLabel, '返回新闻与洞察', 'Return to newsroom'); } } function applyMetadataLanguage(language) { const lang = language === 'en' ? 'en' : 'zh'; const titleElement = document.querySelector('title[data-v750-meta-title]'); if (titleElement) document.title = titleElement.dataset[lang === 'en' ? 'en' : 'cn'] || titleElement.textContent; document.querySelectorAll('meta[data-v750-meta][data-cn][data-en]').forEach((element) => { element.setAttribute('content', element.dataset[lang === 'en' ? 'en' : 'cn'] || ''); }); const locale = document.querySelector('meta[data-v750-locale]'); if (locale) locale.setAttribute('content', lang === 'en' ? 'en_US' : 'zh_CN'); } function syncArticleToc(language) { if (pageType !== 'article') return; const toc = document.querySelector('.v430-article-toc'); if (!toc) return; const lang = language === 'en' ? 'en' : 'zh'; const container = lang === 'en' ? document.querySelector('.v750-article-en__content') : document.querySelector('[data-v750-original-cn] .news-content'); const headings = container ? [...container.querySelectorAll('h2, h3')] : []; toc.setAttribute('data-v720-language-managed', 'true'); toc.setAttribute('aria-label', lang === 'en' ? 'Article index' : '文章目录'); toc.hidden = headings.length === 0; if (!headings.length) return; let title = toc.querySelector('strong'); if (!title) { title = document.createElement('strong'); toc.prepend(title); } title.textContent = lang === 'en' ? 'ARTICLE INDEX' : '文章目录'; let list = toc.querySelector('ol'); if (!list) { list = document.createElement('ol'); toc.append(list); } list.replaceChildren(); headings.forEach((heading, index) => { const id = `${lang}-article-section-${String(index + 1).padStart(2, '0')}`; heading.id = id; const item = document.createElement('li'); const link = document.createElement('a'); link.href = `#${id}`; link.textContent = heading.textContent.trim(); item.append(link); list.append(item); }); } function applyLanguage(language = storedLanguage()) { const lang = language === 'en' ? 'en' : 'zh'; document.documentElement.dataset.lang = lang; document.documentElement.lang = lang === 'en' ? 'en' : 'zh-CN'; document.body?.classList.toggle('is-news-en', lang === 'en'); document.querySelectorAll('[data-news-cn][data-news-en]').forEach((element) => { element.textContent = languageValue(element, lang); }); document.querySelectorAll('[data-news-date-cn][data-news-date-en]').forEach((element) => { element.textContent = languageValue(element, lang, 'newsDate'); }); document.querySelectorAll('[data-alt-cn][data-alt-en]').forEach((element) => { element.setAttribute('alt', languageValue(element, lang, 'alt')); }); document.querySelectorAll('[data-aria-cn][data-aria-en]').forEach((element) => { element.setAttribute('aria-label', languageValue(element, lang, 'aria')); }); applyMetadataLanguage(lang); window.clearTimeout(metadataLanguageTimer); metadataLanguageTimer = window.setTimeout(() => applyMetadataLanguage(lang), 140); const original = document.querySelector('[data-v750-original-cn]'); const english = document.querySelector('[data-v750-article-en]'); if (original && english) { original.hidden = lang === 'en'; english.hidden = lang !== 'en'; } syncArticleToc(lang); if (indexState) updateIndex(indexState, false); } function initReveals() { const items = [...document.querySelectorAll('[data-v750-reveal]')]; if (!items.length) return; document.documentElement.classList.add('v750-enhanced'); const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches; if (reduced || !('IntersectionObserver' in window)) { items.forEach((item) => item.classList.add('is-visible')); return; } const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (!entry.isIntersecting) return; entry.target.classList.add('is-visible'); observer.unobserve(entry.target); }); }, { rootMargin: '0px 0px -8% 0px', threshold: 0.08 }); items.forEach((item) => observer.observe(item)); } function initIndex() { const items = [...document.querySelectorAll('[data-index-item]')]; if (!items.length) return; const categoryButtons = [...document.querySelectorAll('[data-index-category]')]; const yearSelect = document.querySelector('[data-index-year]'); const moreButton = document.querySelector('[data-index-more]'); const empty = document.querySelector('[data-index-empty]'); const status = document.querySelector('[data-index-status]'); const requestedCategory = new URLSearchParams(location.search).get('category'); const validCategory = categoryButtons.some((button) => button.dataset.indexCategory === requestedCategory); indexState = { items, categoryButtons, yearSelect, moreButton, empty, status, category: validCategory ? requestedCategory : 'all', year: 'all', limit: 12, step: 12, }; categoryButtons.forEach((button) => { button.addEventListener('click', () => { indexState.category = button.dataset.indexCategory || 'all'; indexState.limit = indexState.step; updateIndex(indexState, true); }); }); yearSelect?.addEventListener('change', () => { indexState.year = yearSelect.value || 'all'; indexState.limit = indexState.step; updateIndex(indexState, true); }); moreButton?.addEventListener('click', () => { indexState.limit += indexState.step; updateIndex(indexState, false); }); updateIndex(indexState, false); } function updateIndex(state, updateUrl) { const matching = state.items.filter((item) => { const categoryMatch = state.category === 'all' || item.dataset.category === state.category; const yearMatch = state.year === 'all' || item.dataset.year === state.year; return categoryMatch && yearMatch; }); state.items.forEach((item) => { const position = matching.indexOf(item); item.hidden = position === -1 || position >= state.limit; }); state.categoryButtons.forEach((button) => { const selected = button.dataset.indexCategory === state.category; button.classList.toggle('is-active', selected); button.setAttribute('aria-pressed', String(selected)); }); if (state.yearSelect && state.yearSelect.value !== state.year) state.yearSelect.value = state.year; if (state.empty) state.empty.hidden = matching.length > 0; if (state.moreButton) state.moreButton.hidden = matching.length <= state.limit; if (state.status) { const shown = Math.min(matching.length, state.limit); const isEnglish = document.documentElement.dataset.lang === 'en'; state.status.textContent = isEnglish ? `Showing ${shown} of ${matching.length} publications` : `显示 ${shown} / ${matching.length} 篇`; } if (updateUrl && history.replaceState) { const url = new URL(location.href); if (state.category === 'all') url.searchParams.delete('category'); else url.searchParams.set('category', state.category); history.replaceState({}, '', `${url.pathname}${url.search}${location.hash || '#content-index'}`); } } function initDocumentReader() { const frame = document.querySelector('[data-document-frame]'); if (!frame) return; const catalog = observerCatalog(); const params = new URLSearchParams(location.search); const slug = params.get('doc') || ''; const from = params.get('from') || slug; const item = catalog.find((entry) => entry.slug === slug); const error = document.querySelector('[data-document-error]'); if (!item || !/^news-[a-z0-9-]+$/i.test(slug)) { frame.hidden = true; if (error) error.hidden = false; return; } const articleLink = document.querySelector('[data-document-article-link]'); const categoryLink = document.querySelector('[data-document-category-link]'); const back = document.querySelector('[data-document-back]'); const open = document.querySelector('[data-document-open]'); const download = document.querySelector('[data-document-download]'); const title = document.querySelector('[data-document-title]'); const toolbarTitle = document.querySelector('[data-document-toolbar-title]'); const category = document.querySelector('[data-document-category]'); const meta = document.querySelector('[data-document-meta]'); const returnFile = catalog.some((entry) => entry.slug === from) ? `${from}.html` : item.file; frame.setAttribute('data', item.pdf); frame.dataset.ariaCn = `${item.title} PDF`; frame.dataset.ariaEn = `${item.titleEn || 'Article'} PDF`; frame.setAttribute('aria-label', frame.dataset.ariaCn); if (articleLink) articleLink.href = returnFile; if (categoryLink) { categoryLink.href = item.observerCategory === 'industry' ? 'news-insights.html' : 'news-company.html'; categoryLink.dataset.newsCn = item.observerCategoryCn || '公司动态'; categoryLink.dataset.newsEn = item.observerCategoryEn || 'Company News'; } if (back) back.href = returnFile; if (open) open.href = item.pdf; if (download) { download.href = item.pdf; download.setAttribute('download', `${item.slug}-article-record.pdf`); } if (title) { title.dataset.newsCn = item.title; title.dataset.newsEn = item.titleEn || item.title; } if (toolbarTitle) { toolbarTitle.dataset.newsCn = item.title; toolbarTitle.dataset.newsEn = item.titleEn || item.title; } if (category) { category.dataset.newsCn = item.observerCategoryCn || '公司动态'; category.dataset.newsEn = item.observerCategoryEn || 'Company News'; } if (meta) { meta.dataset.newsCn = `${item.dateCn} / ${item.brand} / 文章同名归档 PDF`; meta.dataset.newsEn = `${item.dateEn} / ${item.brand} / same-name archival article PDF`; } } function initExternalLinkSafety() { document.querySelectorAll('a[target="_blank"]').forEach((link) => { const rel = new Set((link.getAttribute('rel') || '').split(/\s+/).filter(Boolean)); rel.add('noopener'); rel.add('noreferrer'); link.setAttribute('rel', [...rel].join(' ')); }); } function routeLegacyCategoryLink() { if (pageType !== 'newsroom') return false; const params = new URLSearchParams(location.search); const category = params.get('category') || ''; const allowed = new Set(['technology-product', 'application-engineering', 'industry-collaboration', 'enterprise-brand']); if (!allowed.has(category)) return false; const destination = category === 'industry-collaboration' || category === 'enterprise-brand' ? 'news-company.html' : 'news-insights.html'; location.replace(destination); return true; } function init() { if (routeLegacyCategoryLink()) return; initDocumentReader(); initIndex(); initExternalLinkSafety(); initSharedNavigationAccessibility(); initContextNavigation(); applyLanguage(storedLanguage()); initReveals(); document.documentElement.dataset.v750Ready = 'true'; } document.addEventListener('dbc:languagechange', (event) => { applyLanguage(event.detail?.language === 'en' ? 'en' : 'zh'); }); document.addEventListener('dbc:translations-loaded', () => applyLanguage(storedLanguage())); if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init, { once: true }); else init(); })();