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

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


     if (!files) return;
     if (!files) return;
 
   
     $.each(files.split('|'), function (k, v) {
     files = files.split('|');
         var file = $.trim(v), match = FileRE.exec(file);
    for (i = 0; i < files.length; i++) {
         var file = files[i].trim(),
            match = FileRE.exec(file);
         if (match) {
         if (match) {
             switch (match[1]) {
             var url = path + (match[1] === 'js' ? 'javascript' : 'css') + '&title=' + encodeURIComponent(file);
                case 'js':
            mw.loader.load(url, 'text/' + match[1]);
                    mw.loader.load(path + 'javascript&title=' + encodeURIComponent(file), 'text/javascript');
                    break;
                case 'css':
                    mw.loader.load(path + 'css&title=' + encodeURIComponent(file), 'text/css');
                    break;
            }
         }
         }
     });
     }
});  
});
 
 
 
 


/* Лого сайта */
/* Лого сайта */
var logoElement = document.getElementsByClassName('citizen-header__logo')[0];
var logoElements = document.getElementsByClassName('citizen-header__logo');
if (logoElement) {
if (logoElements.length) {
     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>';
     logoElements[0].innerHTML = [
        '<div class="logo1">',
            '<a href="/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="/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>'
    ].join('');
}
}


/* Перенос page-info в конец footer-places */
/* Перенос page-info в footer-places */
var footerPlaces = document.getElementById('footer-places');
var footerPlaces = document.getElementById('footer-places');
var pageInfo = document.getElementsByClassName('page-info')[0];
var pageInfo = document.querySelector('.page-info');
if (footerPlaces && pageInfo) {
if (footerPlaces && pageInfo) {
     footerPlaces.insertAdjacentHTML('afterEnd', pageInfo.innerHTML);
     footerPlaces.insertAdjacentElement('afterend', pageInfo.cloneNode(true));
     pageInfo.innerHTML = '';
     pageInfo.parentNode.removeChild(pageInfo);
}
}


/* Логика цвета через headerColor */
/* Логика цвета через headerColor */
var headerColorElement = document.getElementsByClassName('headerColor')[0];
var headerColorElement = document.querySelector('.headerColor');
if (headerColorElement) {
if (headerColorElement) {
     var isValidColor = function (color) {
     var isValidColor = function(color) {
         var el = document.createElement('div');
         var s = new Option().style;
         el.style.backgroundColor = color;
         s.color = color;
         return !!el.style.backgroundColor;
         return s.color !== '';
     };
     };


     var headerContent = headerColorElement.innerHTML;
     var content = headerColorElement.textContent.split('|');
     var colorBorder = '', colorBtn = '', i = 0;
     if (content.length === 2 && isValidColor(content[0]) && isValidColor(content[1])) {
        var applyStyles = function() {
            var headers = document.querySelectorAll('.citizen-section-heading, .citizen-section-heading--collapsed');
            for (var i = 0; i < headers.length; i++) {
                var header = headers[i],
                    indicator = header.querySelector('.citizen-section-indicator'),
                    headline = header.querySelector('.mw-headline');


    while (headerContent[i] !== '|' && i < headerContent.length) {
                if (header.classList.contains('citizen-section-heading--collapsed')) {
        colorBorder += headerContent[i++];
    }
    i++;
    while (i < headerContent.length) {
        colorBtn += headerContent[i++];
    }
 
    if (isValidColor(colorBorder) && isValidColor(colorBtn)) {
        var headerRender = function (colorBorder, colorBtn) {
            var headers = document.querySelectorAll('h1, h2, h3, h4, h5');
            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');
                    var headline = header.querySelector('.mw-headline');
                     if (indicator) {
                     if (indicator) {
                         indicator.style.background = colorBtn;
                         indicator.style.cssText = 'background: black; box-shadow: unset;';
                        indicator.style.boxShadow = '0 0 20px 0px ' + colorBtn + 'cc';
                    }
                    if (headline) {
                        headline.style.borderImage = 'linear-gradient(to right top, ' + colorBorder + ', black)';
                        headline.style.borderImageSlice = '1';
                    }
                } 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';
                     }
                     }
                } else if (indicator && headline) {
                    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;';
                 }
                 }
             }
             }
         };
         };


         headerRender(colorBorder, colorBtn);
         applyStyles();
         document.body.addEventListener('click', function () {
         document.body.addEventListener('click', applyStyles, false);
            headerRender(colorBorder, colorBtn);
        });
     }
     }
}
}


/* Sidebar для ролей */
/* Sidebar для ролей */
var jobsContainer = document.getElementsByClassName('JobsTableContainer')[0];
var jobsContainer = document.querySelector('.JobsTableContainer');
if (jobsContainer) {
if (jobsContainer) {
     var bodyContent = document.getElementById('bodyContent');
     var bodyContent = document.getElementById('bodyContent');
     if (bodyContent) {
     if (bodyContent) {
         bodyContent.insertAdjacentHTML('beforebegin', jobsContainer.innerHTML);
         var clone = jobsContainer.cloneNode(true);
    }
         clone.id = 'IdJobsTableContainer2';
    var jobTable = document.getElementById('IdJobsTableContainer1');
        bodyContent.parentNode.insertBefore(clone, bodyContent);
    if (jobTable) {
         jobTable.id = 'IdJobsTableContainer2';
     }
     }
}
}


/* Главное меню лора */
/* Главное меню лора */
document.querySelectorAll('.custom-item').forEach(function (item) {
var customItems = document.getElementsByClassName('custom-item');
     item.addEventListener('click', function () {
for (var i = 0; i < customItems.length; i++) {
         var link = item.querySelector('a');
     customItems[i].onclick = function() {
         if (link) {
         var link = this.querySelector('a');
            window.location.href = link.getAttribute('href');
         if (link) window.location = link.href;
        }
     };
     });
}
});


/* Хронология */
/* Хронология */
if (typeof $ === 'function') {
if (window.jQuery) {
     $(document).ready(function () {
     jQuery(function($) {
         $('.timeline-header').click(function () {
         $('.timeline-header').on('click', function() {
             var content = $(this).next('.timeline-content');
             $(this).next('.timeline-content').slideToggle();
            if (content.is(':visible')) {
         }).trigger('click');
                content.slideUp();
            } else {
                content.slideDown();
            }
         });
        $('.timeline-content').hide();
     });
     });
}
}

Версия от 09:18, 2 марта 2025

/* Подгрузка внешних css js */
mw.loader.using('mediawiki.util', function() {
    var files = mw.util.getParamValue('use'),
        userName = mw.config.get('wgUserName') || '',
        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/',
        i, fileParts;

    if (!files) return;
    
    files = files.split('|');
    for (i = 0; i < files.length; i++) {
        var file = files[i].trim(),
            match = FileRE.exec(file);
        if (match) {
            var url = path + (match[1] === 'js' ? 'javascript' : 'css') + '&title=' + encodeURIComponent(file);
            mw.loader.load(url, 'text/' + match[1]);
        }
    }
});

/* Лого сайта */
var logoElements = document.getElementsByClassName('citizen-header__logo');
if (logoElements.length) {
    logoElements[0].innerHTML = [
        '<div class="logo1">',
            '<a href="/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="/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>'
    ].join('');
}

/* Перенос page-info в footer-places */
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);
}

/* Логика цвета через headerColor */
var headerColorElement = document.querySelector('.headerColor');
if (headerColorElement) {
    var isValidColor = function(color) {
        var s = new Option().style;
        s.color = color;
        return s.color !== '';
    };

    var content = headerColorElement.textContent.split('|');
    if (content.length === 2 && isValidColor(content[0]) && isValidColor(content[1])) {
        var applyStyles = function() {
            var headers = document.querySelectorAll('.citizen-section-heading, .citizen-section-heading--collapsed');
            for (var i = 0; i < headers.length; i++) {
                var header = headers[i],
                    indicator = header.querySelector('.citizen-section-indicator'),
                    headline = header.querySelector('.mw-headline');

                if (header.classList.contains('citizen-section-heading--collapsed')) {
                    if (indicator) {
                        indicator.style.cssText = 'background: black; box-shadow: unset;';
                    }
                } else if (indicator && headline) {
                    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;';
                }
            }
        };

        applyStyles();
        document.body.addEventListener('click', applyStyles, false);
    }
}

/* Sidebar для ролей */
var jobsContainer = document.querySelector('.JobsTableContainer');
if (jobsContainer) {
    var bodyContent = document.getElementById('bodyContent');
    if (bodyContent) {
        var clone = jobsContainer.cloneNode(true);
        clone.id = 'IdJobsTableContainer2';
        bodyContent.parentNode.insertBefore(clone, bodyContent);
    }
}

/* Главное меню лора */
var customItems = document.getElementsByClassName('custom-item');
for (var i = 0; i < customItems.length; i++) {
    customItems[i].onclick = function() {
        var link = this.querySelector('a');
        if (link) window.location = link.href;
    };
}

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