미디어위키:NationsPanel.js

Nxdsxn (토론 | 기여)님의 2026년 6월 30일 (화) 03:39 판 (새 문서: (function (mw, $) { 'use strict'; function activate(shell, key) { if (!shell || !key) return; var tabs = shell.querySelectorAll('.clbi-nations-state-tab[data-continent]'); var panels = shell.querySelectorAll('.clbi-nations-state-continent[data-continent-panel]'); var matched = false; Array.prototype.forEach.call(tabs, function (tab) { var active = tab.getAttribute('data-continent') === key; tab.classList....)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
  • 오페라: Ctrl-F5를 입력.
(function (mw, $) {
    'use strict';

    function activate(shell, key) {
        if (!shell || !key) return;

        var tabs = shell.querySelectorAll('.clbi-nations-state-tab[data-continent]');
        var panels = shell.querySelectorAll('.clbi-nations-state-continent[data-continent-panel]');
        var matched = false;

        Array.prototype.forEach.call(tabs, function (tab) {
            var active = tab.getAttribute('data-continent') === key;
            tab.classList.toggle('is-active', active);
            tab.setAttribute('aria-selected', active ? 'true' : 'false');
            tab.setAttribute('tabindex', active ? '0' : '0');
            if (active) matched = true;
        });

        if (!matched && tabs.length) {
            key = tabs[0].getAttribute('data-continent');
            tabs[0].classList.add('is-active');
            tabs[0].setAttribute('aria-selected', 'true');
        }

        Array.prototype.forEach.call(panels, function (panel) {
            var active = panel.getAttribute('data-continent-panel') === key;
            panel.classList.toggle('is-active', active);
            if (active) {
                panel.removeAttribute('hidden');
            } else {
                panel.setAttribute('hidden', 'hidden');
            }
        });
    }

    function initOne(shell) {
        if (!shell || shell.getAttribute('data-nations-panel-ready') === '1') return;
        shell.setAttribute('data-nations-panel-ready', '1');

        var tabs = shell.querySelectorAll('.clbi-nations-state-tab[data-continent]');
        var initial = shell.querySelector('.clbi-nations-state-tab.is-active[data-continent]') || tabs[0];

        Array.prototype.forEach.call(tabs, function (tab) {
            tab.addEventListener('click', function (event) {
                event.preventDefault();
                activate(shell, tab.getAttribute('data-continent'));
            });

            tab.addEventListener('keydown', function (event) {
                if (event.key === 'Enter' || event.key === ' ') {
                    event.preventDefault();
                    activate(shell, tab.getAttribute('data-continent'));
                }
            });
        });

        if (initial) {
            activate(shell, initial.getAttribute('data-continent'));
        }
    }

    function init(root) {
        root = root && root.jquery ? root[0] : (root || document);
        var shells = root.querySelectorAll
            ? root.querySelectorAll('.clbi-nations-state-shell')
            : [];

        Array.prototype.forEach.call(shells, initOne);
    }

    window.CLBI_NATIONS_PANEL = {
        init: init,
        activate: activate
    };

    $(function () {
        init(document);
    });

    if (mw && mw.hook) {
        mw.hook('wikipage.content').add(function ($content) {
            init($content);
        });
    }
})(mediaWiki, jQuery);