MediaWiki:Common.js: Difference between revisions

Content deleted Content added
move monthlyconvert js loading here, to reduce blocking
dependence on mw.util
Line 4:
 
$(function() {
// Disable logo link
$('#p-logo a').attr( { href: '#', title: '' } );
mw.loader.using( ['mediawiki.util'] ).done( function() {
// Code for donation forms - https://donate.wikimedia.org/wiki/MediaWiki:DonationForm.js
if ( document.forms['donateForm'] ) {
// Disable logo link
var formJS = mw.util.getParamValue( 'formJS' );
$('#p-logo a').attr( { href: '#', title: '' } );
if ( formJS && formJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
mw.loader.load( '/w/index.php?title=' + formJS + '&action=raw&ctype=text/javascript' );
// Code for donation forms - https://donate.wikimedia.org/wiki/MediaWiki:DonationForm.js
} else {
if ( document.forms['donateForm'] ) {
mw.loader.load( '/w/index.php?title=MediaWiki:DonationForm.js&action=raw&ctype=text/javascript' );
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' );
// Load monthly convert JS if needed
} else {
// TODO: allow loading different JS variants, either here or defined in the Template
mw.loader.load( '/w/index.php?title=MediaWiki:DonationForm.js&action=raw&ctype=text/javascript' );
if ( mw.util.getParamValue('monthlyconvert') ) {
}
mw.loader.load( '/w/index.php?title=MediaWiki:MonthlyConvert.js&action=raw&ctype=text/javascript' );
}
// Load monthly convert JS if needed
}
// TODO: allow loading different JS variants, either here or defined in the Template
 
if ( mw.util.getParamValue('monthlyconvert') ) {
// Code for Thank You pages - https://donate.wikimedia.org/wiki/MediaWiki:ThankYouPage.js
mw.loader.load( '/w/index.php?title=MediaWiki:MonthlyConvert.js&action=raw&ctype=text/javascript' );
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 supportThank You pages - https://donate.wikimedia.org/wiki/MediaWiki:SupportPageThankYouPage.js
if ( mw.config.get( 'wgTitle' ).indexOf('Thank You') !== -1 ) {
// TODO: have a better way to trigger this
mw.loader.load( '/w/index.php?title=MediaWiki:ThankYouPage.js&action=raw&ctype=text/javascript' );
var supportPages = [ 'Ways to Give', 'Problems donating', 'Cancel or change recurring giving',
}
'Matching Gifts', 'Support Page', 'FAQ', 'Tax deductibility',
'US State Solicitation Disclosures', 'Draft:FAQ' ];
// Code for support pages - https://donate.wikimedia.org/wiki/MediaWiki:SupportPage.js
if ( supportPages.indexOf( mw.config.get( 'wgTitle' ).split('/')[0] ) !== -1 ) {
// TODO: have a better way to trigger this
mw.loader.load( '/w/index.php?title=MediaWiki:SupportPage.js&action=raw&ctype=text/javascript' );
var supportPages = [ 'Ways to Give', 'Problems donating', 'Cancel or change recurring giving',
}
'Matching Gifts', 'Support Page', 'FAQ', 'Tax deductibility',
 
'US State Solicitation Disclosures', 'Draft:FAQ' ];
// Load some tools for editors - https://donate.wikimedia.org/wiki/MediaWiki:EditTemplates.js
if ( supportPages.indexOf( mw.config.get( 'wgUserNamewgTitle' ).split('/')[0] ) !== null-1 ) {
mw.loader.load( '/w/index.php?title=MediaWiki:EditTemplatesSupportPage.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 ) {
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
mw.loader.load( '/w/index.php?title=MediaWiki:EditTemplates.js&action=raw&ctype=text/javascript' );
* @rev 6
*/ }
var extraCSS = mw.util.getParamValue( 'withCSS' ),
/**
extraJS = mw.util.getParamValue( 'withJS' );
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 
* @rev 6
if ( extraCSS ) {
*/
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
var extraCSS = mw.util.getParamValue( 'withCSS' ),
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
extraJS = mw.util.getParamValue( 'withJS' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
if ( extraCSS ) {
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
}
if ( extraJS ) {
 
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
} else {
mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
} else {
}
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}
/* 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.
/* 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') {
*/
if ( typeof inlineScriptWhenReady !== 'undefined'() {;
}
inlineScriptWhenReady();
}
} );
});