jbarnette-johnson 1.0.0.200806240111

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/CHANGELOG +5 -0
  2. data/MANIFEST +385 -0
  3. data/MINGW32.mk +124 -0
  4. data/README.rdoc +51 -0
  5. data/Rakefile +166 -0
  6. data/bin/johnson +107 -0
  7. data/cross-compile.txt +38 -0
  8. data/ext/spidermonkey/context.c +122 -0
  9. data/ext/spidermonkey/context.h +19 -0
  10. data/ext/spidermonkey/conversions.c +286 -0
  11. data/ext/spidermonkey/conversions.h +18 -0
  12. data/ext/spidermonkey/debugger.c +208 -0
  13. data/ext/spidermonkey/debugger.h +9 -0
  14. data/ext/spidermonkey/extconf.rb +25 -0
  15. data/ext/spidermonkey/extensions.c +37 -0
  16. data/ext/spidermonkey/extensions.h +12 -0
  17. data/ext/spidermonkey/global.c +40 -0
  18. data/ext/spidermonkey/global.h +11 -0
  19. data/ext/spidermonkey/idhash.c +16 -0
  20. data/ext/spidermonkey/idhash.h +8 -0
  21. data/ext/spidermonkey/immutable_node.c.erb +522 -0
  22. data/ext/spidermonkey/immutable_node.h +22 -0
  23. data/ext/spidermonkey/jroot.h +187 -0
  24. data/ext/spidermonkey/js_land_proxy.c +609 -0
  25. data/ext/spidermonkey/js_land_proxy.h +20 -0
  26. data/ext/spidermonkey/ruby_land_proxy.c +537 -0
  27. data/ext/spidermonkey/ruby_land_proxy.h +17 -0
  28. data/ext/spidermonkey/runtime.c +304 -0
  29. data/ext/spidermonkey/runtime.h +25 -0
  30. data/ext/spidermonkey/spidermonkey.c +20 -0
  31. data/ext/spidermonkey/spidermonkey.h +29 -0
  32. data/js/johnson/browser.js +9 -0
  33. data/js/johnson/browser/env.js +687 -0
  34. data/js/johnson/browser/jquery.js +3444 -0
  35. data/js/johnson/browser/xmlsax.js +1564 -0
  36. data/js/johnson/browser/xmlw3cdom.js +4189 -0
  37. data/js/johnson/cli.js +30 -0
  38. data/js/johnson/prelude.js +80 -0
  39. data/js/johnson/template.js +29 -0
  40. data/lib/hoe.rb +748 -0
  41. data/lib/johnson.rb +46 -0
  42. data/lib/johnson/cli.rb +7 -0
  43. data/lib/johnson/cli/options.rb +56 -0
  44. data/lib/johnson/error.rb +4 -0
  45. data/lib/johnson/nodes.rb +7 -0
  46. data/lib/johnson/nodes/binary_node.rb +64 -0
  47. data/lib/johnson/nodes/for.rb +14 -0
  48. data/lib/johnson/nodes/for_in.rb +12 -0
  49. data/lib/johnson/nodes/function.rb +13 -0
  50. data/lib/johnson/nodes/list.rb +27 -0
  51. data/lib/johnson/nodes/node.rb +68 -0
  52. data/lib/johnson/nodes/ternary_node.rb +20 -0
  53. data/lib/johnson/parser.rb +21 -0
  54. data/lib/johnson/parser/syntax_error.rb +13 -0
  55. data/lib/johnson/runtime.rb +55 -0
  56. data/lib/johnson/spidermonkey/context.rb +10 -0
  57. data/lib/johnson/spidermonkey/debugger.rb +67 -0
  58. data/lib/johnson/spidermonkey/immutable_node.rb +280 -0
  59. data/lib/johnson/spidermonkey/js_land_proxy.rb +62 -0
  60. data/lib/johnson/spidermonkey/mutable_tree_visitor.rb +233 -0
  61. data/lib/johnson/spidermonkey/ruby_land_proxy.rb +52 -0
  62. data/lib/johnson/spidermonkey/runtime.rb +94 -0
  63. data/lib/johnson/version.rb +4 -0
  64. data/lib/johnson/visitable.rb +16 -0
  65. data/lib/johnson/visitors.rb +4 -0
  66. data/lib/johnson/visitors/dot_visitor.rb +167 -0
  67. data/lib/johnson/visitors/ecma_visitor.rb +315 -0
  68. data/lib/johnson/visitors/enumerating_visitor.rb +115 -0
  69. data/lib/johnson/visitors/sexp_visitor.rb +172 -0
  70. data/lib/rails/init.rb +37 -0
  71. data/test/assets/index.html +38 -0
  72. data/test/assets/jquery_test.html +186 -0
  73. data/test/helper.rb +58 -0
  74. data/test/johnson/browser_test.rb +38 -0
  75. data/test/johnson/conversions/array_test.rb +32 -0
  76. data/test/johnson/conversions/boolean_test.rb +17 -0
  77. data/test/johnson/conversions/callable_test.rb +34 -0
  78. data/test/johnson/conversions/file_test.rb +15 -0
  79. data/test/johnson/conversions/nil_test.rb +20 -0
  80. data/test/johnson/conversions/number_test.rb +34 -0
  81. data/test/johnson/conversions/regexp_test.rb +24 -0
  82. data/test/johnson/conversions/string_test.rb +26 -0
  83. data/test/johnson/conversions/struct_test.rb +15 -0
  84. data/test/johnson/conversions/symbol_test.rb +19 -0
  85. data/test/johnson/conversions/thread_test.rb +24 -0
  86. data/test/johnson/error_test.rb +9 -0
  87. data/test/johnson/extensions_test.rb +56 -0
  88. data/test/johnson/nodes/array_literal_test.rb +57 -0
  89. data/test/johnson/nodes/array_node_test.rb +26 -0
  90. data/test/johnson/nodes/binary_node_test.rb +61 -0
  91. data/test/johnson/nodes/bracket_access_test.rb +16 -0
  92. data/test/johnson/nodes/delete_test.rb +11 -0
  93. data/test/johnson/nodes/do_while_test.rb +12 -0
  94. data/test/johnson/nodes/dot_accessor_test.rb +15 -0
  95. data/test/johnson/nodes/export_test.rb +9 -0
  96. data/test/johnson/nodes/for_test.rb +54 -0
  97. data/test/johnson/nodes/function_test.rb +71 -0
  98. data/test/johnson/nodes/if_test.rb +41 -0
  99. data/test/johnson/nodes/import_test.rb +13 -0
  100. data/test/johnson/nodes/label_test.rb +19 -0
  101. data/test/johnson/nodes/object_literal_test.rb +110 -0
  102. data/test/johnson/nodes/return_test.rb +16 -0
  103. data/test/johnson/nodes/semi_test.rb +8 -0
  104. data/test/johnson/nodes/switch_test.rb +55 -0
  105. data/test/johnson/nodes/ternary_test.rb +25 -0
  106. data/test/johnson/nodes/throw_test.rb +9 -0
  107. data/test/johnson/nodes/try_node_test.rb +59 -0
  108. data/test/johnson/nodes/typeof_test.rb +11 -0
  109. data/test/johnson/nodes/unary_node_test.rb +23 -0
  110. data/test/johnson/nodes/void_test.rb +11 -0
  111. data/test/johnson/nodes/while_test.rb +26 -0
  112. data/test/johnson/nodes/with_test.rb +10 -0
  113. data/test/johnson/prelude_test.rb +56 -0
  114. data/test/johnson/runtime_test.rb +46 -0
  115. data/test/johnson/spidermonkey/context_test.rb +21 -0
  116. data/test/johnson/spidermonkey/immutable_node_test.rb +34 -0
  117. data/test/johnson/spidermonkey/js_land_proxy_test.rb +236 -0
  118. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +225 -0
  119. data/test/johnson/spidermonkey/runtime_test.rb +17 -0
  120. data/test/johnson/version_test.rb +13 -0
  121. data/test/johnson/visitors/dot_visitor_test.rb +39 -0
  122. data/test/johnson/visitors/enumerating_visitor_test.rb +12 -0
  123. data/test/johnson_test.rb +16 -0
  124. data/test/jquery_units/test.js +27 -0
  125. data/test/jquery_units/test_helper.js +197 -0
  126. data/test/jquery_units/units/ajax.js +795 -0
  127. data/test/jquery_units/units/core.js +1563 -0
  128. data/test/jquery_units/units/event.js +299 -0
  129. data/test/jquery_units/units/fx.js +427 -0
  130. data/test/jquery_units/units/offset.js +112 -0
  131. data/test/jquery_units/units/selector.js +224 -0
  132. data/test/jspec/helper.js +7 -0
  133. data/test/jspec/jspec.js +192 -0
  134. data/test/jspec/simple_spec.js +68 -0
  135. data/test/parser_test.rb +276 -0
  136. data/todo/.keep +0 -0
  137. metadata +501 -0
@@ -0,0 +1,299 @@
1
+ module("event");
2
+
3
+ test("bind(), with data", function() {
4
+ expect(3);
5
+ var handler = function(event) {
6
+ ok( event.data, "bind() with data, check passed data exists" );
7
+ ok( event.data.foo == "bar", "bind() with data, Check value of passed data" );
8
+ };
9
+ $("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
10
+
11
+ ok( !jQuery.data($("#firstp")[0], "events"), "Event handler unbound when using data." );
12
+ });
13
+
14
+ test("bind(), with data, trigger with data", function() {
15
+ expect(4);
16
+ var handler = function(event, data) {
17
+ ok( event.data, "check passed data exists" );
18
+ ok( event.data.foo == "bar", "Check value of passed data" );
19
+ ok( data, "Check trigger data" );
20
+ ok( data.bar == "foo", "Check value of trigger data" );
21
+ };
22
+ $("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler);
23
+ });
24
+
25
+ test("bind(), multiple events at once", function() {
26
+ expect(2);
27
+ var clickCounter = 0,
28
+ mouseoverCounter = 0;
29
+ var handler = function(event) {
30
+ if (event.type == "click")
31
+ clickCounter += 1;
32
+ else if (event.type == "mouseover")
33
+ mouseoverCounter += 1;
34
+ };
35
+ $("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover");
36
+ ok( clickCounter == 1, "bind() with multiple events at once" );
37
+ ok( mouseoverCounter == 1, "bind() with multiple events at once" );
38
+ });
39
+
40
+ test("bind(), no data", function() {
41
+ expect(1);
42
+ var handler = function(event) {
43
+ ok ( !event.data, "Check that no data is added to the event object" );
44
+ };
45
+ $("#firstp").bind("click", handler).trigger("click");
46
+ });
47
+
48
+ test("bind(), iframes", function() {
49
+ // events don't work with iframes, see #939 - this test fails in IE because of contentDocument
50
+ // var doc = document.getElementById("iframe").contentDocument;
51
+ //
52
+ // doc.body.innerHTML = "<input type='text'/>";
53
+ //
54
+ // var input = doc.getElementsByTagName("input")[0];
55
+ //
56
+ // $(input).bind("click",function() {
57
+ // ok( true, "Binding to element inside iframe" );
58
+ // }).click();
59
+ });
60
+
61
+ test("bind(), trigger change on select", function() {
62
+ expect(3);
63
+ var counter = 0;
64
+ function selectOnChange(event) {
65
+ equals( event.data, counter++, "Event.data is not a global event object" );
66
+ };
67
+ $("#form select").each(function(i){
68
+ $(this).bind('change', i, selectOnChange);
69
+ }).trigger('change');
70
+ });
71
+
72
+ test("bind(), namespaced events, cloned events", function() {
73
+ expect(6);
74
+
75
+ $("#firstp").bind("custom.test",function(e){
76
+ ok(true, "Custom event triggered");
77
+ });
78
+
79
+ $("#firstp").bind("click",function(e){
80
+ ok(true, "Normal click triggered");
81
+ });
82
+
83
+ $("#firstp").bind("click.test",function(e){
84
+ ok(true, "Namespaced click triggered");
85
+ });
86
+
87
+ // Trigger both bound fn (2)
88
+ $("#firstp").trigger("click");
89
+
90
+ // Trigger one bound fn (1)
91
+ $("#firstp").trigger("click.test");
92
+
93
+ // Remove only the one fn
94
+ $("#firstp").unbind("click.test");
95
+
96
+ // Trigger the remaining fn (1)
97
+ $("#firstp").trigger("click");
98
+
99
+ // Remove the remaining fn
100
+ $("#firstp").unbind(".test");
101
+
102
+ // Trigger the remaining fn (0)
103
+ $("#firstp").trigger("custom");
104
+
105
+ // using contents will get comments regular, text, and comment nodes
106
+ $("#nonnodes").contents().bind("tester", function () {
107
+ equals(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
108
+ }).trigger("tester");
109
+
110
+ // Make sure events stick with appendTo'd elements (which are cloned) #2027
111
+ $("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
112
+ ok( $("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
113
+ });
114
+
115
+ test("click()", function() {
116
+ expect(4);
117
+ $('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
118
+ var close = $('spanx', this); // same with $(this).find('span');
119
+ ok( close.length == 0, "Context element does not exist, length must be zero" );
120
+ ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
121
+ return false;
122
+ }).click();
123
+
124
+ $("#check1").click(function() {
125
+ ok( true, "click event handler for checkbox gets fired twice, see #815" );
126
+ }).click();
127
+
128
+ var counter = 0;
129
+ $('#firstp')[0].onclick = function(event) {
130
+ counter++;
131
+ };
132
+ $('#firstp').click();
133
+ ok( counter == 1, "Check that click, triggers onclick event handler also" );
134
+ });
135
+
136
+ test("unbind(event)", function() {
137
+ expect(8);
138
+ var el = $("#firstp");
139
+ el.click(function() {
140
+ ok( true, "Fake normal bind" );
141
+ });
142
+ el.click(function(event) {
143
+ el.unbind(event);
144
+ ok( true, "Fake onebind" );
145
+ });
146
+ el.click().click();
147
+
148
+ el.click(function() { return; });
149
+ el.unbind('click');
150
+ ok( !el[0].onclick, "Handler is removed" ); // Bug #964
151
+
152
+ el.click(function() { return; });
153
+ el.unbind('change',function(){ return; });
154
+ for (var ret in jQuery.data(el[0], "events")['click']) break;
155
+ ok( ret, "Extra handlers weren't accidentally removed." );
156
+
157
+ el.unbind('click');
158
+ ok( !jQuery.data(el[0], "events"), "Removed the events expando after all handlers are unbound." );
159
+
160
+ reset();
161
+ var clickCounter = mouseoverCounter = 0;
162
+ var handler = function(event) {
163
+ if (event.type == "click")
164
+ clickCounter += 1;
165
+ else if (event.type == "mouseover")
166
+ mouseoverCounter += 1;
167
+ };
168
+ $("#firstp").bind("click mouseover", handler).unbind("click mouseover", handler).trigger("click").trigger("mouseover");
169
+ ok( clickCounter == 0, "unbind() with multiple events at once" );
170
+ ok( mouseoverCounter == 0, "unbind() with multiple events at once" );
171
+ });
172
+
173
+ test("trigger(event, [data], [fn])", function() {
174
+ expect(67);
175
+
176
+ var handler = function(event, a, b, c) {
177
+ equals( event.type, "click", "check passed data" );
178
+ equals( a, 1, "check passed data" );
179
+ equals( b, "2", "check passed data" );
180
+ equals( c, "abc", "check passed data" );
181
+ return "test";
182
+ };
183
+
184
+ var handler2 = function(a, b, c) {
185
+ equals( a, 1, "check passed data" );
186
+ equals( b, "2", "check passed data" );
187
+ equals( c, "abc", "check passed data" );
188
+ return false;
189
+ };
190
+
191
+ var handler3 = function(a, b, c, v) {
192
+ equals( a, 1, "check passed data" );
193
+ equals( b, "2", "check passed data" );
194
+ equals( c, "abc", "check passed data" );
195
+ equals( v, "test", "check current value" );
196
+ return "newVal";
197
+ };
198
+
199
+ var handler4 = function(a, b, c, v) {
200
+ equals( a, 1, "check passed data" );
201
+ equals( b, "2", "check passed data" );
202
+ equals( c, "abc", "check passed data" );
203
+ equals( v, "test", "check current value" );
204
+ };
205
+
206
+ // Simulate a "native" click
207
+ $("#firstp")[0].click = function(){
208
+ ok( true, "Native call was triggered" );
209
+ };
210
+
211
+ // Triggers handlrs and native
212
+ // Trigger 5
213
+ $("#firstp").bind("click", handler).trigger("click", [1, "2", "abc"]);
214
+
215
+ // Triggers handlers, native, and extra fn
216
+ // Triggers 9
217
+ $("#firstp").trigger("click", [1, "2", "abc"], handler4);
218
+
219
+ // Simulate a "native" click
220
+ $("#firstp")[0].click = function(){
221
+ ok( false, "Native call was triggered" );
222
+ };
223
+
224
+ // Triggers handlers, native, and extra fn
225
+ // Triggers 7
226
+ $("#firstp").trigger("click", [1, "2", "abc"], handler2);
227
+
228
+ // Trigger only the handlers (no native)
229
+ // Triggers 5
230
+ equals( $("#firstp").triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
231
+
232
+ // Trigger only the handlers (no native) and extra fn
233
+ // Triggers 8
234
+ equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler2), false, "Verify handler response" );
235
+
236
+ // Build fake click event to pass in
237
+ var eventObj = jQuery.event.fix({ type: "foo", target: document.body });
238
+
239
+ // Trigger only the handlers (no native), with external event obj
240
+ // Triggers 5
241
+ equals( $("#firstp").triggerHandler("click", [eventObj, 1, "2", "abc"]), "test", "Verify handler response" );
242
+
243
+ // Trigger only the handlers (no native) and extra fn, with external event obj
244
+ // Triggers 9
245
+ eventObj = jQuery.event.fix({ type: "foo", target: document.body });
246
+ equals( $("#firstp").triggerHandler("click", [eventObj, 1, "2", "abc"], handler), "test", "Verify handler response" );
247
+
248
+ var pass = true;
249
+ try {
250
+ $('input:first')
251
+ .hide()
252
+ .trigger('focus');
253
+ } catch(e) {
254
+ pass = false;
255
+ }
256
+ ok( pass, "Trigger focus on hidden element" );
257
+
258
+ // have the extra handler override the return
259
+ // Triggers 9
260
+ equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler3), "newVal", "Verify triggerHandler return is overwritten by extra function" );
261
+
262
+ // have the extra handler leave the return value alone
263
+ // Triggers 9
264
+ equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler4), "test", "Verify triggerHandler return is not overwritten by extra function" );
265
+ });
266
+
267
+ test("toggle(Function, Function)", function() {
268
+ expect(5);
269
+ var count = 0,
270
+ fn1 = function(e) { count++; },
271
+ fn2 = function(e) { count--; },
272
+ preventDefault = function(e) { e.preventDefault() },
273
+ link = $('#mark');
274
+ link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
275
+ ok( count == 1, "Check for toggle(fn, fn)" );
276
+
277
+ $("#firstp").toggle(function () {
278
+ equals(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" )
279
+ }, function() {}).trigger("click", [ 1, 2, 3 ]);
280
+
281
+ var first = 0;
282
+ $("#simon1").one("click", function() {
283
+ ok( true, "Execute event only once" );
284
+ $(this).toggle(function() {
285
+ ok( first++ == 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
286
+ }, function() {
287
+ ok( first == 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
288
+ });
289
+ return false;
290
+ }).click().click().click();
291
+ });
292
+
293
+ test("jQuery(function($) {})", function() {
294
+ stop();
295
+ jQuery(function($) {
296
+ equals(jQuery, $, "ready doesn't provide an event object, instead it provides a reference to the jQuery function, see http://docs.jquery.com/Events/ready#fn");
297
+ start();
298
+ });
299
+ });
@@ -0,0 +1,427 @@
1
+ module("fx");
2
+
3
+ test("animate(Hash, Object, Function)", function() {
4
+ expect(1);
5
+ stop();
6
+ var hash = {opacity: 'show'};
7
+ var hashCopy = $.extend({}, hash);
8
+ $('#foo').animate(hash, 0, function() {
9
+ ok( hash.opacity == hashCopy.opacity, 'Check if animate changed the hash parameter' );
10
+ start();
11
+ });
12
+ });
13
+
14
+ test("animate option (queue === false)", function () {
15
+ expect(1);
16
+ stop();
17
+
18
+ var order = [];
19
+
20
+ var $foo = $("#foo");
21
+ $foo.animate({width:'100px'}, 200, function () {
22
+ // should finish after unqueued animation so second
23
+ order.push(2);
24
+ });
25
+ $foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
26
+ // short duration and out of queue so should finish first
27
+ order.push(1);
28
+ }});
29
+ $foo.animate({height:'100px'}, 10, function() {
30
+ // queued behind the first animation so should finish third
31
+ order.push(3);
32
+ isSet( order, [ 1, 2, 3], "Animations finished in the correct order" );
33
+ start();
34
+ });
35
+ });
36
+
37
+ test("queue() defaults to 'fx' type", function () {
38
+ expect(2);
39
+ stop();
40
+
41
+ var $foo = $("#foo");
42
+ $foo.queue("fx", [ "sample", "array" ]);
43
+ var arr = $foo.queue();
44
+ isSet(arr, [ "sample", "array" ], "queue() got an array set with type 'fx'");
45
+ $foo.queue([ "another", "one" ]);
46
+ var arr = $foo.queue("fx");
47
+ isSet(arr, [ "another", "one" ], "queue('fx') got an array set with no type");
48
+ // clean up after test
49
+ $foo.queue([]);
50
+
51
+ start();
52
+ });
53
+
54
+ test("stop()", function() {
55
+ expect(3);
56
+ stop();
57
+
58
+ var $foo = $("#nothiddendiv");
59
+ var w = 0;
60
+ $foo.hide().width(200).width();
61
+
62
+ $foo.animate({ width:'show' }, 1000);
63
+ setTimeout(function(){
64
+ var nw = $foo.width();
65
+ ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
66
+ $foo.stop();
67
+
68
+ nw = $foo.width();
69
+ ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
70
+ setTimeout(function(){
71
+ equals( nw, $foo.width(), "The animation didn't continue" );
72
+ start();
73
+ }, 100);
74
+ }, 100);
75
+ });
76
+
77
+ test("stop() - several in queue", function() {
78
+ expect(4);
79
+ stop();
80
+
81
+ var $foo = $("#nothiddendiv");
82
+ var w = 0;
83
+ $foo.hide().width(200).width();
84
+
85
+ $foo.animate({ width:'show' }, 1000);
86
+ $foo.animate({ width:'hide' }, 1000);
87
+ $foo.animate({ width:'show' }, 1000);
88
+ setTimeout(function(){
89
+ equals( $foo.queue().length, 3, "All 3 still in the queue" );
90
+ var nw = $foo.width();
91
+ ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
92
+ $foo.stop();
93
+
94
+ nw = $foo.width();
95
+ ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
96
+ equals( $foo.queue().length, 2, "The next animation continued" );
97
+ $foo.stop(true);
98
+ start();
99
+ }, 100);
100
+ });
101
+
102
+ test("stop(clearQueue)", function() {
103
+ expect(4);
104
+ stop();
105
+
106
+ var $foo = $("#nothiddendiv");
107
+ var w = 0;
108
+ $foo.hide().width(200).width();
109
+
110
+ $foo.animate({ width:'show' }, 1000);
111
+ $foo.animate({ width:'hide' }, 1000);
112
+ $foo.animate({ width:'show' }, 1000);
113
+ setTimeout(function(){
114
+ var nw = $foo.width();
115
+ ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
116
+ $foo.stop(true);
117
+
118
+ nw = $foo.width();
119
+ ok( nw != w, "Stop didn't reset the animation " + nw + "px " + w + "px");
120
+
121
+ equals( $foo.queue().length, 0, "The animation queue was cleared" );
122
+ setTimeout(function(){
123
+ equals( nw, $foo.width(), "The animation didn't continue" );
124
+ start();
125
+ }, 100);
126
+ }, 100);
127
+ });
128
+
129
+ test("stop(clearQueue, gotoEnd)", function() {
130
+ expect(3);
131
+ stop();
132
+
133
+ var $foo = $("#nothiddendiv");
134
+ var w = 0;
135
+ $foo.hide().width(200).width();
136
+
137
+ $foo.animate({ width:'show' }, 1000);
138
+ $foo.animate({ width:'hide' }, 1000);
139
+ $foo.animate({ width:'show' }, 1000);
140
+ $foo.animate({ width:'hide' }, 1000);
141
+ setTimeout(function(){
142
+ var nw = $foo.width();
143
+ ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
144
+ $foo.stop(false, true);
145
+
146
+ nw = $foo.width();
147
+ equals( nw, 200, "Stop() reset the animation" );
148
+
149
+ setTimeout(function(){
150
+ equals( $foo.queue().length, 3, "The next animation continued" );
151
+ $foo.stop(true);
152
+ start();
153
+ }, 100);
154
+ }, 100);
155
+ });
156
+
157
+ test("toggle()", function() {
158
+ expect(3);
159
+ var x = $("#foo");
160
+ ok( x.is(":visible"), "is visible" );
161
+ x.toggle();
162
+ ok( x.is(":hidden"), "is hidden" );
163
+ x.toggle();
164
+ ok( x.is(":visible"), "is visible again" );
165
+ });
166
+
167
+ var visible = {
168
+ Normal: function(elem){},
169
+ "CSS Hidden": function(elem){
170
+ $(this).addClass("hidden");
171
+ },
172
+ "JS Hidden": function(elem){
173
+ $(this).hide();
174
+ }
175
+ };
176
+
177
+ var from = {
178
+ "CSS Auto": function(elem,prop){
179
+ $(elem).addClass("auto" + prop)
180
+ .text("This is a long string of text.");
181
+ return "";
182
+ },
183
+ "JS Auto": function(elem,prop){
184
+ $(elem).css(prop,"auto")
185
+ .text("This is a long string of text.");
186
+ return "";
187
+ },
188
+ "CSS 100": function(elem,prop){
189
+ $(elem).addClass("large" + prop);
190
+ return "";
191
+ },
192
+ "JS 100": function(elem,prop){
193
+ $(elem).css(prop,prop == "opacity" ? 1 : "100px");
194
+ return prop == "opacity" ? 1 : 100;
195
+ },
196
+ "CSS 50": function(elem,prop){
197
+ $(elem).addClass("med" + prop);
198
+ return "";
199
+ },
200
+ "JS 50": function(elem,prop){
201
+ $(elem).css(prop,prop == "opacity" ? 0.50 : "50px");
202
+ return prop == "opacity" ? 0.5 : 50;
203
+ },
204
+ "CSS 0": function(elem,prop){
205
+ $(elem).addClass("no" + prop);
206
+ return "";
207
+ },
208
+ "JS 0": function(elem,prop){
209
+ $(elem).css(prop,prop == "opacity" ? 0 : "0px");
210
+ return 0;
211
+ }
212
+ };
213
+
214
+ var to = {
215
+ "show": function(elem,prop){
216
+ $(elem).hide().addClass("wide"+prop);
217
+ return "show";
218
+ },
219
+ "hide": function(elem,prop){
220
+ $(elem).addClass("wide"+prop);
221
+ return "hide";
222
+ },
223
+ "100": function(elem,prop){
224
+ $(elem).addClass("wide"+prop);
225
+ return prop == "opacity" ? 1 : 100;
226
+ },
227
+ "50": function(elem,prop){
228
+ return prop == "opacity" ? 0.50 : 50;
229
+ },
230
+ "0": function(elem,prop){
231
+ $(elem).addClass("noback");
232
+ return 0;
233
+ }
234
+ };
235
+
236
+ function checkOverflowDisplay(){
237
+ var o = jQuery.css( this, "overflow" );
238
+
239
+ ok(o == "visible", "Overflow should be visible: " + o);
240
+ ok(jQuery.css( this, "display" ) == "inline", "Display shouldn't be tampered with.");
241
+
242
+ start();
243
+ }
244
+
245
+ test("JS Overflow and Display", function() {
246
+ expect(2);
247
+ stop();
248
+ makeTest( "JS Overflow and Display" )
249
+ .addClass("widewidth")
250
+ .css({ overflow: "visible", display: "inline" })
251
+ .addClass("widewidth")
252
+ .text("Some sample text.")
253
+ .before("text before")
254
+ .after("text after")
255
+ .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
256
+ });
257
+
258
+ test("CSS Overflow and Display", function() {
259
+ expect(2);
260
+ stop();
261
+ makeTest( "CSS Overflow and Display" )
262
+ .addClass("overflow inline")
263
+ .addClass("widewidth")
264
+ .text("Some sample text.")
265
+ .before("text before")
266
+ .after("text after")
267
+ .animate({ opacity: 0.5 }, "slow", checkOverflowDisplay);
268
+ });
269
+
270
+ jQuery.each( from, function(fn, f){
271
+ jQuery.each( to, function(tn, t){
272
+ test(fn + " to " + tn, function() {
273
+ var elem = makeTest( fn + " to " + tn );
274
+
275
+ var t_w = t( elem, "width" );
276
+ var f_w = f( elem, "width" );
277
+ var t_h = t( elem, "height" );
278
+ var f_h = f( elem, "height" );
279
+ var t_o = t( elem, "opacity" );
280
+ var f_o = f( elem, "opacity" );
281
+
282
+ var num = 0;
283
+
284
+ if ( t_h == "show" ) num++;
285
+ if ( t_w == "show" ) num++;
286
+ if ( t_w == "hide"||t_w == "show" ) num++;
287
+ if ( t_h == "hide"||t_h == "show" ) num++;
288
+ if ( t_o == "hide"||t_o == "show" ) num++;
289
+ if ( t_w == "hide" ) num++;
290
+ if ( t_o.constructor == Number ) num += 2;
291
+ if ( t_w.constructor == Number ) num += 2;
292
+ if ( t_h.constructor == Number ) num +=2;
293
+
294
+ expect(num);
295
+ stop();
296
+
297
+ var anim = { width: t_w, height: t_h, opacity: t_o };
298
+
299
+ elem.animate(anim, 50, function(){
300
+ if ( t_w == "show" )
301
+ ok( this.style.display == "block", "Showing, display should block: " + this.style.display);
302
+
303
+ if ( t_w == "hide"||t_w == "show" )
304
+ ok(this.style.width.indexOf(f_w) == 0, "Width must be reset to " + f_w + ": " + this.style.width);
305
+
306
+ if ( t_h == "hide"||t_h == "show" )
307
+ ok(this.style.height.indexOf(f_h) == 0, "Height must be reset to " + f_h + ": " + this.style.height);
308
+
309
+ var cur_o = jQuery.attr(this.style, "opacity");
310
+ if ( cur_o !== "" ) cur_o = parseFloat( cur_o );
311
+
312
+ if ( t_o == "hide"||t_o == "show" )
313
+ ok(cur_o == f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
314
+
315
+ if ( t_w == "hide" )
316
+ ok(this.style.display == "none", "Hiding, display should be none: " + this.style.display);
317
+
318
+ if ( t_o.constructor == Number ) {
319
+ ok(cur_o == t_o, "Final opacity should be " + t_o + ": " + cur_o);
320
+
321
+ ok(jQuery.curCSS(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
322
+ }
323
+
324
+ if ( t_w.constructor == Number ) {
325
+ ok(this.style.width == t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
326
+
327
+ var cur_w = jQuery.css(this,"width");
328
+
329
+ ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
330
+ }
331
+
332
+ if ( t_h.constructor == Number ) {
333
+ ok(this.style.height == t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
334
+
335
+ var cur_h = jQuery.css(this,"height");
336
+
337
+ ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
338
+ }
339
+
340
+ if ( t_h == "show" ) {
341
+ var old_h = jQuery.curCSS(this, "height");
342
+ $(elem).append("<br/>Some more text<br/>and some more...");
343
+ ok(old_h != jQuery.css(this, "height" ), "Make sure height is auto.");
344
+ }
345
+
346
+ start();
347
+ });
348
+ });
349
+ });
350
+ });
351
+
352
+ var check = ['opacity','height','width','display','overflow'];
353
+
354
+ jQuery.fn.saveState = function(){
355
+ expect(check.length);
356
+ stop();
357
+ return this.each(function(){
358
+ var self = this;
359
+ self.save = {};
360
+ jQuery.each(check, function(i,c){
361
+ self.save[c] = jQuery.css(self,c);
362
+ });
363
+ });
364
+ };
365
+
366
+ function checkState(){
367
+ var self = this;
368
+ jQuery.each(this.save, function(c,v){
369
+ var cur = jQuery.css(self,c);
370
+ ok( v == cur, "Make sure that " + c + " is reset (Old: " + v + " Cur: " + cur + ")");
371
+ });
372
+ start();
373
+ }
374
+
375
+ // Chaining Tests
376
+ test("Chain fadeOut fadeIn", function() {
377
+ $('#fadein div').saveState().fadeOut('fast').fadeIn('fast',checkState);
378
+ });
379
+ test("Chain fadeIn fadeOut", function() {
380
+ $('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',checkState);
381
+ });
382
+
383
+ test("Chain hide show", function() {
384
+ $('#show div').saveState().hide('fast').show('fast',checkState);
385
+ });
386
+ test("Chain show hide", function() {
387
+ $('#hide div').saveState().show('fast').hide('fast',checkState);
388
+ });
389
+
390
+ test("Chain toggle in", function() {
391
+ $('#togglein div').saveState().toggle('fast').toggle('fast',checkState);
392
+ });
393
+ test("Chain toggle out", function() {
394
+ $('#toggleout div').saveState().toggle('fast').toggle('fast',checkState);
395
+ });
396
+
397
+ test("Chain slideDown slideUp", function() {
398
+ $('#slidedown div').saveState().slideDown('fast').slideUp('fast',checkState);
399
+ });
400
+ test("Chain slideUp slideDown", function() {
401
+ $('#slideup div').saveState().slideUp('fast').slideDown('fast',checkState);
402
+ });
403
+
404
+ test("Chain slideToggle in", function() {
405
+ $('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',checkState);
406
+ });
407
+ test("Chain slideToggle out", function() {
408
+ $('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',checkState);
409
+ });
410
+
411
+ function makeTest( text ){
412
+ var elem = $("<div></div>")
413
+ .attr("id", "test" + makeTest.id++)
414
+ .addClass("box");
415
+
416
+ $("<h4></h4>")
417
+ .text( text )
418
+ .appendTo("#fx-tests")
419
+ .click(function(){
420
+ $(this).next().toggle();
421
+ })
422
+ .after( elem );
423
+
424
+ return elem;
425
+ }
426
+
427
+ makeTest.id = 1;