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.
41 thisCache = cache[ id ];
42 } else if ( typeof data === "undefined" ) {
43 thisCache = emptyObject;
45 thisCache = cache[ id ] = {};
48 // Prevent overriding the named cache with undefined values
49 if ( data !== undefined ) {
51 thisCache[ name ] = data;
54 return name ? 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] );
105 var parts = key.split(".");
106 parts[1] = parts[1] ? "." + parts[1] : "";
108 if ( value === undefined ) {
109 var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
111 if ( data === undefined && this.length ) {
112 data = jQuery.data( this[0], key );
114 return data === undefined && parts[1] ?
115 this.data( parts[0] ) :
118 return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
119 jQuery.data( this, key, value );
124 removeData: function( key ){
125 return this.each(function(){
126 jQuery.removeData( this, key );