MediaWiki:Common.js: Difference between revisions

From WikiDemocracy
Jump to navigationJump to search
Created page with "→Any JavaScript here will be loaded for all users on every page load.: // Add this to your MediaWiki:Common.js page var snipcartScript = document.createElement('script'); snipcartScript.src = 'https://cdn.snipcart.com/themes/v3.0.31/default/snipcart.js'; snipcartScript.id = 'snipcart'; snipcartScript.setAttribute('data-api-key', 'YOUR_PUBLIC_SNIPCART_API_KEY_HERE'); document.head.appendChild(snipcartScript); var snipcartStyle = document.createElement('link'); snipc..."
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
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', 'YOUR_PUBLIC_SNIPCART_API_KEY_HERE');
        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', 'NDQyNjc2NWQtYmQ5OS00MzZhLTkzMWEtMDBmOGQxYmNhZGJmNjM5MTY0NDgxODQ2NzAzNTgy');
            snipcartDiv.hidden = true;
            document.body.appendChild(snipcartDiv);
        }
    });
});

Latest revision as of 01:15, 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', 'NDQyNjc2NWQtYmQ5OS00MzZhLTkzMWEtMDBmOGQxYmNhZGJmNjM5MTY0NDgxODQ2NzAzNTgy');
            snipcartDiv.hidden = true;
            document.body.appendChild(snipcartDiv);
        }
    });
});