(function () { 'use strict'; if (window.__DBC_SITE_V450__) return; window.__DBC_SITE_V450__ = true; const categoryKeys = new Set([ 'all', 'technology-product', 'application-engineering', 'industry-collaboration', 'enterprise-brand' ]); function normalizeCategory(value) { return categoryKeys.has(value) ? value : 'all'; } function setPressed(controls, key, attribute) { controls.forEach(control => { const active = control.getAttribute(attribute) === key; control.classList.toggle('is-active', active); control.setAttribute('aria-pressed', String(active)); }); } function updateQuery(name, value, defaultValue) { if (!window.history || !window.history.replaceState) return; const url = new URL(window.location.href); if (value === defaultValue) url.searchParams.delete(name); else url.searchParams.set(name, value); window.history.replaceState({}, '', `${url.pathname}${url.search}${url.hash}`); } function setupNewsFilters() { const controls = [...document.querySelectorAll('[data-news-filter]')]; const cards = [...document.querySelectorAll('[data-news-category]')]; if (!controls.length || !cards.length) return; const result = document.querySelector('[data-news-result]'); const params = new URLSearchParams(window.location.search); function applyFilter(requested, writeUrl) { const category = normalizeCategory(requested); let visible = 0; cards.forEach(card => { const match = category === 'all' || card.dataset.newsCategory === category; card.hidden = !match; card.setAttribute('aria-hidden', String(!match)); if (match) visible += 1; }); setPressed(controls, category, 'data-news-filter'); if (result) result.textContent = `共 ${visible} 条公开信息`; if (writeUrl) updateQuery('category', category, 'all'); } controls.forEach(control => { control.addEventListener('click', event => { if (control.tagName === 'A') event.preventDefault(); applyFilter(control.dataset.newsFilter || 'all', true); }); }); applyFilter(params.get('category') || 'all', false); } function setupArchiveFilters() { const controls = [...document.querySelectorAll('[data-archive-year]')]; const cards = [...document.querySelectorAll('[data-archive-year-card]')]; if (!controls.length || !cards.length) return; const validYears = new Set(['all', ...cards.map(card => card.dataset.archiveYearCard)]); const result = document.querySelector('[data-archive-result]'); const params = new URLSearchParams(window.location.search); function applyYear(requested, writeUrl) { const year = validYears.has(requested) ? requested : 'all'; let visible = 0; cards.forEach(card => { const match = year === 'all' || card.dataset.archiveYearCard === year; card.hidden = !match; card.setAttribute('aria-hidden', String(!match)); if (match) visible += 1; }); setPressed(controls, year, 'data-archive-year'); if (result) result.textContent = `共 ${visible} 条历史记录`; if (writeUrl) updateQuery('year', year, 'all'); } controls.forEach(control => { control.addEventListener('click', event => { if (control.tagName === 'A') event.preventDefault(); applyYear(control.dataset.archiveYear || 'all', true); }); }); applyYear(params.get('year') || 'all', false); } function markExternalPdfLinks() { document.querySelectorAll('a[href$=".pdf"]').forEach(link => { if (!link.hasAttribute('rel') && link.target === '_blank') { link.rel = 'noopener'; } }); } function init() { setupNewsFilters(); setupArchiveFilters(); markExternalPdfLinks(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init, { once: true }); } else { init(); } })();