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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
Строка 2: Строка 2:
   var content = element.nextElementSibling;
   var content = element.nextElementSibling;
   var isExpanded = content.classList.contains('expanded');
   var isExpanded = content.classList.contains('expanded');
 
 
   var parentBlock = element.closest('.recipe-block');
   var parentBlock = element.closest('.recipe-block');
   var allSections = parentBlock.querySelectorAll('.section-content');
   var allSections = parentBlock.querySelectorAll('.section-content');
    
   var allTitles = parentBlock.querySelectorAll('.section-title');
  for (var i = 0; i < allSections.length; i++) {
 
    allSections[i].classList.remove('expanded');
  allSections.forEach(section => section.classList.remove('expanded'));
   }
   allTitles.forEach(title => title.classList.remove('expanded'));
 
 
  element.classList.toggle('expanded');
 
   if (!isExpanded) {
   if (!isExpanded) {
     content.classList.add('expanded');
     content.classList.add('expanded');
    element.classList.add('expanded');
   }
   }
}
}


document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('DOMContentLoaded', function () {
   var sections = document.querySelectorAll('.section-content');
   var sections = document.querySelectorAll('.section-content');
   for (var i = 0; i < sections.length; i++) {
   sections.forEach(section => section.style.display = 'none');
    sections[i].style.display = 'none';
  }
});
});

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

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

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

  allSections.forEach(section => section.classList.remove('expanded'));
  allTitles.forEach(title => title.classList.remove('expanded'));

  if (!isExpanded) {
    content.classList.add('expanded');
    element.classList.add('expanded');
  }
}

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