X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fdata.js;h=9cc76c603ef5402cae63f42a64fbd3c1758e9cf7;hb=190812c3be99bde536d373b6b6ab65cfe053a532;hp=bf54e752693b767e5aed6eecef53cb6b7271d11b;hpb=89dc1e01435ebeef173c9a843096cd5c1fbc9dd8;p=jquery.git diff --git a/src/data.js b/src/data.js index bf54e75..9cc76c6 100644 --- a/src/data.js +++ b/src/data.js @@ -8,25 +8,24 @@ jQuery.extend({ windowData : elem; - var id = elem[ expando ]; + var id = elem[ expando ], cache = jQuery.cache; // Compute a unique ID for the element - if ( !id ) - id = elem[ expando ] = ++uuid; + if(!id) id = elem[ expando ] = ++uuid; // Only generate the data cache if we're // trying to access or manipulate it - if ( name && !jQuery.cache[ id ] ) - jQuery.cache[ id ] = {}; + if ( name && !cache[ id ] ) + cache[ id ] = {}; + + var thisCache = cache[ id ]; // Prevent overriding the named cache with undefined values - if ( data !== undefined ) - jQuery.cache[ id ][ name ] = data; + if ( data !== undefined ) thisCache[ name ] = data; - // Return the named cache data, or the ID for the element - return name ? - jQuery.cache[ id ][ name ] : - id; + if(name === true) return thisCache + else if(name) return thisCache[name] + else return id }, removeData: function( elem, name ) { @@ -34,21 +33,16 @@ jQuery.extend({ windowData : elem; - var id = elem[ expando ]; + var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ]; // If we want to remove a specific section of the element's data if ( name ) { - if ( jQuery.cache[ id ] ) { + if ( thisCache ) { // Remove the section of cache data - delete jQuery.cache[ id ][ name ]; + delete thisCache[ name ]; // If we've removed all the data, remove the element's cache - name = ""; - - for ( name in jQuery.cache[ id ] ) - break; - - if ( !name ) + if( jQuery.isEmptyObject(thisCache) ) jQuery.removeData( elem ); } @@ -65,7 +59,7 @@ jQuery.extend({ } // Completely remove the data cache - delete jQuery.cache[ id ]; + delete cache[ id ]; } }, queue: function( elem, type, data ) { @@ -98,6 +92,8 @@ jQuery.extend({ jQuery.fn.extend({ data: function( key, value ){ + if(typeof key === "undefined" && this.length) return jQuery.data(this[0], true); + var parts = key.split("."); parts[1] = parts[1] ? "." + parts[1] : "";