6 // Please use with caution
9 // Unique for each copy of jQuery on the page
10 expando: "jQuery" + jQuery.now(),
12 // The following elements throw uncatchable exceptions if you
13 // attempt to add expando properties to them.
20 data: function( elem, name, data ) {
21 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
25 elem = elem == window ?
29 var id = elem[ jQuery.expando ], cache = jQuery.cache, thisCache,
30 isNode = elem.nodeType;
32 if ( !id && typeof name === "string" && data === undefined ) {
36 // Get the data from the object directly
41 // Compute a unique ID for the element
43 elem[ jQuery.expando ] = id = ++jQuery.uuid;
46 // Avoid generating a new cache unless none exists and we
47 // want to manipulate it.
48 if ( typeof name === "object" ) {
50 cache[ id ] = jQuery.extend(true, {}, name);
52 cache[ id ] = function() {
53 return jQuery.extend(true, {}, name);
57 } else if ( !cache[ id ] ) {
62 cache[ id ] = function() {
69 thisCache = isNode? cache[ id ] : cache[ id ]();
71 // Prevent overriding the named cache with undefined values
72 if ( data !== undefined ) {
73 thisCache[ name ] = data;
76 return typeof name === "string" ? thisCache[ name ] : thisCache;
79 removeData: function( elem, name ) {
80 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
84 elem = elem == window ?
88 var isNode = elem.nodeType,
89 id = elem[ jQuery.expando ], cache = jQuery.cache;
90 if ( id && !isNode ) {
93 var thisCache = cache[ id ];
95 // If we want to remove a specific section of the element's data
98 // Remove the section of cache data
99 delete thisCache[ name ];
101 // If we've removed all the data, remove the element's cache
102 if ( jQuery.isEmptyObject(thisCache) ) {
103 jQuery.removeData( elem );
107 // Otherwise, we want to remove all of the element's data
109 if ( jQuery.support.deleteExpando || !isNode ) {
110 delete elem[ jQuery.expando ];
112 } else if ( elem.removeAttribute ) {
113 elem.removeAttribute( jQuery.expando );
116 // Completely remove the data cache
125 data: function( key, value ) {
126 if ( typeof key === "undefined" && this.length ) {
127 return jQuery.data( this[0] );
129 } else if ( typeof key === "object" ) {
130 return this.each(function() {
131 jQuery.data( this, key );
135 var parts = key.split(".");
136 parts[1] = parts[1] ? "." + parts[1] : "";
138 if ( value === undefined ) {
139 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
141 if ( data === undefined && this.length ) {
142 data = jQuery.data( this[0], key );
144 return data === undefined && parts[1] ?
145 this.data( parts[0] ) :
148 return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function() {
149 jQuery.data( this, key, value );
150 jQuery.event.trigger( "changeData" + parts[1] + "!", [parts[0], value], this );
155 removeData: function( key ) {
156 return this.each(function() {
157 jQuery.removeData( this, key );