From: Ed Sanders Date: Thu, 27 Jun 2019 15:57:47 +0000 (+0100) Subject: Avoid Sizzle's :first/:last selectors. Use $.first()/$.last() X-Git-Tag: 1.34.0-rc.0~1250^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=69842c56e51181c7b905d67c6f9ca1086721ceb9 Avoid Sizzle's :first/:last selectors. Use $.first()/$.last() Change-Id: I11751b812cac1cb1e5590e0e94d1fe7cf4b89f7a --- diff --git a/resources/src/jquery/jquery.suggestions.js b/resources/src/jquery/jquery.suggestions.js index 3083b0f58c..5111295b27 100644 --- a/resources/src/jquery/jquery.suggestions.js +++ b/resources/src/jquery/jquery.suggestions.js @@ -237,7 +237,7 @@ 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' ); + result = context.data.$container.find( '.suggestions-result' ).last(); } else { result = selected.prev(); if ( !( result.length && result.hasClass( 'suggestions-result' ) ) ) { @@ -250,14 +250,14 @@ if ( context.data.$container.find( '.suggestions-special' ).html() !== '' ) { 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 ) { // No item selected, go to the first one - result = context.data.$container.find( '.suggestions-results .suggestions-result:first' ); + 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' ); diff --git a/resources/src/mediawiki.Title/Title.js b/resources/src/mediawiki.Title/Title.js index 259febc9a7..3084e12fb1 100644 --- a/resources/src/mediawiki.Title/Title.js +++ b/resources/src/mediawiki.Title/Title.js @@ -609,7 +609,7 @@ Title.newFromFileName = function ( uncleanName ) { /** * Get the file title from an image element * - * var title = mw.Title.newFromImg( $( 'img:first' ) ); + * var title = mw.Title.newFromImg( imageNode ); * * @static * @param {HTMLElement|jQuery} img The image to use as a base diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js index af4b8976f4..3af82226f1 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js @@ -298,7 +298,7 @@ // can change where they are output). if ( !document.getElementById( 'p-lang' ) && document.getElementById( 'p-tb' ) && mw.config.get( 'skin' ) === 'vector' ) { - $( '.portal:last' ).after( + $( '.portal' ).last().after( $( '
' ).attr( { class: 'portal', id: 'p-lang', diff --git a/resources/src/mediawiki.legacy/protect.js b/resources/src/mediawiki.legacy/protect.js index 698857620d..1c4824f38d 100644 --- a/resources/src/mediawiki.legacy/protect.js +++ b/resources/src/mediawiki.legacy/protect.js @@ -199,7 +199,7 @@ getExpiryInputs().on( 'input change', updateExpiry ); getLevelSelectors().on( 'change', updateLevels ); - $( '#mwProtectSet > tbody > tr:first' ).after( $row ); + $( '#mwProtectSet > tbody > tr' ).first().after( $row ); // If there is only one protection type, there is nothing to chain if ( $( '[id ^= mw-protect-table-]' ).length > 1 ) { diff --git a/resources/src/mediawiki.page.gallery.js b/resources/src/mediawiki.page.gallery.js index 0ffc867863..7d098e6fe8 100644 --- a/resources/src/mediawiki.page.gallery.js +++ b/resources/src/mediawiki.page.gallery.js @@ -45,8 +45,8 @@ // Note that if we do have a real image, using this method will generally // give the same answer, but can be different in the case of a very // narrow image where extra padding is added. - imgHeight = $this.children().children( 'div:first' ).height(); - imgWidth = $this.children().children( 'div:first' ).width(); + imgHeight = $this.children().children( 'div' ).first().height(); + imgWidth = $this.children().children( 'div' ).first().width(); } // Hack to make an edge case work ok diff --git a/resources/src/mediawiki.special.userlogin.signup.js b/resources/src/mediawiki.special.userlogin.signup.js index fff2d4e61a..2469381ae4 100644 --- a/resources/src/mediawiki.special.userlogin.signup.js +++ b/resources/src/mediawiki.special.userlogin.signup.js @@ -9,7 +9,7 @@ originalText = $emailLabel.text(), requiredText = mw.message( 'createacct-emailrequired' ).text(), $createByMailCheckbox = $( '#wpCreateaccountMail' ), - $beforePwds = $( '.mw-row-password:first' ).prev(), + $beforePwds = $( '.mw-row-password' ).first().prev(), $pwds; function updateForCheckbox() { diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js index 6b316e5558..01dea8e924 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js @@ -388,7 +388,7 @@ 'Default modules', 't-rldm-nonexistent', 'List of all default modules ', 'd', '#t-rl-nonexistent' ); assert.strictEqual( tbRLDMnonexistentid, - $( '#p-test-tb li:last' )[ 0 ], + $( '#p-test-tb li' ).last()[ 0 ], 'Next node as non-matching CSS selector falls back to appending' ); @@ -396,7 +396,7 @@ 'Default modules', 't-rldm-empty-jquery', 'List of all default modules ', 'd', $( '#t-rl-nonexistent' ) ); assert.strictEqual( tbRLDMemptyjquery, - $( '#p-test-tb li:last' )[ 0 ], + $( '#p-test-tb li' ).last()[ 0 ], 'Next node as empty jQuery object falls back to appending' ); } );