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

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 130 промежуточных версий этого же участника)
Строка 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++) {  
        inputs: ['Водород [1]', 'Сахар [1]', 'Вода [1]'],
            (function(node) {  
        output: 'Маннитол [3]',
                if (node.getAttribute('data-chem-attached')) return;
        effects: ['Эффективно устраняет повреждения мозга.'],
                node.setAttribute('data-chem-attached', '1');
         appearance: 'Непрозрачное'
                node.style.cursor = 'pointer';
      },
                node.addEventListener('click', function() {  
      {
                    var kind = node.getAttribute('data-kind') || '';  
        name: 'Хлор',
                    var wrapper = findWrapper(node, kind);  
        inputs: ['Столовая соль [2]'],
                    if (!wrapper) return;  
        output: ['Натрий [1]', 'Хлор [1]'],
                    var btn = node.querySelector('.collapse-btn');  
        effects: ['Poison (0.5 ед/сек)', 'Наносит 4 Poison за единицу.'],
                   
        appearance: 'Жёлто-зелёный газ, токсичный для человека. Газообразное'
                    if (wrapper.classList.contains('collapsed')) {  
      },
                        wrapper.classList.remove('collapsed');  
      {
                        wrapper.classList.add('expanded');  
        name: 'Фтор',
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';  
        inputs: [],
                        if (btn) btn.textContent = 'свернуть';  
        output: null,
                        var cleanup = function() {
        effects: ['Poison (0.5 ед/сек)', 'Наносит 1 Caustic и 1 Poison за единицу.'],
                            wrapper.style.maxHeight = '';  
        appearance: 'Высокотоксичный бледно-жёлтый газ. Чрезвычайно реактивный. Газообразное'
                            wrapper.removeEventListener('transitionend', cleanup);  
      },
                        };
      {
                        wrapper.addEventListener('transitionend', cleanup);  
        name: 'Железо',
                    } else {  
        inputs: ['Кровь [20]', 'Вода [11]', 'Сахар [2]', 'Диоксид углерода [3]'],
                        var currentHeight = wrapper.scrollHeight;  
        output: ['Железо [0.5]', 'Протеины [4]'],
                        wrapper.style.maxHeight = currentHeight + 'px';
        effects: [
                        wrapper.offsetHeight;
          'Medicine (0.5 ед/сек)',
                        wrapper.classList.remove('expanded');  
          'Poison (0.1 ед/сек)',
                        wrapper.classList.add('collapsed');  
          'Наносит 1 Poison за единицу при метаболизме Arachnid органами.'
                        wrapper.style.maxHeight = '0px';  
        ],
                        if (btn) btn.textContent = 'развернуть';
        appearance: 'Серебристо-серый металл. Металлическое'
                    }
      }
                });  
    ];
            })(headings[hi]);  
 
         }  
    function createRecipeCard(recipe) {
    }
      var card = document.createElement('div');
   
      card.className = 'chem-recipe';
    function findWrapper(node, kind) {
 
         var parent = node.parentNode;  
      var header = document.createElement('div');
        if (!parent) return null;
      header.className = 'chem-header';
         var wrappers = parent.querySelectorAll('.collapsible');  
      header.textContent = recipe.name;
         var wi = 0;  
      card.appendChild(header);
         var wlen = wrappers.length;  
 
        for (; wi < wlen; wi++) {
      var content = document.createElement('div');
            if (wrappers[wi].getAttribute('data-kind') === kind) {
      content.className = 'chem-content';
                return wrappers[wi];  
 
            }  
      if (recipe.inputs.length) {
        }
        var inList = document.createElement('ul');
        return null;  
        for (var i = 0; i < recipe.inputs.length; i++) {
     }  
          var li = document.createElement('li');
   
          li.textContent = recipe.inputs[i];
     if (document.readyState === 'complete' || document.readyState === 'interactive') {  
          inList.appendChild(li);
        initCollapse();  
        }
     } else {
        content.appendChild(document.createElement('hr'));
        document.addEventListener('DOMContentLoaded', initCollapse);  
        content.appendChild(document.createTextNode('Рецепт:'));
    }  
        content.appendChild(inList);
})();
      }
 
      if (recipe.output) {
        var out = document.createElement('p');
        out.textContent = 'Выход: ' + (typeof recipe.output === 'string' ? recipe.output : recipe.output.join(', '));
        content.appendChild(out);
      }
 
      if (recipe.effects.length) {
        var effectList = document.createElement('ul');
        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.createTextNode('Эффекты:'));
         content.appendChild(effectList);
      }
 
      if (recipe.appearance) {
         var ap = document.createElement('p');
         ap.textContent = 'На вид: ' + recipe.appearance;
         content.appendChild(ap);
      }
 
      card.appendChild(content);
 
      // Скрытие/открытие по клику
      header.addEventListener('click', function () {
        content.style.display = content.style.display === 'none' ? 'block' : 'none';
      });
 
      content.style.display = 'none';
 
      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); 
    } 
})();