Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 354: Line 354:
     });
     });
   });
   });
});
mw.loader.using(['jquery', 'mediawiki.util'], function () {
    $(function () {
        $('.main-banner[data-files]').each(function () {
            var $box = $(this);
            // Parse list: pipe or comma separated
            var list = String($box.attr('data-files'))
                .split(/\s*\|\s*|\s*,\s*/)
                .filter(Boolean);
            if (!list.length) return;
            // Pick a random filename
            var pick = list[Math.floor(Math.random() * list.length)];
            // Build a local URL to the raw file
            var src = mw.util.getUrl('Special:FilePath/' + pick);
            // Create the <img>
            var $img = $('<img>', {
                src: src,
                width: 2450,
                height: 450,
                alt: ''
            });
            // Optional link wrapper via data-link
            var href = $box.attr('data-link');
            if (href) {
                var $a = $('<a>', { href: href });
                $a.append($img);
                $box.empty().append($a);
            } else {
                $box.empty().append($img);
            }
        });
    });
});
});