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" ) {
49 cache[ id ] = jQuery.extend(true, {}, name);
51 } else if ( !cache[ id ] ) {
55 thisCache = cache[ id ];
57 // Prevent overriding the named cache with undefined values
58 if ( data !== undefined ) {
59 thisCache[ name ] = data;
62 return typeof name === "string" ? thisCache[ name ] : thisCache;
65 removeData: function( elem, name ) {
66 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
70 elem = elem == window ?
74 var id = elem[ jQuery.expando ], cache = jQuery.cache,
75 isNode = elem.nodeType, thisCache = isNode ? cache[ id ] : id;
77 // If we want to remove a specific section of the element's data
80 // Remove the section of cache data
81 delete thisCache[ name ];
83 // If we've removed all the data, remove the element's cache
84 if ( jQuery.isEmptyObject(thisCache) ) {
85 jQuery.removeData( elem );
89 // Otherwise, we want to remove all of the element's data
91 if ( jQuery.support.deleteExpando || !isNode ) {
92 delete elem[ jQuery.expando ];
94 } else if ( elem.removeAttribute ) {
95 elem.removeAttribute( jQuery.expando );
98 // Completely remove the data cache
107 data: function( key, value ) {
108 if ( typeof key === "undefined" && this.length ) {
109 return jQuery.data( this[0] );
111 } else if ( typeof key === "object" ) {
112 return this.each(function() {
113 jQuery.data( this, key );
117 var parts = key.split(".");
118 parts[1] = parts[1] ? "." + parts[1] : "";
120 if ( value === undefined ) {
121 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
123 if ( data === undefined && this.length ) {
124 data = jQuery.data( this[0], key );
126 return data === undefined && parts[1] ?
127 this.data( parts[0] ) :
130 return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function() {
131 jQuery.data( this, key, value );
136 removeData: function( key ) {
137 return this.each(function() {
138 jQuery.removeData( this, key );