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

Страница интерфейса MediaWiki
м (Откат правок Dantes (обсуждение) к последней версии SHEGARE)
Метки: откат отменено
Нет описания правки
Метка: отменено
Строка 1: Строка 1:
(function(){
    var body = document.body;
    var checkbox = document.getElementById('citizen-pref-theme');
    if(!checkbox) return;
    var elements = [];
    var isMobile = /Mobi|Android/i.test(navigator.userAgent);
    function createFragmentElements(count, createFn){
        var frag = document.createDocumentFragment();
        for(var i=0;i<count;i++){ frag.appendChild(createFn(i)); }
        return frag;
    }
    var config = {
        leavesCount:50,
        batsCount:8,
        websCount:5,
        pumpkinsCount:3,
        leafIcons:['🍂','🍁','🦇','🕸️'],
        pumpkinIcon:'🎃',
        leafMinSize:14,
        leafMaxSize:42,
        pumpkinMinSize:24,
        pumpkinMaxSize:36
    };
    function initLeaves(){
        var leaves = document.createElement('div');
        leaves.className = 'halloween-leaves';
        var frag = createFragmentElements(config.leavesCount,function(){
            var leaf = document.createElement('span');
            leaf.className='halloween-leaf';
            leaf.innerHTML=config.leafIcons[Math.floor(Math.random()*config.leafIcons.length)];
            leaf.style.left=(Math.random()*100)+'%';
            leaf.style.animationDelay=(Math.random()*10)+'s';
            leaf.style.fontSize=(config.leafMinSize+Math.random()*(config.leafMaxSize-config.leafMinSize))+'px';
            leaf.style.opacity=Math.random()*0.7+0.3;
            leaf.style.transform='rotate('+(Math.random()*360)+'deg)';
            return leaf;
        });
        leaves.appendChild(frag);
        body.appendChild(leaves);
        elements.push(leaves);
    }
    function initPumpkins(){
        var heading = document.getElementById('firstHeading');
        if(!heading) return;
        for(var i=0;i<config.pumpkinsCount;i++){
            var pumpkin = document.createElement('span');
            pumpkin.className='halloween-pumpkin';
            pumpkin.innerHTML=config.pumpkinIcon;
            pumpkin.style.margin='0 2px';
            pumpkin.style.fontSize=(config.pumpkinMinSize+Math.random()*(config.pumpkinMaxSize-config.pumpkinMinSize))+'px';
            heading.appendChild(pumpkin);
            floatPumpkin(pumpkin);
            elements.push(pumpkin);
        }
        function floatPumpkin(el){
            var pos=0,dir=1;
            el._interval = setInterval(function(){
                pos+=dir*0.3;
                if(pos>5||pos<0) dir*=-1;
                el.style.transform='translateY('+pos+'px)';
            },30);
        }
    }
    function initLinksEffect(){
        body.addEventListener('mouseover', linkMouseOver);
        body.addEventListener('mouseout', linkMouseOut);
    }
    function linkMouseOver(e){ if(e.target.tagName.toLowerCase()==='a'){ e.target.style.color='#ffa500'; e.target.style.textShadow='0 0 8px #ffa500, 0 0 15px #ff7518'; } }
    function linkMouseOut(e){ if(e.target.tagName.toLowerCase()==='a'){ e.target.style.color=''; e.target.style.textShadow=''; } }
    function initBats(){
        var bats=createFragmentElements(config.batsCount,function(){
            var bat=document.createElement('div');
            bat.className='halloween-bat';
            bat.style.top=(Math.random()*50)+'vh';
            bat.style.left=(-50+Math.random()*100)+'px';
            bat.style.animationDuration=(8+Math.random()*6)+'s';
            return bat;
        });
        body.appendChild(bats);
        elements.push(bats);
    }
    function initWebs(){
        var webs=createFragmentElements(config.websCount,function(){
            var web=document.createElement('div');
            web.className='spider-web';
            web.style.top=(Math.random()*80)+'vh';
            web.style.left=(Math.random()*90)+'vw';
            web.style.transform='rotate('+(Math.random()*360)+'deg)';
            return web;
        });
        body.appendChild(webs);
        elements.push(webs);
    }
    function removeHalloween(){
        for(var i=0;i<elements.length;i++){
            var el=elements[i];
            if(el._interval) clearInterval(el._interval);
            if(el.parentNode) el.parentNode.removeChild(el);
        }
        elements=[];
        body.removeEventListener('mouseover', linkMouseOver);
        body.removeEventListener('mouseout', linkMouseOut);
    }
    function startHalloween(){
        if(isMobile) return;
        elements=[];
        initLeaves();
        initPumpkins();
        initLinksEffect();
        initBats();
        initWebs();
    }
    checkbox.addEventListener('change',function(){
        if(checkbox.checked){
            startHalloween();
        }else{
            removeHalloween();
        }
    });
    if(checkbox.checked){ startHalloween(); }
})();
/*31*/
/*Загрузка АУДИО*/
/*Загрузка АУДИО*/
$(function () {
$(function () {

Версия от 20:25, 23 октября 2025

(function(){
    var body = document.body;
    var checkbox = document.getElementById('citizen-pref-theme');
    if(!checkbox) return;

    var elements = [];
    var isMobile = /Mobi|Android/i.test(navigator.userAgent);

    function createFragmentElements(count, createFn){
        var frag = document.createDocumentFragment();
        for(var i=0;i<count;i++){ frag.appendChild(createFn(i)); }
        return frag;
    }

    var config = {
        leavesCount:50,
        batsCount:8,
        websCount:5,
        pumpkinsCount:3,
        leafIcons:['🍂','🍁','🦇','🕸️'],
        pumpkinIcon:'🎃',
        leafMinSize:14,
        leafMaxSize:42,
        pumpkinMinSize:24,
        pumpkinMaxSize:36
    };

    function initLeaves(){
        var leaves = document.createElement('div');
        leaves.className = 'halloween-leaves';
        var frag = createFragmentElements(config.leavesCount,function(){
            var leaf = document.createElement('span');
            leaf.className='halloween-leaf';
            leaf.innerHTML=config.leafIcons[Math.floor(Math.random()*config.leafIcons.length)];
            leaf.style.left=(Math.random()*100)+'%';
            leaf.style.animationDelay=(Math.random()*10)+'s';
            leaf.style.fontSize=(config.leafMinSize+Math.random()*(config.leafMaxSize-config.leafMinSize))+'px';
            leaf.style.opacity=Math.random()*0.7+0.3;
            leaf.style.transform='rotate('+(Math.random()*360)+'deg)';
            return leaf;
        });
        leaves.appendChild(frag);
        body.appendChild(leaves);
        elements.push(leaves);
    }

    function initPumpkins(){
        var heading = document.getElementById('firstHeading');
        if(!heading) return;
        for(var i=0;i<config.pumpkinsCount;i++){
            var pumpkin = document.createElement('span');
            pumpkin.className='halloween-pumpkin';
            pumpkin.innerHTML=config.pumpkinIcon;
            pumpkin.style.margin='0 2px';
            pumpkin.style.fontSize=(config.pumpkinMinSize+Math.random()*(config.pumpkinMaxSize-config.pumpkinMinSize))+'px';
            heading.appendChild(pumpkin);
            floatPumpkin(pumpkin);
            elements.push(pumpkin);
        }

        function floatPumpkin(el){
            var pos=0,dir=1;
            el._interval = setInterval(function(){
                pos+=dir*0.3;
                if(pos>5||pos<0) dir*=-1;
                el.style.transform='translateY('+pos+'px)';
            },30);
        }
    }

    function initLinksEffect(){
        body.addEventListener('mouseover', linkMouseOver);
        body.addEventListener('mouseout', linkMouseOut);
    }
    function linkMouseOver(e){ if(e.target.tagName.toLowerCase()==='a'){ e.target.style.color='#ffa500'; e.target.style.textShadow='0 0 8px #ffa500, 0 0 15px #ff7518'; } }
    function linkMouseOut(e){ if(e.target.tagName.toLowerCase()==='a'){ e.target.style.color=''; e.target.style.textShadow=''; } }

    function initBats(){
        var bats=createFragmentElements(config.batsCount,function(){
            var bat=document.createElement('div');
            bat.className='halloween-bat';
            bat.style.top=(Math.random()*50)+'vh';
            bat.style.left=(-50+Math.random()*100)+'px';
            bat.style.animationDuration=(8+Math.random()*6)+'s';
            return bat;
        });
        body.appendChild(bats);
        elements.push(bats);
    }

    function initWebs(){
        var webs=createFragmentElements(config.websCount,function(){
            var web=document.createElement('div');
            web.className='spider-web';
            web.style.top=(Math.random()*80)+'vh';
            web.style.left=(Math.random()*90)+'vw';
            web.style.transform='rotate('+(Math.random()*360)+'deg)';
            return web;
        });
        body.appendChild(webs);
        elements.push(webs);
    }

    function removeHalloween(){
        for(var i=0;i<elements.length;i++){
            var el=elements[i];
            if(el._interval) clearInterval(el._interval);
            if(el.parentNode) el.parentNode.removeChild(el);
        }
        elements=[];
        body.removeEventListener('mouseover', linkMouseOver);
        body.removeEventListener('mouseout', linkMouseOut);
    }

    function startHalloween(){ 
        if(isMobile) return;
        elements=[];
        initLeaves();
        initPumpkins();
        initLinksEffect();
        initBats();
        initWebs();
    }

    checkbox.addEventListener('change',function(){
        if(checkbox.checked){
            startHalloween();
        }else{
            removeHalloween();
        }
    });

    if(checkbox.checked){ startHalloween(); }

})();


/*31*/


/*Загрузка АУДИО*/
$(function () {
    var players = document.getElementsByClassName('audio-player');
    for (var i = 0; i < players.length; i++) {
        var src = players[i].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);
            players[i].appendChild(audio);
        }
    }
});



/* Подгрузка внешних css js */
mw.loader.using('mediawiki.util', function() {
    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;
        }
        return getBaseUrl() + (ext === 'js' ? 'javascript' : 'css') + '&title=' + encodeURIComponent(fullName);
    }

    function loadFiles(files) {
        files.forEach(function(file) {
            var url = getFileUrl(file);
            if (url) {
                var ext = file.split('.').pop().toLowerCase();
                mw.loader.load(url, 'text/' + (ext === 'js' ? 'javascript' : 'css'));
            }
        });
    }

    var params = mw.util.getParamValue('use');
    var files = getFilesFromUrl(params);
    loadFiles(files);
});






/* Лого сайта */
(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(
            'Marine_Corps', 
            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.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';
        }
    }
}




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