]> source.dussan.org Git - jquery.git/commitdiff
Core: Fix trim in Android<4.1
authorMichał Gołębiowski <m.goleb@gmail.com>
Thu, 13 Feb 2014 22:48:58 +0000 (14:48 -0800)
committerMichał Gołębiowski <m.goleb@gmail.com>
Thu, 13 Feb 2014 22:48:58 +0000 (14:48 -0800)
src/core.js

index 67b6e71998fabecb77cd28b5bbf99859322f9d95..11c232765a4cac46595cbdcbb88ced980fa4dd85 100644 (file)
@@ -24,6 +24,10 @@ var
                return new jQuery.fn.init( selector, context );
        },
 
+       // Support: Android<4.1
+       // Make sure we trim BOM and NBSP
+       rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
+
        // Matches dashed string for camelizing
        rmsPrefix = /^-ms-/,
        rdashAlpha = /-([\da-z])/gi,
@@ -336,9 +340,21 @@ jQuery.extend({
                return obj;
        },
 
-       trim: function( text ) {
-               return text == null ? "" : trim.call( text );
-       },
+       // Support: Android<4.1
+       // Use native String.trim function wherever possible
+       trim: trim && !trim.call("\uFEFF\xA0") ?
+               function( text ) {
+                       return text == null ?
+                               "" :
+                               trim.call( text );
+               } :
+
+               // Otherwise use our own trimming functionality
+               function( text ) {
+                       return text == null ?
+                               "" :
+                               ( text + "" ).replace( rtrim, "" );
+               },
 
        // results is for internal usage only
        makeArray: function( arr, results ) {