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

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 167 промежуточных версий этого же участника)
Строка 1: Строка 1:
mw.util.addCSS(`
(function() {
.nav-container {
    if (typeof mw === 'undefined' || !window.document) return;
     display: flex;
      
     flex-wrap: wrap;
     function initCollapse() {
    gap: 0.7em;
        var headings = document.querySelectorAll('.chem-heading');  
    margin: 2em;
        var hi = 0;
    justify-content: space-between;
        var len = headings.length;  
}
        for (; hi < len; hi++) {
 
            (function(node) {
.nav-button {
                if (node.getAttribute('data-chem-attached')) return;  
    flex: 1 1 19.55em;
                node.setAttribute('data-chem-attached', '1');
    min-width: 280px;
                node.style.cursor = 'pointer';
    border: 2px solid #000;
                node.addEventListener('click', function() {  
    background: #f8f9fa;
                    var kind = node.getAttribute('data-kind') || '';
    display: flex;
                    var wrapper = findWrapper(node, kind);
    align-items: center;
                    if (!wrapper) return;  
    justify-content: space-between;
                    var btn = node.querySelector('.collapse-btn');
    padding: 12px;
                   
    transition: background 0.3s;
                    if (wrapper.classList.contains('collapsed')) {
}
                        wrapper.classList.remove('collapsed');  
 
                        wrapper.classList.add('expanded');  
.nav-button:hover {
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';  
    background: #e9ecef;
                        if (btn) btn.textContent = 'свернуть';  
}
                        var cleanup = function() {
 
                            wrapper.style.maxHeight = '';  
.nav-button a {
                            wrapper.removeEventListener('transitionend', cleanup);  
     color: #000;
                        };  
     font-size: 30px;
                        wrapper.addEventListener('transitionend', cleanup);  
     text-decoration: none;
                    } else {
    order: 1;
                        var currentHeight = wrapper.scrollHeight;
    flex-grow: 1;
                        wrapper.style.maxHeight = currentHeight + 'px';
    padding-right: 15px;
                        wrapper.offsetHeight;
}
                        wrapper.classList.remove('expanded');
 
                        wrapper.classList.add('collapsed');
.nav-button img {
                        wrapper.style.maxHeight = '0px';
     width: 64px;
                        if (btn) btn.textContent = 'развернуть';  
     height: 64px;
                    }
     order: 2;
                });
     object-fit: contain;
            })(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);  
    }  
})();

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