Avoid Sizzle's :first/:last selectors. Use $.first()/$.last()
authorEd Sanders <esanders@wikimedia.org>
Thu, 27 Jun 2019 15:57:47 +0000 (16:57 +0100)
committerEd Sanders <esanders@wikimedia.org>
Thu, 27 Jun 2019 15:57:47 +0000 (16:57 +0100)
Change-Id: I11751b812cac1cb1e5590e0e94d1fe7cf4b89f7a

resources/src/jquery/jquery.suggestions.js
resources/src/mediawiki.Title/Title.js
resources/src/mediawiki.action/mediawiki.action.edit.preview.js
resources/src/mediawiki.legacy/protect.js
resources/src/mediawiki.page.gallery.js
resources/src/mediawiki.special.userlogin.signup.js
tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js

index 3083b0f..5111295 100644 (file)
                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' ) ) ) {
                                                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' );
index 259febc..3084e12 100644 (file)
@@ -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
index af4b897..3af8222 100644 (file)
                // 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(
                                $( '<div>' ).attr( {
                                        class: 'portal',
                                        id: 'p-lang',
index 6988576..1c4824f 100644 (file)
                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 ) {
index 0ffc867..7d098e6 100644 (file)
@@ -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
index fff2d4e..2469381 100644 (file)
@@ -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() {
index 6b316e5..01dea8e 100644 (file)
                        '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'
                );
 
                        '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'
                );
        } );