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 if ( jQuery.support.deleteExpando ) {
83 delete elem[ jQuery.expando ];
85 } else if ( elem.removeAttribute ) {
86 elem.removeAttribute( jQuery.expando );
89 // Completely remove the data cache
96 data: function( key, value ) {
97 if ( typeof key === "undefined" && this.length ) {
98 return jQuery.data( this[0] );
100 } else if ( typeof key === "object" ) {
101 return this.each(function() {
102 jQuery.data( this, key );
106 var parts = key.split(".");
107 parts[1] = parts[1] ? "." + parts[1] : "";
109 if ( value === undefined ) {
110 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
112 if ( data === undefined && this.length ) {
113 data = jQuery.data( this[0], key );
115 return data === undefined && parts[1] ?
116 this.data( parts[0] ) :
119 return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function() {
120 jQuery.data( this, key, value );
125 removeData: function( key ) {
126 return this.each(function() {
127 jQuery.removeData( this, key );