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

Страница интерфейса MediaWiki
Нет описания правки
Метка: ручная отмена
Нет описания правки
Строка 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 params = mw.util.getParamValue('use'),
         userName = mw.config.get('wgUserName') || '', // Обрабатываем null
         basePath = mw.config.get('wgServer').replace(/^http:/, 'https:')
        FileRE = new RegExp('^(?:MediaWiki:|User:' + mw.util.escapeRegExp(userName) + '/)?[^&<>=%#]*\\.(js|css)$'),
            + mw.config.get('wgScript')  
         path = mw.config.get('wgServer').replace(/^http:/, 'https:') + mw.config.get('wgScript') + '?action=raw&ctype=text/';
            + '?action=raw&ctype=text/',
         userPrefix = 'User:' + (mw.config.get('wgUserName') || '') + '/',
        validExtensions = {js:1, css:1};


     if (!files) return;
     if (!params) return;


     $.each(files.split('|'), function (k, v) {
     params.split('|').forEach(function(param) {
         var file = $.trim(v), match = FileRE.exec(file);
         var file = param.trim(),
        if (match) {
            isSystem = /^MediaWiki:/i.test(file),
             switch (match[1]) {
             parts = file.split('.'),
                case 'js':
            ext = parts[parts.length-1].toLowerCase();
                    mw.loader.load(path + 'javascript&title=' + encodeURIComponent(file), 'text/javascript');
                    break;
                case 'css':
                    mw.loader.load(path + 'css&title=' + encodeURIComponent(file), 'text/css');
                    break;
            }
        }
    });
});  


        if (!validExtensions[ext]) return;
        if (!/^[\w\-\/\.]+$/.test(file)) return;
       
        var prefix = isSystem ? 'MediaWiki:' : userPrefix;
        var fullName = file.indexOf(':') > -1 ? file : prefix + file;
       
        var url = basePath
            + (ext === 'js' ? 'javascript' : 'css')
            + '&title=' + encodeURIComponent(fullName);


        mw.loader.load(url, 'text/' + ext);
    });
});


/* Лого сайта */
(function() {
    var createLogo = function(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',
            'Перейти на заглавную страницу'
        );
        logo1.className = 'logo1';
       
        var logo2 = createLogo(
            'Colonial_Marines',
            mw.config.get('wgScriptPath') + '/images/0/0d/CMlog.png',
            'Перейти на CM'
        );
        logo2.className = 'logo2';
       
        // Добавление в DOM
        logoContainer.appendChild(logo1);
        logoContainer.appendChild(logo2);
    }
})();


/* Лого сайта */
/* Перенос page-info в footer-places */
var logoElement = document.getElementsByClassName('citizen-header__logo')[0];
if (logoElement) {
    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>';
}
 
/* Перенос 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() {
    while (headerContent[i] !== '|' && i < headerContent.length) {
            var headers = document.querySelectorAll('.citizen-section-heading, .citizen-section-heading--collapsed');
        colorBorder += headerContent[i++];
            for (var i = 0; i < headers.length; i++) {
    }
                var header = headers[i],
    i++;
                    indicator = header.querySelector('.citizen-section-indicator'),
    while (i < headerContent.length) {
                    headline = header.querySelector('.mw-headline');
        colorBtn += headerContent[i++];
    }


    if (isValidColor(colorBorder) && isValidColor(colorBtn)) {
                if (header.classList.contains('citizen-section-heading--collapsed')) {
        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);
        });
     }
     }
}
}
Строка 106: Строка 134:
     }
     }
}
}
/* Главное меню лора */
document.querySelectorAll('.custom-item').forEach(function (item) {
    item.addEventListener('click', function () {
        var link = item.querySelector('a');
        if (link) {
            window.location.href = link.getAttribute('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();
     });
     });
}
}

Версия от 19:02, 2 марта 2025

/* Подгрузка внешних css js */
mw.loader.using('mediawiki.util', function() {
    var params = mw.util.getParamValue('use'),
        basePath = mw.config.get('wgServer').replace(/^http:/, 'https:') 
            + mw.config.get('wgScript') 
            + '?action=raw&ctype=text/',
        userPrefix = 'User:' + (mw.config.get('wgUserName') || '') + '/',
        validExtensions = {js:1, css:1};

    if (!params) return;

    params.split('|').forEach(function(param) {
        var file = param.trim(),
            isSystem = /^MediaWiki:/i.test(file),
            parts = file.split('.'),
            ext = parts[parts.length-1].toLowerCase();

        if (!validExtensions[ext]) return;
        if (!/^[\w\-\/\.]+$/.test(file)) return;
        
        var prefix = isSystem ? 'MediaWiki:' : userPrefix;
        var fullName = file.indexOf(':') > -1 ? file : prefix + file;
        
        var url = basePath 
            + (ext === 'js' ? 'javascript' : 'css') 
            + '&title=' + encodeURIComponent(fullName);

        mw.loader.load(url, 'text/' + ext);
    });
});

/* Лого сайта */
(function() {
    var createLogo = function(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',
            'Перейти на заглавную страницу'
        );
        logo1.className = 'logo1';
        
        var logo2 = createLogo(
            'Colonial_Marines', 
            mw.config.get('wgScriptPath') + '/images/0/0d/CMlog.png',
            'Перейти на CM'
        );
        logo2.className = 'logo2';
        
        // Добавление в DOM
        logoContainer.appendChild(logo1);
        logoContainer.appendChild(logo2);
    }
})();

/* Перенос 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.getElementsByClassName('JobsTableContainer')[0];
if (jobsContainer) {
    var bodyContent = document.getElementById('bodyContent');
    if (bodyContent) {
        bodyContent.insertAdjacentHTML('beforebegin', jobsContainer.innerHTML);
    }
    var jobTable = document.getElementById('IdJobsTableContainer1');
    if (jobTable) {
        jobTable.id = 'IdJobsTableContainer2';
    }
}

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