var expando = "jQuery" + now(), uuid = 0, windowData = {};\r
+var emptyObject = {};\r
\r
jQuery.extend({\r
cache: {},\r
windowData :\r
elem;\r
\r
- var id = elem[ expando ], cache = jQuery.cache;\r
+ var id = elem[ expando ], cache = jQuery.cache, thisCache;\r
\r
- // Compute a unique ID for the element\r
- if(!id) id = elem[ expando ] = ++uuid;\r
-\r
- // Only generate the data cache if we're\r
- // trying to access or manipulate it\r
- if ( name && !cache[ id ] )\r
- cache[ id ] = {};\r
+ // Handle the case where there's no name immediately\r
+ if ( !name ) {\r
+ return id;\r
+ }\r
\r
- var thisCache = cache[ id ];\r
+ // Compute a unique ID for the element\r
+ if ( !id ) { \r
+ id = ++uuid;\r
+ }\r
\r
+ // Avoid generating a new cache unless none exists and we\r
+ // want to manipulate it.\r
+ if ( cache[ id ] ) {\r
+ thisCache = cache[ id ];\r
+ } else if ( typeof data === "undefined" ) {\r
+ thisCache = emptyObject;\r
+ } else {\r
+ thisCache = cache[ id ] = {};\r
+ }\r
+ \r
// Prevent overriding the named cache with undefined values\r
- if ( data !== undefined ) thisCache[ name ] = data;\r
-\r
- if(name === true) return thisCache;\r
- else if(name) return thisCache[name];\r
- else return id;\r
+ if ( data !== undefined ) {\r
+ elem[ expando ] = id;\r
+ thisCache[ name ] = data;\r
+ }\r
+ \r
+ return name === true ? thisCache : thisCache[ name ];\r
},\r
\r
removeData: function( elem, name ) {\r
delete thisCache[ name ];\r
\r
// If we've removed all the data, remove the element's cache\r
- if( jQuery.isEmptyObject(thisCache) )\r
+ if ( jQuery.isEmptyObject(thisCache) ) {\r
jQuery.removeData( elem );\r
+ }\r
}\r
\r
// Otherwise, we want to remove all of the element's data\r
// Clean up the element expando\r
try {\r
delete elem[ expando ];\r
- } catch(e){\r
+ } catch( e ) {\r
// IE has trouble directly removing the expando\r
// but it's ok with using removeAttribute\r
- if ( elem.removeAttribute )\r
+ if ( elem.removeAttribute ) {\r
elem.removeAttribute( expando );\r
+ }\r
}\r
\r
// Completely remove the data cache\r
delete cache[ id ];\r
}\r
},\r
+ \r
queue: function( elem, type, data ) {\r
if( !elem ) return;\r
\r