1 var expando = "jQuery" + 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[ jQuery.expando ], cache = jQuery.cache, thisCache,
26 isNode = elem.nodeType;
28 if ( !id && typeof name === "string" && data === undefined ) {
32 // Get the data from the object directly
37 // Compute a unique ID for the element
39 elem[ jQuery.expando ] = id = ++uuid;
42 // Avoid generating a new cache unless none exists and we
43 // want to manipulate it.
44 if ( typeof name === "object" ) {
45 cache[ id ] = jQuery.extend(true, {}, name);
47 } else if ( !cache[ id ] ) {
51 thisCache = cache[ id ];
53 // Prevent overriding the named cache with undefined values
54 if ( data !== undefined ) {
55 thisCache[ name ] = data;
58 return typeof name === "string" ? thisCache[ name ] : thisCache;
61 removeData: function( elem, name ) {
62 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
66 elem = elem == window ?
70 var id = elem[ jQuery.expando ], cache = jQuery.cache,
71 isNode = elem.nodeType, thisCache = isNode ? cache[ id ] : id;
73 // If we want to remove a specific section of the element's data
76 // Remove the section of cache data
77 delete thisCache[ name ];
79 // If we've removed all the data, remove the element's cache
80 if ( jQuery.isEmptyObject(thisCache) ) {
81 jQuery.removeData( elem );
85 // Otherwise, we want to remove all of the element's data
87 if ( jQuery.support.deleteExpando || !isNode ) {
88 delete elem[ jQuery.expando ];
90 } else if ( elem.removeAttribute ) {
91 elem.removeAttribute( jQuery.expando );
94 // 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 );