ext.uls.interface: remove some needless uses of jQuery

* $(node).prop(foo) -> node.foo

* For objects only expected to represent a single element,
  use native querySelector() and its natural null return
  fallback, instead of `$(), $.length, $()` etc.

* Fix a few minor non-voting eslint warnings that were in the CI
  output about line length and unknown type "bool".

* Remove presumed outdated comment about Vector splitting,
  per T234907.

* Rename ulsPosition to configPosition to be more clearly
  different from ulsPopupPosition.

* Remove various 'uls' prefixes of local variables,
  since this is ULS code in the ULS repository.

Change-Id: I1c617bf48283f47dc948550111c515faf173d1eb
This commit is contained in:
Timo Tijhof
2021-04-15 02:16:30 +01:00
committed by Krinkle
parent 7b2338cef5
commit 977e6c68c2

View File

@@ -57,11 +57,11 @@
* on the contents of the page. * on the contents of the page.
* For other skins, check if ULSDisplayInputAndDisplaySettingsInInterlanguage contains the current skin. * For other skins, check if ULSDisplayInputAndDisplaySettingsInInterlanguage contains the current skin.
* *
* @return {bool} * @return {boolean}
*/ */
function isUsingStandaloneLanguageButton() { function isUsingStandaloneLanguageButton() {
var skin = mw.config.get( 'skin' ); var skin = mw.config.get( 'skin' );
// special handling for Vector. This can be removed when Vector is split into 2 separate skins. // special handling for Vector.
return skin === 'vector' ? $( '#p-lang-btn' ).length > 0 : return skin === 'vector' ? $( '#p-lang-btn' ).length > 0 :
mw.config.get( 'wgULSDisplaySettingsInInterlanguage' ); mw.config.get( 'wgULSDisplaySettingsInInterlanguage' );
} }
@@ -118,33 +118,30 @@
* @param {string} previousAutonym * @param {string} previousAutonym
*/ */
function showUndoTooltip( previousLang, previousAutonym ) { function showUndoTooltip( previousLang, previousAutonym ) {
var $ulsTrigger, ulsPopup, ulsPopupPosition, var trigger, popup, popupPosition,
ulsPosition = mw.config.get( 'wgULSPosition' ); configPosition = mw.config.get( 'wgULSPosition' ),
triggerSelector = ( configPosition === 'interlanguage' ) ?
$ulsTrigger = ( ulsPosition === 'interlanguage' ) ? '.uls-settings-trigger, .mw-interlanguage-selector' :
$( '.uls-settings-trigger, .mw-interlanguage-selector' ) : '.uls-trigger';
$( '.uls-trigger' );
// Fallback if no entry point is present // Fallback if no entry point is present
if ( !$ulsTrigger.length ) { trigger = document.querySelector( triggerSelector ) || document.querySelector( '#pt-preferences' );
$ulsTrigger = $( '#pt-preferences' );
}
// Skip tooltip if there is no element to attach the tooltip to. // Skip tooltip if there is no element to attach the tooltip to.
// It will cause errors otherwise. // It will cause errors otherwise.
if ( !$ulsTrigger.length ) { if ( !trigger ) {
return; return;
} }
function hideTipsy() { function hideTipsy() {
ulsPopup.toggle( false ); popup.toggle( false );
} }
function showTipsy( timeout ) { function showTipsy( timeout ) {
var tipsyTimer = 0; var tipsyTimer = 0;
ulsPopup.toggle( true ); popup.toggle( true );
ulsPopup.toggleClipping( false ); popup.toggleClipping( false );
// if the mouse is over the tooltip, do not hide // if the mouse is over the tooltip, do not hide
$( '.uls-tipsy' ).on( 'mouseover', function () { $( '.uls-tipsy' ).on( 'mouseover', function () {
@@ -156,18 +153,18 @@
tipsyTimer = setTimeout( hideTipsy, timeout ); tipsyTimer = setTimeout( hideTipsy, timeout );
} }
if ( ulsPosition === 'interlanguage' ) { if ( configPosition === 'interlanguage' ) {
ulsPopupPosition = 'after'; popupPosition = 'after';
} else { } else {
ulsPopupPosition = 'below'; popupPosition = 'below';
} }
ulsPopup = new OO.ui.PopupWidget( { popup = new OO.ui.PopupWidget( {
padded: true, padded: true,
width: 300, width: 300,
classes: [ 'uls-tipsy' ], classes: [ 'uls-tipsy' ],
// Automatically positioned relative to the trigger // Automatically positioned relative to the trigger
$floatableContainer: $ulsTrigger, $floatableContainer: $( trigger ),
position: ulsPopupPosition, position: popupPosition,
$content: ( function () { $content: ( function () {
var messageKey, $link; var messageKey, $link;
@@ -206,7 +203,7 @@
}() ) }() )
} ); } );
ulsPopup.$element.appendTo( document.body ); popup.$element.appendTo( document.body );
// The interlanguage position needs some time to settle down // The interlanguage position needs some time to settle down
setTimeout( function () { setTimeout( function () {
@@ -215,7 +212,7 @@
}, 700 ); }, 700 );
// manually show the tooltip // manually show the tooltip
$ulsTrigger.on( 'mouseover', function () { $( trigger ).on( 'mouseover', function () {
// show only if the ULS panel is not shown // show only if the ULS panel is not shown
// eslint-disable-next-line no-jquery/no-sizzle // eslint-disable-next-line no-jquery/no-sizzle
if ( !$( '.uls-menu:visible' ).length ) { if ( !$( '.uls-menu:visible' ).length ) {
@@ -228,6 +225,7 @@
* Adds display and input settings to the ULS dialog after loading their code. * Adds display and input settings to the ULS dialog after loading their code.
* *
* @param {ULS} uls instance * @param {ULS} uls instance
* @return {jQuery.Promise}
*/ */
function loadDisplayAndInputSettings( uls ) { function loadDisplayAndInputSettings( uls ) {
return mw.loader.using( languageSettingsModules ).then( function () { return mw.loader.using( languageSettingsModules ).then( function () {
@@ -239,24 +237,25 @@
function initInterface() { function initInterface() {
var $pLang, var $pLang,
clickHandler, clickHandler,
// T273928: No change to the heading should be made in modern Vector when the language button is present // T273928: No change to the heading should be made in modern Vector when the language
// button is present
isButton = isUsingStandaloneLanguageButton(), isButton = isUsingStandaloneLanguageButton(),
$ulsTrigger = $( '.uls-trigger' ), $trigger = $( '.uls-trigger' ),
anonMode = ( mw.user.isAnon() && anonMode = ( mw.user.isAnon() &&
!mw.config.get( 'wgULSAnonCanChangeLanguage' ) ), !mw.config.get( 'wgULSAnonCanChangeLanguage' ) ),
ulsPosition = mw.config.get( 'wgULSPosition' ); configPosition = mw.config.get( 'wgULSPosition' );
if ( ulsPosition === 'interlanguage' ) { if ( configPosition === 'interlanguage' ) {
// TODO: Refactor this block // TODO: Refactor this block
// The interlanguage links section. // The interlanguage links section.
$pLang = $( '#p-lang' ); $pLang = $( '#p-lang' );
// Add an element near the interlanguage links header // Add an element near the interlanguage links header
$ulsTrigger = $( '<button>' ) $trigger = $( '<button>' )
.addClass( 'uls-settings-trigger' ); .addClass( 'uls-settings-trigger' );
// Append ULS cog to languages section. // Append ULS cog to languages section.
$pLang.prepend( $ulsTrigger ); $pLang.prepend( $trigger );
// Take care of any other elements with this class. // Take care of any other elements with this class.
$ulsTrigger = $( '.uls-settings-trigger' ); $trigger = $( '.uls-settings-trigger' );
if ( !$pLang.find( 'div ul' ).children().length && isButton ) { if ( !$pLang.find( 'div ul' ).children().length && isButton ) {
// Replace the title of the interlanguage links area // Replace the title of the interlanguage links area
@@ -265,12 +264,12 @@
.text( mw.msg( 'uls-plang-title-languages' ) ); .text( mw.msg( 'uls-plang-title-languages' ) );
} }
$ulsTrigger.attr( { $trigger.attr( {
title: mw.msg( 'ext-uls-select-language-settings-icon-tooltip' ) title: mw.msg( 'ext-uls-select-language-settings-icon-tooltip' )
} ); } );
clickHandler = function ( e, eventParams ) { clickHandler = function ( e, eventParams ) {
var languagesettings = $ulsTrigger.data( 'languagesettings' ), var languagesettings = $trigger.data( 'languagesettings' ),
languageSettingsOptions; languageSettingsOptions;
if ( languagesettings ) { if ( languagesettings ) {
@@ -316,14 +315,14 @@
}; };
mw.loader.using( languageSettingsModules, function () { mw.loader.using( languageSettingsModules, function () {
$ulsTrigger.languagesettings( languageSettingsOptions ).trigger( 'click' ); $trigger.languagesettings( languageSettingsOptions ).trigger( 'click' );
} ); } );
e.stopPropagation(); e.stopPropagation();
}; };
} else if ( anonMode ) { } else if ( anonMode ) {
clickHandler = function ( e, eventParams ) { clickHandler = function ( e, eventParams ) {
var languagesettings = $ulsTrigger.data( 'languagesettings' ); var languagesettings = $trigger.data( 'languagesettings' );
e.preventDefault(); e.preventDefault();
@@ -333,15 +332,15 @@
} }
} else { } else {
mw.loader.using( languageSettingsModules, function () { mw.loader.using( languageSettingsModules, function () {
$ulsTrigger.languagesettings(); $trigger.languagesettings();
$ulsTrigger.trigger( 'click', eventParams ); $trigger.trigger( 'click', eventParams );
} ); } );
} }
}; };
} else { } else {
clickHandler = function ( e, eventParams ) { clickHandler = function ( e, eventParams ) {
var uls = $ulsTrigger.data( 'uls' ); var uls = $trigger.data( 'uls' );
e.preventDefault(); e.preventDefault();
@@ -351,7 +350,7 @@
} }
} else { } else {
mw.loader.using( 'ext.uls.mediawiki', function () { mw.loader.using( 'ext.uls.mediawiki', function () {
$ulsTrigger.uls( { $trigger.uls( {
quickList: function () { quickList: function () {
return mw.uls.getFrequentLanguageList(); return mw.uls.getFrequentLanguageList();
}, },
@@ -374,14 +373,14 @@
// Allow styles to apply first and position to work by // Allow styles to apply first and position to work by
// delaying the activation after them. // delaying the activation after them.
setTimeout( function () { setTimeout( function () {
$ulsTrigger.trigger( 'click', eventParams ); $trigger.trigger( 'click', eventParams );
}, 0 ); }, 0 );
} ); } );
} }
}; };
} }
$ulsTrigger.on( 'click', clickHandler ); $trigger.on( 'click', clickHandler );
// Bind language settings to preferences page link // Bind language settings to preferences page link
$( '#uls-preferences-link' ) $( '#uls-preferences-link' )
@@ -390,7 +389,7 @@
e.type === 'click' || e.type === 'click' ||
e.type === 'keypress' && e.which === 13 e.type === 'keypress' && e.which === 13
) { ) {
$ulsTrigger.trigger( 'click', { $trigger.trigger( 'click', {
source: 'preferences' source: 'preferences'
} ); } );
} }
@@ -475,8 +474,8 @@
// Trigger the click handler to open ULS once ready // Trigger the click handler to open ULS once ready
if ( standalone ) { if ( standalone ) {
// Provide access to display and input settings if this entry point is the single point // Provide access to display and input settings if this entry point is the single
// of access to all language settings. // point of access to all language settings.
uls = $target.data( 'uls' ); uls = $target.data( 'uls' );
loadDisplayAndInputSettings( uls ).always( function () { loadDisplayAndInputSettings( uls ).always( function () {
$target.trigger( 'click' ); $target.trigger( 'click' );