1 var expando = "jQuery" + now(), uuid = 0, windowData = {};
9 // The following elements throw uncatchable exceptions if you
10 // attempt to add expando properties to them.
17 data: function( elem, name, data ) {
18 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
22 elem = elem == window ?
26 var id = elem[ expando ], cache = jQuery.cache, thisCache;
28 // Handle the case where there's no name immediately
33 // Compute a unique ID for the element
38 // Avoid generating a new cache unless none exists and we
39 // want to manipulate it.
40 if ( typeof name === "object" ) {
42 thisCache = cache[ id ] = jQuery.extend(true, {}, name);
43 } else if ( cache[ id ] ) {
44 thisCache = cache[ id ];
45 } else if ( typeof data === "undefined" ) {
46 thisCache = emptyObject;
48 thisCache = cache[ id ] = {};
51 // Prevent overriding the named cache with undefined values
52 if ( data !== undefined ) {
54 thisCache[ name ] = data;
57 return typeof name === "string" ? thisCache[ name ] : thisCache;
60 removeData: function( elem, name ) {
61 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
65 elem = elem == window ?
69 var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ];
71 // If we want to remove a specific section of the element's data
74 // Remove the section of cache data
75 delete thisCache[ name ];
77 // If we've removed all the data, remove the element's cache
78 if ( jQuery.isEmptyObject(thisCache) ) {
79 jQuery.removeData( elem );
83 // Otherwise, we want to remove all of the element's data
85 // Clean up the element expando
87 delete elem[ expando ];
89 // IE has trouble directly removing the expando
90 // but it's ok with using removeAttribute
91 if ( elem.removeAttribute ) {
92 elem.removeAttribute( expando );
96 // Completely remove the data cache
103 data: function( key, value ){
104 if ( typeof key === "undefined" && this.length ) {
105 return jQuery.data( this[0] );
107 } else if ( typeof key === "object" ) {
108 return this.each(function() {
109 jQuery.data( this, key );
113 var parts = key.split(".");
114 parts[1] = parts[1] ? "." + parts[1] : "";
116 if ( value === undefined ) {
117 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
119 if ( data === undefined && this.length ) {
120 data = jQuery.data( this[0], key );
122 return data === undefined && parts[1] ?
123 this.data( parts[0] ) :
126 return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
127 jQuery.data( this, key, value );
132 removeData: function( key ){
133 return this.each(function(){
134 jQuery.removeData( this, key );