Use ES5 String.prototype.trim() instead of jQuery.trim()
authorFomafix <fomafix@googlemail.com>
Sun, 21 Jan 2018 19:10:42 +0000 (20:10 +0100)
committerFomafix <fomafix@googlemail.com>
Sun, 21 Jan 2018 19:33:07 +0000 (20:33 +0100)
Replace:
* $.trim( str ) by str.trim()

Ensure that str is a string before calling str.trim().

Change-Id: I48f08fdac1e7d802813563c4691e9bbaf2c78336

resources/src/jquery/jquery.colorUtil.js
resources/src/jquery/jquery.tablesorter.js
resources/src/mediawiki.special/mediawiki.special.block.js
resources/src/mediawiki.special/mediawiki.special.changecredentials.js
resources/src/mediawiki.special/mediawiki.special.userlogin.signup.js
resources/src/mediawiki.widgets/mw.widgets.CategoryMultiselectWidget.js
resources/src/mediawiki/htmlform/multiselect.js
resources/src/mediawiki/mediawiki.Title.js
resources/src/mediawiki/mediawiki.jqueryMsg.js
resources/src/mediawiki/mediawiki.template.js

index a5b136d..d46d009 100644 (file)
@@ -29,6 +29,9 @@
                        if ( color && Array.isArray( color ) && color.length === 3 ) {
                                return color;
                        }
+                       if ( typeof color !== 'string' ) {
+                               return undefined;
+                       }
 
                        // Look for rgb(num,num,num)
                        // eslint-disable-next-line no-cond-assign
@@ -77,7 +80,7 @@
                        }
 
                        // Otherwise, we're most likely dealing with a named color
-                       return $.colorUtil.colors[ $.trim( color ).toLowerCase() ];
+                       return $.colorUtil.colors[ color.trim().toLowerCase() ];
                },
 
                /**
index 6d67ade..5ca866e 100644 (file)
                                if ( rowIndex !== lastRowIndex ) {
                                        lastRowIndex = rowIndex;
                                        cellIndex = $( rows[ rowIndex ] ).data( 'columnToCell' )[ column ];
-                                       nodeValue = $.trim( getElementSortKey( rows[ rowIndex ].cells[ cellIndex ] ) );
+                                       nodeValue = getElementSortKey( rows[ rowIndex ].cells[ cellIndex ] ).trim();
                                }
                        } else {
                                nodeValue = '';
                },
                format: function ( s ) {
                        var tsc;
-                       s = $.trim( s.toLowerCase() );
+                       s = s.toLowerCase().trim();
                        if ( ts.collationRegex ) {
                                tsc = ts.collationTable;
                                s = s.replace( ts.collationRegex, function ( match ) {
                        return ts.rgx.url[ 0 ].test( s );
                },
                format: function ( s ) {
-                       return $.trim( s.replace( ts.rgx.url[ 1 ], '' ) );
+                       return s.replace( ts.rgx.url[ 1 ], '' ).trim();
                },
                type: 'text'
        } );
                },
                format: function ( s ) {
                        var match, y;
-                       s = $.trim( s.toLowerCase() );
+                       s = s.toLowerCase().trim();
 
                        if ( ( match = s.match( ts.dateRegex[ 0 ] ) ) !== null ) {
                                if ( mw.config.get( 'wgDefaultDateFormat' ) === 'mdy' || mw.config.get( 'wgPageContentLanguage' ) === 'en' ) {
        ts.addParser( {
                id: 'number',
                is: function ( s ) {
-                       return $.tablesorter.numberRegex.test( $.trim( s ) );
+                       return $.tablesorter.numberRegex.test( s.trim() );
                },
                format: function ( s ) {
                        return $.tablesorter.formatDigit( s );
index 49e471e..ba93195 100644 (file)
@@ -23,7 +23,7 @@
                        expiryWidget = infuseOrNull( 'mw-input-wpExpiry' );
 
                function updateBlockOptions() {
-                       var blocktarget = $.trim( blockTargetWidget.getValue() ),
+                       var blocktarget = blockTargetWidget.getValue().trim(),
                                isEmpty = blocktarget === '',
                                isIp = mw.util.isIPAddress( blocktarget, true ),
                                isIpRange = isIp && blocktarget.match( /\/\d+$/ ),
index 9592879..ad8a4f4 100644 (file)
@@ -17,7 +17,7 @@
                                        currentApiPromise = undefined;
                                }
 
-                               password = $.trim( password );
+                               password = password.trim();
 
                                if ( password === '' ) {
                                        self.setErrors( [] );
index 10e19e7..8a61afb 100644 (file)
@@ -82,7 +82,7 @@
                        var apiPromise,
                                d = $.Deferred();
 
-                       if ( $.trim( $usernameInput.val() ) === '' ) {
+                       if ( $usernameInput.val().trim() === '' ) {
                                d.resolve( { valid: true, messages: [] } );
                                return d.promise();
                        }
index d14a47a..c673eb2 100644 (file)
                        promises = [],
                        deferred = $.Deferred();
 
-               if ( $.trim( input ) === '' ) {
+               if ( input.trim() === '' ) {
                        deferred.resolve( [] );
                        return deferred.promise();
                }
index d295ca7..8a44251 100644 (file)
@@ -9,7 +9,7 @@
                        oldClass = ( ' ' + $oldContainer.attr( 'class' ) + ' ' ).replace( /(mw-htmlform-field-HTMLMultiSelectField|mw-chosen|mw-htmlform-dropdown)/g, '' ),
                        $select = $( '<select>' ),
                        dataPlaceholder = mw.message( 'htmlform-chosen-placeholder' );
-               oldClass = $.trim( oldClass );
+               oldClass = oldClass.trim();
                $select.attr( {
                        name: name,
                        multiple: 'multiple',
index 53cbd60..9db2771 100644 (file)
                namespace = defaultNamespace === undefined ? NS_MAIN : defaultNamespace;
 
                // Normalise additional whitespace
-               title = $.trim( title.replace( /\s/g, ' ' ) );
+               title = title.replace( /\s/g, ' ' ).trim();
 
                // Process initial colon
                if ( title !== '' && title[ 0 ] === ':' ) {
                                ext = parts.pop();
 
                                // Remove whitespace of the name part (that W/O extension)
-                               title = $.trim( parts.join( '.' ) );
+                               title = parts.join( '.' ).trim();
 
                                // Cut, if too long and append file extension
                                title = trimFileNameToByteLength( title, ext );
                        } else {
 
                                // Missing file extension
-                               title = $.trim( parts.join( '.' ) );
+                               title = parts.join( '.' ).trim();
 
                                // Name has no file extension and a fallback wasn't provided either
                                return null;
index 8b25a0b..ea91afe 100644 (file)
                 * @return {string} Localized namespace name
                 */
                ns: function ( nodes ) {
-                       var ns = $.trim( textify( nodes[ 0 ] ) );
+                       var ns = textify( nodes[ 0 ] ).trim();
                        if ( !/^\d+$/.test( ns ) ) {
                                ns = mw.config.get( 'wgNamespaceIds' )[ ns.replace( / /g, '_' ).toLowerCase() ];
                        }
index 5e0e343..4a3157c 100644 (file)
                compile: function ( src ) {
                        return {
                                render: function () {
-                                       return $( $.parseHTML( $.trim( src ) ) );
+                                       return $( $.parseHTML( src.trim() ) );
                                }
                        };
                }