X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fdata.js;h=b7a6ab9723c0e91deb1260c435dd986eaee67c79;hb=626624a19a6cbd70b44da08ee2123ba79f8e2bb0;hp=cf3cf606a96d88fcc97820d68e92b6471352c7d6;hpb=3a0a35288304ab5289a1815055623b18de4dc9f6;p=jquery.git diff --git a/src/data.js b/src/data.js index cf3cf60..b7a6ab9 100644 --- a/src/data.js +++ b/src/data.js @@ -1,7 +1,8 @@ (function( jQuery ) { var windowData = {}, - rbrace = /^(?:\{.*\}|\[.*\])$/; + rbrace = /^(?:\{.*\}|\[.*\])$/, + rdigit = /\d/; jQuery.extend({ cache: {}, @@ -128,8 +129,8 @@ jQuery.extend({ 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() { @@ -157,7 +158,7 @@ jQuery.fn.extend({ data = data === "true" ? true : data === "false" ? false : data === "null" ? null : - !isNaN( data ) ? parseFloat( data ) : + rdigit.test( data ) && !isNaN( data ) ? parseFloat( data ) : rbrace.test( data ) ? jQuery.parseJSON( data ) : data; } catch( e ) {}