跳转到内容

MediaWiki:Common.js:修订间差异

来自SCR公司
无编辑摘要
标签移动版编辑 移动版网页编辑 高级移动版编辑
无编辑摘要
标签移动版编辑 移动版网页编辑 高级移动版编辑
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
(function () {
 
   function toggleCollapse(header) {
document.addEventListener('DOMContentLoaded', () => {
   document.querySelectorAll('.scr-collapse-header').forEach(header => {
     const content = header.nextElementSibling;
     const content = header.nextElementSibling;
     const textNode = header.querySelector('.scr-collapse-text');
     const textOpen = header.dataset.open;
     const expanded = header.getAttribute('aria-expanded') === 'true';
     const textClose = header.dataset.close;
 
    header.setAttribute('aria-expanded', String(!expanded));
    content.hidden = expanded;
 
    textNode.textContent = expanded
      ? textNode.dataset.open
      : textNode.dataset.close;
  }


  document.addEventListener('click', function (e) {
    header.addEventListener('click', () => {
    const header = e.target.closest('.scr-collapse-header');
      const expanded = content.style.maxHeight && content.style.maxHeight !== '0px';
    if (!header) return;
    toggleCollapse(header);
  });


  document.addEventListener('keydown', function (e) {
      if (expanded) {
    if (e.key !== 'Enter' && e.key !== ' ') return;
        content.style.maxHeight = '0';
    const header = e.target.closest('.scr-collapse-header');
        header.textContent = textOpen;
    if (!header) return;
      } else {
    e.preventDefault();
        content.style.maxHeight = content.scrollHeight + 'px';
     toggleCollapse(header);
        header.textContent = textClose;
      }
     });
   });
   });
})();
});

2026年1月7日 (三) 01:07的版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */

document.addEventListener('DOMContentLoaded', () => {
  document.querySelectorAll('.scr-collapse-header').forEach(header => {
    const content = header.nextElementSibling;
    const textOpen = header.dataset.open;
    const textClose = header.dataset.close;

    header.addEventListener('click', () => {
      const expanded = content.style.maxHeight && content.style.maxHeight !== '0px';

      if (expanded) {
        content.style.maxHeight = '0';
        header.textContent = textOpen;
      } else {
        content.style.maxHeight = content.scrollHeight + 'px';
        header.textContent = textClose;
      }
    });
  });
});