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

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показана 21 промежуточная версия этого же участника)
Строка 1: Строка 1:
(function() {
(function() {  
    var today = new Date();
     if (typeof mw === 'undefined' || !window.document) return;  
    var month = today.getMonth() + 1;
   
     if (month === 10 || month === 11) {
    function initCollapse() {  
        mw.loader.load('/w/index.php?title=MediaWiki:Test.css&action=raw&ctype=text/css');
        var headings = document.querySelectorAll('.chem-heading');  
 
        var hi = 0;  
        mw.hook('wikipage.content').add(function($content) {
        var len = headings.length;  
            var leaves = document.createElement('div');
        for (; hi < len; hi++) {
            leaves.className = 'halloween-leaves';
            (function(node) {  
            document.body.appendChild(leaves);
                 if (node.getAttribute('data-chem-attached')) return;  
 
                 node.setAttribute('data-chem-attached', '1');  
            for (var i = 0; i < 30; i++) {
                 node.style.cursor = 'pointer';
                 var leaf = document.createElement('span');
                node.addEventListener('click', function() {
                 leaf.className = 'halloween-leaf';
                    var kind = node.getAttribute('data-kind') || '';
                 leaf.innerHTML = ['🍂','🍁','🦇','🕸️'][Math.floor(Math.random()*4)];
                    var wrapper = findWrapper(node, kind);
                leaf.style.left = Math.random()*100+'%';
                    if (!wrapper) return;
                leaf.style.animationDelay = (Math.random()*5)+'s';
                    var btn = node.querySelector('.collapse-btn');
                leaf.style.fontSize = (12+Math.random()*24)+'px';
                   
                leaves.appendChild(leaf);
                    if (wrapper.classList.contains('collapsed')) {
            }
                        wrapper.classList.remove('collapsed');  
 
                        wrapper.classList.add('expanded');  
            var firstHeading = document.getElementById('firstHeading');
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';
            if (firstHeading) {
                        if (btn) btn.textContent = 'свернуть';  
                var pumpkin = document.createElement('span');
                        var cleanup = function() {
                pumpkin.className = 'halloween-pumpkin';
                            wrapper.style.maxHeight = '';
                pumpkin.innerHTML = ' 🎃 ';
                            wrapper.removeEventListener('transitionend', cleanup);
                 firstHeading.appendChild(pumpkin);
                        };  
            }
                        wrapper.addEventListener('transitionend', cleanup);  
 
                    } else {
            var links = document.getElementsByTagName('a');
                        var currentHeight = wrapper.scrollHeight;
            for (var i = 0; i < links.length; i++) {
                        wrapper.style.maxHeight = currentHeight + 'px';  
                links[i].style.transition = 'color 0.3s ease';
                        wrapper.offsetHeight;
                 links[i].onmouseover = function() { this.style.color = '#ffa500'; };
                        wrapper.classList.remove('expanded');
                links[i].onmouseout = function() { this.style.color = ''; };
                        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); 
    } 
})();