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

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показаны 4 промежуточные версии этого же участника)
Строка 1: Строка 1:
(function () {
(function() {  
var words = {
    if (typeof mw === 'undefined' || !window.document) return;
"властью": "#e74c3c",
   
"ответственность": "#9b59b6",
    function initCollapse() {  
"Процедуры": "#2980b9",
        var headings = document.querySelectorAll('.chem-heading');
"ядерный": "#f1c40f",
        var hi = 0;
"диск": "#e67e22",
        var len = headings.length;
"станции": "#1abc9c",
        for (; hi < len; hi++) {
"ГСБ": "#2c3e50",
            (function(node) {
"увольнение": "#c0392b",
                if (node.getAttribute('data-chem-attached')) return;
"офицера": "#16a085",
                node.setAttribute('data-chem-attached', '1');
"банановая": "#d35400"
                node.style.cursor = 'pointer';
};
                node.addEventListener('click', function() {
 
                    var kind = node.getAttribute('data-kind') || '';  
function colorize(root) {
                    var wrapper = findWrapper(node, kind);
if (!root) return;
                    if (!wrapper) return;  
var elements = root.querySelectorAll("*");
                    var btn = node.querySelector('.collapse-btn');
for (var i = 0; i < elements.length; i++) {
                   
var el = elements[i];
                    if (wrapper.classList.contains('collapsed')) {
if (el.tagName.match(/H[1-6]|TH|TABLE|PRE|CODE/) || el.classList.contains("citizen-section-heading") || el.classList.contains("mw-headline")) continue;
                        wrapper.classList.remove('collapsed');
el.innerHTML = el.innerHTML.replace(/\b(властью|ответственность|Процедуры|ядерный|диск|станции|ГСБ|увольнение|офицера|банановая)\b/g,
                        wrapper.classList.add('expanded');  
function(match) {
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';
return '<span style="color:' + words[match] + '; font-weight:600;">' + match + '</span>';
                        if (btn) btn.textContent = 'свернуть';
});
                        var cleanup = function() {
}
                            wrapper.style.maxHeight = '';  
}
                            wrapper.removeEventListener('transitionend', cleanup);
 
                        };  
var section = document.querySelector("#Ваши_обязанности");
                        wrapper.addEventListener('transitionend', cleanup);
colorize(section);
                    } 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); 
    } 
})();