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

편집 요약 없음
편집 요약 없음
1번째 줄: 1번째 줄:
(function (mw, $) {
/* =========================================
'use strict';
  COASTLINE: BLACK ICE - Nations Tab Panel
  하단 국가 패널 대륙 탭 전환 전용
  ========================================= */
(function () {
    'use strict';


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


    var tabs = shell.querySelectorAll('.clbi-nations-simple-tab[data-continent]');
        var tabs = Array.prototype.slice.call(panel.querySelectorAll('.clbi-nations-tabpanel-tab[data-continent]'));
    var panels = shell.querySelectorAll('.clbi-nations-simple-continent[data-continent-panel]');
        var bodies = Array.prototype.slice.call(panel.querySelectorAll('.clbi-nations-tabpanel-continent[data-continent-panel]'));
    var matched = false;


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


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


function bindShell(shell) {
        tabs.forEach(function (tab) {
    if (!shell || shell.getAttribute('data-clbi-nations-simple-bound') === '1') return;
            tab.setAttribute('role', 'tab');
            tab.setAttribute('tabindex', '0');
            tab.addEventListener('click', function () {
                activate(tab.getAttribute('data-continent'));
            });
            tab.addEventListener('keydown', function (event) {
                if (event.key === 'Enter' || event.key === ' ') {
                    event.preventDefault();
                    activate(tab.getAttribute('data-continent'));
                }
            });
        });


    shell.setAttribute('data-clbi-nations-simple-bound', '1');
        var initial = panel.querySelector('.clbi-nations-tabpanel-tab.is-active[data-continent]') || tabs[0];
        if (initial) activate(initial.getAttribute('data-continent'));
    }


     shell.addEventListener('click', function (event) {
     function init(root) {
         var tab = event.target.closest ? event.target.closest('.clbi-nations-simple-tab[data-continent]') : null;
         var scope = root && root.querySelectorAll ? root : document;
        if (!tab || !shell.contains(tab)) return;
        Array.prototype.forEach.call(scope.querySelectorAll('.clbi-nations-tabpanel'), initPanel);
        activate(shell, tab.getAttribute('data-continent'));
     }
     });


     shell.addEventListener('keydown', function (event) {
     window.CLBI_NATIONS_PANEL = {
         var tab = event.target.closest ? event.target.closest('.clbi-nations-simple-tab[data-continent]') : null;
         init: init
        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-simple-tab.is-active[data-continent]') || shell.querySelector('.clbi-nations-simple-tab[data-continent]');
     if (window.mw && mw.hook) {
    if (active) activate(shell, active.getAttribute('data-continent'));
        mw.hook('wikipage.content').add(function ($content) {
}
            init($content && $content[0] ? $content[0] : document);
        });
    }


function init(root) {
     if (document.readyState === 'loading') {
     root = root && root.jquery ? root[0] : (root || document);
        document.addEventListener('DOMContentLoaded', function () { init(document); });
    var shells = root.querySelectorAll ? root.querySelectorAll('.clbi-nations-simple-shell[data-clbi-nations-simple]') : [];
     } else {
    Array.prototype.forEach.call(shells, bindShell);
         init(document);
}
     }
 
})();
window.CLBI_NationsPanelSimple = { 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));

2026년 6월 30일 (화) 06:16 판

/* =========================================
   COASTLINE: BLACK ICE - Nations Tab Panel
   하단 국가 패널 대륙 탭 전환 전용
   ========================================= */
(function () {
    'use strict';

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

        var tabs = Array.prototype.slice.call(panel.querySelectorAll('.clbi-nations-tabpanel-tab[data-continent]'));
        var bodies = Array.prototype.slice.call(panel.querySelectorAll('.clbi-nations-tabpanel-continent[data-continent-panel]'));

        function activate(continent) {
            tabs.forEach(function (tab) {
                var active = tab.getAttribute('data-continent') === continent;
                tab.classList.toggle('is-active', active);
                tab.setAttribute('aria-selected', active ? 'true' : 'false');
            });

            bodies.forEach(function (body) {
                var active = body.getAttribute('data-continent-panel') === continent;
                body.classList.toggle('is-active', active);
                if (active) {
                    body.removeAttribute('hidden');
                    body.setAttribute('aria-hidden', 'false');
                } else {
                    body.setAttribute('hidden', 'hidden');
                    body.setAttribute('aria-hidden', 'true');
                }
            });
        }

        tabs.forEach(function (tab) {
            tab.setAttribute('role', 'tab');
            tab.setAttribute('tabindex', '0');
            tab.addEventListener('click', function () {
                activate(tab.getAttribute('data-continent'));
            });
            tab.addEventListener('keydown', function (event) {
                if (event.key === 'Enter' || event.key === ' ') {
                    event.preventDefault();
                    activate(tab.getAttribute('data-continent'));
                }
            });
        });

        var initial = panel.querySelector('.clbi-nations-tabpanel-tab.is-active[data-continent]') || tabs[0];
        if (initial) activate(initial.getAttribute('data-continent'));
    }

    function init(root) {
        var scope = root && root.querySelectorAll ? root : document;
        Array.prototype.forEach.call(scope.querySelectorAll('.clbi-nations-tabpanel'), initPanel);
    }

    window.CLBI_NATIONS_PANEL = {
        init: init
    };

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

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', function () { init(document); });
    } else {
        init(document);
    }
})();