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

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 129 промежуточных версий этого же участника)
Строка 1: Строка 1:
body {
(function() {  
  background-color: #121212;
    if (typeof mw === 'undefined' || !window.document) return;  
  color: #e0e0e0;
   
}
    function initCollapse() {  
 
        var headings = document.querySelectorAll('.chem-heading');  
#chemistry-recipes {
        var hi = 0;
  margin-top: 1em;
        var len = headings.length;
}
        for (; hi < len; hi++) {
 
            (function(node) {
/* Общий стиль карточек */
                if (node.getAttribute('data-chem-attached')) return;
.chem-recipe {
                node.setAttribute('data-chem-attached', '1');  
  border-radius: 10px;
                node.style.cursor = 'pointer';  
  margin-bottom: 1em;
                node.addEventListener('click', function() {
  box-shadow: 0 2px 6px rgba(0,0,0,0.6);
                    var kind = node.getAttribute('data-kind') || '';  
  overflow: hidden;
                    var wrapper = findWrapper(node, kind);  
  background-color: #1e1e1e;
                    if (!wrapper) return;  
  color: #e0e0e0;
                    var btn = node.querySelector('.collapse-btn');  
}
                   
 
                    if (wrapper.classList.contains('collapsed')) {  
/* Шапка карточки */
                        wrapper.classList.remove('collapsed');  
.chem-header {
                        wrapper.classList.add('expanded');  
  padding: 0.8em 1em;
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';  
  font-weight: bold;
                        if (btn) btn.textContent = 'свернуть';  
  font-size: 1.2em;
                        var cleanup = function() {
  cursor: pointer;
                            wrapper.style.maxHeight = '';  
  user-select: none;
                            wrapper.removeEventListener('transitionend', cleanup);  
  color: #fff;
                        };
}
                        wrapper.addEventListener('transitionend', cleanup);
 
                    } else {
/* Контент карточки */
                        var currentHeight = wrapper.scrollHeight;
.chem-content {
                        wrapper.style.maxHeight = currentHeight + 'px';  
  padding: 1em;
                        wrapper.offsetHeight;  
  background-color: #262626;
                        wrapper.classList.remove('expanded');  
  display: none;
                        wrapper.classList.add('collapsed');
}
                        wrapper.style.maxHeight = '0px';  
 
                        if (btn) btn.textContent = 'развернуть';  
.chem-content ul {
                    }  
  margin: 0.4em 0 0.8em 1.2em;
                });
  padding-left: 1em;
            })(headings[hi]);
}
        }
 
    }  
.chem-content p {
   
  margin: 0.4em 0;
    function findWrapper(node, kind) {  
}
        var parent = node.parentNode;  
 
        if (!parent) return null;  
.chem-content hr {
        var wrappers = parent.querySelectorAll('.collapsible');
  border: none;
        var wi = 0;  
  border-top: 1px solid #444;
        var wlen = wrappers.length;
  margin: 0.5em 0;
        for (; wi < wlen; wi++) {
}
            if (wrappers[wi].getAttribute('data-kind') === kind) {  
 
                return wrappers[wi];  
/* Индивидуальные цвета */
            }  
.chem-mannitol .chem-header {
        }
  background-color: #6a5acd; /* фиолетовый */
        return null;  
}
    }  
 
   
.chem-chlorine .chem-header {
    if (document.readyState === 'complete' || document.readyState === 'interactive') {  
  background-color: #9acd32; /* жёлто-зелёный */
        initCollapse();  
}
    } else {
 
        document.addEventListener('DOMContentLoaded', initCollapse);  
.chem-fluorine .chem-header {
    }
  background-color: #ffcc00; /* бледно-жёлтый */
})();
  color: #000;
}
 
.chem-iron .chem-header {
  background-color: #b0b0b0; /* стальной серый */
  color: #000;
}

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