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

편집 요약 없음
태그: 되돌려진 기여
편집 요약 없음
태그: 수동 되돌리기
1번째 줄: 1번째 줄:
(function (mw, $) {
(function (mw, $) {
'use strict';
    'use strict';
function setActive(panel, key) {
 
if (!panel || !key) return;
    function activate(shell, key) {
var tabs = panel.querySelectorAll('.clbi-nations-state-tab[data-continent]');
        if (!shell || !key) return;
var panes = panel.querySelectorAll('.clbi-nations-state-continent[data-continent-panel]');
 
Array.prototype.forEach.call(tabs, function (tab) {
        var tabs = shell.querySelectorAll('.clbi-nations-state-tab[data-continent]');
var active = tab.getAttribute('data-continent') === key;
        var panels = shell.querySelectorAll('.clbi-nations-state-continent[data-continent-panel]');
tab.classList.toggle('is-active', active);
        var matched = false;
tab.setAttribute('aria-selected', active ? 'true' : 'false');
 
});
        Array.prototype.forEach.call(tabs, function (tab) {
Array.prototype.forEach.call(panes, function (pane) {
            var active = tab.getAttribute('data-continent') === key;
var active = pane.getAttribute('data-continent-panel') === key;
            tab.classList.toggle('is-active', active);
pane.classList.toggle('is-active', active);
            tab.setAttribute('aria-selected', active ? 'true' : 'false');
if (active) {
            tab.setAttribute('tabindex', active ? '0' : '0');
pane.removeAttribute('hidden');
            if (active) matched = true;
} else {
        });
pane.setAttribute('hidden', 'hidden');
 
}
        if (!matched && tabs.length) {
});
            key = tabs[0].getAttribute('data-continent');
}
            tabs[0].classList.add('is-active');
function init(root) {
            tabs[0].setAttribute('aria-selected', 'true');
root = root && root.jquery ? root[0] : (root || document);
        }
var panels = root.querySelectorAll ? root.querySelectorAll('.clbi-nations-state-shell') : [];
 
Array.prototype.forEach.call(panels, function (panel) {
        Array.prototype.forEach.call(panels, function (panel) {
if (panel.getAttribute('data-nations-panel-ready') === '1') return;
            var active = panel.getAttribute('data-continent-panel') === key;
panel.setAttribute('data-nations-panel-ready', '1');
            panel.classList.toggle('is-active', active);
var activeTab = panel.querySelector('.clbi-nations-state-tab.is-active[data-continent]') || panel.querySelector('.clbi-nations-state-tab[data-continent]');
            if (active) {
if (activeTab) setActive(panel, activeTab.getAttribute('data-continent'));
                panel.removeAttribute('hidden');
panel.addEventListener('click', function (event) {
            } else {
var tab = event.target.closest ? event.target.closest('.clbi-nations-state-tab[data-continent]') : null;
                panel.setAttribute('hidden', 'hidden');
if (!tab || !panel.contains(tab)) return;
            }
event.preventDefault();
        });
setActive(panel, tab.getAttribute('data-continent'));
    }
});
 
panel.addEventListener('keydown', function (event) {
    function initOne(shell) {
if (event.key !== 'Enter' && event.key !== ' ') return;
        if (!shell || shell.getAttribute('data-nations-panel-ready') === '1') return;
var tab = event.target.closest ? event.target.closest('.clbi-nations-state-tab[data-continent]') : null;
        shell.setAttribute('data-nations-panel-ready', '1');
if (!tab || !panel.contains(tab)) return;
 
event.preventDefault();
        var tabs = shell.querySelectorAll('.clbi-nations-state-tab[data-continent]');
setActive(panel, tab.getAttribute('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) {
window.CLBI_NationsPanel = { init: init, setActive: setActive };
                event.preventDefault();
$(init);
                activate(shell, tab.getAttribute('data-continent'));
if (mw && mw.hook) {
            });
mw.hook('wikipage.content').add(function ($content) {
 
init($content && $content[0] ? $content[0] : document);
            tab.addEventListener('keydown', function (event) {
});
                if (event.key === 'Enter' || event.key === ' ') {
}
                    event.preventDefault();
}(window.mediaWiki, window.jQuery));
                    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);

2026년 6월 30일 (화) 04:36 판

(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);