diff --git a/resources/js/ext.uls.interface.js b/resources/js/ext.uls.interface.js index 1518afee..21388217 100644 --- a/resources/js/ext.uls.interface.js +++ b/resources/js/ext.uls.interface.js @@ -57,11 +57,11 @@ * on the contents of the page. * For other skins, check if ULSDisplayInputAndDisplaySettingsInInterlanguage contains the current skin. * - * @return {bool} + * @return {boolean} */ function isUsingStandaloneLanguageButton() { 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 : mw.config.get( 'wgULSDisplaySettingsInInterlanguage' ); } @@ -118,33 +118,30 @@ * @param {string} previousAutonym */ function showUndoTooltip( previousLang, previousAutonym ) { - var $ulsTrigger, ulsPopup, ulsPopupPosition, - ulsPosition = mw.config.get( 'wgULSPosition' ); - - $ulsTrigger = ( ulsPosition === 'interlanguage' ) ? - $( '.uls-settings-trigger, .mw-interlanguage-selector' ) : - $( '.uls-trigger' ); + var trigger, popup, popupPosition, + configPosition = mw.config.get( 'wgULSPosition' ), + triggerSelector = ( configPosition === 'interlanguage' ) ? + '.uls-settings-trigger, .mw-interlanguage-selector' : + '.uls-trigger'; // Fallback if no entry point is present - if ( !$ulsTrigger.length ) { - $ulsTrigger = $( '#pt-preferences' ); - } + trigger = document.querySelector( triggerSelector ) || document.querySelector( '#pt-preferences' ); // Skip tooltip if there is no element to attach the tooltip to. // It will cause errors otherwise. - if ( !$ulsTrigger.length ) { + if ( !trigger ) { return; } function hideTipsy() { - ulsPopup.toggle( false ); + popup.toggle( false ); } function showTipsy( timeout ) { var tipsyTimer = 0; - ulsPopup.toggle( true ); - ulsPopup.toggleClipping( false ); + popup.toggle( true ); + popup.toggleClipping( false ); // if the mouse is over the tooltip, do not hide $( '.uls-tipsy' ).on( 'mouseover', function () { @@ -156,18 +153,18 @@ tipsyTimer = setTimeout( hideTipsy, timeout ); } - if ( ulsPosition === 'interlanguage' ) { - ulsPopupPosition = 'after'; + if ( configPosition === 'interlanguage' ) { + popupPosition = 'after'; } else { - ulsPopupPosition = 'below'; + popupPosition = 'below'; } - ulsPopup = new OO.ui.PopupWidget( { + popup = new OO.ui.PopupWidget( { padded: true, width: 300, classes: [ 'uls-tipsy' ], // Automatically positioned relative to the trigger - $floatableContainer: $ulsTrigger, - position: ulsPopupPosition, + $floatableContainer: $( trigger ), + position: popupPosition, $content: ( function () { 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 setTimeout( function () { @@ -215,7 +212,7 @@ }, 700 ); // manually show the tooltip - $ulsTrigger.on( 'mouseover', function () { + $( trigger ).on( 'mouseover', function () { // show only if the ULS panel is not shown // eslint-disable-next-line no-jquery/no-sizzle if ( !$( '.uls-menu:visible' ).length ) { @@ -228,6 +225,7 @@ * Adds display and input settings to the ULS dialog after loading their code. * * @param {ULS} uls instance + * @return {jQuery.Promise} */ function loadDisplayAndInputSettings( uls ) { return mw.loader.using( languageSettingsModules ).then( function () { @@ -239,24 +237,25 @@ function initInterface() { var $pLang, 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(), - $ulsTrigger = $( '.uls-trigger' ), + $trigger = $( '.uls-trigger' ), anonMode = ( mw.user.isAnon() && !mw.config.get( 'wgULSAnonCanChangeLanguage' ) ), - ulsPosition = mw.config.get( 'wgULSPosition' ); + configPosition = mw.config.get( 'wgULSPosition' ); - if ( ulsPosition === 'interlanguage' ) { + if ( configPosition === 'interlanguage' ) { // TODO: Refactor this block // The interlanguage links section. $pLang = $( '#p-lang' ); // Add an element near the interlanguage links header - $ulsTrigger = $( '