3 test("jQuery.data", function() {
\r
5 var div = jQuery("#foo")[0];
\r
6 equals( jQuery.data(div, "test"), undefined, "Check for no data exists" );
\r
7 jQuery.data(div, "test", "success");
\r
8 equals( jQuery.data(div, "test"), "success", "Check for added data" );
\r
9 jQuery.data(div, "test", "overwritten");
\r
10 equals( jQuery.data(div, "test"), "overwritten", "Check for overwritten data" );
\r
11 jQuery.data(div, "test", undefined);
\r
12 equals( jQuery.data(div, "test"), "overwritten", "Check that data wasn't removed");
\r
13 jQuery.data(div, "test", null);
\r
14 ok( jQuery.data(div, "test") === null, "Check for null data");
\r
17 test(".data()", function() {
\r
19 var div = jQuery("#foo");
\r
20 equals( div.data("test"), undefined, "Check for no data exists" );
\r
21 div.data("test", "success");
\r
22 equals( div.data("test"), "success", "Check for added data" );
\r
23 div.data("test", "overwritten");
\r
24 equals( div.data("test"), "overwritten", "Check for overwritten data" );
\r
25 div.data("test", undefined);
\r
26 equals( div.data("test"), "overwritten", "Check that data wasn't removed");
\r
27 div.data("test", null);
\r
28 ok( div.data("test") === null, "Check for null data");
\r
30 div.data("test", "overwritten");
\r
31 var hits = {test:0}, gets = {test:0};
\r
34 .bind("setData",function(e,key,value){ hits[key] += value; })
\r
35 .bind("setData.foo",function(e,key,value){ hits[key] += value; })
\r
36 .bind("getData",function(e,key){ gets[key] += 1; })
\r
37 .bind("getData.foo",function(e,key){ gets[key] += 3; });
\r
39 div.data("test.foo", 2);
\r
40 equals( div.data("test"), "overwritten", "Check for original data" );
\r
41 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
42 equals( div.data("test.bar"), "overwritten", "Check for unmatched namespace" );
\r
43 equals( hits.test, 2, "Check triggered setter functions" );
\r
44 equals( gets.test, 5, "Check triggered getter functions" );
\r
49 div.data("test", 1);
\r
50 equals( div.data("test"), 1, "Check for original data" );
\r
51 equals( div.data("test.foo"), 2, "Check for namespaced data" );
\r
52 equals( div.data("test.bar"), 1, "Check for unmatched namespace" );
\r
53 equals( hits.test, 1, "Check triggered setter functions" );
\r
54 equals( gets.test, 5, "Check triggered getter functions" );
\r
60 .bind("getData",function(e,key){ return key + "root"; })
\r
61 .bind("getData.foo",function(e,key){ return key + "foo"; });
\r
63 equals( div.data("test"), "testroot", "Check for original data" );
\r
64 equals( div.data("test.foo"), "testfoo", "Check for namespaced data" );
\r
65 equals( div.data("test.bar"), "testroot", "Check for unmatched namespace" );
\r
68 var $elem = jQuery({});
\r
69 equals( $elem.data('nothing'), undefined, "Non-existent data returns undefined");
\r
70 equals( $elem.data('null',null).data('null'), null, "null's are preserved");
\r
71 equals( $elem.data('emptyString','').data('emptyString'), '', "Empty strings are preserved");
\r
72 equals( $elem.data('false',false).data('false'), false, "false's are preserved");
\r
78 test("jQuery.removeData", function() {
\r
80 var div = jQuery("#foo")[0];
\r
81 jQuery.data(div, "test", "testing");
\r
82 jQuery.removeData(div, "test");
\r
83 equals( jQuery.data(div, "test"), undefined, "Check removal of data" );
\r
86 test(".removeData()", function() {
\r
88 var div = jQuery("#foo");
\r
89 div.data("test", "testing");
\r
90 div.removeData("test");
\r
91 equals( div.data("test"), undefined, "Check removal of data" );
\r
93 div.data("test", "testing");
\r
94 div.data("test.foo", "testing2");
\r
95 div.removeData("test.bar");
\r
96 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
97 equals( div.data("test"), "testing", "Make sure data is intact" );
\r
99 div.removeData("test");
\r
100 equals( div.data("test.foo"), "testing2", "Make sure data is intact" );
\r
101 equals( div.data("test"), undefined, "Make sure data is intact" );
\r
103 div.removeData("test.foo");
\r
104 equals( div.data("test.foo"), undefined, "Make sure data is intact" );
\r
107 test("queue() defaults to 'fx' type", function () {
\r
111 var $foo = jQuery("#foo");
\r
112 $foo.queue("fx", [ "sample", "array" ]);
\r
113 var arr = $foo.queue();
\r
114 isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'");
\r
115 $foo.queue([ "another", "one" ]);
\r
116 var arr = $foo.queue("fx");
\r
117 isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type");
\r
118 // clean up after test
\r
124 test("queue() with other types",function() {
\r
128 var $div = jQuery({});
\r
131 .queue('foo',function(){
\r
132 equals( ++counter, 1, "Dequeuing" );
\r
133 jQuery.dequeue(this,'foo');
\r
135 .queue('foo',function(){
\r
136 equals( ++counter, 2, "Dequeuing" );
\r
137 jQuery(this).dequeue('foo');
\r
139 .queue('foo',function(){
\r
140 equals( ++counter, 3, "Dequeuing" );
\r
142 .queue('foo',function(){
\r
143 equals( ++counter, 4, "Dequeuing" );
\r
146 equals( $div.queue('foo').length, 4, "Testing queue length" );
\r
148 $div.dequeue('foo');
\r
150 equals( counter, 3, "Testing previous call to dequeue" );
\r
151 equals( $div.queue('foo').length, 1, "Testing queue length" );
\r
153 $div.dequeue('foo');
\r
155 equals( counter, 4, "Testing previous call to dequeue" );
\r
156 equals( $div.queue('foo').length, 0, "Testing queue length" );
\r
162 test("queue(name) passes in the next item in the queue as a parameter", function() {
\r
165 var div = jQuery({});
\r
168 div.queue("foo", function(next) {
\r
169 equals(++counter, 1, "Dequeueing");
\r
171 }).queue("foo", function(next) {
\r
172 equals(++counter, 2, "Next was called");
\r
174 }).queue("bar", function() {
\r
175 equals(++counter, 3, "Other queues are not triggered by next()")
\r
178 div.dequeue("foo");
\r
183 test("queue(name) passes in the next item in the queue as a parameter", function() {
\r
186 var div = jQuery({});
\r
189 div.queue("foo", function(next) {
\r
190 equals(++counter, 1, "Dequeueing");
\r
192 }).queue("foo", function(next) {
\r
193 equals(++counter, 2, "Next was called");
\r
195 }).queue("bar", function() {
\r
196 equals(++counter, 3, "Other queues are not triggered by next()")
\r
199 div.dequeue("foo");
\r
204 test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
\r
207 var div = jQuery({});
\r
210 div.queue(function(next) {
\r
211 equals(++counter, 1, "Dequeueing");
\r
213 }).queue(function(next) {
\r
214 equals(++counter, 2, "Next was called");
\r
216 }).queue("bar", function() {
\r
217 equals(++counter, 3, "Other queues are not triggered by next()")
\r
223 test("clearQueue(name) clears the queue", function() {
\r
226 var div = jQuery({});
\r
229 div.queue("foo", function(next) {
\r
231 jQuery(this).clearQueue("foo");
\r
233 }).queue("foo", function(next) {
\r
237 div.dequeue("foo");
\r
239 equals(counter, 1, "the queue was cleared");
\r
244 test("clearQueue() clears the fx queue", function() {
\r
247 var div = jQuery({});
\r
250 div.queue(function(next) {
\r
252 setTimeout(function() { jQuery(this).clearQueue(); next(); }, 50);
\r
253 }).queue(function(next) {
\r
257 equals(counter, 1, "the queue was cleared");
\r