MediaWiki:Common.js

MediaWiki interface page
Revision as of 22:43, 4 October 2021 by PrivateTarkus (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.
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function() { 
  //==== Movelist Toggles ====
  if (document.getElementsByClassName("movelist-toggles")) {
    // Hide all move lists
    var $movelists = $('.movelist');
    
    var currentMovelist = 1;
    
    displayMovelist(currentMovelist);
    $('.movelist-toggle-button').each(addToggles);
    
    function swapMovelist(e) {
      var movelistToggleClicked = $(this).data("id");
      var nextMovelist = movelistToggleClicked.substring(movelistToggleClicked.length - 1);
      if (currentMovelist != nextMovelist) {
        currentMovelist = nextMovelist;
        displayMovelist(nextMovelist);
      }
    }
    
    function displayMovelist(target) {
      hideAllMovelists();
      $("#movelist-" + target).css("display", "block");
      $("#movelist-toggle-" + target).addClass("movelist-toggle-on");
    }
    
    function hideAllMovelists() {
      $movelists.css("display", "none");
      $('.movelist-toggle-button').removeClass("movelist-toggle-on").addClass("movelist-toggle-off");
    }
    
    function addToggles() {
      $(this).data("id", $(this).attr("id"));
      $(this).click(swapMovelist);
    }
  }
});