Streamline a few pieces of JavaScript code
The main goal here is to reduce complexity. For example, the method to remove a parameter from the current URL is never used with another parameter. The complexity is not needed. This is inspired by the changes I have seen in Icaf086f. Change-Id: If22c25e84f50ac380320cd581690835ddb70f01d
This commit is contained in:
committed by
jenkins-bot
parent
459d55c5d3
commit
a5ae7cb556
@@ -58,27 +58,24 @@
|
||||
}
|
||||
|
||||
function toggleLoading( $btnSubmit, isLoading ) {
|
||||
if ( isLoading ) {
|
||||
$btnSubmit.text( mw.msg( 'ext-uls-setlang-loading' ) );
|
||||
} else {
|
||||
$btnSubmit.text( mw.msg( 'ext-uls-setlang-accept' ) );
|
||||
}
|
||||
|
||||
$btnSubmit.prop( 'disabled', isLoading );
|
||||
$btnSubmit
|
||||
.text( mw.msg( isLoading ? 'ext-uls-setlang-loading' : 'ext-uls-setlang-accept' ) )
|
||||
.prop( 'disabled', isLoading );
|
||||
}
|
||||
|
||||
function removeParam( key ) {
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
function currentUrlWithoutSetLang() {
|
||||
var uri = new mw.Uri();
|
||||
delete uri.query[ key ];
|
||||
delete uri.query.setlang;
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
function removeSetLangFromHistory() {
|
||||
var urlWithoutSetLang = removeParam( 'setlang' );
|
||||
if ( urlWithoutSetLang === mw.Uri().toString() ) {
|
||||
return;
|
||||
if ( 'setlang' in mw.Uri().query ) {
|
||||
history.replaceState( null, 'no-setlang-url', currentUrlWithoutSetLang() );
|
||||
}
|
||||
history.replaceState( null, 'no-setlang-url', urlWithoutSetLang );
|
||||
}
|
||||
|
||||
function updateLanguage( langCode ) {
|
||||
@@ -88,7 +85,7 @@
|
||||
languagecode: langCode,
|
||||
formatversion: 2
|
||||
} ).done( function () {
|
||||
location.replace( removeParam( 'setlang' ) );
|
||||
location.replace( currentUrlWithoutSetLang() );
|
||||
} ).fail( function ( code, result ) {
|
||||
var apiErrorInfo = mw.msg( 'ext-uls-setlang-unknown-error' );
|
||||
if ( result.error && result.error.info ) {
|
||||
|
||||
Reference in New Issue
Block a user