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

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показаны 174 промежуточные версии этого же участника)
Строка 1: Строка 1:
if (mw.config.get('wgPageName') === 'Тест') {
(function() {
    window.addEventListener('load', function () {
    if (typeof mw === 'undefined' || !window.document) return;
        var banner = document.createElement('div');
   
        banner.id = 'info-banner';
    function initCollapse() {
        banner.innerHTML = 'Внимание: информация на этой странице может измениться!';
        var headings = document.querySelectorAll('.chem-heading');
        document.body.appendChild(banner);
        var hi = 0;
       
        var len = headings.length;
        var style = document.createElement('style');
        for (; hi < len; hi++) {
        style.innerHTML =  
            (function(node) {
            '#info-banner {' +
                if (node.getAttribute('data-chem-attached')) return;
            'position: fixed;' +
                node.setAttribute('data-chem-attached', '1');
            'top: 0;' +
                node.style.cursor = 'pointer';
            'left: 0;' +
                node.addEventListener('click', function() {  
            'width: 100%;' +
                    var kind = node.getAttribute('data-kind') || '';
            'background-color: #f0ad4e;' +
                    var wrapper = findWrapper(node, kind);  
            'color: #fff;' +
                    if (!wrapper) return;
            'text-align: center;' +
                    var btn = node.querySelector('.collapse-btn');  
            'padding: 10px 0;' +
                   
            'font-size: 16px;' +
                    if (wrapper.classList.contains('collapsed')) {
            'z-index: 9999;' +
                        wrapper.classList.remove('collapsed');  
            'font-weight: bold;' +
                        wrapper.classList.add('expanded');  
             '}';
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';
 
                        if (btn) btn.textContent = 'свернуть';
         document.head.appendChild(style);
                        var cleanup = function() {
 
                            wrapper.style.maxHeight = '';
         banner.addEventListener('click', function () {
                            wrapper.removeEventListener('transitionend', cleanup);  
             banner.style.display = 'none';
                        };  
         });
                        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);  
    }
})();

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