4 rbrace = /^(?:\{.*\}|\[.*\])$/,
10 // Please use with caution
13 // Unique for each copy of jQuery on the page
14 expando: "jQuery" + jQuery.now(),
16 // The following elements throw uncatchable exceptions if you
17 // attempt to add expando properties to them.
20 // Ban all objects except for Flash (which handle expandos)
21 "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
25 data: function( elem, name, data ) {
26 if ( !jQuery.acceptData( elem ) ) {
30 elem = elem == window ?
34 var id = elem[ jQuery.expando ], cache = jQuery.cache, thisCache,
35 isNode = elem.nodeType,
38 if ( !id && typeof name === "string" && data === undefined ) {
42 // Get the data from the object directly
47 // Compute a unique ID for the element
49 elem[ jQuery.expando ] = id = ++jQuery.uuid;
52 // Avoid generating a new cache unless none exists and we
53 // want to manipulate it.
54 if ( typeof name === "object" ) {
56 cache[ id ] = jQuery.extend(cache[ id ], name);
59 store = jQuery.extend(cache[ id ], name);
60 cache[ id ] = function() {
65 } else if ( !cache[ id ] ) {
71 cache[ id ] = function() {
78 thisCache = isNode ? cache[ id ] : cache[ id ]();
80 // Prevent overriding the named cache with undefined values
81 if ( data !== undefined ) {
82 thisCache[ name ] = data;
85 return typeof name === "string" ? thisCache[ name ] : thisCache;
88 removeData: function( elem, name ) {
89 if ( !jQuery.acceptData( elem ) ) {
93 elem = elem == window ?
97 var isNode = elem.nodeType,
98 id = elem[ jQuery.expando ], cache = jQuery.cache;
99 if ( id && !isNode ) {
102 var thisCache = cache[ id ];
104 // If we want to remove a specific section of the element's data
107 // Remove the section of cache data
108 delete thisCache[ name ];
110 // If we've removed all the data, remove the element's cache
111 if ( jQuery.isEmptyObject(thisCache) ) {
112 jQuery.removeData( elem );
116 // Otherwise, we want to remove all of the element's data
118 if ( jQuery.support.deleteExpando || !isNode ) {
119 delete elem[ jQuery.expando ];
121 } else if ( elem.removeAttribute ) {
122 elem.removeAttribute( jQuery.expando );
125 // Completely remove the data cache
132 // A method for determining if a DOM node can handle the data expando
133 acceptData: function( elem ) {
134 if ( elem.nodeName ) {
135 match = jQuery.noData[ elem.nodeName.toLowerCase() ];
138 return !(match === true || elem.getAttribute("classid") !== match);
147 data: function( key, value ) {
148 if ( typeof key === "undefined" ) {
149 return this.length ? jQuery.data( this[0] ) : null;
151 } else if ( typeof key === "object" ) {
152 return this.each(function() {
153 jQuery.data( this, key );
157 var parts = key.split(".");
158 parts[1] = parts[1] ? "." + parts[1] : "";
160 if ( value === undefined ) {
161 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
163 // Try to fetch any internally stored data first
164 if ( data === undefined && this.length ) {
165 data = jQuery.data( this[0], key );
167 // If nothing was found internally, try to fetch any
168 // data from the HTML5 data-* attribute
169 if ( data === undefined && this[0].nodeType === 1 ) {
170 data = this[0].getAttribute( "data-" + key );
172 if ( typeof data === "string" ) {
174 data = data === "true" ? true :
175 data === "false" ? false :
176 data === "null" ? null :
177 rdigit.test( data ) && !isNaN( data ) ? parseFloat( data ) :
178 rbrace.test( data ) ? jQuery.parseJSON( data ) :
188 return data === undefined && parts[1] ?
189 this.data( parts[0] ) :
193 return this.each(function() {
194 var $this = jQuery( this ), args = [ parts[0], value ];
196 $this.triggerHandler( "setData" + parts[1] + "!", args );
197 jQuery.data( this, key, value );
198 $this.triggerHandler( "changeData" + parts[1] + "!", args );
203 removeData: function( key ) {
204 return this.each(function() {
205 jQuery.removeData( this, key );