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:
@@ -24,7 +24,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ULSDialog = function ( options ) {
|
var ULSDialog = function ( options ) {
|
||||||
var $dialog = options.container,
|
var noop = function () { },
|
||||||
|
$dialog = options.container,
|
||||||
hasOverlay = options.hasOverlay,
|
hasOverlay = options.hasOverlay,
|
||||||
$overlay,
|
$overlay,
|
||||||
// Source: https://github.com/ghosh/Micromodal/blob/master/lib/src/index.js#L4
|
// Source: https://github.com/ghosh/Micromodal/blob/master/lib/src/index.js#L4
|
||||||
@@ -40,7 +41,9 @@
|
|||||||
'embed',
|
'embed',
|
||||||
'[contenteditable]',
|
'[contenteditable]',
|
||||||
'[tabindex]:not([tabindex^="-"])'
|
'[tabindex]:not([tabindex^="-"])'
|
||||||
];
|
],
|
||||||
|
afterClose = options.afterClose || noop,
|
||||||
|
afterOpen = options.afterOpen || noop;
|
||||||
|
|
||||||
function getFocusableNodes() {
|
function getFocusableNodes() {
|
||||||
return $dialog.find( FOCUSABLE_NODES.join( ', ' ) );
|
return $dialog.find( FOCUSABLE_NODES.join( ', ' ) );
|
||||||
@@ -156,12 +159,14 @@
|
|||||||
addEvents();
|
addEvents();
|
||||||
showOverlay();
|
showOverlay();
|
||||||
focusFirstNodeOrOverlay();
|
focusFirstNodeOrOverlay();
|
||||||
|
afterOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
$dialog.hide();
|
$dialog.hide();
|
||||||
removeEvents();
|
removeEvents();
|
||||||
hideOverlay();
|
hideOverlay();
|
||||||
|
afterClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
function elem() {
|
function elem() {
|
||||||
|
|||||||
@@ -73,9 +73,12 @@
|
|||||||
return uri.toString();
|
return uri.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeSetlangFromHistory() {
|
function removeSetLangFromHistory() {
|
||||||
var urlWithoutSetlang = removeParam( 'setlang' );
|
var urlWithoutSetLang = removeParam( 'setlang' );
|
||||||
history.replaceState( null, 'no-setlang-url', urlWithoutSetlang );
|
if ( urlWithoutSetLang === mw.Uri().toString() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
history.replaceState( null, 'no-setlang-url', urlWithoutSetLang );
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLanguage( langCode ) {
|
function updateLanguage( langCode ) {
|
||||||
@@ -120,7 +123,6 @@
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
$cancelBtn.on( 'click', function () {
|
$cancelBtn.on( 'click', function () {
|
||||||
removeSetlangFromHistory();
|
|
||||||
ulsDialog.close();
|
ulsDialog.close();
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
@@ -132,7 +134,7 @@
|
|||||||
$ulsDialog, ulsSetLangDialog;
|
$ulsDialog, ulsSetLangDialog;
|
||||||
|
|
||||||
if ( currentLangCode === setLangCode ) {
|
if ( currentLangCode === setLangCode ) {
|
||||||
removeSetlangFromHistory();
|
removeSetLangFromHistory();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +142,8 @@
|
|||||||
$ulsDialog = createSetLangDialog( setLangName, setLangCode );
|
$ulsDialog = createSetLangDialog( setLangName, setLangCode );
|
||||||
ulsSetLangDialog = new mw.uls.Dialog( {
|
ulsSetLangDialog = new mw.uls.Dialog( {
|
||||||
container: $ulsDialog,
|
container: $ulsDialog,
|
||||||
hasOverlay: true
|
hasOverlay: true,
|
||||||
|
afterClose: removeSetLangFromHistory
|
||||||
} );
|
} );
|
||||||
|
|
||||||
addSetLangDialogEvents( ulsSetLangDialog );
|
addSetLangDialogEvents( ulsSetLangDialog );
|
||||||
|
|||||||
Reference in New Issue
Block a user