X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fdata.js;h=ac082dd6e97187071f985be94926af83ad9ceb27;hb=6dfdb14753c66cfd38f8445bd6119ef4a1274d5e;hp=cf3cf606a96d88fcc97820d68e92b6471352c7d6;hpb=3a0a35288304ab5289a1815055623b18de4dc9f6;p=jquery.git diff --git a/src/data.js b/src/data.js index cf3cf60..ac082dd 100644 --- a/src/data.js +++ b/src/data.js @@ -1,7 +1,8 @@ (function( jQuery ) { var windowData = {}, - rbrace = /^(?:\{.*\}|\[.*\])$/; + rbrace = /^(?:\{.*\}|\[.*\])$/, + rdigit = /\d/; jQuery.extend({ cache: {}, @@ -51,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; }; @@ -62,6 +64,7 @@ jQuery.extend({ } else if ( !cache[ id ] ) { if ( isNode ) { cache[ id ] = {}; + } else { store = {}; cache[ id ] = function() { @@ -128,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() { @@ -157,7 +160,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 ) {}