jquery data: adding missing semicolons
[jquery.git] / src / data.js
1 var expando = "jQuery" + now(), uuid = 0, windowData = {};\r
2 \r
3 jQuery.extend({\r
4         cache: {},\r
5         \r
6         expando:expando,\r
7 \r
8         data: function( elem, name, data ) {\r
9                 elem = elem == window ?\r
10                         windowData :\r
11                         elem;\r
12 \r
13                 var id = elem[ expando ], cache = jQuery.cache;\r
14 \r
15                 // Compute a unique ID for the element\r
16                 if(!id) id = elem[ expando ] = ++uuid;\r
17 \r
18                 // Only generate the data cache if we're\r
19                 // trying to access or manipulate it\r
20                 if ( name && !cache[ id ] )\r
21                         cache[ id ] = {};\r
22 \r
23                 var thisCache = cache[ id ];\r
24 \r
25                 // Prevent overriding the named cache with undefined values\r
26                 if ( data !== undefined ) thisCache[ name ] = data;\r
27 \r
28                 if(name === true) return thisCache;\r
29                 else if(name) return thisCache[name];\r
30                 else return id;\r
31         },\r
32 \r
33         removeData: function( elem, name ) {\r
34                 elem = elem == window ?\r
35                         windowData :\r
36                         elem;\r
37 \r
38                 var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ];\r
39 \r
40                 // If we want to remove a specific section of the element's data\r
41                 if ( name ) {\r
42                         if ( thisCache ) {\r
43                                 // Remove the section of cache data\r
44                                 delete thisCache[ name ];\r
45 \r
46                                 // If we've removed all the data, remove the element's cache\r
47                                 if( jQuery.isEmptyObject(thisCache) )\r
48                                         jQuery.removeData( elem );\r
49                         }\r
50 \r
51                 // Otherwise, we want to remove all of the element's data\r
52                 } else {\r
53                         // Clean up the element expando\r
54                         try {\r
55                                 delete elem[ expando ];\r
56                         } catch(e){\r
57                                 // IE has trouble directly removing the expando\r
58                                 // but it's ok with using removeAttribute\r
59                                 if ( elem.removeAttribute )\r
60                                         elem.removeAttribute( expando );\r
61                         }\r
62 \r
63                         // Completely remove the data cache\r
64                         delete cache[ id ];\r
65                 }\r
66         },\r
67         queue: function( elem, type, data ) {\r
68                 if( !elem ) return;\r
69 \r
70                 type = (type || "fx") + "queue";\r
71                 var q = jQuery.data( elem, type );\r
72 \r
73                 // Speed up dequeue by getting out quickly if this is just a lookup\r
74                 if( !data ) return q || [];\r
75 \r
76                 if ( !q || jQuery.isArray(data) )\r
77                         q = jQuery.data( elem, type, jQuery.makeArray(data) );\r
78                 else\r
79                         q.push( data );\r
80 \r
81                 return q;\r
82         },\r
83 \r
84         dequeue: function( elem, type ){\r
85                 type = type || "fx";\r
86 \r
87                 var queue = jQuery.queue( elem, type ), fn = queue.shift();\r
88 \r
89                 // If the fx queue is dequeued, always remove the progress sentinel\r
90                 if( fn === "inprogress" ) fn = queue.shift();\r
91 \r
92                 if( fn ) {\r
93                         // Add a progress sentinel to prevent the fx queue from being\r
94                         // automatically dequeued\r
95                         if( type == "fx" ) queue.unshift("inprogress");\r
96 \r
97                         fn.call(elem, function() { jQuery.dequeue(elem, type); });\r
98                 }\r
99         }\r
100 });\r
101 \r
102 jQuery.fn.extend({\r
103         data: function( key, value ){\r
104                 if(typeof key === "undefined" && this.length) return jQuery.data(this[0], true);\r
105 \r
106                 var parts = key.split(".");\r
107                 parts[1] = parts[1] ? "." + parts[1] : "";\r
108 \r
109                 if ( value === undefined ) {\r
110                         var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);\r
111 \r
112                         if ( data === undefined && this.length )\r
113                                 data = jQuery.data( this[0], key );\r
114 \r
115                         return data === undefined && parts[1] ?\r
116                                 this.data( parts[0] ) :\r
117                                 data;\r
118                 } else\r
119                         return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){\r
120                                 jQuery.data( this, key, value );\r
121                         });\r
122         },\r
123 \r
124         removeData: function( key ){\r
125                 return this.each(function(){\r
126                         jQuery.removeData( this, key );\r
127                 });\r
128         },\r
129         queue: function(type, data){\r
130                 if ( typeof type !== "string" ) {\r
131                         data = type;\r
132                         type = "fx";\r
133                 }\r
134 \r
135                 if ( data === undefined )\r
136                         return jQuery.queue( this[0], type );\r
137 \r
138                 return this.each(function(i, elem){\r
139                         var queue = jQuery.queue( this, type, data );\r
140 \r
141                         if( type == "fx" && queue[0] !== "inprogress" )\r
142                                 jQuery.dequeue( this, type )\r
143                 });\r
144         },\r
145         dequeue: function(type){\r
146                 return this.each(function(){\r
147                         jQuery.dequeue( this, type );\r
148                 });\r
149         },\r
150         clearQueue: function(type){\r
151                 return this.queue( type || "fx", [] );\r
152         }\r
153 });