미디어위키:NationsPanel.js: 두 판 사이의 차이

편집 요약 없음
태그: 수동 되돌리기
편집 요약 없음
1번째 줄: 1번째 줄:
(function (mw, $) {
(function (mw, $) {
    'use strict';
'use strict';


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


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


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


        if (!matched && tabs.length) {
    Array.prototype.forEach.call(panels, function (panel) {
            key = tabs[0].getAttribute('data-continent');
        var active = panel.getAttribute('data-continent-panel') === key;
            tabs[0].classList.add('is-active');
        panel.classList.toggle('is-active', active);
             tabs[0].setAttribute('aria-selected', 'true');
        if (active) {
            panel.removeAttribute('hidden');
        } else {
             panel.setAttribute('hidden', 'hidden');
         }
         }
    });
}


        Array.prototype.forEach.call(panels, function (panel) {
function bindShell(shell) {
            var active = panel.getAttribute('data-continent-panel') === key;
    if (!shell || shell.getAttribute('data-clbi-nations-v2-bound') === '1') return;
            panel.classList.toggle('is-active', active);
            if (active) {
                panel.removeAttribute('hidden');
            } else {
                panel.setAttribute('hidden', 'hidden');
            }
        });
    }


     function initOne(shell) {
     shell.setAttribute('data-clbi-nations-v2-bound', '1');
        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]');
    shell.addEventListener('click', function (event) {
         var initial = shell.querySelector('.clbi-nations-state-tab.is-active[data-continent]') || tabs[0];
         var tab = event.target.closest ? event.target.closest('.clbi-nations-v2-tab[data-continent]') : null;
         if (!tab || !shell.contains(tab)) return;
        activate(shell, tab.getAttribute('data-continent'));
    });


        Array.prototype.forEach.call(tabs, function (tab) {
    shell.addEventListener('keydown', function (event) {
            tab.addEventListener('click', function (event) {
        var tab = event.target.closest ? event.target.closest('.clbi-nations-v2-tab[data-continent]') : null;
                event.preventDefault();
        if (!tab || !shell.contains(tab)) return;
                activate(shell, tab.getAttribute('data-continent'));
        if (event.key !== 'Enter' && event.key !== ' ') return;
            });
        event.preventDefault();
        activate(shell, tab.getAttribute('data-continent'));
    });


            tab.addEventListener('keydown', function (event) {
    var active = shell.querySelector('.clbi-nations-v2-tab.is-active[data-continent]') || shell.querySelector('.clbi-nations-v2-tab[data-continent]');
                if (event.key === 'Enter' || event.key === ' ') {
    if (active) activate(shell, active.getAttribute('data-continent'));
                    event.preventDefault();
}
                    activate(shell, tab.getAttribute('data-continent'));
                }
            });
        });


        if (initial) {
function init(root) {
            activate(shell, initial.getAttribute('data-continent'));
    root = root && root.jquery ? root[0] : (root || document);
        }
    var shells = root.querySelectorAll ? root.querySelectorAll('.clbi-nations-v2-shell[data-clbi-nations-v2]') : [];
    }
    Array.prototype.forEach.call(shells, bindShell);
 
}
    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_NationsPanelV2 = { init: init, activate: activate };
    }


    window.CLBI_NATIONS_PANEL = {
$(init);
        init: init,
        activate: activate
    };


     $(function () {
if (mw && mw.hook) {
         init(document);
     mw.hook('wikipage.content').add(function ($content) {
         init($content && $content[0] ? $content[0] : document);
     });
     });
 
}
    if (mw && mw.hook) {
}(window.mediaWiki, window.jQuery));
        mw.hook('wikipage.content').add(function ($content) {
            init($content);
        });
    }
})(mediaWiki, jQuery);

2026년 6월 30일 (화) 05:07 판

(function (mw, $) {
'use strict';

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

    var tabs = shell.querySelectorAll('.clbi-nations-v2-tab[data-continent]');
    var panels = shell.querySelectorAll('.clbi-nations-v2-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', '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 bindShell(shell) {
    if (!shell || shell.getAttribute('data-clbi-nations-v2-bound') === '1') return;

    shell.setAttribute('data-clbi-nations-v2-bound', '1');

    shell.addEventListener('click', function (event) {
        var tab = event.target.closest ? event.target.closest('.clbi-nations-v2-tab[data-continent]') : null;
        if (!tab || !shell.contains(tab)) return;
        activate(shell, tab.getAttribute('data-continent'));
    });

    shell.addEventListener('keydown', function (event) {
        var tab = event.target.closest ? event.target.closest('.clbi-nations-v2-tab[data-continent]') : null;
        if (!tab || !shell.contains(tab)) return;
        if (event.key !== 'Enter' && event.key !== ' ') return;
        event.preventDefault();
        activate(shell, tab.getAttribute('data-continent'));
    });

    var active = shell.querySelector('.clbi-nations-v2-tab.is-active[data-continent]') || shell.querySelector('.clbi-nations-v2-tab[data-continent]');
    if (active) activate(shell, active.getAttribute('data-continent'));
}

function init(root) {
    root = root && root.jquery ? root[0] : (root || document);
    var shells = root.querySelectorAll ? root.querySelectorAll('.clbi-nations-v2-shell[data-clbi-nations-v2]') : [];
    Array.prototype.forEach.call(shells, bindShell);
}

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

$(init);

if (mw && mw.hook) {
    mw.hook('wikipage.content').add(function ($content) {
        init($content && $content[0] ? $content[0] : document);
    });
}
}(window.mediaWiki, window.jQuery));