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
@@ -24,8 +24,7 @@
|
||||
'use strict';
|
||||
|
||||
var ULSDialog = function ( options ) {
|
||||
var noop = function () { },
|
||||
$dialog = options.container,
|
||||
var $dialog = options.container,
|
||||
hasOverlay = options.hasOverlay,
|
||||
$overlay,
|
||||
// Source: https://github.com/ghosh/Micromodal/blob/master/lib/src/index.js#L4
|
||||
@@ -42,8 +41,8 @@
|
||||
'[contenteditable]',
|
||||
'[tabindex]:not([tabindex^="-"])'
|
||||
],
|
||||
afterClose = options.afterClose || noop,
|
||||
afterOpen = options.afterOpen || noop;
|
||||
afterOpen = options.afterOpen,
|
||||
afterClose = options.afterClose;
|
||||
|
||||
function getFocusableNodes() {
|
||||
return $dialog.find( FOCUSABLE_NODES.join( ', ' ) );
|
||||
@@ -159,15 +158,19 @@
|
||||
addEvents();
|
||||
showOverlay();
|
||||
focusFirstNodeOrOverlay();
|
||||
if ( afterOpen ) {
|
||||
afterOpen();
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
$dialog.hide();
|
||||
removeEvents();
|
||||
hideOverlay();
|
||||
if ( afterClose ) {
|
||||
afterClose();
|
||||
}
|
||||
}
|
||||
|
||||
function elem() {
|
||||
return $dialog;
|
||||
|
||||
@@ -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
|
||||
.text( mw.msg( isLoading ? 'ext-uls-setlang-loading' : 'ext-uls-setlang-accept' ) )
|
||||
.prop( 'disabled', isLoading );
|
||||
}
|
||||
|
||||
$btnSubmit.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