Remove setlang URL parameter on dialog close

Add two new options for ext.uls.dialog - afterOpen and afterClose.
These are callback function which will be triggered after the dialog
opens or closes.

Using the afterClose callback in ext.uls.setlang to remove the
setlang parameter from the URL if the dialog is closed without
pressing any button. This might happen if the user closes the dialog
by pressing Esc, or by clicking on the overlay.

Also see: Ie3215d12d9c77f15597495e21610707b272eeee9

In addition, renamed all occurrence of setlang to setLang.

Bug: T63115
Change-Id: Icaf086f947b1d91bf7ad5b36f126da0be1fc7747
This commit is contained in:
Abijeet
2020-01-14 14:53:20 +05:30
committed by jenkins-bot
parent 1375f0c56c
commit 459d55c5d3
2 changed files with 16 additions and 8 deletions

View File

@@ -73,9 +73,12 @@
return uri.toString();
}
function removeSetlangFromHistory() {
var urlWithoutSetlang = removeParam( 'setlang' );
history.replaceState( null, 'no-setlang-url', urlWithoutSetlang );
function removeSetLangFromHistory() {
var urlWithoutSetLang = removeParam( 'setlang' );
if ( urlWithoutSetLang === mw.Uri().toString() ) {
return;
}
history.replaceState( null, 'no-setlang-url', urlWithoutSetLang );
}
function updateLanguage( langCode ) {
@@ -120,7 +123,6 @@
} );
$cancelBtn.on( 'click', function () {
removeSetlangFromHistory();
ulsDialog.close();
} );
}
@@ -132,7 +134,7 @@
$ulsDialog, ulsSetLangDialog;
if ( currentLangCode === setLangCode ) {
removeSetlangFromHistory();
removeSetLangFromHistory();
return;
}
@@ -140,7 +142,8 @@
$ulsDialog = createSetLangDialog( setLangName, setLangCode );
ulsSetLangDialog = new mw.uls.Dialog( {
container: $ulsDialog,
hasOverlay: true
hasOverlay: true,
afterClose: removeSetLangFromHistory
} );
addSetLangDialogEvents( ulsSetLangDialog );