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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
$(document).ready(function () {
// Добавляем иконки к элементам рецепта
   // Анимация раскрытия контента
document.querySelectorAll('.recipe-list li').forEach(function(item) {
  $('.collapsible-header').click(function () {
   if (!item.classList.contains('instruction') && item === item.parentElement.lastElementChild) return;
    var content = $(this).next('.collapsible-content');
 
    content.slideToggle(300, function() {
  var icon = document.createElement('img');
      // Анимация появления элементов после раскрытия
  icon.className = 'chem-icon';
      $(this).find('li').each(function (index) {
  icon.src = 'Beaker.png';
        $(this).css('animation-delay', (index * 0.1) + 's');
  item.insertBefore(icon, item.firstChild);
        $(this).addClass('visible');
});
      });
 
// Обновляем обработчик раскрытия с учётом новых элементов
$('.collapsible-header').click(function() {
  var content = $(this).next('.collapsible-content');
  content.slideToggle(300, function() {
    $(this).find('li').each(function(index) {
      $(this).css('animation-delay', index * 0.1 + 's')
            .toggleClass('visible', $(this).is(':visible'));
     });
     });
    $(this).toggleClass('open');
   }).toggleClass('active');
   });
 
  // Устанавливаем цвет границы из data-атрибута
  $('.recipe-card').each(function () {
    var borderColor = $(this).attr('data-border');
    if (borderColor) {
      $(this).css('border-color', borderColor);
    }
  });
});
});
// Добавляем выходной продукт в data-атрибут
(function() {
  var recipes = document.querySelectorAll('.recipe-card');
 
  for (var i = 0; i < recipes.length; i++) {
    var lastItem = recipes[i].querySelector('.recipe-list li:last-child');
    if (lastItem) {
      var outputName = lastItem.textContent.replace(/\s*\[\d+\]$/, '');
      recipes[i].setAttribute('data-output', outputName);
    }
  }
})();

Версия от 20:01, 3 мая 2025

// Добавляем иконки к элементам рецепта
document.querySelectorAll('.recipe-list li').forEach(function(item) {
  if (!item.classList.contains('instruction') && item === item.parentElement.lastElementChild) return;
  
  var icon = document.createElement('img');
  icon.className = 'chem-icon';
  icon.src = 'Beaker.png';
  item.insertBefore(icon, item.firstChild);
});

// Обновляем обработчик раскрытия с учётом новых элементов
$('.collapsible-header').click(function() {
  var content = $(this).next('.collapsible-content');
  content.slideToggle(300, function() {
    $(this).find('li').each(function(index) {
      $(this).css('animation-delay', index * 0.1 + 's')
             .toggleClass('visible', $(this).is(':visible'));
    });
  }).toggleClass('active');
});