1 var expando = "jQuery" + now(), uuid = 0, windowData = {};
9 data: function( elem, name, data ) {
10 elem = elem == window ?
14 var id = elem[ expando ], cache = jQuery.cache, thisCache;
16 // Handle the case where there's no name immediately
21 // Compute a unique ID for the element
26 // Avoid generating a new cache unless none exists and we
27 // want to manipulate it.
29 thisCache = cache[ id ];
30 } else if ( typeof data === "undefined" ) {
31 thisCache = emptyObject;
33 thisCache = cache[ id ] = {};
36 // Prevent overriding the named cache with undefined values
37 if ( data !== undefined ) {
39 thisCache[ name ] = data;
42 return name ? thisCache[ name ] : thisCache;
45 removeData: function( elem, name ) {
46 elem = elem == window ?
50 var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ];
52 // If we want to remove a specific section of the element's data
55 // Remove the section of cache data
56 delete thisCache[ name ];
58 // If we've removed all the data, remove the element's cache
59 if ( jQuery.isEmptyObject(thisCache) ) {
60 jQuery.removeData( elem );
64 // Otherwise, we want to remove all of the element's data
66 // Clean up the element expando
68 delete elem[ expando ];
70 // IE has trouble directly removing the expando
71 // but it's ok with using removeAttribute
72 if ( elem.removeAttribute ) {
73 elem.removeAttribute( expando );
77 // Completely remove the data cache
84 data: function( key, value ){
85 if ( typeof key === "undefined" && this.length ) {
86 return jQuery.data( this[0] );
89 var parts = key.split(".");
90 parts[1] = parts[1] ? "." + parts[1] : "";
92 if ( value === undefined ) {
93 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
95 if ( data === undefined && this.length ) {
96 data = jQuery.data( this[0], key );
98 return data === undefined && parts[1] ?
99 this.data( parts[0] ) :
102 return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
103 jQuery.data( this, key, value );
108 removeData: function( key ){
109 return this.each(function(){
110 jQuery.removeData( this, key );