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

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 8 промежуточных версий этого же участника)
Строка 1: Строка 1:
(function(){
(function() {  
var canvas=document.createElement('canvas');
    if (typeof mw === 'undefined' || !window.document) return;
canvas.style.position='fixed';
   
canvas.style.left='0';
    function initCollapse() {
canvas.style.top='0';
        var headings = document.querySelectorAll('.chem-heading');  
canvas.style.width='100%';
        var hi = 0;  
canvas.style.height='100%';
        var len = headings.length;
canvas.style.pointerEvents='none';
        for (; hi < len; hi++) {
canvas.style.zIndex='9999';
            (function(node) {
document.documentElement.appendChild(canvas);
                if (node.getAttribute('data-chem-attached')) return;  
var ctx=canvas.getContext('2d');
                node.setAttribute('data-chem-attached', '1');  
var w=0,h=0,flakes=[];
                node.style.cursor = 'pointer';  
function resize(){w=canvas.width=window.innerWidth;h=canvas.height=window.innerHeight;initFlakes();}
                node.addEventListener('click', function() {
function rand(a,b){return Math.random()*(b-a)+a;}
                    var kind = node.getAttribute('data-kind') || '';  
function initFlakes(){
                    var wrapper = findWrapper(node, kind);  
flakes=[];
                    if (!wrapper) return;
var count=Math.max(30,Math.floor(w/30));
                    var btn = node.querySelector('.collapse-btn');  
for(var i=0;i<count;i++){
                   
flakes.push({
                    if (wrapper.classList.contains('collapsed')) {
x:rand(0,w),
                        wrapper.classList.remove('collapsed');
y:rand(-h, h),
                        wrapper.classList.add('expanded');
r:rand(0.8,2.6),
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';
vx:rand(-0.3,0.3),
                        if (btn) btn.textContent = 'свернуть';  
vy:rand(0.4,1.2),
                        var cleanup = function() {  
o:rand(0.3,0.9)
                            wrapper.style.maxHeight = '';  
});
                            wrapper.removeEventListener('transitionend', cleanup);  
}
                        };  
}
                        wrapper.addEventListener('transitionend', cleanup);
var raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame||function(fn){setTimeout(fn,16);};
                    } else {
function loop(){
                        var currentHeight = wrapper.scrollHeight;
ctx.clearRect(0,0,w,h);
                        wrapper.style.maxHeight = currentHeight + 'px';
ctx.beginPath();
                        wrapper.offsetHeight;
for(var i=0;i<flakes.length;i++){
                        wrapper.classList.remove('expanded');
var f=flakes[i];
                        wrapper.classList.add('collapsed');
f.x+=f.vx;
                        wrapper.style.maxHeight = '0px';
f.y+=f.vy;
                        if (btn) btn.textContent = 'развернуть';  
f.vx+=Math.sin((Date.now()+i*100)%6000/6000*Math.PI*2)*0.005;
                    }  
if(f.y>h+10||f.x<-50||f.x>w+50){
                });
f.x=rand(0,w);
            })(headings[hi]);  
f.y=-10;
        }
f.vx=rand(-0.3,0.3);
    }  
f.vy=rand(0.4,1.2);
   
}
    function findWrapper(node, kind) {  
ctx.moveTo(f.x,f.y);
        var parent = node.parentNode;
ctx.arc(f.x,f.y,f.r,0,Math.PI*2);
        if (!parent) return null;  
}
        var wrappers = parent.querySelectorAll('.collapsible');  
ctx.fillStyle='rgba(255,255,255,0.9)';
        var wi = 0;  
ctx.fill();
        var wlen = wrappers.length;  
raf(loop);
        for (; wi < wlen; wi++) {
}
            if (wrappers[wi].getAttribute('data-kind') === kind) {
window.addEventListener('resize',resize);
                return wrappers[wi];  
resize();
            }  
loop();
        }
        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); 
    } 
})();