MediaWiki:Common.js

Revision as of 09:20, 15 February 2025 by Minionguyjpro (talk | contribs) (Created page with "Any JavaScript here will be loaded for all users on every page load.: mw.loader.using("mediawiki.util").then(function () { function loadIFrame(button) { var container = button.nextElementSibling; // Gets the next div var url = button.getAttribute("data-url"); // Gets the iframe URL // Hide button button.style.display = "none"; // Insert iframe dynamically container.innerHTML = '<iframe src="' + url + '" height="3...")
(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.
/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using("mediawiki.util").then(function () {
    function loadIFrame(button) {
        var container = button.nextElementSibling; // Gets the next div
        var url = button.getAttribute("data-url"); // Gets the iframe URL

        // Hide button
        button.style.display = "none";

        // Insert iframe dynamically
        container.innerHTML = '<iframe src="' + url + '" height="300" width="100%" style="border: none;"></iframe>';
        container.style.display = "block";
    }

    // Attach event listener to all buttons with class "tap-to-load"
    document.addEventListener("click", function (event) {
        if (event.target.matches(".tap-to-load")) {
            loadIFrame(event.target);
        }
    });
});