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,237 +3,234 @@
* *
* @class jQuery.plugin.accessKeyLabel * @class jQuery.plugin.accessKeyLabel
*/ */
( function () {
// Cached access key modifiers for used browser // Cached access key modifiers for used browser
var cachedAccessKeyModifiers, var cachedAccessKeyModifiers,
// Whether to use 'test-' instead of correct prefix (used for testing) // Whether to use 'test-' instead of correct prefix (used for testing)
useTestPrefix = false, useTestPrefix = false,
// tag names which can have a label tag // tag names which can have a label tag
// https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Form-associated_content // https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Form-associated_content
labelable = 'button, input, textarea, keygen, meter, output, progress, select'; 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. * 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. * The result is dependant on the ua paramater or the current platform.
* For browsers that support accessKeyLabel, #getAccessKeyLabel never calls here. * For browsers that support accessKeyLabel, #getAccessKeyLabel never calls here.
* Valid key values that are returned can be: ctrl, alt, option, shift, esc * Valid key values that are returned can be: ctrl, alt, option, shift, esc
* *
* @private * @private
* @param {Object} [ua] An object with a 'userAgent' and 'platform' property. * @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 * @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; var profile, accessKeyModifiers;
// use cached prefix if possible // use cached prefix if possible
if ( !ua && cachedAccessKeyModifiers ) { if ( !ua && cachedAccessKeyModifiers ) {
return cachedAccessKeyModifiers; return cachedAccessKeyModifiers;
} }
profile = $.client.profile( ua ); profile = $.client.profile( ua );
switch ( profile.name ) { switch ( profile.name ) {
case 'chrome': case 'chrome':
case 'opera': case 'opera':
if ( profile.name === 'opera' && profile.versionNumber < 15 ) { if ( profile.name === 'opera' && profile.versionNumber < 15 ) {
accessKeyModifiers = [ 'shift', 'esc' ]; accessKeyModifiers = [ 'shift', 'esc' ];
} else if ( profile.platform === 'mac' ) { } else if ( profile.platform === 'mac' ) {
accessKeyModifiers = [ 'ctrl', 'option' ]; accessKeyModifiers = [ 'ctrl', 'option' ];
} else {
// Chrome/Opera on Windows or Linux
// (both alt- and alt-shift work, but alt with E, D, F etc does not
// work since they are browser shortcuts)
accessKeyModifiers = [ 'alt', 'shift' ];
}
break;
case 'firefox':
case 'iceweasel':
if ( profile.versionBase < 2 ) {
// Before v2, Firefox used alt, though it was rebindable in about:config
accessKeyModifiers = [ 'alt' ];
} else {
if ( profile.platform === 'mac' ) {
if ( profile.versionNumber < 14 ) {
accessKeyModifiers = [ 'ctrl' ];
} else {
accessKeyModifiers = [ 'ctrl', 'option' ];
}
} else { } else {
// Chrome/Opera on Windows or Linux
// (both alt- and alt-shift work, but alt with E, D, F etc does not
// work since they are browser shortcuts)
accessKeyModifiers = [ 'alt', 'shift' ]; accessKeyModifiers = [ 'alt', 'shift' ];
} }
break; }
case 'firefox': break;
case 'iceweasel': case 'safari':
if ( profile.versionBase < 2 ) { case 'konqueror':
// Before v2, Firefox used alt, though it was rebindable in about:config if ( profile.platform === 'win' ) {
accessKeyModifiers = [ 'alt' ];
} else {
if ( profile.platform === 'mac' ) {
if ( profile.versionNumber < 14 ) {
accessKeyModifiers = [ 'ctrl' ];
} else {
accessKeyModifiers = [ 'ctrl', 'option' ];
}
} else {
accessKeyModifiers = [ 'alt', 'shift' ];
}
}
break;
case 'safari':
case 'konqueror':
if ( profile.platform === 'win' ) {
accessKeyModifiers = [ 'alt' ];
} else {
if ( profile.layoutVersion > 526 ) {
// Non-Windows Safari with webkit_version > 526
accessKeyModifiers = [ 'ctrl', profile.platform === 'mac' ? 'option' : 'alt' ];
} else {
accessKeyModifiers = [ 'ctrl' ];
}
}
break;
case 'msie':
case 'edge':
accessKeyModifiers = [ 'alt' ]; accessKeyModifiers = [ 'alt' ];
break; } else {
default: if ( profile.layoutVersion > 526 ) {
accessKeyModifiers = profile.platform === 'mac' ? [ 'ctrl' ] : [ 'alt' ]; // Non-Windows Safari with webkit_version > 526
break; accessKeyModifiers = [ 'ctrl', profile.platform === 'mac' ? 'option' : 'alt' ];
} } else {
accessKeyModifiers = [ 'ctrl' ];
// cache modifiers
if ( !ua ) {
cachedAccessKeyModifiers = accessKeyModifiers;
}
return accessKeyModifiers;
}
/**
* Get the access key label for an element.
*
* Will use native accessKeyLabel if available (currently only in Firefox 8+),
* falls back to #getAccessKeyModifiers.
*
* @private
* @param {HTMLElement} element Element to get the label for
* @return {string} Access key label
*/
function getAccessKeyLabel( element ) {
// abort early if no access key
if ( !element.accessKey ) {
return '';
}
// use accessKeyLabel if possible
// https://html.spec.whatwg.org/multipage/interaction.html#dom-accesskeylabel
if ( !useTestPrefix && element.accessKeyLabel ) {
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.
*
* @private
* @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 ) {
var oldTitle, parts, regexp, newTitle, accessKeyLabel,
separatorMsg = mw.message( 'word-separator' ).plain();
oldTitle = titleElement.title;
if ( !oldTitle ) {
// don't add a title if the element didn't have one before
return;
}
parts = ( separatorMsg + mw.message( 'brackets' ).plain() ).split( '$1' );
regexp = new RegExp( parts.map( mw.util.escapeRegExp ).join( '.*?' ) + '$' );
newTitle = oldTitle.replace( regexp, '' );
accessKeyLabel = getAccessKeyLabel( element );
if ( accessKeyLabel ) {
// Should be build the same as in Linker::titleAttrib
newTitle += separatorMsg + mw.message( 'brackets', accessKeyLabel ).plain();
}
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 ) {
var id, $element, $label, $labelParent;
updateTooltipOnElement( element, element );
// update associated label if there is one
$element = $( element );
if ( $element.is( labelable ) ) {
// Search it using 'for' attribute
id = element.id.replace( /"/g, '\\"' );
if ( id ) {
$label = $( 'label[for="' + id + '"]' );
if ( $label.length === 1 ) {
updateTooltipOnElement( element, $label[ 0 ] );
} }
} }
break;
// Search it as parent, because the form control can also be inside the label element itself case 'msie':
$labelParent = $element.parents( 'label' ); case 'edge':
if ( $labelParent.length === 1 ) { accessKeyModifiers = [ 'alt' ];
updateTooltipOnElement( element, $labelParent[ 0 ] ); break;
} default:
} accessKeyModifiers = profile.platform === 'mac' ? [ 'ctrl' ] : [ 'alt' ];
break;
} }
/** // cache modifiers
* Update the titles for all elements in a jQuery selection. if ( !ua ) {
* cachedAccessKeyModifiers = accessKeyModifiers;
* @return {jQuery} }
* @chainable return accessKeyModifiers;
*/ }
$.fn.updateTooltipAccessKeys = function () {
return this.each( function () {
updateTooltip( this );
} );
};
/** /**
* getAccessKeyModifiers * Get the access key label for an element.
* *
* @method updateTooltipAccessKeys_getAccessKeyModifiers * Will use native accessKeyLabel if available (currently only in Firefox 8+),
* @inheritdoc #getAccessKeyModifiers * falls back to #getAccessKeyModifiers.
*/ *
$.fn.updateTooltipAccessKeys.getAccessKeyModifiers = getAccessKeyModifiers; * @private
* @param {HTMLElement} element Element to get the label for
* @return {string} Access key label
*/
function getAccessKeyLabel( element ) {
// abort early if no access key
if ( !element.accessKey ) {
return '';
}
// use accessKeyLabel if possible
// https://html.spec.whatwg.org/multipage/interaction.html#dom-accesskeylabel
if ( !useTestPrefix && element.accessKeyLabel ) {
return element.accessKeyLabel;
}
return ( useTestPrefix ? 'test' : getAccessKeyModifiers().join( '-' ) ) + '-' + element.accessKey;
}
/** /**
* getAccessKeyLabel * Update the title for an element (on the element with the access key or it's label) to show
* * the correct access key label.
* @method updateTooltipAccessKeys_getAccessKeyLabel *
* @inheritdoc #getAccessKeyLabel * @private
*/ * @param {HTMLElement} element Element with the accesskey
$.fn.updateTooltipAccessKeys.getAccessKeyLabel = getAccessKeyLabel; * @param {HTMLElement} titleElement Element with the title to update (may be the same as `element`)
*/
function updateTooltipOnElement( element, titleElement ) {
var oldTitle, parts, regexp, newTitle, accessKeyLabel,
separatorMsg = mw.message( 'word-separator' ).plain();
/** oldTitle = titleElement.title;
* getAccessKeyPrefix if ( !oldTitle ) {
* // don't add a title if the element didn't have one before
* @method updateTooltipAccessKeys_getAccessKeyPrefix return;
* @deprecated since 1.27 Use #getAccessKeyModifiers }
* @param {Object} [ua] An object with a 'userAgent' and 'platform' property.
* @return {string}
*/
$.fn.updateTooltipAccessKeys.getAccessKeyPrefix = function ( ua ) {
return getAccessKeyModifiers( ua ).join( '-' ) + '-';
};
/** parts = ( separatorMsg + mw.message( 'brackets' ).plain() ).split( '$1' );
* Switch test mode on and off. regexp = new RegExp( parts.map( mw.util.escapeRegExp ).join( '.*?' ) + '$' );
* newTitle = oldTitle.replace( regexp, '' );
* @method updateTooltipAccessKeys_setTestMode accessKeyLabel = getAccessKeyLabel( element );
* @param {boolean} mode New mode
*/
$.fn.updateTooltipAccessKeys.setTestMode = function ( mode ) {
useTestPrefix = mode;
};
/** if ( accessKeyLabel ) {
* @class jQuery // Should be build the same as in Linker::titleAttrib
* @mixins jQuery.plugin.accessKeyLabel newTitle += separatorMsg + mw.message( 'brackets', accessKeyLabel ).plain();
*/ }
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 ) {
var id, $element, $label, $labelParent;
updateTooltipOnElement( element, element );
// update associated label if there is one
$element = $( element );
if ( $element.is( labelable ) ) {
// Search it using 'for' attribute
id = element.id.replace( /"/g, '\\"' );
if ( id ) {
$label = $( 'label[for="' + id + '"]' );
if ( $label.length === 1 ) {
updateTooltipOnElement( element, $label[ 0 ] );
}
}
// Search it as parent, because the form control can also be inside the label element itself
$labelParent = $element.parents( 'label' );
if ( $labelParent.length === 1 ) {
updateTooltipOnElement( element, $labelParent[ 0 ] );
}
}
}
/**
* Update the titles for all elements in a jQuery selection.
*
* @return {jQuery}
* @chainable
*/
$.fn.updateTooltipAccessKeys = function () {
return this.each( function () {
updateTooltip( this );
} );
};
/**
* getAccessKeyModifiers
*
* @method updateTooltipAccessKeys_getAccessKeyModifiers
* @inheritdoc #getAccessKeyModifiers
*/
$.fn.updateTooltipAccessKeys.getAccessKeyModifiers = getAccessKeyModifiers;
/**
* getAccessKeyLabel
*
* @method updateTooltipAccessKeys_getAccessKeyLabel
* @inheritdoc #getAccessKeyLabel
*/
$.fn.updateTooltipAccessKeys.getAccessKeyLabel = getAccessKeyLabel;
/**
* getAccessKeyPrefix
*
* @method updateTooltipAccessKeys_getAccessKeyPrefix
* @deprecated since 1.27 Use #getAccessKeyModifiers
* @param {Object} [ua] An object with a 'userAgent' and 'platform' property.
* @return {string}
*/
$.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 ) {
useTestPrefix = mode;
};
/**
* @class jQuery
* @mixins jQuery.plugin.accessKeyLabel
*/

File diff suppressed because it is too large Load diff