X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fdata.js;h=085db0bb32f6a12dcb974f78f059d972c735d976;hb=97e134fe80a734b97170bf43c9459511f4e165c7;hp=4b557de0c9e4b441fcfd16fb6e081aa0ec74545e;hpb=19cd84cf3261ee412a2521df73dcf9d6cfba04a3;p=jquery.git diff --git a/src/data.js b/src/data.js index 4b557de..085db0b 100644 --- a/src/data.js +++ b/src/data.js @@ -1,4 +1,5 @@ var expando = "jQuery" + now(), uuid = 0, windowData = {}; +var emptyObject = {}; jQuery.extend({ cache: {}, @@ -10,24 +11,35 @@ jQuery.extend({ windowData : elem; - var id = elem[ expando ], cache = jQuery.cache; + var id = elem[ expando ], cache = jQuery.cache, thisCache; - // Compute a unique ID for the element - if(!id) id = elem[ expando ] = ++uuid; - - // Only generate the data cache if we're - // trying to access or manipulate it - if ( name && !cache[ id ] ) - cache[ id ] = {}; + // Handle the case where there's no name immediately + if ( !name ) { + return id; + } - var thisCache = cache[ id ]; + // Compute a unique ID for the element + if ( !id ) { + id = ++uuid; + } + // Avoid generating a new cache unless none exists and we + // want to manipulate it. + if ( cache[ id ] ) { + thisCache = cache[ id ]; + } else if ( typeof data === "undefined" ) { + thisCache = emptyObject; + } else { + thisCache = cache[ id ] = {}; + } + // Prevent overriding the named cache with undefined values - if ( data !== undefined ) thisCache[ name ] = data; - - if(name === true) return thisCache; - else if(name) return thisCache[name]; - else return id; + if ( data !== undefined ) { + elem[ expando ] = id; + thisCache[ name ] = data; + } + + return name === true ? thisCache : thisCache[ name ]; }, removeData: function( elem, name ) { @@ -44,8 +56,9 @@ jQuery.extend({ delete thisCache[ name ]; // If we've removed all the data, remove the element's cache - if( jQuery.isEmptyObject(thisCache) ) + if ( jQuery.isEmptyObject(thisCache) ) { jQuery.removeData( elem ); + } } // Otherwise, we want to remove all of the element's data @@ -53,17 +66,19 @@ jQuery.extend({ // Clean up the element expando try { delete elem[ expando ]; - } catch(e){ + } catch( e ) { // IE has trouble directly removing the expando // but it's ok with using removeAttribute - if ( elem.removeAttribute ) + if ( elem.removeAttribute ) { elem.removeAttribute( expando ); + } } // Completely remove the data cache delete cache[ id ]; } }, + queue: function( elem, type, data ) { if( !elem ) return;