3 test("expando", function(){
\r
6 equals("expando" in jQuery, true, "jQuery is exposing the expando");
\r
10 equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
\r
12 jQuery.data(obj, true);
\r
13 equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
\r
15 jQuery.data(obj, 'test');
\r
16 equals( jQuery.expando in obj, false, "jQuery.data did not add an expando to the object" );
\r
18 jQuery.data(obj, "foo", "bar");
\r
19 equals( jQuery.expando in obj, true, "jQuery.data added an expando to the object" );
\r
21 var id = obj[jQuery.expando];
\r
22 equals( id in jQuery.cache, true, "jQuery.data added an entry to jQuery.cache" );
\r
24 equals( jQuery.cache[id].foo, "bar", "jQuery.data worked correctly" );
\r
27 test("jQuery.data", function() {
\r
29 var div = jQuery("#foo")[0];
\r
30 equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );
\r
32 jQuery.data(div, "test", "success");
\r
33 equals( jQuery.data(div, "test"), "success", "Check for added data" );
\r
35 var data = jQuery.data(div);
\r
36 same( data, { "test": "success" }, "Return complete data set" );
\r
38 jQuery.data(div, "test", "overwritten");
\r
39 equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" );
\r
41 jQuery.data(div, "test", undefined);
\r
42 equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed");
\r
44 jQuery.data(div, "test", null);
\r
45 ok( jQuery.data(div, "test") === null, "Check for null data");
\r
48 test(".data()", function() {
\r
51 var div = jQuery("#foo");
\r
52 div.data("test", "success");
\r
53 isObj( div.data(), {test: "success"}, "data() get the entire data object" )
\r
56 test(".data(String) and .data(String, Object)", function() {
\r
58 var div = jQuery("#foo");
\r
59 equals( div.data("test"), undefined, "Check for no data exists" );
\r
60 div.data("test", "success");
\r
61 equals( div.data("test"), "success", "Check for added data" );
\r
62 div.data("test", "overwritten");
\r
63 equals( div.data("test"), "overwritten", "Check for overwritten data" );
\r
64 div.data("test", undefined);
\r
65 equals( div.data("test"), "overwritten", "Check that data wasn't removed");
\r
66 div.data("test", null);
\r
67 ok( div.data("test") === null, "Check for null data");
\r
69 div.data("test", "overwritten");
\r
70 var hits = {test:0}, gets = {test:0};
\r
73 .bind("setData",function(e,key,value){ hits[key] += value; })
\r
74 .bind("setData.foo",function(e,key,value){ hits[key] += value; })
\r
75 .bind("getData",function(e,key){ gets[key] += 1; })
\r
76 .bind("getData.foo",function(e,key){ gets[key] += 3; });
\r
78 div.data("test.foo", 2);
\r
79 equals( div.data("test"), "overwritten", "Check for original data" );
\r
80 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
81 equals( div.data("test.bar"), "overwritten", "Check for unmatched namespace" );
\r
82 equals( hits.test, 2, "Check triggered setter functions" );
\r
83 equals( gets.test, 5, "Check triggered getter functions" );
\r
88 div.data("test", 1);
\r
89 equals( div.data("test"), 1, "Check for original data" );
\r
90 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
91 equals( div.data("test.bar"), 1, "Check for unmatched namespace" );
\r
92 equals( hits.test, 1, "Check triggered setter functions" );
\r
93 equals( gets.test, 5, "Check triggered getter functions" );
\r
99 .bind("getData",function(e,key){ return key + "root"; })
\r
100 .bind("getData.foo",function(e,key){ return key + "foo"; });
\r
102 equals( div.data("test"), "testroot", "Check for original data" );
\r
103 equals( div.data("test.foo"), "testfoo", "Check for namespaced data" );
\r
104 equals( div.data("test.bar"), "testroot", "Check for unmatched namespace" );
\r
107 var $elem = jQuery({});
\r
108 equals( $elem.data('nothing'), undefined, "Non-existent data returns undefined");
\r
109 equals( $elem.data('null',null).data('null'), null, "null's are preserved");
\r
110 equals( $elem.data('emptyString','').data('emptyString'), '', "Empty strings are preserved");
\r
111 equals( $elem.data('false',false).data('false'), false, "false's are preserved");
\r
114 $elem.removeData();
\r
117 test("jQuery.removeData", function() {
\r
119 var div = jQuery("#foo")[0];
\r
120 jQuery.data(div, "test", "testing");
\r
121 jQuery.removeData(div, "test");
\r
122 equals( jQuery.data(div, "test"), undefined, "Check removal of data" );
\r
125 test(".removeData()", function() {
\r
127 var div = jQuery("#foo");
\r
128 div.data("test", "testing");
\r
129 div.removeData("test");
\r
130 equals( div.data("test"), undefined, "Check removal of data" );
\r
132 div.data("test", "testing");
\r
133 div.data("test.foo", "testing2");
\r
134 div.removeData("test.bar");
\r
135 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
136 equals( div.data("test"), "testing", "Make sure data is intact" );
\r
138 div.removeData("test");
\r
139 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
140 equals( div.data("test"), undefined, "Make sure data is intact" );
\r
142 div.removeData("test.foo");
\r
143 equals( div.data("test.foo"), undefined, "Make sure data is intact" );
\r
146 test("queue() defaults to 'fx' type", function () {
\r
152 var $foo = jQuery("#foo");
\r
154 $foo.queue(function() {
\r
156 setTimeout(function() {
\r
157 jQuery(self).dequeue("fx");
\r
160 }).queue(function() {
\r
161 ok( "dequeuing 'fx' calls queues created with no name" )
\r
166 test("queue() with other types",function() {
\r
170 var $div = jQuery({});
\r
173 .queue('foo',function(){
\r
174 equals( ++counter, 1, "Dequeuing" );
\r
175 jQuery.dequeue(this,'foo');
\r
177 .queue('foo',function(){
\r
178 equals( ++counter, 2, "Dequeuing" );
\r
179 jQuery(this).dequeue('foo');
\r
181 .queue('foo',function(){
\r
182 equals( ++counter, 3, "Dequeuing" );
\r
184 .queue('foo',function(){
\r
185 equals( ++counter, 4, "Dequeuing" );
\r
188 equals( $div.queue('foo').length, 4, "Testing queue length" );
\r
190 $div.dequeue('foo');
\r
192 equals( counter, 3, "Testing previous call to dequeue" );
\r
193 equals( $div.queue('foo').length, 1, "Testing queue length" );
\r
195 $div.dequeue('foo');
\r
197 equals( counter, 4, "Testing previous call to dequeue" );
\r
198 equals( $div.queue('foo').length, 0, "Testing queue length" );
\r
201 test("queue(name) passes in the next item in the queue as a parameter", function() {
\r
204 var div = jQuery({});
\r
207 div.queue("foo", function(next) {
\r
208 equals(++counter, 1, "Dequeueing");
\r
210 }).queue("foo", function(next) {
\r
211 equals(++counter, 2, "Next was called");
\r
213 }).queue("bar", function() {
\r
214 equals(++counter, 3, "Other queues are not triggered by next()")
\r
217 div.dequeue("foo");
\r
220 test("queue(name) passes in the next item in the queue as a parameter", function() {
\r
223 var div = jQuery({});
\r
226 div.queue("foo", function(next) {
\r
227 equals(++counter, 1, "Dequeueing");
\r
229 }).queue("foo", function(next) {
\r
230 equals(++counter, 2, "Next was called");
\r
232 }).queue("bar", function() {
\r
233 equals(++counter, 3, "Other queues are not triggered by next()")
\r
236 div.dequeue("foo");
\r
239 test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
\r
243 var div = jQuery({});
\r
246 div.queue(function(next) {
\r
247 equals(++counter, 1, "Dequeueing");
\r
249 setTimeout(function() { next() }, 500);
\r
250 }).queue(function(next) {
\r
251 equals(++counter, 2, "Next was called");
\r
254 }).queue("bar", function() {
\r
255 equals(++counter, 3, "Other queues are not triggered by next()")
\r
260 test("clearQueue(name) clears the queue", function() {
\r
263 var div = jQuery({});
\r
266 div.queue("foo", function(next) {
\r
268 jQuery(this).clearQueue("foo");
\r
270 }).queue("foo", function(next) {
\r
274 div.dequeue("foo");
\r
276 equals(counter, 1, "the queue was cleared");
\r
279 test("clearQueue() clears the fx queue", function() {
\r
282 var div = jQuery({});
\r
285 div.queue(function(next) {
\r
288 setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50);
\r
289 }).queue(function(next) {
\r
293 equals(counter, 1, "the queue was cleared");
\r