X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fdata.js;h=ac082dd6e97187071f985be94926af83ad9ceb27;hb=6dfdb14753c66cfd38f8445bd6119ef4a1274d5e;hp=dc08a563a95adae9dc0bd99a14b94dd02279aafc;hpb=e0b24306a86629f02576017f25d295fbe07f21a5;p=jquery.git diff --git a/src/data.js b/src/data.js index dc08a56..ac082dd 100644 --- a/src/data.js +++ b/src/data.js @@ -1,8 +1,8 @@ (function( jQuery ) { var windowData = {}, - rnum = /^-?\d+(?:\.\d+)?(?:E\d+)?$/, - rbrace = /^(?:{.*}|\[.*\])$/; + rbrace = /^(?:\{.*\}|\[.*\])$/, + rdigit = /\d/; jQuery.extend({ cache: {}, @@ -52,9 +52,10 @@ jQuery.extend({ // want to manipulate it. if ( typeof name === "object" ) { if ( isNode ) { - cache[ id ] = jQuery.extend(true, {}, name); + cache[ id ] = jQuery.extend(cache[ id ], name); + } else { - store = jQuery.extend(true, {}, name); + store = jQuery.extend(cache[ id ], name); cache[ id ] = function() { return store; }; @@ -63,6 +64,7 @@ jQuery.extend({ } else if ( !cache[ id ] ) { if ( isNode ) { cache[ id ] = {}; + } else { store = {}; cache[ id ] = function() { @@ -129,8 +131,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() { @@ -158,7 +160,7 @@ jQuery.fn.extend({ 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 ) {}