MediaWiki:Common.js: Difference between revisions

From WikiDemocracy
Jump to navigationJump to search
No edit summary
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. */
mw.loader.using('mediawiki.util', function() {
    $(document).ready(function() {
        // 1. Inject the Snipcart Stylesheet into the Head
        var snipcartStyle = document.createElement('link');
        snipcartStyle.rel = 'stylesheet';
        snipcartStyle.href = 'https://cdn.snipcart.com/themes/v3.0.31/default/snipcart.css';
        document.head.appendChild(snipcartStyle);


// Add this to your MediaWiki:Common.js page
        // 2. Inject the Snipcart JavaScript Engine into the Head
var snipcartScript = document.createElement('script');
        var snipcartScript = document.createElement('script');
snipcartScript.src = 'https://cdn.snipcart.com/themes/v3.0.31/default/snipcart.js';
        snipcartScript.src = 'https://cdn.snipcart.com/themes/v3.0.31/default/snipcart.js';
snipcartScript.id = 'snipcart';
        snipcartScript.async = true;
snipcartScript.setAttribute('data-api-key', 'MmVhODYxZWItMmRiZC00ZmQxLWE3ODgtMDY2NGI0ODE2NTg3NjM5MTY0NDgxODQ2NzAzNTgy');
        document.head.appendChild(snipcartScript);
document.head.appendChild(snipcartScript);


var snipcartStyle = document.createElement('link');
        // 3. Create the REQUIRED hidden container hidden in the Body for the API Key
snipcartStyle.rel = 'stylesheet';
        if (!document.getElementById('snipcart')) {
snipcartStyle.href = 'https://cdn.snipcart.com/themes/v3.0.31/default/snipcart.css';
            var snipcartDiv = document.createElement('div');
document.head.appendChild(snipcartStyle);
            snipcartDiv.id = 'snipcart';
            snipcartDiv.setAttribute('data-api-key', 'MmVhODYxZWItMmRiZC00ZmQxLWE3ODgtMDY2NGI0ODE2NTg3NjM5MTY0NDgxODQ2NzAzNTgy');
            snipcartDiv.hidden = true;
            document.body.appendChild(snipcartDiv);
        }
    });
});

Revision as of 00:51, 8 June 2026

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using('mediawiki.util', function() {
    $(document).ready(function() {
        // 1. Inject the Snipcart Stylesheet into the Head
        var snipcartStyle = document.createElement('link');
        snipcartStyle.rel = 'stylesheet';
        snipcartStyle.href = 'https://cdn.snipcart.com/themes/v3.0.31/default/snipcart.css';
        document.head.appendChild(snipcartStyle);

        // 2. Inject the Snipcart JavaScript Engine into the Head
        var snipcartScript = document.createElement('script');
        snipcartScript.src = 'https://cdn.snipcart.com/themes/v3.0.31/default/snipcart.js';
        snipcartScript.async = true;
        document.head.appendChild(snipcartScript);

        // 3. Create the REQUIRED hidden container hidden in the Body for the API Key
        if (!document.getElementById('snipcart')) {
            var snipcartDiv = document.createElement('div');
            snipcartDiv.id = 'snipcart';
            snipcartDiv.setAttribute('data-api-key', 'MmVhODYxZWItMmRiZC00ZmQxLWE3ODgtMDY2NGI0ODE2NTg3NjM5MTY0NDgxODQ2NzAzNTgy');
            snipcartDiv.hidden = true;
            document.body.appendChild(snipcartDiv);
        }
    });
});