MediaWiki:Common.js

From Donate
Revision as of 14:22, 27 July 2020 by Pcoombe (talk | contribs) (allow loading alternative donation form script - phab:T255865)
Jump to navigation Jump to search

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.
/**
 * MediaWiki:Common.js - Any JavaScript here will be loaded for all users on every page load.
 **/

$(function() {
    // Code for donation forms - https://donate.wikimedia.org/wiki/MediaWiki:DonationForm.js
    if ( document.forms['donateForm'] ) {
        var formJS = mw.util.getParamValue( 'formJS' );
        if ( formJS && formJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
            mw.loader.load( '/w/index.php?title=' + formJS + '&action=raw&ctype=text/javascript' );
        } else {
            mw.loader.load( '/w/index.php?title=MediaWiki:DonationForm.js&action=raw&ctype=text/javascript' );
        }
    }

    // Code for Thank You pages - https://donate.wikimedia.org/wiki/MediaWiki:ThankYouPage.js
    if ( mw.config.get( 'wgTitle' ).indexOf('Thank You') !== -1 ) {
        mw.loader.load( '/w/index.php?title=MediaWiki:ThankYouPage.js&action=raw&ctype=text/javascript' );
    }

    // Code for support pages - https://donate.wikimedia.org/wiki/MediaWiki:SupportPage.js
    // TODO: have a better way to trigger this
    var supportPages = [ 'Ways to Give', 'Problems donating', 'Cancel or change recurring giving', 
                         'Matching Gifts', 'Support Page', 'FAQ', 'Tax deductibility',
                         'US State Solicitation Disclosures' ];
    if ( supportPages.indexOf( mw.config.get( 'wgTitle' ).split('/')[0] ) !== -1 ) {
        mw.loader.load( '/w/index.php?title=MediaWiki:SupportPage.js&action=raw&ctype=text/javascript' );
    }

    // Load some tools for editors - https://donate.wikimedia.org/wiki/MediaWiki:EditTemplates.js
    if ( mw.config.get( 'wgUserName' ) !== null ) {
        mw.loader.load( '/w/index.php?title=MediaWiki:EditTemplates.js&action=raw&ctype=text/javascript' );
    }

   /* HACK to run certain inline scripts when document ready (e.g. so jquery is avaliable)
        TODO: Make suitable for multiple scripts. Or figure out a better way to do this.
    */
    if ( typeof inlineScriptWhenReady !== 'undefined') {
        inlineScriptWhenReady();
    }
});