Always $-prefix jQuery variable names

Change-Id: I82d7788fbd01b73fc8a3255d5af2de75c85279e1
This commit is contained in:
Ed Sanders 2019-10-04 21:43:40 +01:00
parent 5f3b268c3f
commit a3e3a80329
15 changed files with 143 additions and 138 deletions

View file

@ -230,65 +230,69 @@
* Highlight a result in the results table
*
* @param {Object} context
* @param {jQuery|string} result `<tr>` to highlight, or 'prev' or 'next'
* @param {jQuery|string} $result `<tr>` 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 );

View file

@ -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 = $( '<div>' )
.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 = $( '<a>' )
$gitInfo = $( '<a>' )
.attr( 'href', this.data.gitViewUrl )
.text( gitInfo );
.text( gitInfoText );
} else {
$gitInfo = $( document.createTextNode( gitInfoText ) );
}
}
bitDiv( 'mwversion' )
.append( $( '<a>' ).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 );

View file

@ -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 : $( '<li>' ).append( e );
} ) );
if ( text.text() !== $errorBox.text() ) {
if ( $text.text() !== $errorBox.text() ) {
replace = true;
}
}

View file

@ -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 );
}
}
};

View file

@ -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' );

View file

@ -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 = $( '<div>' )
$rcFiltersRow = $( '<div>' )
.addClass( 'mw-rcfilters-ui-row' )
.append(
this.$content
@ -181,7 +181,7 @@ FilterTagMultiselectWidget = function MwRcfiltersUiFilterTagMultiselectWidget( c
);
if ( !mw.user.isAnon() ) {
rcFiltersRow.append(
$rcFiltersRow.append(
$( '<div>' )
.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(
$( '<div>' )
.addClass( 'mw-rcfilters-ui-cell' )
.addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-cell-reset' )
@ -225,7 +225,7 @@ FilterTagMultiselectWidget = function MwRcfiltersUiFilterTagMultiselectWidget( c
$( '<div>' )
.addClass( 'mw-rcfilters-ui-table' )
.addClass( 'mw-rcfilters-ui-filterTagMultiselectWidget-wrapper-filters' )
.append( rcFiltersRow )
.append( $rcFiltersRow )
);
// Initialize

View file

@ -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 = $( '<div>' );
$descriptionContainer = $( '<div>' );
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( $( '<div>' ).addClass( 'description' ).append( tmp ) );
$descriptionContainer.append( $( '<div>' ).addClass( 'description' ).append( $tmp ) );
if ( ppi.info && ppi.info.length ) {
for ( j = 0; j < ppi.info.length; j++ ) {
descriptionContainer.append( $( '<div>' )
$descriptionContainer.append( $( '<div>' )
.addClass( 'info' )
.append( Util.parseHTML( ppi.info[ j ] ) )
);
@ -1422,7 +1422,7 @@
case 'limit':
if ( ppi.highmax !== undefined ) {
descriptionContainer.append( $( '<div>' )
$descriptionContainer.append( $( '<div>' )
.addClass( 'info' )
.append(
Util.parseMsg(
@ -1433,7 +1433,7 @@
)
);
} else {
descriptionContainer.append( $( '<div>' )
$descriptionContainer.append( $( '<div>' )
.addClass( 'info' )
.append(
Util.parseMsg( 'api-help-param-limit', ppi.max ),
@ -1453,7 +1453,7 @@
tmp += 'max';
}
if ( tmp !== '' ) {
descriptionContainer.append( $( '<div>' )
$descriptionContainer.append( $( '<div>' )
.addClass( 'info' )
.append( Util.parseMsg(
'api-help-param-integer-' + tmp,
@ -1487,41 +1487,41 @@
);
}
if ( tmp.length ) {
descriptionContainer.append( $( '<div>' )
$descriptionContainer.append( $( '<div>' )
.addClass( 'info' )
.append( Util.parseHTML( tmp.join( ' ' ) ) )
);
}
}
if ( 'maxbytes' in ppi ) {
descriptionContainer.append( $( '<div>' )
$descriptionContainer.append( $( '<div>' )
.addClass( 'info' )
.append( Util.parseMsg( 'api-help-param-maxbytes', ppi.maxbytes ) )
);
}
if ( 'maxchars' in ppi ) {
descriptionContainer.append( $( '<div>' )
$descriptionContainer.append( $( '<div>' )
.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( $( '<var>' ).text( ppi.usedTemplateVars[ j ] ) );
$tmp = $tmp.add( $( '<var>' ).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( $( '<div>' )
$descriptionContainer.append( $( '<div>' )
.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: $( '<ul>' ).append( pi.examples.map( function ( example ) {
var a = $( '<a>' )
var $a = $( '<a>' )
.attr( 'href', '#' + example.query )
.html( example.description );
a.find( 'a' ).contents().unwrap(); // Can't nest links
return $( '<li>' ).append( a );
$a.find( 'a' ).contents().unwrap(); // Can't nest links
return $( '<li>' ).append( $a );
} ) )
}
} ) );
@ -1939,7 +1939,7 @@
}
that.deprecatedItemsFieldset = new OO.ui.FieldsetLayout().addItems( deprecatedItems ).toggle( false );
tmp = $( '<fieldset>' )
$tmp = $( '<fieldset>' )
.toggle( !that.deprecatedItemsFieldset.isEmpty() )
.append(
$( '<legend>' ).append(
@ -1952,10 +1952,10 @@
.appendTo( that.$element );
that.deprecatedItemsFieldset.on( 'add', function () {
this.toggle( !that.deprecatedItemsFieldset.isEmpty() );
}, [], tmp );
}, [], $tmp );
that.deprecatedItemsFieldset.on( 'remove', function () {
this.toggle( !that.deprecatedItemsFieldset.isEmpty() );
}, [], tmp );
}, [], $tmp );
// Load stored params, if any, then update the booklet if we
// have subpages (or else just update our valid-indicator).

View file

@ -11,13 +11,13 @@
// slower and more complicated. It works fine to treat them as HTML elements.)
function isPrefsChanged() {
// eslint-disable-next-line no-jquery/no-sizzle
var inputs = $( '#mw-prefs-form :input[name]' ),
var $inputs = $( '#mw-prefs-form :input[name]' ),
input, $input, inputType,
index, optIndex,
opt;
for ( index = 0; index < inputs.length; index++ ) {
input = inputs[ index ];
for ( index = 0; index < $inputs.length; index++ ) {
input = $inputs[ index ];
$input = $( input );
// Different types of inputs have different methods for accessing defaults

View file

@ -3,21 +3,19 @@
*/
( function () {
$( function () {
var allowEmail, allowEmailFromNewUsers;
allowEmail = $( '#wpAllowEmail' );
allowEmailFromNewUsers = $( '#wpAllowEmailFromNewUsers' );
var $allowEmail = $( '#wpAllowEmail' ),
$allowEmailFromNewUsers = $( '#wpAllowEmailFromNewUsers' );
function toggleDisabled() {
if ( allowEmail.is( ':checked' ) && allowEmail.is( ':enabled' ) ) {
allowEmailFromNewUsers.prop( 'disabled', false );
if ( $allowEmail.is( ':checked' ) && $allowEmail.is( ':enabled' ) ) {
$allowEmailFromNewUsers.prop( 'disabled', false );
} else {
allowEmailFromNewUsers.prop( 'disabled', true );
$allowEmailFromNewUsers.prop( 'disabled', true );
}
}
if ( allowEmail ) {
allowEmail.on( 'change', toggleDisabled );
if ( $allowEmail ) {
$allowEmail.on( 'change', toggleDisabled );
toggleDisabled();
}
} );

View file

@ -70,17 +70,17 @@
// This function is called onload and onhashchange.
function detectHash() {
var hash = location.hash,
matchedElement, parentSection;
matchedElement, $parentSection;
if ( hash.match( /^#mw-prefsection-[\w]+$/ ) ) {
mw.storage.session.remove( 'mwpreferences-prevTab' );
switchPrefTab( hash.slice( 1 ) );
} else if ( hash.match( /^#mw-[\w-]+$/ ) ) {
matchedElement = document.getElementById( hash.slice( 1 ) );
parentSection = $( matchedElement ).parent().closest( '[id^="mw-prefsection-"]' );
if ( parentSection.length ) {
$parentSection = $( matchedElement ).parent().closest( '[id^="mw-prefsection-"]' );
if ( $parentSection.length ) {
mw.storage.session.remove( 'mwpreferences-prevTab' );
// Switch to proper tab and scroll to selected item.
switchPrefTab( parentSection.attr( 'id' ), true );
switchPrefTab( $parentSection.attr( 'id' ), true );
matchedElement.scrollIntoView();
}
}

View file

@ -141,18 +141,20 @@
* @inheritdoc
*/
mw.widgets.ExpiryWidget.static.reusePreInfuseDOM = function ( node, config ) {
var relativeElement = $( node ).find( '.mw-widget-ExpiryWidget-relative' );
var $relativeElement = $( node ).find( '.mw-widget-ExpiryWidget-relative' );
config = mw.widgets.ExpiryWidget.parent.static.reusePreInfuseDOM( node, config );
if ( relativeElement.hasClass( 'oo-ui-textInputWidget' ) ) {
// eslint-disable-next-line no-jquery/no-class-state
if ( $relativeElement.hasClass( 'oo-ui-textInputWidget' ) ) {
config.RelativeInputClass = OO.ui.TextInputWidget;
} else if ( relativeElement.hasClass( 'mw-widget-selectWithInputWidget' ) ) {
// eslint-disable-next-line no-jquery/no-class-state
} else if ( $relativeElement.hasClass( 'mw-widget-selectWithInputWidget' ) ) {
config.RelativeInputClass = mw.widgets.SelectWithInputWidget;
}
config.relativeInput = config.RelativeInputClass.static.reusePreInfuseDOM(
relativeElement,
$relativeElement,
config.relativeInput
);

View file

@ -62,22 +62,22 @@
// Use this instead of <input type="hidden">, because hidden inputs do not have separate
// 'value' and 'defaultValue' properties. The script on Special:Preferences
// (mw.special.preferences.confirmClose) checks this property to see if a field was changed.
this.hiddenInput = $( '<textarea>' )
this.$hiddenInput = $( '<textarea>' )
.addClass( 'oo-ui-element-hidden' )
.attr( 'name', config.name )
.appendTo( this.$element );
// Update with preset values
// Set the default value (it might be different from just being empty)
this.hiddenInput.prop( 'defaultValue', this.getItems().map( function ( item ) {
this.$hiddenInput.prop( 'defaultValue', this.getItems().map( function ( item ) {
return item.getData();
} ).join( '\n' ) );
this.on( 'change', function ( items ) {
this.hiddenInput.val( items.map( function ( item ) {
this.$hiddenInput.val( items.map( function ( item ) {
return item.getData();
} ).join( '\n' ) );
// Trigger a 'change' event as if a user edited the text
// (it is not triggered when changing the value from JS code).
this.hiddenInput.trigger( 'change' );
this.$hiddenInput.trigger( 'change' );
}.bind( this ) );
}
};

View file

@ -72,22 +72,22 @@
// Use this instead of <input type="hidden">, because hidden inputs do not have separate
// 'value' and 'defaultValue' properties. The script on Special:Preferences
// (mw.special.preferences.confirmClose) checks this property to see if a field was changed.
this.hiddenInput = $( '<textarea>' )
this.$hiddenInput = $( '<textarea>' )
.addClass( 'oo-ui-element-hidden' )
.attr( 'name', config.name )
.appendTo( this.$element );
// Update with preset values
// Set the default value (it might be different from just being empty)
this.hiddenInput.prop( 'defaultValue', this.getItems().map( function ( item ) {
this.$hiddenInput.prop( 'defaultValue', this.getItems().map( function ( item ) {
return item.getData();
} ).join( '\n' ) );
this.on( 'change', function ( items ) {
this.hiddenInput.val( items.map( function ( item ) {
this.$hiddenInput.val( items.map( function ( item ) {
return item.getData();
} ).join( '\n' ) );
// Trigger a 'change' event as if a user edited the text
// (it is not triggered when changing the value from JS code).
this.hiddenInput.trigger( 'change' );
this.$hiddenInput.trigger( 'change' );
}.bind( this ) );
}

View file

@ -45,14 +45,14 @@
// Use this instead of <input type="hidden">, because hidden inputs do not have separate
// 'value' and 'defaultValue' properties. The script on Special:Preferences
// (mw.special.preferences.confirmClose) checks this property to see if a field was changed.
this.hiddenInput = $( '<textarea>' )
this.$hiddenInput = $( '<textarea>' )
.addClass( 'oo-ui-element-hidden' )
.attr( 'name', config.name )
.appendTo( this.$element );
// Update with preset values
this.updateHiddenInput();
// Set the default value (it might be different from just being empty)
this.hiddenInput.prop( 'defaultValue', this.getSelectedUsernames().join( '\n' ) );
this.$hiddenInput.prop( 'defaultValue', this.getSelectedUsernames().join( '\n' ) );
}
this.menu = this.getMenu();
@ -153,10 +153,10 @@
*/
mw.widgets.UsersMultiselectWidget.prototype.updateHiddenInput = function () {
if ( 'hiddenInput' in this ) {
this.hiddenInput.val( this.getSelectedUsernames().join( '\n' ) );
this.$hiddenInput.val( this.getSelectedUsernames().join( '\n' ) );
// Trigger a 'change' event as if a user edited the text
// (it is not triggered when changing the value from JS code).
this.hiddenInput.trigger( 'change' );
this.$hiddenInput.trigger( 'change' );
}
};

View file

@ -329,13 +329,13 @@
* @return {Object|string} Plain JavaScript value representing the node.
*/
function getDomStructure( node ) {
var $node, children, processedChildren, i, len, el;
var $node, $children, processedChildren, i, len, el;
$node = $( node );
if ( node.nodeType === Node.ELEMENT_NODE ) {
children = $node.contents();
$children = $node.contents();
processedChildren = [];
for ( i = 0, len = children.length; i < len; i++ ) {
el = children[ i ];
for ( i = 0, len = $children.length; i < len; i++ ) {
el = $children[ i ];
if ( el.nodeType === Node.ELEMENT_NODE || el.nodeType === Node.TEXT_NODE ) {
processedChildren.push( getDomStructure( el ) );
}