diff --git a/resources/src/jquery/jquery.suggestions.js b/resources/src/jquery/jquery.suggestions.js index 31afe3e9d1b..7e8053591ae 100644 --- a/resources/src/jquery/jquery.suggestions.js +++ b/resources/src/jquery/jquery.suggestions.js @@ -230,65 +230,69 @@ * Highlight a result in the results table * * @param {Object} context - * @param {jQuery|string} result `` to highlight, or 'prev' or 'next' + * @param {jQuery|string} $result `` to highlight, or 'prev' or 'next' * @param {boolean} updateTextbox If true, put the suggestion in the textbox */ - function highlight( context, result, updateTextbox ) { - var selected = context.data.$container.find( '.suggestions-result-current' ); - if ( !result.get || selected.get( 0 ) !== result.get( 0 ) ) { - if ( result === 'prev' ) { - if ( selected.hasClass( 'suggestions-special' ) ) { - result = context.data.$container.find( '.suggestions-result' ).last(); + function highlight( context, $result, updateTextbox ) { + var $selected = context.data.$container.find( '.suggestions-result-current' ); + if ( !$result.get || $selected.get( 0 ) !== $result.get( 0 ) ) { + if ( $result === 'prev' ) { + // eslint-disable-next-line no-jquery/no-class-state + if ( $selected.hasClass( 'suggestions-special' ) ) { + $result = context.data.$container.find( '.suggestions-result' ).last(); } else { - result = selected.prev(); - if ( !( result.length && result.hasClass( 'suggestions-result' ) ) ) { + $result = $selected.prev(); + // eslint-disable-next-line no-jquery/no-class-state + if ( !( $result.length && $result.hasClass( 'suggestions-result' ) ) ) { // there is something in the DOM between selected element and the wrapper, bypass it - result = selected.parents( '.suggestions-results > *' ).prev().find( '.suggestions-result' ).eq( 0 ); + $result = $selected.parents( '.suggestions-results > *' ).prev().find( '.suggestions-result' ).eq( 0 ); } - if ( selected.length === 0 ) { + if ( $selected.length === 0 ) { // we are at the beginning, so lets jump to the last item if ( context.data.$container.find( '.suggestions-special' ).html() !== '' ) { - result = context.data.$container.find( '.suggestions-special' ); + $result = context.data.$container.find( '.suggestions-special' ); } else { - result = context.data.$container.find( '.suggestions-results .suggestions-result' ).last(); + $result = context.data.$container.find( '.suggestions-results .suggestions-result' ).last(); } } } - } else if ( result === 'next' ) { - if ( selected.length === 0 ) { + } else if ( $result === 'next' ) { + if ( $selected.length === 0 ) { // No item selected, go to the first one - result = context.data.$container.find( '.suggestions-results .suggestions-result' ).first(); - if ( result.length === 0 && context.data.$container.find( '.suggestions-special' ).html() !== '' ) { + $result = context.data.$container.find( '.suggestions-results .suggestions-result' ).first(); + if ( $result.length === 0 && context.data.$container.find( '.suggestions-special' ).html() !== '' ) { // No suggestion exists, go to the special one directly - result = context.data.$container.find( '.suggestions-special' ); + $result = context.data.$container.find( '.suggestions-special' ); } } else { - result = selected.next(); - if ( !( result.length && result.hasClass( 'suggestions-result' ) ) ) { + $result = $selected.next(); + // eslint-disable-next-line no-jquery/no-class-state + if ( !( $result.length && $result.hasClass( 'suggestions-result' ) ) ) { // there is something in the DOM between selected element and the wrapper, bypass it - result = selected.parents( '.suggestions-results > *' ).next().find( '.suggestions-result' ).eq( 0 ); + $result = $selected.parents( '.suggestions-results > *' ).next().find( '.suggestions-result' ).eq( 0 ); } - if ( selected.hasClass( 'suggestions-special' ) ) { - result = $( [] ); + // eslint-disable-next-line no-jquery/no-class-state + if ( $selected.hasClass( 'suggestions-special' ) ) { + $result = $( [] ); } else if ( - result.length === 0 && + $result.length === 0 && context.data.$container.find( '.suggestions-special' ).html() !== '' ) { // We were at the last item, jump to the specials! - result = context.data.$container.find( '.suggestions-special' ); + $result = context.data.$container.find( '.suggestions-special' ); } } } - selected.removeClass( 'suggestions-result-current' ); - result.addClass( 'suggestions-result-current' ); + $selected.removeClass( 'suggestions-result-current' ); + $result.addClass( 'suggestions-result-current' ); } if ( updateTextbox ) { - if ( result.length === 0 || result.is( '.suggestions-special' ) ) { + if ( $result.length === 0 || $result.is( '.suggestions-special' ) ) { restore( context ); } else { - context.data.$textbox.val( result.data( 'text' ) ); + context.data.$textbox.val( $result.data( 'text' ) ); // .val() doesn't call any event handlers, so // let the world know what happened context.data.$textbox.trigger( 'change' ); @@ -508,7 +512,7 @@ * @param {number} key Code of key pressed */ function keypress( e, context, key ) { - var selected, + var $selected, // eslint-disable-next-line no-jquery/no-sizzle wasVisible = context.data.$container.is( ':visible' ), preventDefault = false; @@ -543,25 +547,25 @@ // Enter case 13: preventDefault = wasVisible; - selected = context.data.$container.find( '.suggestions-result-current' ); + $selected = context.data.$container.find( '.suggestions-result-current' ); hide( context ); - if ( selected.length === 0 || context.data.selectedWithMouse ) { + if ( $selected.length === 0 || context.data.selectedWithMouse ) { // If nothing is selected or if something was selected with the mouse // cancel any current requests and allow the form to be submitted // (simply don't prevent default behavior). cancel( context ); preventDefault = false; - } else if ( selected.is( '.suggestions-special' ) ) { + } else if ( $selected.is( '.suggestions-special' ) ) { if ( typeof context.config.special.select === 'function' ) { // Allow the callback to decide whether to prevent default or not - if ( context.config.special.select.call( selected, context.data.$textbox, 'keyboard' ) === true ) { + if ( context.config.special.select.call( $selected, context.data.$textbox, 'keyboard' ) === true ) { preventDefault = false; } } } else { if ( typeof context.config.result.select === 'function' ) { // Allow the callback to decide whether to prevent default or not - if ( context.config.result.select.call( selected, context.data.$textbox, 'keyboard' ) === true ) { + if ( context.config.result.select.call( $selected, context.data.$textbox, 'keyboard' ) === true ) { preventDefault = false; } } @@ -644,7 +648,7 @@ visibleResults: 0, // Suggestion the last mousedown event occurred on - mouseDownOn: $( [] ), + $mouseDownOn: $( [] ), $textbox: $( this ), selectedWithMouse: false }; @@ -658,13 +662,13 @@ // textbox loses focus. Instead, listen for a mousedown followed // by a mouseup on the same div. .on( 'mousedown', function ( e ) { - context.data.mouseDownOn = $( e.target ).closest( '.suggestions-results .suggestions-result' ); + context.data.$mouseDownOn = $( e.target ).closest( '.suggestions-results .suggestions-result' ); } ) .on( 'mouseup', function ( e ) { var $result = $( e.target ).closest( '.suggestions-results .suggestions-result' ), - $other = context.data.mouseDownOn; + $other = context.data.$mouseDownOn; - context.data.mouseDownOn = $( [] ); + context.data.$mouseDownOn = $( [] ); if ( $result.get( 0 ) !== $other.get( 0 ) ) { return; } @@ -691,13 +695,13 @@ // textbox loses focus. Instead, listen for a mousedown followed // by a mouseup on the same div. .on( 'mousedown', function ( e ) { - context.data.mouseDownOn = $( e.target ).closest( '.suggestions-special' ); + context.data.$mouseDownOn = $( e.target ).closest( '.suggestions-special' ); } ) .on( 'mouseup', function ( e ) { var $special = $( e.target ).closest( '.suggestions-special' ), - $other = context.data.mouseDownOn; + $other = context.data.$mouseDownOn; - context.data.mouseDownOn = $( [] ); + context.data.$mouseDownOn = $( [] ); if ( $special.get( 0 ) !== $other.get( 0 ) ) { return; } @@ -761,7 +765,7 @@ .on( 'blur', function () { // When losing focus because of a mousedown // on a suggestion, don't hide the suggestions - if ( context.data.mouseDownOn.length > 0 ) { + if ( context.data.$mouseDownOn.length > 0 ) { return; } hide( context ); diff --git a/resources/src/mediawiki.debug/debug.js b/resources/src/mediawiki.debug/debug.js index 52fdb704c50..bd14e98892f 100644 --- a/resources/src/mediawiki.debug/debug.js +++ b/resources/src/mediawiki.debug/debug.js @@ -114,7 +114,7 @@ * Construct the HTML for the debugging toolbar */ buildHtml: function () { - var $container, $bits, panes, id, gitInfo; + var $container, $bits, panes, id, gitInfoText, $gitInfo; $container = $( '
' ) .attr( { @@ -188,20 +188,21 @@ paneTriggerBitDiv( 'includes', 'PHP includes', this.data.includes.length ); - gitInfo = ''; if ( this.data.gitRevision !== false ) { - gitInfo = '(' + this.data.gitRevision.slice( 0, 7 ) + ')'; + gitInfoText = '(' + this.data.gitRevision.slice( 0, 7 ) + ')'; if ( this.data.gitViewUrl !== false ) { - gitInfo = $( '' ) + $gitInfo = $( '' ) .attr( 'href', this.data.gitViewUrl ) - .text( gitInfo ); + .text( gitInfoText ); + } else { + $gitInfo = $( document.createTextNode( gitInfoText ) ); } } bitDiv( 'mwversion' ) .append( $( '' ).attr( 'href', 'https://www.mediawiki.org/' ).text( 'MediaWiki' ) ) .append( document.createTextNode( ': ' + this.data.mwVersion + ' ' ) ) - .append( gitInfo ); + .append( $gitInfo ); if ( this.data.gitBranch !== false ) { bitDiv( 'gitbranch' ).text( 'Git branch: ' + this.data.gitBranch ); diff --git a/resources/src/mediawiki.htmlform.checker.js b/resources/src/mediawiki.htmlform.checker.js index 473635a53ef..ff3630ec244 100644 --- a/resources/src/mediawiki.htmlform.checker.js +++ b/resources/src/mediawiki.htmlform.checker.js @@ -111,7 +111,7 @@ * @chainable */ mw.htmlform.Checker.prototype.setErrors = function ( valid, errors, forceReplacement ) { - var $oldErrorBox, tagName, showFunc, text, replace, + var $oldErrorBox, tagName, showFunc, $text, replace, $errorBox = this.$errorBox; if ( errors.length === 0 ) { @@ -137,11 +137,11 @@ $errorBox[ 0 ].tagName.toLowerCase() !== tagName ); if ( !replace ) { - text = $( '<' + tagName + '>' ) + $text = $( '<' + tagName + '>' ) .append( errors.map( function ( e ) { return errors.length === 1 ? e : $( '
  • ' ).append( e ); } ) ); - if ( text.text() !== $errorBox.text() ) { + if ( $text.text() !== $errorBox.text() ) { replace = true; } } diff --git a/resources/src/mediawiki.htmlform/hide-if.js b/resources/src/mediawiki.htmlform/hide-if.js index c8f8cc91451..a8049ae0c4d 100644 --- a/resources/src/mediawiki.htmlform/hide-if.js +++ b/resources/src/mediawiki.htmlform/hide-if.js @@ -223,17 +223,17 @@ mw.loader.using( modules ).done( function () { $fields.each( function () { - var v, i, fields, test, func, spec, self, + var v, i, fields, test, func, spec, $elOrLayout, $el = $( this ); if ( $el.is( '[data-ooui]' ) ) { - // self should be a FieldLayout that mixes in mw.htmlform.Element - self = OO.ui.FieldLayout.static.infuse( $el ); - spec = self.hideIf; + // $elOrLayout should be a FieldLayout that mixes in mw.htmlform.Element + $elOrLayout = OO.ui.FieldLayout.static.infuse( $el ); + spec = $elOrLayout.hideIf; // The original element has been replaced with infused one - $el = self.$element; + $el = $elOrLayout.$element; } else { - self = $el; + $elOrLayout = $el; spec = $el.data( 'hideIf' ); } @@ -247,12 +247,12 @@ // The .toggle() method works mostly the same for jQuery objects and OO.ui.Widget func = function () { var shouldHide = test(); - self.toggle( !shouldHide ); + $elOrLayout.toggle( !shouldHide ); // It is impossible to submit a form with hidden fields failing validation, e.g. one that // is required. However, validity is not checked for disabled fields, as these are not // submitted with the form. So we should also disable fields when hiding them. - if ( self instanceof $ ) { + if ( $elOrLayout instanceof $ ) { // This also finds elements inside any nested fields (in case of HTMLFormFieldCloner), // which is problematic. But it works because: // * HTMLFormFieldCloner::createFieldsForKey() copies 'hide-if' rules to nested fields @@ -260,7 +260,7 @@ // handlers for parents first // * Event handlers are fired in the order they were registered, so even if the handler // for parent messed up the child, the handle for child will run next and fix it - self.find( 'input, textarea, select' ).each( function () { + $elOrLayout.find( 'input, textarea, select' ).each( function () { var $this = $( this ); if ( shouldHide ) { if ( $this.data( 'was-disabled' ) === undefined ) { @@ -272,14 +272,14 @@ } } ); } else { - // self is a OO.ui.FieldLayout + // $elOrLayout is a OO.ui.FieldLayout if ( shouldHide ) { - if ( self.wasDisabled === undefined ) { - self.wasDisabled = self.fieldWidget.isDisabled(); + if ( $elOrLayout.wasDisabled === undefined ) { + $elOrLayout.wasDisabled = $elOrLayout.fieldWidget.isDisabled(); } - self.fieldWidget.setDisabled( true ); - } else if ( self.wasDisabled !== undefined ) { - self.fieldWidget.setDisabled( self.wasDisabled ); + $elOrLayout.fieldWidget.setDisabled( true ); + } else if ( $elOrLayout.wasDisabled !== undefined ) { + $elOrLayout.fieldWidget.setDisabled( $elOrLayout.wasDisabled ); } } }; diff --git a/resources/src/mediawiki.rcfilters/ui/ChangesListWrapperWidget.js b/resources/src/mediawiki.rcfilters/ui/ChangesListWrapperWidget.js index 64085678594..98cefb52e5e 100644 --- a/resources/src/mediawiki.rcfilters/ui/ChangesListWrapperWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/ChangesListWrapperWidget.js @@ -205,10 +205,10 @@ ChangesListWrapperWidget.prototype.emphasizeNewChanges = function ( from ) { selector = this.inEnhancedMode() ? 'table.mw-enhanced-rc[data-mw-ts]' : 'li[data-mw-ts]', - set = this.$element.find( selector ), - length = set.length; + $set = this.$element.find( selector ), + length = $set.length; - set.each( function ( index ) { + $set.each( function ( index ) { var $this = $( this ), ts = $this.data( 'mw-ts' ); diff --git a/resources/src/mediawiki.rcfilters/ui/FilterTagMultiselectWidget.js b/resources/src/mediawiki.rcfilters/ui/FilterTagMultiselectWidget.js index 7c8a2f5a264..ade25f8139d 100644 --- a/resources/src/mediawiki.rcfilters/ui/FilterTagMultiselectWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/FilterTagMultiselectWidget.js @@ -22,7 +22,7 @@ var ViewSwitchWidget = require( './ViewSwitchWidget.js' ), * @cfg {boolean} [collapsed] Filter area is collapsed */ FilterTagMultiselectWidget = function MwRcfiltersUiFilterTagMultiselectWidget( controller, model, savedQueriesModel, config ) { - var rcFiltersRow, + var $rcFiltersRow, title = new OO.ui.LabelWidget( { label: mw.msg( 'rcfilters-activefilters' ), classes: [ 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-content-title' ] @@ -172,7 +172,7 @@ FilterTagMultiselectWidget = function MwRcfiltersUiFilterTagMultiselectWidget( c // wide the button is; the button also changes its width depending // on language and its state, so the safest way to present both side // by side is with a table layout - rcFiltersRow = $( '
    ' ) + $rcFiltersRow = $( '
    ' ) .addClass( 'mw-rcfilters-ui-row' ) .append( this.$content @@ -181,7 +181,7 @@ FilterTagMultiselectWidget = function MwRcfiltersUiFilterTagMultiselectWidget( c ); if ( !mw.user.isAnon() ) { - rcFiltersRow.append( + $rcFiltersRow.append( $( '
    ' ) .addClass( 'mw-rcfilters-ui-cell' ) .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-cell-save' ) @@ -198,7 +198,7 @@ FilterTagMultiselectWidget = function MwRcfiltersUiFilterTagMultiselectWidget( c // Event this.viewsSelectWidget.connect( this, { choose: 'onViewsSelectWidgetChoose' } ); - rcFiltersRow.append( + $rcFiltersRow.append( $( '
    ' ) .addClass( 'mw-rcfilters-ui-cell' ) .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-cell-reset' ) @@ -225,7 +225,7 @@ FilterTagMultiselectWidget = function MwRcfiltersUiFilterTagMultiselectWidget( c $( '
    ' ) .addClass( 'mw-rcfilters-ui-table' ) .addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-filters' ) - .append( rcFiltersRow ) + .append( $rcFiltersRow ) ); // Initialize diff --git a/resources/src/mediawiki.special.apisandbox/apisandbox.js b/resources/src/mediawiki.special.apisandbox/apisandbox.js index c2c59609e9c..a52f3ec2d51 100644 --- a/resources/src/mediawiki.special.apisandbox/apisandbox.js +++ b/resources/src/mediawiki.special.apisandbox/apisandbox.js @@ -1383,7 +1383,7 @@ * @return {OO.ui.FieldLayout} return.helpField */ ApiSandbox.PageLayout.prototype.makeWidgetFieldLayouts = function ( ppi, name ) { - var j, l, widget, descriptionContainer, tmp, flag, count, button, widgetField, helpField, layoutConfig; + var j, l, widget, $descriptionContainer, tmp, $tmp, flag, count, button, widgetField, helpField, layoutConfig; widget = Util.createWidgetForParameter( ppi ); if ( ppi.tokentype ) { @@ -1393,20 +1393,20 @@ widget.on( 'change', this.updateTemplatedParameters, [ null ], this ); } - descriptionContainer = $( '
    ' ); + $descriptionContainer = $( '
    ' ); - tmp = Util.parseHTML( ppi.description ); - tmp.filter( 'dl' ).makeCollapsible( { + $tmp = Util.parseHTML( ppi.description ); + $tmp.filter( 'dl' ).makeCollapsible( { collapsed: true } ).children( '.mw-collapsible-toggle' ).each( function () { var $this = $( this ); $this.parent().prev( 'p' ).append( $this ); } ); - descriptionContainer.append( $( '
    ' ).addClass( 'description' ).append( tmp ) ); + $descriptionContainer.append( $( '
    ' ).addClass( 'description' ).append( $tmp ) ); if ( ppi.info && ppi.info.length ) { for ( j = 0; j < ppi.info.length; j++ ) { - descriptionContainer.append( $( '
    ' ) + $descriptionContainer.append( $( '
    ' ) .addClass( 'info' ) .append( Util.parseHTML( ppi.info[ j ] ) ) ); @@ -1422,7 +1422,7 @@ case 'limit': if ( ppi.highmax !== undefined ) { - descriptionContainer.append( $( '
    ' ) + $descriptionContainer.append( $( '
    ' ) .addClass( 'info' ) .append( Util.parseMsg( @@ -1433,7 +1433,7 @@ ) ); } else { - descriptionContainer.append( $( '
    ' ) + $descriptionContainer.append( $( '
    ' ) .addClass( 'info' ) .append( Util.parseMsg( 'api-help-param-limit', ppi.max ), @@ -1453,7 +1453,7 @@ tmp += 'max'; } if ( tmp !== '' ) { - descriptionContainer.append( $( '
    ' ) + $descriptionContainer.append( $( '
    ' ) .addClass( 'info' ) .append( Util.parseMsg( 'api-help-param-integer-' + tmp, @@ -1487,41 +1487,41 @@ ); } if ( tmp.length ) { - descriptionContainer.append( $( '
    ' ) + $descriptionContainer.append( $( '
    ' ) .addClass( 'info' ) .append( Util.parseHTML( tmp.join( ' ' ) ) ) ); } } if ( 'maxbytes' in ppi ) { - descriptionContainer.append( $( '
    ' ) + $descriptionContainer.append( $( '
    ' ) .addClass( 'info' ) .append( Util.parseMsg( 'api-help-param-maxbytes', ppi.maxbytes ) ) ); } if ( 'maxchars' in ppi ) { - descriptionContainer.append( $( '
    ' ) + $descriptionContainer.append( $( '
    ' ) .addClass( 'info' ) .append( Util.parseMsg( 'api-help-param-maxchars', ppi.maxchars ) ) ); } if ( ppi.usedTemplateVars && ppi.usedTemplateVars.length ) { - tmp = $(); + $tmp = $(); for ( j = 0, l = ppi.usedTemplateVars.length; j < l; j++ ) { - tmp = tmp.add( $( '' ).text( ppi.usedTemplateVars[ j ] ) ); + $tmp = $tmp.add( $( '' ).text( ppi.usedTemplateVars[ j ] ) ); if ( j === l - 2 ) { - tmp = tmp.add( mw.message( 'and' ).parseDom() ); - tmp = tmp.add( mw.message( 'word-separator' ).parseDom() ); + $tmp = $tmp.add( mw.message( 'and' ).parseDom() ); + $tmp = $tmp.add( mw.message( 'word-separator' ).parseDom() ); } else if ( j !== l - 1 ) { - tmp = tmp.add( mw.message( 'comma-separator' ).parseDom() ); + $tmp = $tmp.add( mw.message( 'comma-separator' ).parseDom() ); } } - descriptionContainer.append( $( '
    ' ) + $descriptionContainer.append( $( '
    ' ) .addClass( 'info' ) .append( Util.parseMsg( 'apisandbox-templated-parameter-reason', ppi.usedTemplateVars.length, - tmp + $tmp ) ) ); } @@ -1533,7 +1533,7 @@ } ), { align: 'inline', classes: [ 'mw-apisandbox-help-field' ], - label: descriptionContainer + label: $descriptionContainer } ); @@ -1784,7 +1784,7 @@ Util.fetchModuleInfo( this.apiModule ) .done( function ( pi ) { - var prefix, i, j, tmp, + var prefix, i, j, tmp, $tmp, items = [], deprecatedItems = [], buttons = [], @@ -1858,11 +1858,11 @@ width: 'auto', padded: true, $content: $( '