Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 128 промежуточных версий этого же участника)
Строка 1: Строка 1:
mw.loader.using('mediawiki.util', function () {
(function() {  
  $(function () {
    if (typeof mw === 'undefined' || !window.document) return;
    var container = document.getElementById('chemistry-recipes');
   
    if (!container) return;
    function initCollapse() {  
 
        var headings = document.querySelectorAll('.chem-heading');  
    var recipes = [
        var hi = 0;  
      {
        var len = headings.length;
        name: 'Зомби-кислота',
        for (; hi < len; hi++) {
        class: 'zombieacid',
            (function(node) {  
        inputs: ['Диловен [1]', 'Аммиак [1]', 'Кровь зомби [2]'],
                if (node.getAttribute('data-chem-attached')) return;
        output: 'Зомби-кислота [3]',
                node.setAttribute('data-chem-attached', '1');
        effects: ['Вызывает мутации и оживление тканей.'],
                node.style.cursor = 'pointer';
        appearance: 'Ядовито-зелёная жидкость.'
                node.addEventListener('click', function() {  
      },
                    var kind = node.getAttribute('data-kind') || '';  
      {
                    var wrapper = findWrapper(node, kind);  
        name: 'Маннитол',
                    if (!wrapper) return;  
        class: 'mannitol',
                    var btn = node.querySelector('.collapse-btn');  
        inputs: ['Водород [1]', 'Сахар [1]', 'Вода [1]'],
                   
        output: 'Маннитол [3]',
                    if (wrapper.classList.contains('collapsed')) {  
        effects: ['Эффективно устраняет повреждения мозга.'],
                        wrapper.classList.remove('collapsed');
        appearance: 'Непрозрачное.'
                        wrapper.classList.add('expanded');  
      }
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';  
    ];
                        if (btn) btn.textContent = 'свернуть';  
 
                        var cleanup = function() {
    function createRecipeCard(recipe) {
                            wrapper.style.maxHeight = '';  
      var card = document.createElement('div');
                            wrapper.removeEventListener('transitionend', cleanup);  
      card.className = 'chem-recipe chem-' + recipe.class;
                        };
 
                        wrapper.addEventListener('transitionend', cleanup);  
      var header = document.createElement('div');
                    } else {
      header.className = 'chem-header';
                        var currentHeight = wrapper.scrollHeight;  
      header.textContent = recipe.name;
                        wrapper.style.maxHeight = currentHeight + 'px';  
      card.appendChild(header);
                        wrapper.offsetHeight;  
 
                        wrapper.classList.remove('expanded');  
      var content = document.createElement('div');
                        wrapper.classList.add('collapsed');  
      content.className = 'chem-content';
                        wrapper.style.maxHeight = '0px';  
 
                        if (btn) btn.textContent = 'развернуть';  
      // Ингредиенты
                    }
      if (recipe.inputs.length) {
                });
        var inList = document.createElement('ul');
            })(headings[hi]);  
        inList.className = 'chem-inputs';
        }  
        for (var i = 0; i < recipe.inputs.length; i++) {
    }
          var li = document.createElement('li');
   
          li.textContent = recipe.inputs[i];
    function findWrapper(node, kind) {  
          inList.appendChild(li);
         var parent = node.parentNode;
        }
        if (!parent) return null;  
        content.appendChild(inList);
         var wrappers = parent.querySelectorAll('.collapsible');  
 
         var wi = 0;  
        // Стрелка + Beaker
        var wlen = wrappers.length;  
        var arrow = document.createElement('div');
        for (; wi < wlen; wi++) {  
        arrow.className = 'chem-arrow';
            if (wrappers[wi].getAttribute('data-kind') === kind) {
        arrow.innerHTML = '<span>↓</span><img src="/images/thumb/4/4f/Beaker.png/32px-Beaker.png" alt="Beaker" />';
                return wrappers[wi];  
        content.appendChild(arrow);
            }
      }
         }  
 
         return null;  
      // Результат
    }  
      if (recipe.output) {
   
        var out = document.createElement('p');
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        out.className = 'chem-output';
        initCollapse();  
        out.textContent = 'Получаем: ' + recipe.output;
     } else {  
        content.appendChild(out);
        document.addEventListener('DOMContentLoaded', initCollapse);  
      }
     }  
 
})();
      // Эффекты
      if (recipe.effects.length) {
         var effectList = document.createElement('ul');
         effectList.className = 'chem-effects';
         for (var j = 0; j < recipe.effects.length; j++) {
          var ef = document.createElement('li');
          ef.textContent = recipe.effects[j];
          effectList.appendChild(ef);
         }
         content.appendChild(document.createElement('hr'));
        content.appendChild(document.createTextNode('Эффекты:'));
        content.appendChild(effectList);
      }
 
      // Внешний вид
      if (recipe.appearance) {
        var ap = document.createElement('p');
        ap.textContent = 'На вид: ' + recipe.appearance;
        content.appendChild(ap);
      }
 
      // Скрытие по клику
      header.addEventListener('click', function () {
        content.style.display = content.style.display === 'none' ? 'block' : 'none';
      });
 
      content.style.display = 'none';
      card.appendChild(content);
      return card;
     }
 
    for (var k = 0; k < recipes.length; k++) {
      container.appendChild(createRecipeCard(recipes[k]));
     }
  });
});

Текущая версия от 13:10, 4 апреля 2026

(function() { 
    if (typeof mw === 'undefined' || !window.document) return; 
    
    function initCollapse() { 
        var headings = document.querySelectorAll('.chem-heading'); 
        var hi = 0; 
        var len = headings.length; 
        for (; hi < len; hi++) { 
            (function(node) { 
                if (node.getAttribute('data-chem-attached')) return; 
                node.setAttribute('data-chem-attached', '1'); 
                node.style.cursor = 'pointer'; 
                node.addEventListener('click', function() { 
                    var kind = node.getAttribute('data-kind') || ''; 
                    var wrapper = findWrapper(node, kind); 
                    if (!wrapper) return; 
                    var btn = node.querySelector('.collapse-btn'); 
                    
                    if (wrapper.classList.contains('collapsed')) { 
                        wrapper.classList.remove('collapsed'); 
                        wrapper.classList.add('expanded'); 
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px'; 
                        if (btn) btn.textContent = 'свернуть'; 
                        var cleanup = function() { 
                            wrapper.style.maxHeight = ''; 
                            wrapper.removeEventListener('transitionend', cleanup); 
                        }; 
                        wrapper.addEventListener('transitionend', cleanup); 
                    } else { 
                        var currentHeight = wrapper.scrollHeight; 
                        wrapper.style.maxHeight = currentHeight + 'px'; 
                        wrapper.offsetHeight; 
                        wrapper.classList.remove('expanded'); 
                        wrapper.classList.add('collapsed'); 
                        wrapper.style.maxHeight = '0px'; 
                        if (btn) btn.textContent = 'развернуть'; 
                    } 
                }); 
            })(headings[hi]); 
        } 
    } 
    
    function findWrapper(node, kind) { 
        var parent = node.parentNode; 
        if (!parent) return null; 
        var wrappers = parent.querySelectorAll('.collapsible'); 
        var wi = 0; 
        var wlen = wrappers.length; 
        for (; wi < wlen; wi++) { 
            if (wrappers[wi].getAttribute('data-kind') === kind) { 
                return wrappers[wi]; 
            } 
        } 
        return null; 
    } 
    
    if (document.readyState === 'complete' || document.readyState === 'interactive') { 
        initCollapse(); 
    } else { 
        document.addEventListener('DOMContentLoaded', initCollapse); 
    } 
})();