1 var expando = "jQuery" + now(), uuid = 0, windowData = {};
8 // The following elements throw uncatchable exceptions if you
9 // attempt to add expando properties to them.
16 data: function( elem, name, data ) {
17 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
21 elem = elem == window ?
25 var id = elem[ expando ], cache = jQuery.cache, thisCache;
27 if ( !id && typeof name === "string" && data === undefined ) {
31 // Compute a unique ID for the element
36 // Avoid generating a new cache unless none exists and we
37 // want to manipulate it.
38 if ( typeof name === "object" ) {
40 thisCache = cache[ id ] = jQuery.extend(true, {}, name);
42 } else if ( !cache[ id ] ) {
47 thisCache = cache[ id ];
49 // Prevent overriding the named cache with undefined values
50 if ( data !== undefined ) {
51 thisCache[ name ] = data;
54 return typeof name === "string" ? thisCache[ name ] : thisCache;
57 removeData: function( elem, name ) {
58 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
62 elem = elem == window ?
66 var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ];
68 // If we want to remove a specific section of the element's data
71 // Remove the section of cache data
72 delete thisCache[ name ];
74 // If we've removed all the data, remove the element's cache
75 if ( jQuery.isEmptyObject(thisCache) ) {
76 jQuery.removeData( elem );
80 // Otherwise, we want to remove all of the element's data
82 // Clean up the element expando
84 delete elem[ expando ];
86 // IE has trouble directly removing the expando
87 // but it's ok with using removeAttribute
88 if ( elem.removeAttribute ) {
89 elem.removeAttribute( expando );
93 // Completely remove the data cache
100 data: function( key, value ) {
101 if ( typeof key === "undefined" && this.length ) {
102 return jQuery.data( this[0] );
104 } else if ( typeof key === "object" ) {
105 return this.each(function() {
106 jQuery.data( this, key );
110 var parts = key.split(".");
111 parts[1] = parts[1] ? "." + parts[1] : "";
113 if ( value === undefined ) {
114 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
116 if ( data === undefined && this.length ) {
117 data = jQuery.data( this[0], key );
119 return data === undefined && parts[1] ?
120 this.data( parts[0] ) :
123 return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function() {
124 jQuery.data( this, key, value );
129 removeData: function( key ) {
130 return this.each(function() {
131 jQuery.removeData( this, key );