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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
Строка 85: Строка 85:
(function () {
(function () {
     var btn = document.createElement('div');
     var btn = document.createElement('div');
    btn.title = 'Наверх';
     btn.style.position = 'fixed';
     btn.style.position = 'fixed';
     btn.style.bottom = '20px';
     btn.style.bottom = '20px';
Строка 90: Строка 91:
     btn.style.width = '50px';
     btn.style.width = '50px';
     btn.style.height = '50px';
     btn.style.height = '50px';
     btn.style.background = 'url(' + mw.config.get('wgScriptPath') + '/images/Edagger.gif) no-repeat center';
     btn.style.background = 'url(' + mw.config.get('wgScriptPath') + '/images/AI_icon.gif) no-repeat center/contain';
    btn.style.backgroundSize = 'contain';
     btn.style.opacity = '0.8';
     btn.style.opacity = '0.5';
     btn.style.cursor = 'pointer';
     btn.style.cursor = 'pointer';
     btn.style.display = 'none';
     btn.style.display = 'none';
     btn.style.zIndex = '9999';
     btn.style.zIndex = '10000';
    btn.style.transition = 'opacity 0.3s, transform 0.2s';
   
     document.body.appendChild(btn);
     document.body.appendChild(btn);
   
 
     function toggleButton() {
     function toggleButton() {
         btn.style.display = window.scrollY > 100 ? 'block' : 'none';
        var show = document.documentElement.scrollTop > 100;
         btn.style.display = show ? 'block' : 'none';
        btn.style.opacity = show ? '0.8' : '0';
     }
     }
   
 
     function scrollToTop() {
     function scrollToTop() {
         window.scrollTo({ top: 0, behavior: 'instant' });
         window.scrollTo(0, 0);
     }
     }
    btn.addEventListener('mouseover', function() {
        btn.style.opacity = '1';
        btn.style.transform = 'scale(1.1)';
    });
      
      
    btn.addEventListener('mouseout', function() {
        btn.style.opacity = '0.8';
        btn.style.transform = 'scale(1)';
    });
     btn.addEventListener('click', scrollToTop);
     btn.addEventListener('click', scrollToTop);
     window.addEventListener('scroll', toggleButton);
     window.addEventListener('scroll', toggleButton);
    window.addEventListener('resize', toggleButton);
    toggleButton();
})();
})();



Версия от 18:30, 29 марта 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);
    }
})();


/*кнопки прокрутки вверх*/
(function () {
    var btn = document.createElement('div');
    btn.title = 'Наверх';
    btn.style.position = 'fixed';
    btn.style.bottom = '20px';
    btn.style.right = '20px';
    btn.style.width = '50px';
    btn.style.height = '50px';
    btn.style.background = 'url(' + mw.config.get('wgScriptPath') + '/images/AI_icon.gif) no-repeat center/contain';
    btn.style.opacity = '0.8';
    btn.style.cursor = 'pointer';
    btn.style.display = 'none';
    btn.style.zIndex = '10000';
    btn.style.transition = 'opacity 0.3s, transform 0.2s';
    
    document.body.appendChild(btn);

    function toggleButton() {
        var show = document.documentElement.scrollTop > 100;
        btn.style.display = show ? 'block' : 'none';
        btn.style.opacity = show ? '0.8' : '0';
    }

    function scrollToTop() {
        window.scrollTo(0, 0);
    }

    btn.addEventListener('mouseover', function() {
        btn.style.opacity = '1';
        btn.style.transform = 'scale(1.1)';
    });
    
    btn.addEventListener('mouseout', function() {
        btn.style.opacity = '0.8';
        btn.style.transform = 'scale(1)';
    });

    btn.addEventListener('click', scrollToTop);
    window.addEventListener('scroll', toggleButton);
    window.addEventListener('resize', toggleButton);
    toggleButton();
})();



/* Перенос 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 && jobsContainer.innerHTML) {
    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');
    });
}