跳转到内容

MediaWiki:Common.js:修订间差异

来自SCR公司
无编辑摘要
标签移动版编辑 移动版网页编辑 高级移动版编辑
无编辑摘要
标签移动版编辑 移动版网页编辑 高级移动版编辑
 
(未显示同一用户的1个中间版本)
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
document.addEventListener("DOMContentLoaded", () => {
  const headers = document.querySelectorAll('.scr-collapse-header');


document.addEventListener('DOMContentLoaded', () => {
   headers.forEach(header => {
   document.querySelectorAll('.scr-collapse-header').forEach(header => {
     const content = header.nextElementSibling;
     const content = header.nextElementSibling;
     const textOpen = header.dataset.open;
    const symbol = header.querySelector('.scr-collapse-symbol');
     const textClose = header.dataset.close;
 
     const textOpen = header.getAttribute('data-text-open') || '+ 展开';
     const textClose = header.getAttribute('data-text-close') || '- 收起';
    const defaultState = header.getAttribute('data-default') || 'closed';
 
    if (defaultState === 'open') {
      content.style.maxHeight = content.scrollHeight + "px";
      symbol.textContent = textClose;
    } else {
      content.style.maxHeight = "0";
      symbol.textContent = textOpen;
    }


     header.addEventListener('click', () => {
     header.addEventListener('click', () => {
       const expanded = content.style.maxHeight && content.style.maxHeight !== '0px';
       if (content.style.maxHeight && content.style.maxHeight !== "0px") {
 
         content.style.maxHeight = "0";
      if (expanded) {
         symbol.textContent = textOpen;
         content.style.maxHeight = '0';
         header.textContent = textOpen;
       } else {
       } else {
         content.style.maxHeight = content.scrollHeight + 'px';
         content.style.maxHeight = content.scrollHeight + "px";
         header.textContent = textClose;
         symbol.textContent = textClose;
       }
       }
     });
     });
   });
   });
});
});

2026年1月7日 (三) 01:27的最新版本

document.addEventListener("DOMContentLoaded", () => {
  const headers = document.querySelectorAll('.scr-collapse-header');

  headers.forEach(header => {
    const content = header.nextElementSibling;
    const symbol = header.querySelector('.scr-collapse-symbol');

    const textOpen = header.getAttribute('data-text-open') || '+ 展开';
    const textClose = header.getAttribute('data-text-close') || '- 收起';
    const defaultState = header.getAttribute('data-default') || 'closed';

    if (defaultState === 'open') {
      content.style.maxHeight = content.scrollHeight + "px";
      symbol.textContent = textClose;
    } else {
      content.style.maxHeight = "0";
      symbol.textContent = textOpen;
    }

    header.addEventListener('click', () => {
      if (content.style.maxHeight && content.style.maxHeight !== "0px") {
        content.style.maxHeight = "0";
        symbol.textContent = textOpen;
      } else {
        content.style.maxHeight = content.scrollHeight + "px";
        symbol.textContent = textClose;
      }
    });
  });
});