Jump to content

MediaWiki:Common.js

From Creature Breeder Wiki
Revision as of 22:51, 17 April 2026 by Gremlinarvinr (talk | contribs) (Created page with "Creature Infobox Image Toggle: (function () { function initCreatureInfoboxes() { document.querySelectorAll('.infobox-creature').forEach(function (box) { var tabs = box.querySelectorAll('.ci-tab'); var imgs = box.querySelectorAll('.ci-img'); tabs.forEach(function (tab, index) { tab.addEventListener('click', function () { // Hide all images, deactivate all tabs img...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Creature Infobox Image Toggle */
(function () {
    function initCreatureInfoboxes() {
        document.querySelectorAll('.infobox-creature').forEach(function (box) {
            var tabs = box.querySelectorAll('.ci-tab');
            var imgs = box.querySelectorAll('.ci-img');

            tabs.forEach(function (tab, index) {
                tab.addEventListener('click', function () {
                    // Hide all images, deactivate all tabs
                    imgs.forEach(function (img) { img.style.display = 'none'; });
                    tabs.forEach(function (t) { t.classList.remove('ci-tab-active'); });

                    // Show selected image, activate selected tab
                    if (imgs[index]) imgs[index].style.display = 'block';
                    tab.classList.add('ci-tab-active');
                });
            });
        });
    }

    // Run after the DOM is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initCreatureInfoboxes);
    } else {
        initCreatureInfoboxes();
    }
}());