/** * RailwaySystem - Visual Portal Common Interactive Engine v2.0 * 纯静态 · 离线友好 · 零网络 CDN 依赖 */ const GITLAB_DOCS_BASE = "http://192.168.139.218:9980/sict/railwaysystem/-/blob/feat/cicd-pipeline/"; document.addEventListener('DOMContentLoaded', () => { // 1. 导航栏高亮当前页面 const currentPath = window.location.pathname.split('/').pop() || 'index.html'; document.querySelectorAll('.nav-link, .dropdown-item a').forEach(link => { const href = link.getAttribute('href'); if (href === currentPath || (currentPath === '' && href === 'index.html')) { link.classList.add('active'); } }); // 2. 文档跳转拦截与 GitLab 自动重定向保护 document.querySelectorAll('a').forEach(anchor => { const href = anchor.getAttribute('href'); if (href && href.includes('.md')) { anchor.setAttribute('target', '_blank'); anchor.setAttribute('rel', 'noopener noreferrer'); // 如果仍有相对路径,自动转换为 GitLab 远程在线路径 if (!href.startsWith('http://') && !href.startsWith('https://')) { let cleanRel = href.replace(/^(\.\.\/)+/, ''); if (!cleanRel.startsWith('docs/')) { cleanRel = 'docs/' + cleanRel; } anchor.setAttribute('href', GITLAB_DOCS_BASE + cleanRel); } } }); // 3. 抽屉 (Drawer) 机制 const drawerBackdrop = document.getElementById('drawer-backdrop'); const drawerCloseBtn = document.getElementById('drawer-close-btn'); window.openDrawer = function(title, contentHtml) { const drawerTitle = document.getElementById('drawer-title'); const drawerBody = document.getElementById('drawer-body'); if (drawerTitle) drawerTitle.textContent = title; if (drawerBody) drawerBody.innerHTML = contentHtml; if (drawerBackdrop) { drawerBackdrop.classList.add('active'); document.body.style.overflow = 'hidden'; } }; window.closeDrawer = function() { if (drawerBackdrop) { drawerBackdrop.classList.remove('active'); document.body.style.overflow = ''; } }; if (drawerCloseBtn) { drawerCloseBtn.addEventListener('click', window.closeDrawer); } if (drawerBackdrop) { drawerBackdrop.addEventListener('click', (e) => { if (e.target === drawerBackdrop) { window.closeDrawer(); } }); } // ESC 键关闭抽屉或弹窗 document.addEventListener('keydown', (e) => { if (e.key === 'Escape') { window.closeDrawer(); window.closeModal && window.closeModal(); } }); // 4. 手风琴折叠面板 (Accordion) document.querySelectorAll('.accordion-header').forEach(header => { header.addEventListener('click', () => { const item = header.closest('.accordion-item'); if (item) { item.classList.toggle('open'); } }); }); // 5. 选项卡 (Tabs) 切换 document.querySelectorAll('.tab-trigger').forEach(tab => { tab.addEventListener('click', () => { const tabGroup = tab.getAttribute('data-tab-group'); const targetId = tab.getAttribute('data-target'); // 切换触发器状态 document.querySelectorAll(`.tab-trigger[data-tab-group="${tabGroup}"]`).forEach(t => t.classList.remove('active')); tab.classList.add('active'); // 切换内容面板 document.querySelectorAll(`.tab-panel[data-tab-group="${tabGroup}"]`).forEach(p => p.style.display = 'none'); const targetPanel = document.getElementById(targetId); if (targetPanel) { targetPanel.style.display = 'block'; } }); }); });