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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 137 промежуточных версий 2 участников)
Строка 1: Строка 1:
/*Подгрузка внешних css js*/
mw.loader.using('mediawiki.util', function () {
    var files = mw.util.getParamValue('use'),
        userName = mw.config.get('wgUserName') || '', // Обрабатываем null
        FileRE = new RegExp('^(?:MediaWiki:|User:' + mw.util.escapeRegExp(userName) + '/)?[^&<>=%#]*\\.(js|css)$'),
        path = mw.config.get('wgServer').replace(/^http:/, 'https:') + mw.config.get('wgScript') + '?action=raw&ctype=text/';


     if (!files) return;
/* Аудиоплееры */
(function(){
    var players = document.getElementsByClassName('audio-player');
    for(var i=0;i<players.length;i++){
        (function(p){
            var src = p.getAttribute('data-src');
            if(src){
                var audio = document.createElement('audio');
                audio.setAttribute('controls','controls');
                audio.setAttribute('preload','none');
                var source = document.createElement('source');
                source.setAttribute('src',src);
                source.setAttribute('type','audio/mpeg');
                audio.appendChild(source);
                p.appendChild(audio);
            }
        })(players[i]);
    }
})();
 
/* Подгрузка внешних CSS/JS */
(function(){
    if(typeof mw === 'undefined') return;
 
    function getFilesFromUrl(param){
        if(!param) return [];
        return param.split('|').map(function(file){ return file.trim(); });
    }
 
    function getBaseUrl(){
        var server = mw.config.get('wgServer').replace(/^http:/,'https:');
        var script = mw.config.get('wgScript');
        return server + script + '?action=raw&ctype=text/';
    }
 
     function isValidExtension(ext){ return ext === 'js' || ext === 'css'; }
 
    function getFileUrl(file){
        var prefix = file.indexOf('MediaWiki:') === 0 ? 'MediaWiki:' : 'User:' + (mw.config.get('wgUserName') || '') + '/';
        var fullName = file.indexOf(':') > -1 ? file : prefix + file;
        var ext = file.split('.').pop().toLowerCase();
        if(!isValidExtension(ext)){
            console.error('Недопустимое расширение файла:', file);
            return null;
        }
        var timestamp = new Date().getTime();
        return getBaseUrl() + (ext==='js' ? 'javascript' : 'css') + '&title=' + encodeURIComponent(fullName) + '&_=' + timestamp;
    }


     $.each(files.split('|'), function (k, v) {
     function loadFiles(files){
         var file = $.trim(v), match = FileRE.exec(file);
         for(var i=0;i<files.length;i++){
        if (match) {
            var url = getFileUrl(files[i]);
            switch (match[1]) {
            if(url){
                case 'js':
                var ext = files[i].split('.').pop().toLowerCase();
                    mw.loader.load(path + 'javascript&title=' + encodeURIComponent(file), 'text/javascript');
                 mw.loader.load(url,'text/' + (ext==='js' ? 'javascript' : 'css'));
                    break;
                 case 'css':
                    mw.loader.load(path + 'css&title=' + encodeURIComponent(file), 'text/css');
                    break;
             }
             }
         }
         }
    }
    mw.loader.using('mediawiki.util', function(){
        var params = mw.util.getParamValue('use');
        var files = getFilesFromUrl(params);
        loadFiles(files);
     });
     });
});  
})();


/* Логотипы сайта */
(function(){
    function createLogo(url,imgSrc,title){
        var container = document.createElement('div'),
            link = document.createElement('a'),
            img = document.createElement('img');
        link.className = 'mw-logo citizen-header__button';
        link.href = mw.util.getUrl(url);
        link.title = title;


        img.className = 'mw-logo-icon';
        img.src = imgSrc;
        img.alt = '';
        img.setAttribute('aria-hidden','true');
        img.width = 32;
        img.height = 32;


/*Блок временно*/
         link.appendChild(img);
if (mw.config.get('wgPageName') === 'Лордзос') {
         container.appendChild(link);
    window.addEventListener('load', function () {
         return container;
         var banner = document.createElement('div');
    }
         banner.id = 'info-banner';
        banner.innerHTML = 'Внимание: информация на этой странице может измениться!';
        document.body.appendChild(banner);
          
        var style = document.createElement('style');
        style.innerHTML =
            '#info-banner {' +
            'position: fixed;' +
            'top: 0;' +
            'left: 0;' +
            'width: 100%;' +
            'background-color: #343a40;' +  /* Темный фон */
            'color: #f8f9fa;' +  /* Светлый текст */
            'text-align: center;' +
            'padding: 10px 0;' +
            'font-size: 16px;' +
            'z-index: 9999;' +
            'font-weight: bold;' +
            'cursor: pointer;' +
            '}';


         document.head.appendChild(style);
    var logoContainer = document.querySelector('.citizen-header__logo');
    if(logoContainer){
         while(logoContainer.firstChild) logoContainer.removeChild(logoContainer.firstChild);


         banner.addEventListener('click', function () {
         var logo1 = createLogo('Заглавная_страница', mw.config.get('wgScriptPath') + '/resources/assets/logo.png', 'Перейти на заглавную страницу');
             banner.style.display = 'none';
        var logo2 = createLogo('Marine_Corps', mw.config.get('wgScriptPath') + '/images/0/0d/CMlog.png', 'Перейти на CM');
         });
 
        logoContainer.appendChild(logo1);
        logoContainer.appendChild(logo2);
    }
})();
 
/* Перенос page-info и цвет заголовков */
(function(){
    var footerPlaces = document.getElementById('footer-places');
    var pageInfo = document.querySelector('.page-info');
    if(footerPlaces && pageInfo){
        footerPlaces.insertAdjacentElement('afterend', pageInfo.cloneNode(true));
        pageInfo.parentNode.removeChild(pageInfo);
    }
 
    var headerColorElement = document.querySelector('.headerColor');
    if(headerColorElement){
        var content = headerColorElement.textContent.split('|');
        if(content.length === 2){
            var headers = document.querySelectorAll('.citizen-section-heading, .citizen-section-heading--collapsed');
             for(var hi=0; hi<headers.length; hi++){
                var header = headers[hi],
                    indicator = header.querySelector('.citizen-section-indicator'),
                    headline = header.querySelector('.mw-headline');
                if(!indicator || !headline) continue;
                if(header.classList.contains('citizen-section-heading--collapsed')){
                    indicator.style.cssText = 'background: black; box-shadow: unset;';
                } else {
                    indicator.style.cssText = 'background: ' + content[1] + '; box-shadow: 0 0 20px 0px ' + content[1] + 'cc;';
                    headline.style.cssText = 'border-image: linear-gradient(to right top,' + content[0] + ', black); border-image-slice:1;';
                }
            }
        }
    }
})();
 
/* Sidebar для ролей */
(function(){
    var jobsContainer = document.querySelector('.JobsTableContainer');
    if(jobsContainer && jobsContainer.innerHTML.trim()){
        var bodyContent = document.getElementById('bodyContent');
        if(bodyContent){
            bodyContent.insertAdjacentHTML('beforebegin', jobsContainer.innerHTML);
            var jobTable = document.getElementById('IdJobsTableContainer1');
            if(jobTable) jobTable.id = 'IdJobsTableContainer2';
        }
    }
})();
 
/* Хронология */
(function(){
    if(!window.jQuery) return;
    jQuery(function($){
        $('.timeline-header').on('click', function(){
            $(this).next('.timeline-content').slideToggle();
         }).trigger('click');
     });
     });
}
})();


/* Галерея */
(function(){
    var root = document.getElementById('ss-art-gallery');
    if(!root) return;


    function q(a,b){ return a.querySelector(b); }
    function qa(a,b){ return Array.prototype.slice.call(a.querySelectorAll(b)); }


    var chips = qa(root,'.ss-chip');


    function setFilter(val){
        for(var ci=0; ci<chips.length; ci++){
            var c = chips[ci];
            var active = (c.getAttribute('data-filter')===val || (val==='all' && c.getAttribute('data-filter')==='all'));
            c.classList.toggle('ss-chip-active', active);
        }


/* Лого сайта */
        var sections = qa(root,'.ss-section');
var logoElement = document.getElementsByClassName('citizen-header__logo')[0];
        for(var si=0; si<sections.length; si++){
if (logoElement) {
            var section = sections[si];
    logoElement.innerHTML = '<div class="logo1"><a href="https://spacestories.club/index.php?title=Заглавная страница" class="mw-logo citizen-header__button" title="Перейти на заглавную страницу"><img class="mw-logo-icon" src="/resources/assets/logo.png" alt="" aria-hidden="true" height="32" width="32"></a></div><div class="logo2"><a href="https://spacestories.club/index.php?title=Colonial_Marines" class="mw-logo citizen-header__button" title="Перейти на заглавную страницу CM"><img class="mw-logo-icon" src="/images/0/0d/CMlog.png" alt="" aria-hidden="true" height="32" width="32"></a></div>';
            var cards = qa(section,'.ss-card');
}
            var visibleCount = 0;
            for(var cj=0; cj<cards.length; cj++){
                var card = cards[cj];
                var show = (val==='all' || val===card.getAttribute('data-artist'));
                card.classList.toggle('ss-hidden', !show);
                if(show) visibleCount++;
            }
            section.style.display = (val==='all' || visibleCount>0)?'block':'none';
        }
    }


/* Перенос page-info в конец footer-places */
    for(var i=0;i<chips.length;i++){
var footerPlaces = document.getElementById('footer-places');
        (function(ch){
var pageInfo = document.getElementsByClassName('page-info')[0];
            ch.addEventListener('click', function(){ setFilter(ch.getAttribute('data-filter')); });
if (footerPlaces && pageInfo) {
        })(chips[i]);
     footerPlaces.insertAdjacentHTML('afterEnd', pageInfo.innerHTML);
    }
    pageInfo.innerHTML = '';
     setFilter('all');
}


/* Логика цвета через headerColor */
    var modal = document.createElement('div');
var headerColorElement = document.getElementsByClassName('headerColor')[0];
     modal.className = 'ss-modal';
if (headerColorElement) {
    modal.innerHTML = '<div class="ss-modal-inner"><img class="ss-modal-img" alt=""/></div><div class="ss-modal-close" role="button">✖ Закрыть</div>';
     var isValidColor = function (color) {
    root.appendChild(modal);
        var el = document.createElement('div');
        el.style.backgroundColor = color;
        return !!el.style.backgroundColor;
    };


     var headerContent = headerColorElement.innerHTML;
     var modalImg = q(modal,'.ss-modal-img');
    var colorBorder = '', colorBtn = '', i = 0;


     while (headerContent[i] !== '|' && i < headerContent.length) {
     function originalFromThumb(u){
        colorBorder += headerContent[i++];
        if(!u) return u;
        if(u.indexOf('/thumb/')>-1){
            var s = u.replace('/thumb/','/');
            s = s.replace(/\/[^\/]*$/,'');
            return s;
        }
        return u;
     }
     }
     i++;
 
     while (i < headerContent.length) {
     var images = qa(root,'.ss-card img');
         colorBtn += headerContent[i++];
     for(var ii=0; ii<images.length; ii++){
         (function(img){
            img.style.cursor='zoom-in';
            img.addEventListener('click', function(e){
                e.preventDefault();
                var src = originalFromThumb(img.getAttribute('src')) || img.getAttribute('src');
                modalImg.setAttribute('src',src);
                modalImg.style.maxWidth='90vw';
                modalImg.style.maxHeight='90vh';
                modal.classList.add('open');
            });
        })(images[ii]);
     }
     }


     if (isValidColor(colorBorder) && isValidColor(colorBtn)) {
     function closeModal(){ modal.classList.remove('open'); }
        var headerRender = function (colorBorder, colorBtn) {
    modal.addEventListener('click', function(e){ if(e.target===modal||e.target.classList.contains('ss-modal-close')) closeModal(); });
            var headers = document.querySelectorAll('h1, h2, h3, h4, h5');
    document.addEventListener('keydown', function(e){ if(e.key==='Escape') closeModal(); });
            for (var j = 0; j < headers.length; j++) {
})();
                var header = headers[j];
 
                if (header.className === 'citizen-section-heading') {
/* Меню лора */
                    var indicator = header.querySelector('.citizen-sections-enabled, .citizen-section-indicator');
(function(){
                    var headline = header.querySelector('.mw-headline');
    var items = document.querySelectorAll('.custom-item');
                    if (indicator) {
    for(var mi=0; mi<items.length; mi++){
                        indicator.style.background = colorBtn;
        (function(item){
                        indicator.style.boxShadow = '0 0 20px 0px ' + colorBtn + 'cc';
            var icon = item.querySelector('.custom-icon');
                    }
            var linkEl = item.querySelector('a');
                    if (headline) {
            if(!linkEl) return;
                        headline.style.borderImage = 'linear-gradient(to right top, ' + colorBorder + ', black)';
 
                        headline.style.borderImageSlice = '1';
            var href = linkEl.getAttribute('href');
                    }
            item.style.cursor='pointer';
                } else if (header.className === 'citizen-section-heading citizen-section-heading--collapsed') {
                    var collapsedIndicator = header.querySelector('.citizen-sections-enabled, .citizen-section-heading--collapsed, .citizen-section-indicator');
                    if (collapsedIndicator) {
                        collapsedIndicator.style.background = 'black';
                        collapsedIndicator.style.boxShadow = 'unset';
                    }
                }
            }
        };


        headerRender(colorBorder, colorBtn);
            item.onclick = function(){ window.location.href = href; };
        document.body.addEventListener('click', function () {
            item.onmousemove = function(e){
            headerRender(colorBorder, colorBtn);
                var rect = item.getBoundingClientRect();
         });
                var x = e.clientX - rect.left;
                var y = e.clientY - rect.top;
                var moveX = (x - rect.width/2)*0.02;
                var moveY = (y - rect.height/2)*0.02;
                item.style.backgroundPosition = (50 + moveX) + '% ' + (50 + moveY) + '%';
                if(icon) icon.style.transform = 'translateY(-8px) scale(1.08)';
                var hue = Math.round((x/rect.width)*360);
                item.style.boxShadow =
                    '0 0 15px hsla(' + hue + ',100%,60%,0.7), ' +
                    '0 0 30px hsla(' + ((hue+30)%360) + ',100%,50%,0.4), ' +
                    '0 8px 20px rgba(0,0,0,0.5)';
            };
            item.onmouseleave = function(){
                item.style.backgroundPosition='50% 50%';
                if(icon) icon.style.transform='translateY(0) scale(1)';
                item.style.boxShadow='0 4px 10px rgba(0,0,0,0.3)';
            };
         })(items[mi]);
     }
     }
}
})();


/* Sidebar для ролей */
/* Химия */
var jobsContainer = document.getElementsByClassName('JobsTableContainer')[0];
(function(){
if (jobsContainer) {
    if(typeof mw==='undefined'||!window.document) return;
    var bodyContent = document.getElementById('bodyContent');
    function initCollapse(){
    if (bodyContent) {
        var headings = document.querySelectorAll('.chem-heading');
        bodyContent.insertAdjacentHTML('beforebegin', jobsContainer.innerHTML);
        for(var hi=0;hi<headings.length;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){
                        if(wrapper.classList.contains('collapsed')){
                            wrapper.classList.remove('collapsed');
                            wrapper.classList.add('expanded');
                        } else {
                            wrapper.classList.remove('expanded');
                            wrapper.classList.add('collapsed');
                        }
                    }
                });
            })(headings[hi]);
        }
     }
     }
    var jobTable = document.getElementById('IdJobsTableContainer1');
    if (jobTable) {
        jobTable.id = 'IdJobsTableContainer2';
    }
}


/* Главное меню лора */
    function findWrapper(node,kind){
document.querySelectorAll('.custom-item').forEach(function (item) {
        var parent = node.parentNode;
    item.addEventListener('click', function () {
        if(!parent) return null;
         var link = item.querySelector('a');
         var wrappers = parent.querySelectorAll('.collapsible');
         if (link) {
         for(var wi=0;wi<wrappers.length;wi++){
             window.location.href = link.getAttribute('href');
             if(wrappers[wi].getAttribute('data-kind')===kind) return wrappers[wi];
         }
         }
    });
        return null;
});
    }


/* Хронология */
    if(document.readyState==='complete'||document.readyState==='interactive'){
if (typeof $ === 'function') {
        initCollapse();
    $(document).ready(function () {
    } else {
        $('.timeline-header').click(function () {
        document.addEventListener('DOMContentLoaded', initCollapse);
            var content = $(this).next('.timeline-content');
    }
            if (content.is(':visible')) {
})();
                content.slideUp();
            } else {
                content.slideDown();
            }
        });
        $('.timeline-content').hide();
    });
}

Текущая версия от 21:51, 29 января 2026


/* Аудиоплееры */
(function(){
    var players = document.getElementsByClassName('audio-player');
    for(var i=0;i<players.length;i++){
        (function(p){
            var src = p.getAttribute('data-src');
            if(src){
                var audio = document.createElement('audio');
                audio.setAttribute('controls','controls');
                audio.setAttribute('preload','none');
                var source = document.createElement('source');
                source.setAttribute('src',src);
                source.setAttribute('type','audio/mpeg');
                audio.appendChild(source);
                p.appendChild(audio);
            }
        })(players[i]);
    }
})();

/* Подгрузка внешних CSS/JS */
(function(){
    if(typeof mw === 'undefined') return;

    function getFilesFromUrl(param){
        if(!param) return [];
        return param.split('|').map(function(file){ return file.trim(); });
    }

    function getBaseUrl(){
        var server = mw.config.get('wgServer').replace(/^http:/,'https:');
        var script = mw.config.get('wgScript');
        return server + script + '?action=raw&ctype=text/';
    }

    function isValidExtension(ext){ return ext === 'js' || ext === 'css'; }

    function getFileUrl(file){
        var prefix = file.indexOf('MediaWiki:') === 0 ? 'MediaWiki:' : 'User:' + (mw.config.get('wgUserName') || '') + '/';
        var fullName = file.indexOf(':') > -1 ? file : prefix + file;
        var ext = file.split('.').pop().toLowerCase();
        if(!isValidExtension(ext)){
            console.error('Недопустимое расширение файла:', file);
            return null;
        }
        var timestamp = new Date().getTime();
        return getBaseUrl() + (ext==='js' ? 'javascript' : 'css') + '&title=' + encodeURIComponent(fullName) + '&_=' + timestamp;
    }

    function loadFiles(files){
        for(var i=0;i<files.length;i++){
            var url = getFileUrl(files[i]);
            if(url){
                var ext = files[i].split('.').pop().toLowerCase();
                mw.loader.load(url,'text/' + (ext==='js' ? 'javascript' : 'css'));
            }
        }
    }

    mw.loader.using('mediawiki.util', function(){
        var params = mw.util.getParamValue('use');
        var files = getFilesFromUrl(params);
        loadFiles(files);
    });
})();

/* Логотипы сайта */
(function(){
    function createLogo(url,imgSrc,title){
        var container = document.createElement('div'),
            link = document.createElement('a'),
            img = document.createElement('img');
        link.className = 'mw-logo citizen-header__button';
        link.href = mw.util.getUrl(url);
        link.title = title;

        img.className = 'mw-logo-icon';
        img.src = imgSrc;
        img.alt = '';
        img.setAttribute('aria-hidden','true');
        img.width = 32;
        img.height = 32;

        link.appendChild(img);
        container.appendChild(link);
        return container;
    }

    var logoContainer = document.querySelector('.citizen-header__logo');
    if(logoContainer){
        while(logoContainer.firstChild) logoContainer.removeChild(logoContainer.firstChild);

        var logo1 = createLogo('Заглавная_страница', mw.config.get('wgScriptPath') + '/resources/assets/logo.png', 'Перейти на заглавную страницу');
        var logo2 = createLogo('Marine_Corps', mw.config.get('wgScriptPath') + '/images/0/0d/CMlog.png', 'Перейти на CM');

        logoContainer.appendChild(logo1);
        logoContainer.appendChild(logo2);
    }
})();

/* Перенос page-info и цвет заголовков */
(function(){
    var footerPlaces = document.getElementById('footer-places');
    var pageInfo = document.querySelector('.page-info');
    if(footerPlaces && pageInfo){
        footerPlaces.insertAdjacentElement('afterend', pageInfo.cloneNode(true));
        pageInfo.parentNode.removeChild(pageInfo);
    }

    var headerColorElement = document.querySelector('.headerColor');
    if(headerColorElement){
        var content = headerColorElement.textContent.split('|');
        if(content.length === 2){
            var headers = document.querySelectorAll('.citizen-section-heading, .citizen-section-heading--collapsed');
            for(var hi=0; hi<headers.length; hi++){
                var header = headers[hi],
                    indicator = header.querySelector('.citizen-section-indicator'),
                    headline = header.querySelector('.mw-headline');
                if(!indicator || !headline) continue;
                if(header.classList.contains('citizen-section-heading--collapsed')){
                    indicator.style.cssText = 'background: black; box-shadow: unset;';
                } else {
                    indicator.style.cssText = 'background: ' + content[1] + '; box-shadow: 0 0 20px 0px ' + content[1] + 'cc;';
                    headline.style.cssText = 'border-image: linear-gradient(to right top,' + content[0] + ', black); border-image-slice:1;';
                }
            }
        }
    }
})();

/* Sidebar для ролей */
(function(){
    var jobsContainer = document.querySelector('.JobsTableContainer');
    if(jobsContainer && jobsContainer.innerHTML.trim()){
        var bodyContent = document.getElementById('bodyContent');
        if(bodyContent){
            bodyContent.insertAdjacentHTML('beforebegin', jobsContainer.innerHTML);
            var jobTable = document.getElementById('IdJobsTableContainer1');
            if(jobTable) jobTable.id = 'IdJobsTableContainer2';
        }
    }
})();

/* Хронология */
(function(){
    if(!window.jQuery) return;
    jQuery(function($){
        $('.timeline-header').on('click', function(){
            $(this).next('.timeline-content').slideToggle();
        }).trigger('click');
    });
})();

/* Галерея */
(function(){
    var root = document.getElementById('ss-art-gallery');
    if(!root) return;

    function q(a,b){ return a.querySelector(b); }
    function qa(a,b){ return Array.prototype.slice.call(a.querySelectorAll(b)); }

    var chips = qa(root,'.ss-chip');

    function setFilter(val){
        for(var ci=0; ci<chips.length; ci++){
            var c = chips[ci];
            var active = (c.getAttribute('data-filter')===val || (val==='all' && c.getAttribute('data-filter')==='all'));
            c.classList.toggle('ss-chip-active', active);
        }

        var sections = qa(root,'.ss-section');
        for(var si=0; si<sections.length; si++){
            var section = sections[si];
            var cards = qa(section,'.ss-card');
            var visibleCount = 0;
            for(var cj=0; cj<cards.length; cj++){
                var card = cards[cj];
                var show = (val==='all' || val===card.getAttribute('data-artist'));
                card.classList.toggle('ss-hidden', !show);
                if(show) visibleCount++;
            }
            section.style.display = (val==='all' || visibleCount>0)?'block':'none';
        }
    }

    for(var i=0;i<chips.length;i++){
        (function(ch){
            ch.addEventListener('click', function(){ setFilter(ch.getAttribute('data-filter')); });
        })(chips[i]);
    }
    setFilter('all');

    var modal = document.createElement('div');
    modal.className = 'ss-modal';
    modal.innerHTML = '<div class="ss-modal-inner"><img class="ss-modal-img" alt=""/></div><div class="ss-modal-close" role="button">✖ Закрыть</div>';
    root.appendChild(modal);

    var modalImg = q(modal,'.ss-modal-img');

    function originalFromThumb(u){
        if(!u) return u;
        if(u.indexOf('/thumb/')>-1){
            var s = u.replace('/thumb/','/'); 
            s = s.replace(/\/[^\/]*$/,''); 
            return s;
        }
        return u;
    }

    var images = qa(root,'.ss-card img');
    for(var ii=0; ii<images.length; ii++){
        (function(img){
            img.style.cursor='zoom-in';
            img.addEventListener('click', function(e){
                e.preventDefault();
                var src = originalFromThumb(img.getAttribute('src')) || img.getAttribute('src');
                modalImg.setAttribute('src',src);
                modalImg.style.maxWidth='90vw';
                modalImg.style.maxHeight='90vh';
                modal.classList.add('open');
            });
        })(images[ii]);
    }

    function closeModal(){ modal.classList.remove('open'); }
    modal.addEventListener('click', function(e){ if(e.target===modal||e.target.classList.contains('ss-modal-close')) closeModal(); });
    document.addEventListener('keydown', function(e){ if(e.key==='Escape') closeModal(); });
})();

/* Меню лора */
(function(){
    var items = document.querySelectorAll('.custom-item');
    for(var mi=0; mi<items.length; mi++){
        (function(item){
            var icon = item.querySelector('.custom-icon');
            var linkEl = item.querySelector('a');
            if(!linkEl) return;

            var href = linkEl.getAttribute('href');
            item.style.cursor='pointer';

            item.onclick = function(){ window.location.href = href; };
            item.onmousemove = function(e){
                var rect = item.getBoundingClientRect();
                var x = e.clientX - rect.left;
                var y = e.clientY - rect.top;
                var moveX = (x - rect.width/2)*0.02;
                var moveY = (y - rect.height/2)*0.02;
                item.style.backgroundPosition = (50 + moveX) + '% ' + (50 + moveY) + '%';
                if(icon) icon.style.transform = 'translateY(-8px) scale(1.08)';
                var hue = Math.round((x/rect.width)*360);
                item.style.boxShadow =
                    '0 0 15px hsla(' + hue + ',100%,60%,0.7), ' +
                    '0 0 30px hsla(' + ((hue+30)%360) + ',100%,50%,0.4), ' +
                    '0 8px 20px rgba(0,0,0,0.5)';
            };
            item.onmouseleave = function(){
                item.style.backgroundPosition='50% 50%';
                if(icon) icon.style.transform='translateY(0) scale(1)';
                item.style.boxShadow='0 4px 10px rgba(0,0,0,0.3)';
            };
        })(items[mi]);
    }
})();

/* Химия */
(function(){
    if(typeof mw==='undefined'||!window.document) return;
    function initCollapse(){
        var headings = document.querySelectorAll('.chem-heading');
        for(var hi=0;hi<headings.length;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){
                        if(wrapper.classList.contains('collapsed')){
                            wrapper.classList.remove('collapsed');
                            wrapper.classList.add('expanded');
                        } else {
                            wrapper.classList.remove('expanded');
                            wrapper.classList.add('collapsed');
                        }
                    }
                });
            })(headings[hi]);
        }
    }

    function findWrapper(node,kind){
        var parent = node.parentNode;
        if(!parent) return null;
        var wrappers = parent.querySelectorAll('.collapsible');
        for(var wi=0;wi<wrappers.length;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);
    }
})();