MediaWiki:Common.js: Difference between revisions

From jugglingpatterns
(Undo revision 679 by Ks (talk))
Tag: Undo
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


// In Common.js or another script loaded by MediaWiki

// Wait for the document to be ready
$(function () {
$(function () {
var animationPlace = document.getElementById('siteswapanimation');
// Get the element with id 'siteswapanimation'
siteswap=animationPlace.innerHTML;
var animationPlace = document.getElementById('siteswapanimation');

// Check if the element exists
}());
if (animationPlace) {
// Extract the siteswapnr value from the innerHTML of the element
var siteswapnr = animationPlace.innerHTML.trim();

// Perform your logic with siteswapnr
console.log("siteswapnr " + siteswapnr);

// The rest of your script...
import('/js/siteswap.mjs').then(({ default: Siteswap }) => {
var sw = new Siteswap(siteswapnr);
console.log(JSON.stringify(sw));

// ... rest of your script ...
}).catch((error) => {
console.error("Error loading module:", error);
});
} else {
console.error("Element with id 'siteswapanimation' not found.");
}
});

Revision as of 16:06, 14 November 2023

/* Any JavaScript here will be loaded for all users on every page load. */

// In Common.js or another script loaded by MediaWiki

// Wait for the document to be ready
$(function () {
    // Get the element with id 'siteswapanimation'
    var animationPlace = document.getElementById('siteswapanimation');

    // Check if the element exists
    if (animationPlace) {
        // Extract the siteswapnr value from the innerHTML of the element
        var siteswapnr = animationPlace.innerHTML.trim();

        // Perform your logic with siteswapnr
        console.log("siteswapnr " + siteswapnr);

        // The rest of your script...
        import('/js/siteswap.mjs').then(({ default: Siteswap }) => {
            var sw = new Siteswap(siteswapnr);
            console.log(JSON.stringify(sw));

            // ... rest of your script ...
        }).catch((error) => {
            console.error("Error loading module:", error);
        });
    } else {
        console.error("Element with id 'siteswapanimation' not found.");
    }
});