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

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

Страница интерфейса MediaWiki
Нет описания правки
Метка: отменено
Нет описания правки
 
(не показана 51 промежуточная версия этого же участника)
Строка 1: Строка 1:
$(function() {
(function() {  
  var btn = $('<div>▲ Наверх</div>').css({
    if (typeof mw === 'undefined' || !window.document) return;
     position:'fixed', bottom:'20px', right:'20px',
      
     padding:'5px 10px', background:'#444', color:'#fff',
     function initCollapse() {
    cursor:'pointer', borderRadius:'5px', zIndex:9999
        var headings = document.querySelectorAll('.chem-heading');  
  }).appendTo('body');
        var hi = 0;
 
        var len = headings.length;
  var menu = $('<div></div>').css({
        for (; hi < len; hi++) {
    position:'fixed', bottom:'60px', right:'20px',
            (function(node) {  
    maxHeight:'300px', overflow:'auto',
                if (node.getAttribute('data-chem-attached')) return;
    padding:'5px 10px', background:'#fff', border:'1px solid #444',
                node.setAttribute('data-chem-attached', '1');
    borderRadius:'5px', display:'none', zIndex:9999
                node.style.cursor = 'pointer';
  }).appendTo('body');
                node.addEventListener('click', function() {
 
                    var kind = node.getAttribute('data-kind') || '';
  $('h1, h2, h3').each(function() {
                    var wrapper = findWrapper(node, kind);
    var id = $(this).attr('id');
                    if (!wrapper) return;
    if (!id) {
                    var btn = node.querySelector('.collapse-btn');  
      id = 'hdr-' + Math.random().toString(36).substr(2,5);
                   
      $(this).attr('id', id);
                    if (wrapper.classList.contains('collapsed')) {  
    }
                        wrapper.classList.remove('collapsed');
    var link = $('<div>'+$(this).text()+'</div>').css({
                        wrapper.classList.add('expanded');  
      cursor:'pointer', padding:'2px 0'
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';
    }).appendTo(menu);
                        if (btn) btn.textContent = 'свернуть';
     link.click(function() {
                        var cleanup = function() {
      $('html, body').animate({scrollTop:$('#'+id).offset().top}, 500);
                            wrapper.style.maxHeight = '';
      menu.hide();
                            wrapper.removeEventListener('transitionend', cleanup);  
    });
                        };
  });
                        wrapper.addEventListener('transitionend', cleanup);  
 
                    } else {
  btn.click(function() {
                        var currentHeight = wrapper.scrollHeight;
    menu.toggle();
                        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); 
    } 
})();