Jump to content

MediaWiki:Common.js

From Megabonk Wiki
Revision as of 21:22, 4 October 2025 by MegaAdmin (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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* MediaWiki:Common.js — expandable build rows */
mw.loader.using(['mediawiki.api', 'mediawiki.util']).then(function () {
  var api = new mw.Api();

  function togglePanel($btn) {
    var targetId = $btn.attr('data-target');             // e.g. build-panel-Fox_Builds%2FWhatever
    var $panel = $('#' + targetId);
    var slug = $panel.data('slug');                      // set in template via data-slug
    var $row = $('#build-panel-row-' + slug);
    var $content = $panel.find('.build-content');
    var $loading = $panel.find('.build-loading');

    var isOpen = $row.is(':visible');
    if (isOpen) { $row.hide(); $btn.text('Show'); return; }

    if ($content.data('loaded') === 1) { $row.show(); $btn.text('Hide'); return; }

    $loading.show(); $row.show(); $btn.text('Hide');

    var title = $panel.data('title');                    // original page title (with spaces)

    api.get({
      action: 'parse',
      page: title,
      prop: 'text',
      disableeditsection: 1,
      formatversion: 2
    }).then(function (data) {
      var html = (data && data.parse && data.parse.text) ? data.parse.text : '<em>Could not load content.</em>';
      $content.html(html);
      $content.data('loaded', 1);
    }).catch(function () {
      $content.html('<em>Error while loading content.</em>');
    }).always(function () {
      $loading.hide();
    });
  }

  $(document).on('click', '.build-toggle', function () { togglePanel($(this)); });
});