aboutsummaryrefslogtreecommitdiffstats
path: root/src/core.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/core.js')
-rw-r--r--src/core.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/core.js b/src/core.js
index 50e167657..3f156a5fd 100644
--- a/src/core.js
+++ b/src/core.js
@@ -27,7 +27,8 @@ var jQuery = function( selector, context ) {
rnotwhite = /\S/,
// Used for trimming whitespace
- rtrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g,
+ trimLeft = /^\s+/,
+ trimRight = /\s+$/,
// Match a standalone tag
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
@@ -567,9 +568,20 @@ jQuery.extend({
return object;
},
- trim: function( text ) {
- return (text || "").replace( rtrim, "" );
- },
+ // Use native String.trim function wherever possible
+ trim: String.trim ?
+ function( text ) {
+ return text == null ?
+ "" :
+ String.trim( text );
+ } :
+
+ // Otherwise use our own trimming functionality
+ function( text ) {
+ return text == null ?
+ "" :
+ text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
+ },
// results is for internal usage only
makeArray: function( array, results ) {
@@ -720,6 +732,13 @@ if ( indexOf ) {
};
}
+// Verify that \s matches non-breaking spaces
+// (IE fails on this test)
+if ( !/\s/.test( "\xA0" ) ) {
+ trimLeft = /^[\s\xA0]+/;
+ trimRight = /[\s\xA0]+$/;
+}
+
// All jQuery objects should point back to these
rootjQuery = jQuery(document);