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

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 126 промежуточных версий этого же участника)
Строка 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);  
 
                    if (!wrapper) return;  
     function createRecipeCard(recipe) {
                    var btn = node.querySelector('.collapse-btn');  
      var card = document.createElement('div');
                   
      card.className = 'chem-recipe chem-' + recipe.class;
                    if (wrapper.classList.contains('collapsed')) {
 
                        wrapper.classList.remove('collapsed');  
      var header = document.createElement('div');
                        wrapper.classList.add('expanded');  
      header.className = 'chem-header';
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';  
      header.textContent = recipe.name;
                        if (btn) btn.textContent = 'свернуть';  
      card.appendChild(header);
                        var cleanup = function() {
 
                            wrapper.style.maxHeight = '';  
      var content = document.createElement('div');
                            wrapper.removeEventListener('transitionend', cleanup);  
      content.className = 'chem-content';
                        };
 
                        wrapper.addEventListener('transitionend', cleanup);  
      var mixRow = document.createElement('div');
                    } else {  
      mixRow.className = 'chem-mixrow';
                        var currentHeight = wrapper.scrollHeight;  
 
                        wrapper.style.maxHeight = currentHeight + 'px';  
      var inputCol = document.createElement('div');
                        wrapper.offsetHeight;
      inputCol.className = 'chem-column inputs';
                        wrapper.classList.remove('expanded');
      recipe.inputs.forEach(function (input) {
                        wrapper.classList.add('collapsed');  
        var p = document.createElement('p');
                        wrapper.style.maxHeight = '0px';  
        p.textContent = input;
                        if (btn) btn.textContent = 'развернуть';  
        inputCol.appendChild(p);
                    }
      });
                });  
 
            })(headings[hi]);  
      var beakerCol = document.createElement('div');
         }
      beakerCol.className = 'chem-column beaker';
    }
 
   
      // Вставка изображения пробирки через ParserFunction
    function findWrapper(node, kind) {
      var beakerFrame = document.createElement('span');
         var parent = node.parentNode;  
      beakerFrame.innerHTML = mw.html.escape('[[Файл:Beaker.png|link=|64px]]');
        if (!parent) return null;
      beakerCol.appendChild(beakerFrame);
         var wrappers = parent.querySelectorAll('.collapsible');  
 
         var wi = 0;
      var outputCol = document.createElement('div');
        var wlen = wrappers.length;  
      outputCol.className = 'chem-column output';
         for (; wi < wlen; wi++) {
      outputCol.textContent = recipe.output;
            if (wrappers[wi].getAttribute('data-kind') === kind) {
 
                return wrappers[wi];  
      mixRow.appendChild(inputCol);
            }  
      mixRow.appendChild(beakerCol);
        }
      mixRow.appendChild(outputCol);
        return null;  
 
     }  
      content.appendChild(mixRow);
   
 
     if (document.readyState === 'complete' || document.readyState === 'interactive') {  
      if (recipe.effects.length) {
        initCollapse();  
        var effectList = document.createElement('ul');
     } else {
        effectList.className = 'chem-effects';
        document.addEventListener('DOMContentLoaded', initCollapse);  
        recipe.effects.forEach(function (eff) {
    }  
          var li = document.createElement('li');
})();
          li.textContent = eff;
          effectList.appendChild(li);
        });
        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;
     }
 
     recipes.forEach(function (r) {
      container.appendChild(createRecipeCard(r));
     });
 
    // Преобразуем вики-разметку в HTML
    mw.hook('wikipage.content').fire(container);
  });
});

Текущая версия от 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); 
    } 
})();