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,
33 if ( !id && typeof name === "string" && data === undefined ) {
37 // Get the data from the object directly
42 // Compute a unique ID for the element
44 elem[ jQuery.expando ] = id = ++jQuery.uuid;
47 // Avoid generating a new cache unless none exists and we
48 // want to manipulate it.
49 if ( typeof name === "object" ) {
51 cache[ id ] = jQuery.extend(true, {}, name);
53 store = jQuery.extend(true, {}, name);
54 cache[ id ] = function() {
59 } else if ( !cache[ id ] ) {
64 cache[ id ] = function() {
71 thisCache = isNode ? cache[ id ] : cache[ id ]();
73 // Prevent overriding the named cache with undefined values
74 if ( data !== undefined ) {
75 thisCache[ name ] = data;
78 return typeof name === "string" ? thisCache[ name ] : thisCache;
81 removeData: function( elem, name ) {
82 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
86 elem = elem == window ?
90 var isNode = elem.nodeType,
91 id = elem[ jQuery.expando ], cache = jQuery.cache;
92 if ( id && !isNode ) {
95 var thisCache = cache[ id ];
97 // If we want to remove a specific section of the element's data
100 // Remove the section of cache data
101 delete thisCache[ name ];
103 // If we've removed all the data, remove the element's cache
104 if ( jQuery.isEmptyObject(thisCache) ) {
105 jQuery.removeData( elem );
109 // Otherwise, we want to remove all of the element's data
111 if ( jQuery.support.deleteExpando || !isNode ) {
112 delete elem[ jQuery.expando ];
114 } else if ( elem.removeAttribute ) {
115 elem.removeAttribute( jQuery.expando );
118 // Completely remove the data cache
127 data: function( key, value ) {
128 if ( typeof key === "undefined" && this.length ) {
129 return jQuery.data( this[0] );
131 } else if ( typeof key === "object" ) {
132 return this.each(function() {
133 jQuery.data( this, key );
137 var parts = key.split(".");
138 parts[1] = parts[1] ? "." + parts[1] : "";
140 if ( value === undefined ) {
141 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
143 if ( data === undefined && this.length ) {
144 data = jQuery.data( this[0], key );
147 return data === undefined && parts[1] ?
148 this.data( parts[0] ) :
152 return this.each(function() {
153 var $this = jQuery( this ), args = [ parts[0], value ];
155 $this.triggerHandler( "setData" + parts[1] + "!", args );
156 jQuery.data( this, key, value );
157 $this.triggerHandler( "changeData" + parts[1] + "!", args );
162 removeData: function( key ) {
163 return this.each(function() {
164 jQuery.removeData( this, key );