git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix bug when accessing .data() on an empty set. Return null rather than throwing...
[jquery.git]
/
src
/
data.js
diff --git
a/src/data.js
b/src/data.js
index
abe4689
..
b7a6ab9
100644
(file)
--- a/
src/data.js
+++ b/
src/data.js
@@
-1,8
+1,8
@@
(function( jQuery ) {
var windowData = {},
(function( jQuery ) {
var windowData = {},
- rnum = /^-?\d+(?:\.\d+)$/,
- rbrace = /^(?:{.*}|\[.*\])$/;
+ rbrace = /^(?:\{.*\}|\[.*\])$/,
+ rdigit = /\d/;
jQuery.extend({
cache: {},
jQuery.extend({
cache: {},
@@
-129,8
+129,8
@@
jQuery.extend({
jQuery.fn.extend({
data: function( key, value ) {
jQuery.fn.extend({
data: function( key, value ) {
- if ( typeof key === "undefined" && this.length ) {
- return jQuery.data( this[0] );
+ if ( typeof key === "undefined" ) {
+ return this.length ? jQuery.data( this[0] ) : null;
} else if ( typeof key === "object" ) {
return this.each(function() {
} else if ( typeof key === "object" ) {
return this.each(function() {
@@
-158,7
+158,7
@@
jQuery.fn.extend({
data = data === "true" ? true :
data === "false" ? false :
data === "null" ? null :
data = data === "true" ? true :
data === "false" ? false :
data === "null" ? null :
- rnum.test( data ) ? parseFloat( data ) :
+ rdigit.test( data ) && !isNaN( data ) ? parseFloat( data ) :
rbrace.test( data ) ? jQuery.parseJSON( data ) :
data;
} catch( e ) {}
rbrace.test( data ) ? jQuery.parseJSON( data ) :
data;
} catch( e ) {}