(function( jQuery ) {
var windowData = {},
- rnum = /^-?\d+(?:\.\d+)$/,
- rbrace = /^{.*}$/;
+ rbrace = /^(?:\{.*\}|\[.*\])$/,
+ rdigit = /\d/;
jQuery.extend({
cache: {},
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() {
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 ) {}