8 // Please use with caution
11 // Unique for each copy of jQuery on the page
12 expando: "jQuery" + jQuery.now(),
14 // The following elements throw uncatchable exceptions if you
15 // attempt to add expando properties to them.
22 data: function( elem, name, data ) {
23 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
27 elem = elem == window ?
31 var id = elem[ jQuery.expando ], cache = jQuery.cache, thisCache,
32 isNode = elem.nodeType,
35 if ( !id && typeof name === "string" && data === undefined ) {
39 // Get the data from the object directly
44 // Compute a unique ID for the element
46 elem[ jQuery.expando ] = id = ++jQuery.uuid;
49 // Avoid generating a new cache unless none exists and we
50 // want to manipulate it.
51 if ( typeof name === "object" ) {
53 cache[ id ] = jQuery.extend(true, {}, name);
55 store = jQuery.extend(true, {}, name);
56 cache[ id ] = function() {
61 } else if ( !cache[ id ] ) {
66 cache[ id ] = function() {
73 thisCache = isNode ? cache[ id ] : cache[ id ]();
75 // Prevent overriding the named cache with undefined values
76 if ( data !== undefined ) {
77 thisCache[ name ] = data;
80 return typeof name === "string" ? thisCache[ name ] : thisCache;
83 removeData: function( elem, name ) {
84 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
88 elem = elem == window ?
92 var isNode = elem.nodeType,
93 id = elem[ jQuery.expando ], cache = jQuery.cache;
94 if ( id && !isNode ) {
97 var thisCache = cache[ id ];
99 // If we want to remove a specific section of the element's data
102 // Remove the section of cache data
103 delete thisCache[ name ];
105 // If we've removed all the data, remove the element's cache
106 if ( jQuery.isEmptyObject(thisCache) ) {
107 jQuery.removeData( elem );
111 // Otherwise, we want to remove all of the element's data
113 if ( jQuery.support.deleteExpando || !isNode ) {
114 delete elem[ jQuery.expando ];
116 } else if ( elem.removeAttribute ) {
117 elem.removeAttribute( jQuery.expando );
120 // Completely remove the data cache
129 data: function( key, value ) {
130 if ( typeof key === "undefined" && this.length ) {
131 return jQuery.data( this[0] );
133 } else if ( typeof key === "object" ) {
134 return this.each(function() {
135 jQuery.data( this, key );
139 var parts = key.split(".");
140 parts[1] = parts[1] ? "." + parts[1] : "";
142 if ( value === undefined ) {
143 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
145 if ( data === undefined && this.length ) {
146 data = jQuery.data( this[0], key );
149 return data === undefined && parts[1] ?
150 this.data( parts[0] ) :
154 return this.each(function() {
155 var $this = jQuery( this ), args = [ parts[0], value ];
157 $this.triggerHandler( "setData" + parts[1] + "!", args );
158 jQuery.data( this, key, value );
159 $this.triggerHandler( "changeData" + parts[1] + "!", args );
164 removeData: function( key ) {
165 return this.each(function() {
166 jQuery.removeData( this, key );