跳转到内容

MediaWiki:Common.js:修订间差异

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


     header.setAttribute('aria-expanded', String(!expanded));
     const textOpen = header.getAttribute('data-text-open') || '+ 展开';
     content.hidden = expanded;
    const textClose = header.getAttribute('data-text-close') || '- 收起';
     const defaultState = header.getAttribute('data-default') || 'closed';


     textNode.textContent = expanded
     if (defaultState === 'open') {
       ? textNode.dataset.open
       content.style.maxHeight = content.scrollHeight + "px";
       : textNode.dataset.close;
       symbol.textContent = textClose;
  }
    } else {
 
      content.style.maxHeight = "0";
  document.addEventListener('click', function (e) {
      symbol.textContent = textOpen;
    const header = e.target.closest('.scr-collapse-header');
     }
    if (!header) return;
     toggleCollapse(header);
  });


  document.addEventListener('keydown', function (e) {
    header.addEventListener('click', () => {
    if (e.key !== 'Enter' && e.key !== ' ') return;
      if (content.style.maxHeight && content.style.maxHeight !== "0px") {
    const header = e.target.closest('.scr-collapse-header');
        content.style.maxHeight = "0";
    if (!header) return;
        symbol.textContent = textOpen;
    e.preventDefault();
      } else {
     toggleCollapse(header);
        content.style.maxHeight = content.scrollHeight + "px";
        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;
      }
    });
  });
});