MediaWiki:Common.js

From Medivia Online Wiki
Revision as of 13:38, 25 November 2025 by Eldrin (talk | contribs)

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$(function () {

    $('.map-toggle').on('click', function () {
        console.log("Toggle clicked, loading map...");
        var mapId = $(this).attr('data-mapid');
        var box = $('#mw-customcollapsible-' + mapId);

        // Already loaded?
        if (box.attr('data-loaded') === "1") {
            return;
        }

        var x = box.attr('data-x');
        var y = box.attr('data-y');
        var z = box.attr('data-z');
        var zoom = box.attr('data-zoom');
        var w = box.attr('data-width');
        var h = box.attr('data-height');

        // Build mapper tag (NO template strings!)
        var code = "{{#mapper:" +
            x + "|" +
            y + "|" +
            z + "|" +
            zoom + "|" +
            w + "|" +
            h + "}}";

        new mw.Api().post({
            action: 'parse',
            text: code,
            prop: 'text'
        }).done(function (data) {
            var html = data.parse.text["*"];
            box.find('.map-placeholder').replaceWith(html);
            box.attr('data-loaded', "1");
        });

    });

});