mediawiki.util: Remove redundant file closures

Modules loaded with packageFiles are always executed in module scope
(with a closure), even in debug mode.

The behaviour of non-packageFiles debug mode is the only reason files
have closures.

Bug: T50886
Change-Id: I4c553961eab0f665e4ae123e11c92b255367fcfb
This commit is contained in:
Fomafix 2019-09-06 09:48:58 +02:00 committed by Krinkle
parent 8697ba8354
commit 6f5535d3cc
3 changed files with 749 additions and 750 deletions

View file

@ -0,0 +1,5 @@
{
"parserOptions": {
"sourceType": "module"
}
}

View file

@ -3,10 +3,9 @@
*
* @class jQuery.plugin.accessKeyLabel
*/
( function () {
// Cached access key modifiers for used browser
var cachedAccessKeyModifiers,
// Cached access key modifiers for used browser
var cachedAccessKeyModifiers,
// Whether to use 'test-' instead of correct prefix (used for testing)
useTestPrefix = false,
@ -15,7 +14,7 @@
// https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Form-associated_content
labelable = 'button, input, textarea, keygen, meter, output, progress, select';
/**
/**
* Find the modifier keys that need to be pressed together with the accesskey to trigger the input.
*
* The result is dependant on the ua paramater or the current platform.
@ -26,7 +25,7 @@
* @param {Object} [ua] An object with a 'userAgent' and 'platform' property.
* @return {Array} Array with 1 or more of the string values, in this order: ctrl, option, alt, shift, esc
*/
function getAccessKeyModifiers( ua ) {
function getAccessKeyModifiers( ua ) {
var profile, accessKeyModifiers;
// use cached prefix if possible
@ -94,9 +93,9 @@
cachedAccessKeyModifiers = accessKeyModifiers;
}
return accessKeyModifiers;
}
}
/**
/**
* Get the access key label for an element.
*
* Will use native accessKeyLabel if available (currently only in Firefox 8+),
@ -106,7 +105,7 @@
* @param {HTMLElement} element Element to get the label for
* @return {string} Access key label
*/
function getAccessKeyLabel( element ) {
function getAccessKeyLabel( element ) {
// abort early if no access key
if ( !element.accessKey ) {
return '';
@ -117,9 +116,9 @@
return element.accessKeyLabel;
}
return ( useTestPrefix ? 'test' : getAccessKeyModifiers().join( '-' ) ) + '-' + element.accessKey;
}
}
/**
/**
* Update the title for an element (on the element with the access key or it's label) to show
* the correct access key label.
*
@ -127,7 +126,7 @@
* @param {HTMLElement} element Element with the accesskey
* @param {HTMLElement} titleElement Element with the title to update (may be the same as `element`)
*/
function updateTooltipOnElement( element, titleElement ) {
function updateTooltipOnElement( element, titleElement ) {
var oldTitle, parts, regexp, newTitle, accessKeyLabel,
separatorMsg = mw.message( 'word-separator' ).plain();
@ -149,15 +148,15 @@
if ( oldTitle !== newTitle ) {
titleElement.title = newTitle;
}
}
}
/**
/**
* Update the title for an element to show the correct access key label.
*
* @private
* @param {HTMLElement} element Element with the accesskey
*/
function updateTooltip( element ) {
function updateTooltip( element ) {
var id, $element, $label, $labelParent;
updateTooltipOnElement( element, element );
@ -179,37 +178,37 @@
updateTooltipOnElement( element, $labelParent[ 0 ] );
}
}
}
}
/**
/**
* Update the titles for all elements in a jQuery selection.
*
* @return {jQuery}
* @chainable
*/
$.fn.updateTooltipAccessKeys = function () {
$.fn.updateTooltipAccessKeys = function () {
return this.each( function () {
updateTooltip( this );
} );
};
};
/**
/**
* getAccessKeyModifiers
*
* @method updateTooltipAccessKeys_getAccessKeyModifiers
* @inheritdoc #getAccessKeyModifiers
*/
$.fn.updateTooltipAccessKeys.getAccessKeyModifiers = getAccessKeyModifiers;
$.fn.updateTooltipAccessKeys.getAccessKeyModifiers = getAccessKeyModifiers;
/**
/**
* getAccessKeyLabel
*
* @method updateTooltipAccessKeys_getAccessKeyLabel
* @inheritdoc #getAccessKeyLabel
*/
$.fn.updateTooltipAccessKeys.getAccessKeyLabel = getAccessKeyLabel;
$.fn.updateTooltipAccessKeys.getAccessKeyLabel = getAccessKeyLabel;
/**
/**
* getAccessKeyPrefix
*
* @method updateTooltipAccessKeys_getAccessKeyPrefix
@ -217,23 +216,21 @@
* @param {Object} [ua] An object with a 'userAgent' and 'platform' property.
* @return {string}
*/
$.fn.updateTooltipAccessKeys.getAccessKeyPrefix = function ( ua ) {
$.fn.updateTooltipAccessKeys.getAccessKeyPrefix = function ( ua ) {
return getAccessKeyModifiers( ua ).join( '-' ) + '-';
};
};
/**
/**
* Switch test mode on and off.
*
* @method updateTooltipAccessKeys_setTestMode
* @param {boolean} mode New mode
*/
$.fn.updateTooltipAccessKeys.setTestMode = function ( mode ) {
$.fn.updateTooltipAccessKeys.setTestMode = function ( mode ) {
useTestPrefix = mode;
};
};
/**
/**
* @class jQuery
* @mixins jQuery.plugin.accessKeyLabel
*/
}() );

View file

@ -1,26 +1,25 @@
( function () {
'use strict';
'use strict';
var util,
var util,
config = require( './config.json' );
require( './jquery.accessKeyLabel.js' );
require( './jquery.accessKeyLabel.js' );
/**
/**
* Encode the string like PHP's rawurlencode
* @ignore
*
* @param {string} str String to be encoded.
* @return {string} Encoded string
*/
function rawurlencode( str ) {
function rawurlencode( str ) {
str = String( str );
return encodeURIComponent( str )
.replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' )
.replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /~/g, '%7E' );
}
}
/**
/**
* Private helper function used by util.escapeId*()
* @ignore
*
@ -29,7 +28,7 @@
* in DefaultSettings.php
* @return {string} Encoded string
*/
function escapeIdInternal( str, mode ) {
function escapeIdInternal( str, mode ) {
str = String( str );
switch ( mode ) {
@ -42,14 +41,14 @@
default:
throw new Error( 'Unrecognized ID escaping mode ' + mode );
}
}
}
/**
/**
* Utility library
* @class mw.util
* @singleton
*/
util = {
util = {
/**
* Encode the string like PHP's rawurlencode
@ -532,21 +531,21 @@
// eslint-disable-next-line no-useless-escape
return str.replace( /([\\{}()|.?*+\-^$\[\]])/g, '\\$1' );
}
};
};
// Not allowed outside unit tests
if ( window.QUnit ) {
// Not allowed outside unit tests
if ( window.QUnit ) {
util.setOptionsForTest = function ( opts ) {
var oldConfig = config;
config = $.extend( {}, config, opts );
return oldConfig;
};
}
}
/**
/**
* Initialisation of mw.util.$content
*/
function init() {
function init() {
util.$content = ( function () {
var i, l, $node, selectors;
@ -573,11 +572,9 @@
// skin and has not yet inserted bodytext yet.
return $( 'body' );
}() );
}
}
$( init );
$( init );
mw.util = util;
module.exports = util;
}() );
mw.util = util;
module.exports = util;