MediaWiki:Common.js: Difference between revisions

Content deleted Content added
allow country confirm to be triggered by url
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 5:
$(function() {
 
mw.loader.using( ['mediawiki.util', 'mediawiki.Uri'] ).done( function() {
 
// If Jimmy tweets a bare link to https://donate.wikimedia.org/w/index.php?title=Special:LandingPage
// we are gonna have a bad time as geolocation doesn't happen. Do a redirect to send them round again
try {
var uriurl = new mw.UriURL( window.location.href );
if (
if ( uri.query.title === 'Special:LandingPage' && uri.query.country === undefined && uri.query.retried === undefined ) {
url.searchParams.get( 'title' ) === 'Special:LandingPage' &&
url.searchParams.get( 'country' ) === null &&
url.searchParams.get( 'retried' ) === null
}) {
console.log( 'redirecting to pick up country parameter' );
uriurl.pathpathname = '/';
uriurl.querysearchParams.set( 'retried =', 1 ); // only do this once
delete uriurl.querysearchParams.delete( 'title' );
window.location.href = uriurl.toString();
}
} catch (error) {
Line 39 ⟶ 43:
}
 
// Allow manual country selection and reload
// Run this only when needed
var enableCountrySelect = function() {
var language = mw.config.get('wgPageContentLanguage'),
countrySelect = document.getElementById('country-select');
 
// Translations
if ( language !== 'en' && language !== 'en-gb' ) {
const translationsUrl = 'https://donate.wikimedia.org/wiki/Module:Country_links/data.json?action=raw';
$.getJSON( translationsUrl, function( translations ) {
if ( translations[language] ) {
var list = Array.from( countrySelect.options );
list.forEach( option => {
option.innerText = translations[language][option.value] || option.innerText;
});
});
// Sort for new language
list.sort( function(a, b) {
return a.innerText.localeCompare( b.innerText );
});
});
for ( var i = 0; i < list.length; i++ ) {
list[i].parentNode.appendChild( list[i] );
}
}
}
}
});
});
}
}
 
document.getElementById('country-select-go').addEventListener( 'click', function(e) {
if ( countrySelect.value ) {
// Chapter countries, use the built-in donatewiki redirects
mw.loader.using( ['mediawiki.Uri'] ).done( function() {
if ( countrySelect.value === 'DE' ) {
var uri = new mw.Uri( document.location.href );
window.location = 'https://donate.wikimedia.org/?country=DE';
uri.query.country = countrySelect.value;
} else if ( countrySelect.value === 'CH' ) {
document.location = uri.toString();
window.location = 'https://donate.wikimedia.org/?country=CH';
});
} else {
}
var uriurl = new mw.UriURL( document.location.href );
});
url.searchParams.set( 'country', countrySelect.value );
};
document window.location = uriurl.toString();
}
}
});
};
 
if ( document.getElementById('country-change') ) {
document.getElementById('country-change').addEventListener( 'click', function(e) {
document.getElementById('country-change-select').style.display = 'block';
enableCountrySelect();
});
});
}
}
 
if ( document.getElementById('geolocate-error') ) {
enableCountrySelect();
}
}
 
// Fundraise Up privacy footer
try {
if ( mw.util.getParamValue('fundraiseupScript') ) {
let uri = new mw.Uri( window.location.href );
document.getElementById('countrydonate-confirmprivacy-third-party').style.display = 'block';
if ( uri.query.showCountryConfirm ) {
document.getElementById('country-confirm').style.display = 'block';
}
} catch (error) {
console.warn('Error parsing URL. Possibly due to unreplaced % signs?');
}
 
Line 105 ⟶ 110:
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', 'Workplace giving' ];
if ( supportPages.indexOf( mw.config.get( 'wgTitle' ).split('/')[0] ) !== -1 || document.querySelector( '.language-switcher' ) ) {
mw.loader.load( '/w/index.php?title=MediaWiki:SupportPage.js&action=raw&ctype=text/javascript' );
}