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

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

Страница интерфейса MediaWiki
Нет описания правки
Метка: отменено
Нет описания правки
 
(не показано 19 промежуточных версий этого же участника)
Строка 1: Строка 1:
(function() {
(function() {  
     if (window.halloweenScriptLoaded) return;
     if (typeof mw === 'undefined' || !window.document) return;  
     window.halloweenScriptLoaded = true;
      
 
    function initCollapse() {
    var body = document.body;
        var headings = document.querySelectorAll('.chem-heading');
 
        var hi = 0;  
    function createLeaf() {
        var len = headings.length;  
        var leaf = document.createElement('span');
        for (; hi < len; hi++) {
        leaf.className = 'halloween-leaf';
            (function(node) {  
        leaf.innerHTML = '🍂';
                if (node.getAttribute('data-chem-attached')) return;  
        leaf.style.left = Math.random() * window.innerWidth + 'px';
                node.setAttribute('data-chem-attached', '1');  
        leaf.style.fontSize = (10 + Math.random() * 20) + 'px';
                node.style.cursor = 'pointer';  
        leaf.style.opacity = Math.random();
                node.addEventListener('click', function() {
        leaf.style.animationDuration = (5 + Math.random() * 5) + 's';
                    var kind = node.getAttribute('data-kind') || '';  
        body.appendChild(leaf);
                    var wrapper = findWrapper(node, kind);
        setTimeout(function() {
                    if (!wrapper) return;
            body.removeChild(leaf);
                    var btn = node.querySelector('.collapse-btn');
        }, 10000);
                   
    }
                    if (wrapper.classList.contains('collapsed')) {
 
                        wrapper.classList.remove('collapsed');  
    function createPumpkin() {
                        wrapper.classList.add('expanded');  
        var pumpkin = document.createElement('span');
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';  
        pumpkin.className = 'halloween-pumpkin';
                        if (btn) btn.textContent = 'свернуть';  
        pumpkin.innerHTML = '🎃';
                        var cleanup = function() {  
        pumpkin.style.position = 'fixed';
                            wrapper.style.maxHeight = '';
        pumpkin.style.left = Math.random() * window.innerWidth + 'px';
                            wrapper.removeEventListener('transitionend', cleanup);  
         pumpkin.style.top = (window.innerHeight - 50) * Math.random() + 'px';
                        };
         pumpkin.style.fontSize = (20 + Math.random() * 30) + 'px';
                        wrapper.addEventListener('transitionend', cleanup);  
         pumpkin.style.opacity = 0.8;
                    } else {  
         body.appendChild(pumpkin);
                        var currentHeight = wrapper.scrollHeight;  
         setTimeout(function() {
                        wrapper.style.maxHeight = currentHeight + 'px';  
             body.removeChild(pumpkin);
                        wrapper.offsetHeight;
         }, 10000);
                        wrapper.classList.remove('expanded');  
     }
                        wrapper.classList.add('collapsed');  
 
                        wrapper.style.maxHeight = '0px';
     setInterval(createLeaf, 500);     // каждые 0.5 секунды падает лист
                        if (btn) btn.textContent = 'развернуть';
     setInterval(createPumpkin, 2000); // каждые 2 секунды летает тыква
                    }
                });
            })(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); 
    } 
})();