MediaWiki:Common.js: відмінності між версіями

нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 85: Рядок 85:
         $(this).addClass('active');
         $(this).addClass('active');


         // Якщо активна вкладка ігор перемикаємо на профіль спочатку
         // If games tab is active switch to profile first, then scroll
         var $gamesTab = $('.player-tab[data-tab="games"]');
        var $profileTab = $('.player-tab[data-tab="profile"], .player-tab[data-tab="info"]');
         var $gamesTab   = $('.player-tab[data-tab="games"]');
         var gamesActive = $gamesTab.length && $gamesTab.hasClass('active');
         var gamesActive = $gamesTab.length && $gamesTab.hasClass('active');
        if (gamesActive && target !== 'top') {
            activatePlayerTab('profile');
        }


         var delay = gamesActive ? 60 : 0;
         function doScroll() {
        setTimeout(function () {
             if (target === 'top') {
             if (target === 'top') {
                 $('html, body').animate({ scrollTop: 0 }, 280);
                 $('html, body').animate({ scrollTop: 0 }, 280);
Рядок 105: Рядок 102:
                 }
                 }
             }
             }
         }, delay);
         }
 
        if (gamesActive) {
            // Click the profile tab to switch
            $profileTab.trigger('click');
            // Wait for tab switch + DOM
            setTimeout(doScroll, 120);
        } else {
            doScroll();
        }
     });
     });


Рядок 556: Рядок 562:
     var $root = $context || $(document);
     var $root = $context || $(document);
     var roleMap = {
     var roleMap = {
         'Мир': { bg:'rgba(76,175,125,0.12)', color:'#7dd4a6', border:'rgba(76,175,125,0.22)' },
        // Мирний — light red (city team color)
         'Шер': { bg:'rgba(91,143,255,0.12)',   color:'#7da8ff', border:'rgba(91,143,255,0.22)' },
         'Мир': { bg:'rgba(200,70,70,0.10)',   color:'#e89090', border:'rgba(200,70,70,0.20)' },
         'Маф': { bg:'rgba(200,76,76,0.12)',   color:'#e08888', border:'rgba(200,76,76,0.22)' },
        // Шериф — gold/amber
         'Дон': { bg:'rgba(255,215,0,0.10)',    color:'#ffd700', border:'rgba(255,215,0,0.22)' }
         'Шер': { bg:'rgba(210,168,60,0.12)', color:'#d4a843', border:'rgba(210,168,60,0.25)' },
        // Мафія — medium grey
         'Маф': { bg:'rgba(100,100,115,0.18)', color:'#aaa8b8', border:'rgba(120,120,140,0.30)'},
        // Дон — lighter grey
         'Дон': { bg:'rgba(80,80,95,0.14)',    color:'#9896a8', border:'rgba(100,100,120,0.24)'}
     };
     };


Рядок 889: Рядок 899:
// ============================================================
// ============================================================
// 17. BANNER SEARCH
// 17. BANNER SEARCH
// ============================================================
$(function () {
    // ── MEDALS helper — adds gold/silver/bronze circles to first-column cells ──
    function addMedals($t) {
        $t.find('tbody tr, tr').filter(function () {
            return $(this).find('td').length >= 2;
        }).each(function () {
            var $tds = $(this).find('td');
            var raw = $tds.eq(0).text().trim();
            var n = parseInt(raw);
            if (isNaN(n) || n < 1 || n > 3) return;
            if ($tds.eq(0).find('[class^="mcc-rank"]').length) return;
            $tds.eq(0).html('<span class="mcc-rank-' + n + '">' + n + '</span>');
        });
    }
    // ── Tables that need medals: closedcups, rank, getnames, wide rank (Період/Фіналіст) ──
    $('.content .mw-parser-output .wikitable').each(function () {
        var $t = $(this);
        if ($t.hasClass('mcc-rating-table')) return;
        var $ths = $t.find('tr').first().find('th');
        if (!$ths.length) return;
        var h0 = $ths.eq(0).text().trim();
        // Wide rank tables: № + more than 5 columns (Період, Фіналіст)
        if (h0.indexOf('№') !== -1 && $ths.length > 5) {
            addMedals($t);
            return;
        }
        // Explicit class-based
        if ($t.hasClass('closedcups') || $t.hasClass('rank')) {
            addMedals($t);
        }
    });
    // ── Get Names tables — auto-number ──
    $('.content .mw-parser-output .wikitable.getnames').each(function () {
        var $t = $(this);
        var $headerRow = $t.find('tr').first();
        if ($headerRow.find('th').first().text().trim() === '№') return;
        $headerRow.prepend('<th style="width:38px;text-align:center">№</th>');
        var n = 1;
        $t.find('tbody tr, tr').filter(function () {
            return $(this).find('td').length > 0;
        }).each(function () {
            var badge = n <= 3
                ? '<span class="mcc-rank-' + n + '">' + n + '</span>'
                : ('<span style="display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;font-size:12px;font-weight:600">' + n + '</span>');
            $(this).prepend('<td style="text-align:center;padding:10px 8px">' + badge + '</td>');
            n++;
        });
    });
    // ── Season final table — auto-number (Пан/Пані | І | П | ДБ | Дія | Σ) ──
    $('.content .mw-parser-output .wikitable').each(function () {
        var $t = $(this);
        if ($t.hasClass('mcc-rating-table') || $t.hasClass('mcc-final-table')) return;
        var $ths = $t.find('tr').first().find('th');
        if (!$ths.length) return;
        var h0 = $ths.eq(0).text().trim();
        var hLast = $ths.last().text().trim();
        var isFinal = (h0 === 'Пан/Пані' || h0 === 'Пан' || h0 === 'Гравець')
                  && hLast === 'Σ';
        if (!isFinal) return;
        $t.addClass('mcc-final-table');
        $t.find('tr').first().prepend('<th style="width:36px;text-align:center">#</th>');
        var n = 1;
        $t.find('tbody tr').each(function () {
            var $tds = $(this).find('td');
            if (!$tds.length) return;
            var badge = n <= 3
                ? '<span class="mcc-rank-' + n + '">' + n + '</span>'
                : n;
            $(this).prepend('<td style="text-align:center;padding:10px 8px">' + badge + '</td>');
            n++;
        });
    });
});
// ============================================================
// SEASON RATING TABLE — medals + color extremes for №|Пан/Пані|Σ|І|%
// ============================================================
$(function () {
    if (isMccFullwidth()) return;
    function processRatingTable($t) {
        var headers = [];
        $t.find('tr').first().find('th').each(function () {
            headers.push($(this).text().trim());
        });
        if (headers[0] !== '№') return;
        if (headers.length < 4) return;
        var hasSigma = (headers[2] && headers[2].indexOf('Σ') !== -1);
        if (!hasSigma) return;
        if (headers.length > 8) return; // wide tables handled elsewhere
        var iGames = 3;
        var iPct  = 4;
        var hasI  = headers[iGames] === 'І';
        var hasPct = headers[iPct]  === '%';
        $t.addClass('mcc-rating-table');
        var $rows = $t.find('tbody tr').filter(function () {
            return $(this).find('td').length >= 4;
        });
        if (!$rows.length) return;
        // Medals top 3
        $rows.each(function () {
            var $tds = $(this).find('td');
            var n = parseInt($tds.eq(0).text().trim());
            if (n >= 1 && n <= 3) {
                $tds.eq(0).html('<span class="mcc-rank-' + n + '">' + n + '</span>');
            }
        });
        // Σ white
        $rows.each(function () {
            $(this).find('td').eq(2).css({ color: '#ffffff', fontWeight: '700' });
        });
        // Games extremes
        if (hasI) {
            var gVals = [];
            $rows.each(function () {
                var v = parseInt($(this).find('td').eq(iGames).text().trim());
                if (!isNaN(v) && v > 0) gVals.push(v);
            });
            if (gVals.length > 1) {
                var gMax = Math.max.apply(null, gVals);
                var gMin = Math.min.apply(null, gVals);
                $rows.each(function () {
                    var $td = $(this).find('td').eq(iGames);
                    var v = parseInt($td.text().trim());
                    if (isNaN(v)) return;
                    if (v === gMax) $td.addClass('mcc-games-hi');
                    else if (v === gMin) $td.addClass('mcc-games-lo');
                });
            }
        }
        // WR extremes
        if (hasPct) {
            var pVals = [];
            $rows.each(function () {
                var v = parseFloat($(this).find('td').eq(iPct).text().trim().replace('%',''));
                if (!isNaN(v)) pVals.push(v);
            });
            if (pVals.length > 1) {
                var pMax = Math.max.apply(null, pVals);
                var pMin = Math.min.apply(null, pVals);
                $rows.each(function () {
                    var $td = $(this).find('td').eq(iPct);
                    var v = parseFloat($td.text().trim().replace('%',''));
                    if (isNaN(v)) return;
                    if (v === pMax) $td.addClass('mcc-wr-hi');
                    else if (v === pMin) $td.addClass('mcc-wr-lo');
                });
            }
        }
    }
    $('.content .mw-parser-output .wikitable').each(function () {
        processRatingTable($(this));
    });
});
// ============================================================
// PLAYER GAMES FILTERS — pre-rendered tab (server-side FetchData)
// ============================================================
$(function () {
    var $content = $('#tab-games');
    if (!$content.length) return;
    var $table = $content.find('table').first();
    if (!$table.length) return;
    applyWinrateColors($content);
    applyRolePills($content);
    buildGamesFilters($content, $table);
});
// ============================================================
// 17. BANNER SEARCH
// ============================================================
$(function () {
    var $searchInput = $('#searchInput');
    if (!$searchInput.length) return;
    $searchInput.on('keydown', function (e) {
        if (e.key === 'Enter') {
            var q = $(this).val().trim();
            if (q) window.location.href = '/index.php?search=' + encodeURIComponent(q);
        }
    });
});