git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Switch to using String.prototype.trim from String.trim as it's more-widely available.
[jquery.git]
/
src
/
core.js
diff --git
a/src/core.js
b/src/core.js
index
9fa311d
..
699b87a
100644
(file)
--- a/
src/core.js
+++ b/
src/core.js
@@
-18,7
+18,7
@@
var jQuery = function( selector, context ) {
// A simple way to check for HTML strings or ID strings
// (both of which we optimize for)
// A simple way to check for HTML strings or ID strings
// (both of which we optimize for)
- quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/,
+ quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$|^#([\w\-]+)$/,
// Is it a simple selector
isSimple = /^.[^:#\[\.,]*$/,
// Is it a simple selector
isSimple = /^.[^:#\[\.,]*$/,
@@
-27,7
+27,8
@@
var jQuery = function( selector, context ) {
rnotwhite = /\S/,
// Used for trimming whitespace
rnotwhite = /\S/,
// Used for trimming whitespace
- rtrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g,
+ trimLeft = /^\s+/,
+ trimRight = /\s+$/,
// Match a standalone tag
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
// Match a standalone tag
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
@@
-49,9
+50,10
@@
var jQuery = function( selector, context ) {
// Save a reference to some core methods
toString = Object.prototype.toString,
// Save a reference to some core methods
toString = Object.prototype.toString,
- hasOwnProperty = Object.prototype.hasOwnProperty,
+ hasOwn = Object.prototype.hasOwnProperty,
push = Array.prototype.push,
slice = Array.prototype.slice,
push = Array.prototype.push,
slice = Array.prototype.slice,
+ trim = String.prototype.trim,
indexOf = Array.prototype.indexOf;
jQuery.fn = jQuery.prototype = {
indexOf = Array.prototype.indexOf;
jQuery.fn = jQuery.prototype = {
@@
-450,9
+452,9
@@
jQuery.extend({
}
// Not own constructor property must be Object
}
// Not own constructor property must be Object
- if ( obj.constructor
- && !hasOwnProperty.call(obj, "constructor")
- && !hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ) {
+ if ( obj.constructor &&
+ !hasOwn.call(obj, "constructor") &&
+ !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
return false;
}
return false;
}
@@
-462,7
+464,7
@@
jQuery.extend({
var key;
for ( key in obj ) {}
var key;
for ( key in obj ) {}
- return key === undefined || hasOwnProperty.call( obj, key );
+ return key === undefined || hasOwn.call( obj, key );
},
isEmptyObject: function( obj ) {
},
isEmptyObject: function( obj ) {
@@
-567,9
+569,20
@@
jQuery.extend({
return object;
},
return object;
},
- trim: function( text ) {
- return (text || "").replace( rtrim, "" );
- },
+ // Use native String.trim function wherever possible
+ trim: trim ?
+ function( text ) {
+ return text == null ?
+ "" :
+ trim.call( 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 ) {
// results is for internal usage only
makeArray: function( array, results ) {
@@
-623,12
+636,14
@@
jQuery.extend({
},
grep: function( elems, callback, inv ) {
},
grep: function( elems, callback, inv ) {
- var ret = [];
+ var ret = [], retVal;
+ inv = !!inv;
// Go through the array, only saving the items
// that pass the validator function
for ( var i = 0, length = elems.length; i < length; i++ ) {
// Go through the array, only saving the items
// that pass the validator function
for ( var i = 0, length = elems.length; i < length; i++ ) {
- if ( !inv !== !callback( elems[ i ], i ) ) {
+ retVal = !!callback( elems[ i ], i );
+ if ( inv !== retVal ) {
ret.push( elems[ i ] );
}
}
ret.push( elems[ i ] );
}
}
@@
-693,7
+708,7
@@
jQuery.extend({
/(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
!/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) ||
/(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
!/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) ||
- [];
+ [];
return { browser: match[1] || "", version: match[2] || "0" };
},
return { browser: match[1] || "", version: match[2] || "0" };
},
@@
-718,6
+733,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);
// All jQuery objects should point back to these
rootjQuery = jQuery(document);
@@
-748,7
+770,7
@@
function doScrollCheck() {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
- } catch( error ) {
+ } catch(e) {
setTimeout( doScrollCheck, 1 );
return;
}
setTimeout( doScrollCheck, 1 );
return;
}
@@
-799,9
+821,9
@@
function access( elems, key, value, exec, fn, pass ) {
}
// Getting an attribute
}
// Getting an attribute
- return length ? fn( elems[0], key ) : null;
+ return length ? fn( elems[0], key ) : undefined;
}
function now() {
}
function now() {
- return (new Date).getTime();
+ return (new Date()).getTime();
}
}