MediaWiki:Test.js: различия между версиями

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
function toggleSection(element) {
function toggleSection(element) {
   var content = element.nextElementSibling;
   const content = element.nextElementSibling;
   var isExpanded = content.classList.contains('expanded');
   const isExpanded = element.classList.contains('expanded');


   var parentBlock = element.closest('.recipe-block');
   const parentBlock = element.closest('.recipe-block');
   var allSections = parentBlock.querySelectorAll('.section-content');
   const allContents = parentBlock.querySelectorAll('.section-content');
   var allTitles = parentBlock.querySelectorAll('.section-title');
   const allTitles = parentBlock.querySelectorAll('.section-title');


   allSections.forEach(section => section.classList.remove('expanded'));
   allContents.forEach(sec => {
   allTitles.forEach(title => title.classList.remove('expanded'));
    sec.classList.remove('expanded');
    sec.style.display = 'none';
  });
 
   allTitles.forEach(t => t.classList.remove('expanded'));


   if (!isExpanded) {
   if (!isExpanded) {
    element.classList.add('expanded');
     content.classList.add('expanded');
     content.classList.add('expanded');
     element.classList.add('expanded');
     content.style.display = 'block';
   }
   }
}
}


document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', function () {
   var sections = document.querySelectorAll('.section-content');
   const allSections = document.querySelectorAll('.section-content');
   sections.forEach(section => section.style.display = 'none');
   allSections.forEach(section => section.style.display = 'none');
});
});

Версия от 02:58, 17 июня 2025

function toggleSection(element) {
  const content = element.nextElementSibling;
  const isExpanded = element.classList.contains('expanded');

  const parentBlock = element.closest('.recipe-block');
  const allContents = parentBlock.querySelectorAll('.section-content');
  const allTitles = parentBlock.querySelectorAll('.section-title');

  allContents.forEach(sec => {
    sec.classList.remove('expanded');
    sec.style.display = 'none';
  });

  allTitles.forEach(t => t.classList.remove('expanded'));

  if (!isExpanded) {
    element.classList.add('expanded');
    content.classList.add('expanded');
    content.style.display = 'block';
  }
}

document.addEventListener('DOMContentLoaded', function () {
  const allSections = document.querySelectorAll('.section-content');
  allSections.forEach(section => section.style.display = 'none');
});