smparkes-envjs 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/bin/envjsrb +157 -73
  2. data/bin/jquery-1.3.2-test.js +11 -4
  3. data/lib/envjs/env.js +935 -11028
  4. data/lib/envjs/net/cgi.rb +94 -0
  5. data/lib/envjs/net/file.rb +4 -4
  6. data/lib/envjs/runtime.rb +80 -24
  7. data/test/call-load-test.js +0 -2
  8. data/test/firebug/errorIcon.png +0 -0
  9. data/test/firebug/firebug.css +209 -0
  10. data/test/firebug/firebug.html +23 -0
  11. data/test/firebug/firebug.js +672 -0
  12. data/test/firebug/firebugx.js +10 -0
  13. data/test/firebug/infoIcon.png +0 -0
  14. data/test/firebug/warningIcon.png +0 -0
  15. data/test/fixtures/html/events.html +171 -0
  16. data/test/fixtures/html/iframe1.html +46 -0
  17. data/test/fixtures/html/iframe1a.html +46 -0
  18. data/test/fixtures/html/iframe2.html +45 -0
  19. data/test/fixtures/html/iframe3.html +28 -0
  20. data/test/fixtures/html/iframeN.html +57 -0
  21. data/test/fixtures/html/malformed.html +181 -0
  22. data/test/fixtures/html/scope.html +81 -0
  23. data/test/fixtures/html/trivial.html +19 -0
  24. data/test/fixtures/html/with_js.html +26 -0
  25. data/test/fixtures/images/icon-blue.png +0 -0
  26. data/test/fixtures/js/external_script.js +1 -0
  27. data/test/fixtures/js/script.js +1 -0
  28. data/test/fixtures/js/script_error.js +2 -0
  29. data/test/html/malformed.html +1 -0
  30. data/test/index.html +21 -19
  31. data/test/{primaryTests.js → primary-tests.js} +1 -3
  32. data/test/{prototype.js → prototype-test.js} +0 -2
  33. data/test/qunit/qunit/qunit.css +0 -0
  34. data/test/qunit/qunit/qunit.js +2 -2
  35. data/test/{qunit/qunit/qunit.js.smp → specs/dist/env.spec.js} +539 -7
  36. data/test/specs/envjs.spec.css +46 -0
  37. data/test/specs/parser/html.js +31 -0
  38. data/test/specs/parser/spec.html +40 -0
  39. data/test/specs/parser/xml.js +31 -0
  40. data/test/specs/qunit.bdd.js +210 -0
  41. data/test/{qunit.smp/qunit → specs}/qunit.css +0 -0
  42. data/test/{qunit.smp/qunit → specs}/qunit.js +2 -2
  43. data/test/specs/template/spec-0.js +31 -0
  44. data/test/specs/template/spec-1.js +31 -0
  45. data/test/specs/template/spec.html +40 -0
  46. data/test/specs/window/css.js +23 -0
  47. data/test/specs/window/dialog.js +25 -0
  48. data/test/specs/window/document.js +23 -0
  49. data/test/specs/window/event.js +25 -0
  50. data/test/specs/window/history.js +34 -0
  51. data/test/specs/window/location.js +34 -0
  52. data/test/specs/window/navigator.js +71 -0
  53. data/test/specs/window/screen.js +42 -0
  54. data/test/specs/window/spec.html +48 -0
  55. data/test/specs/window/timer.js +26 -0
  56. data/test/specs/window/window.js +53 -0
  57. data/test/specs/xhr/spec.html +47 -0
  58. data/test/specs/xhr/xhr.js +31 -0
  59. data/test/test.js +10 -0
  60. data/test/unit/elementmembers.js +31 -0
  61. data/test/unit/nu.validator.js +34 -0
  62. data/test/unit/onload.js +1 -3
  63. data/test/unit/parser.js +106 -98
  64. data/test/unit/prototypecompat.js +2 -2
  65. data/test/vendor/jQuery/1.3.2/ChangeLog.txt +98 -0
  66. data/test/vendor/jQuery/1.3.2/GPL-LICENSE.txt +278 -0
  67. data/test/vendor/jQuery/1.3.2/MIT-LICENSE.txt +20 -0
  68. data/test/vendor/jQuery/1.3.2/Makefile +154 -0
  69. data/test/vendor/jQuery/1.3.2/README +67 -0
  70. data/test/vendor/jQuery/1.3.2/build/ant-contrib-0.6.jar +0 -0
  71. data/test/vendor/jQuery/1.3.2/build/build/min.js +11 -0
  72. data/test/vendor/jQuery/1.3.2/build/build/pack.js +19 -0
  73. data/test/vendor/jQuery/1.3.2/build/js/Packer.js +209 -0
  74. data/test/vendor/jQuery/1.3.2/build/js/ParseMaster.js +106 -0
  75. data/test/vendor/jQuery/1.3.2/build/js/Words.js +62 -0
  76. data/test/vendor/jQuery/1.3.2/build/js/base2.js +978 -0
  77. data/test/vendor/jQuery/1.3.2/build/js/jsmin.js +316 -0
  78. data/test/vendor/jQuery/1.3.2/build/js/json.js +117 -0
  79. data/test/vendor/jQuery/1.3.2/build/js/pack.js +316 -0
  80. data/test/vendor/jQuery/1.3.2/build/js/parse.js +105 -0
  81. data/test/vendor/jQuery/1.3.2/build/js/writeFile.js +19 -0
  82. data/test/vendor/jQuery/1.3.2/build/js/xml.js +25 -0
  83. data/test/vendor/jQuery/1.3.2/build/js.jar +0 -0
  84. data/test/vendor/jQuery/1.3.2/build/runtest/env.js +1 -0
  85. data/test/vendor/jQuery/1.3.2/build/runtest/test.js +106 -0
  86. data/test/vendor/jQuery/1.3.2/build/runtest/testrunner.js +197 -0
  87. data/test/vendor/jQuery/1.3.2/build/speed/benchmarker.css +65 -0
  88. data/test/vendor/jQuery/1.3.2/build/speed/benchmarker.js +181 -0
  89. data/test/vendor/jQuery/1.3.2/build/speed/index.html +72 -0
  90. data/test/vendor/jQuery/1.3.2/build/speed/jquery-basis.js +3549 -0
  91. data/test/vendor/jQuery/1.3.2/build/style.xsl +99 -0
  92. data/test/vendor/jQuery/1.3.2/build/yuicompressor-2.4.2.jar +0 -0
  93. data/test/vendor/jQuery/1.3.2/build.xml +123 -0
  94. data/test/vendor/jQuery/1.3.2/dist/jquery.js +4376 -0
  95. data/test/vendor/jQuery/1.3.2/reminder.txt +3 -0
  96. data/test/vendor/jQuery/1.3.2/src/ajax.js +541 -0
  97. data/test/vendor/jQuery/1.3.2/src/core.js +1255 -0
  98. data/test/vendor/jQuery/1.3.2/src/data.js +145 -0
  99. data/test/vendor/jQuery/1.3.2/src/dimensions.js +49 -0
  100. data/test/vendor/jQuery/1.3.2/src/event.js +684 -0
  101. data/test/vendor/jQuery/1.3.2/src/fx.js +407 -0
  102. data/test/vendor/jQuery/1.3.2/src/intro.js +13 -0
  103. data/test/vendor/jQuery/1.3.2/src/offset.js +155 -0
  104. data/test/vendor/jQuery/1.3.2/src/outro.js +1 -0
  105. data/test/vendor/jQuery/1.3.2/src/selector.js +1015 -0
  106. data/test/vendor/jQuery/1.3.2/src/support.js +112 -0
  107. data/test/vendor/jQuery/1.3.2/test/data/cow.jpg +0 -0
  108. data/test/vendor/jQuery/1.3.2/test/data/dashboard.xml +11 -0
  109. data/test/vendor/jQuery/1.3.2/test/data/echoQuery.php +1 -0
  110. data/test/vendor/jQuery/1.3.2/test/data/iframe.html +8 -0
  111. data/test/vendor/jQuery/1.3.2/test/data/json.php +9 -0
  112. data/test/vendor/jQuery/1.3.2/test/data/json_assigned_obj.js +1 -0
  113. data/test/vendor/jQuery/1.3.2/test/data/json_obj.js +1 -0
  114. data/test/vendor/jQuery/1.3.2/test/data/jsonp.php +10 -0
  115. data/test/vendor/jQuery/1.3.2/test/data/name.html +1 -0
  116. data/test/vendor/jQuery/1.3.2/test/data/name.php +29 -0
  117. data/test/vendor/jQuery/1.3.2/test/data/offset/absolute.html +39 -0
  118. data/test/vendor/jQuery/1.3.2/test/data/offset/body.html +24 -0
  119. data/test/vendor/jQuery/1.3.2/test/data/offset/fixed.html +33 -0
  120. data/test/vendor/jQuery/1.3.2/test/data/offset/relative.html +31 -0
  121. data/test/vendor/jQuery/1.3.2/test/data/offset/scroll.html +39 -0
  122. data/test/vendor/jQuery/1.3.2/test/data/offset/static.html +31 -0
  123. data/test/vendor/jQuery/1.3.2/test/data/offset/table.html +43 -0
  124. data/test/vendor/jQuery/1.3.2/test/data/params_html.php +12 -0
  125. data/test/vendor/jQuery/1.3.2/test/data/test.html +7 -0
  126. data/test/vendor/jQuery/1.3.2/test/data/test.js +3 -0
  127. data/test/vendor/jQuery/1.3.2/test/data/test.php +7 -0
  128. data/test/vendor/jQuery/1.3.2/test/data/test2.html +5 -0
  129. data/test/vendor/jQuery/1.3.2/test/data/test3.html +3 -0
  130. data/test/vendor/jQuery/1.3.2/test/data/testrunner.js +1 -0
  131. data/test/vendor/jQuery/1.3.2/test/data/text.php +12 -0
  132. data/test/vendor/jQuery/1.3.2/test/data/with_fries.xml +25 -0
  133. data/test/vendor/jQuery/1.3.2/test/index.html +229 -0
  134. data/test/vendor/jQuery/1.3.2/test/jqenv-1259090275493.html +247 -0
  135. data/test/vendor/jQuery/1.3.2/test/jqenv-1259091671501.html +247 -0
  136. data/test/vendor/jQuery/1.3.2/test/jqenv-1259175319655.html +247 -0
  137. data/test/vendor/jQuery/1.3.2/test/offset.html +28 -0
  138. data/test/vendor/jQuery/1.3.2/test/otherlibs/jquery/1.2.1/jquery.js +11 -0
  139. data/test/vendor/jQuery/1.3.2/test/otherlibs/jquery/1.2.3/jquery.js +11 -0
  140. data/test/vendor/jQuery/1.3.2/test/otherlibs/mootools/1.11/mootools.js +1577 -0
  141. data/test/vendor/jQuery/1.3.2/test/otherlibs/prototype/1.6.0.2/prototype.js +4221 -0
  142. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/builder.js +131 -0
  143. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/controls.js +835 -0
  144. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/dragdrop.js +944 -0
  145. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/effects.js +1090 -0
  146. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/scriptaculous.js +51 -0
  147. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/slider.js +278 -0
  148. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/unittest.js +564 -0
  149. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/builder.js +136 -0
  150. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/controls.js +965 -0
  151. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/dragdrop.js +974 -0
  152. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/effects.js +1122 -0
  153. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/scriptaculous.js +58 -0
  154. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/slider.js +275 -0
  155. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/sound.js +55 -0
  156. data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/unittest.js +568 -0
  157. data/test/vendor/jQuery/1.3.2/test/polluted.php +64 -0
  158. data/test/vendor/jQuery/1.3.2/test/qunit/testrunner.js +780 -0
  159. data/test/vendor/jQuery/1.3.2/test/qunit/testsuite.css +120 -0
  160. data/test/vendor/jQuery/1.3.2/test/test.js +41 -0
  161. data/test/vendor/jQuery/1.3.2/test/unit/ajax.js +856 -0
  162. data/test/vendor/jQuery/1.3.2/test/unit/core.js +1872 -0
  163. data/test/vendor/jQuery/1.3.2/test/unit/data.js +160 -0
  164. data/test/vendor/jQuery/1.3.2/test/unit/dimensions.js +86 -0
  165. data/test/vendor/jQuery/1.3.2/test/unit/event.js +670 -0
  166. data/test/vendor/jQuery/1.3.2/test/unit/fx.js +451 -0
  167. data/test/vendor/jQuery/1.3.2/test/unit/offset.js +173 -0
  168. data/test/vendor/jQuery/1.3.2/test/unit/selector.js +395 -0
  169. data/test/vendor/jQuery/1.3.2/test/xhtml.php +5 -0
  170. data/test/vendor/jQuery/1.3.2/version.txt +1 -0
  171. metadata +158 -22
  172. data/lib/envjs/runtime.rb.smp +0 -133
  173. data/test/envjs-call-load-test.js +0 -5
  174. data/test/envjs-prototype.js +0 -5
  175. data/test/qunit/package.json +0 -21
  176. data/test/qunit/test/index.html +0 -17
  177. data/test/qunit/test/same.js +0 -1368
  178. data/test/qunit/test/test.js +0 -136
  179. data/test/qunit.smp/package.json +0 -21
  180. data/test/qunit.smp/test/index.html +0 -17
  181. data/test/qunit.smp/test/same.js +0 -1368
  182. data/test/qunit.smp/test/test.js +0 -136
  183. data/test/rhino-call-load-test.js +0 -5
  184. data/test/rhino-prototype.js +0 -5
  185. data/test/test-with-envs-jar.js +0 -8
  186. data/test/test-with-rhino-jar.js +0 -9
@@ -0,0 +1,670 @@
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
+ equals( event.data.foo, "bar", "bind() with data, Check value of passed data" );
8
+ };
9
+ jQuery("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
10
+
11
+ ok( !jQuery.data(jQuery("#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
+ equals( event.data.foo, "bar", "Check value of passed data" );
19
+ ok( data, "Check trigger data" );
20
+ equals( data.bar, "foo", "Check value of trigger data" );
21
+ };
22
+ jQuery("#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
+ jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover");
36
+ equals( clickCounter, 1, "bind() with multiple events at once" );
37
+ equals( 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
+ jQuery("#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
+ // jQuery(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
+ jQuery("#form select").each(function(i){
68
+ jQuery(this).bind('change', i, selectOnChange);
69
+ }).trigger('change');
70
+ });
71
+
72
+ test("bind(), namespaced events, cloned events", function() {
73
+ expect(6);
74
+
75
+ jQuery("#firstp").bind("custom.test",function(e){
76
+ ok(true, "Custom event triggered");
77
+ });
78
+
79
+ jQuery("#firstp").bind("click",function(e){
80
+ ok(true, "Normal click triggered");
81
+ });
82
+
83
+ jQuery("#firstp").bind("click.test",function(e){
84
+ ok(true, "Namespaced click triggered");
85
+ });
86
+
87
+ // Trigger both bound fn (2)
88
+ jQuery("#firstp").trigger("click");
89
+
90
+ // Trigger one bound fn (1)
91
+ jQuery("#firstp").trigger("click.test");
92
+
93
+ // Remove only the one fn
94
+ jQuery("#firstp").unbind("click.test");
95
+
96
+ // Trigger the remaining fn (1)
97
+ jQuery("#firstp").trigger("click");
98
+
99
+ // Remove the remaining fn
100
+ jQuery("#firstp").unbind(".test");
101
+
102
+ // Trigger the remaining fn (0)
103
+ jQuery("#firstp").trigger("custom");
104
+
105
+ // using contents will get comments regular, text, and comment nodes
106
+ jQuery("#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
+ jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
112
+ ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
113
+ });
114
+
115
+ test("bind(), multi-namespaced events", function() {
116
+ expect(6);
117
+
118
+ var order = [
119
+ "click.test.abc",
120
+ "click.test.abc",
121
+ "click.test",
122
+ "click.test.abc",
123
+ "click.test",
124
+ "custom.test2"
125
+ ];
126
+
127
+ function check(name, msg){
128
+ same(name, order.shift(), msg);
129
+ }
130
+
131
+ jQuery("#firstp").bind("custom.test",function(e){
132
+ check("custom.test", "Custom event triggered");
133
+ });
134
+
135
+ jQuery("#firstp").bind("custom.test2",function(e){
136
+ check("custom.test2", "Custom event triggered");
137
+ });
138
+
139
+ jQuery("#firstp").bind("click.test",function(e){
140
+ check("click.test", "Normal click triggered");
141
+ });
142
+
143
+ jQuery("#firstp").bind("click.test.abc",function(e){
144
+ check("click.test.abc", "Namespaced click triggered");
145
+ });
146
+
147
+ // Trigger both bound fn (1)
148
+ jQuery("#firstp").trigger("click.test.abc");
149
+
150
+ // Trigger one bound fn (1)
151
+ jQuery("#firstp").trigger("click.abc");
152
+
153
+ // Trigger two bound fn (2)
154
+ jQuery("#firstp").trigger("click.test");
155
+
156
+ // Remove only the one fn
157
+ jQuery("#firstp").unbind("click.abc");
158
+
159
+ // Trigger the remaining fn (1)
160
+ jQuery("#firstp").trigger("click");
161
+
162
+ // Remove the remaining fn
163
+ jQuery("#firstp").unbind(".test");
164
+
165
+ // Trigger the remaining fn (1)
166
+ jQuery("#firstp").trigger("custom");
167
+ });
168
+
169
+ test("unbind(type)", function() {
170
+ expect( 0 );
171
+
172
+ var $elem = jQuery("#firstp"),
173
+ message;
174
+
175
+ function error(){
176
+ ok( false, message );
177
+ }
178
+
179
+ message = "unbind passing function";
180
+ $elem.bind('error', error).unbind('error',error).triggerHandler('error');
181
+
182
+ message = "unbind all from event";
183
+ $elem.bind('error', error).unbind('error').triggerHandler('error');
184
+
185
+ message = "unbind all";
186
+ $elem.bind('error', error).unbind().triggerHandler('error');
187
+
188
+ message = "unbind many with function";
189
+ $elem.bind('error error2',error)
190
+ .unbind('error error2', error )
191
+ .trigger('error').triggerHandler('error2');
192
+
193
+ message = "unbind many"; // #3538
194
+ $elem.bind('error error2',error)
195
+ .unbind('error error2')
196
+ .trigger('error').triggerHandler('error2');
197
+ });
198
+
199
+ test("unbind(eventObject)", function() {
200
+ expect(4);
201
+
202
+ var $elem = jQuery("#firstp"),
203
+ num;
204
+
205
+ function assert( expected ){
206
+ num = 0;
207
+ $elem.trigger('foo').triggerHandler('bar');
208
+ equals( num, expected, "Check the right handlers are triggered" );
209
+ }
210
+
211
+ $elem
212
+ // This handler shouldn't be unbound
213
+ .bind('foo', function(){
214
+ num += 1;
215
+ })
216
+ .bind('foo', function(e){
217
+ $elem.unbind( e )
218
+ num += 2;
219
+ })
220
+ // Neither this one
221
+ .bind('bar', function(){
222
+ num += 4;
223
+ });
224
+
225
+ assert( 7 );
226
+ assert( 5 );
227
+
228
+ $elem.unbind('bar');
229
+ assert( 1 );
230
+
231
+ $elem.unbind();
232
+ assert( 0 );
233
+ });
234
+
235
+ test("trigger() shortcuts", function() {
236
+ expect(6);
237
+ jQuery('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
238
+ var close = jQuery('spanx', this); // same with jQuery(this).find('span');
239
+ equals( close.length, 0, "Context element does not exist, length must be zero" );
240
+ ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
241
+ return false;
242
+ }).click();
243
+
244
+ jQuery("#check1").click(function() {
245
+ ok( true, "click event handler for checkbox gets fired twice, see #815" );
246
+ }).click();
247
+
248
+ var counter = 0;
249
+ jQuery('#firstp')[0].onclick = function(event) {
250
+ counter++;
251
+ };
252
+ jQuery('#firstp').click();
253
+ equals( counter, 1, "Check that click, triggers onclick event handler also" );
254
+
255
+ var clickCounter = 0;
256
+ jQuery('#simon1')[0].onclick = function(event) {
257
+ clickCounter++;
258
+ };
259
+ jQuery('#simon1').click();
260
+ equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
261
+
262
+ jQuery('<img />').load(function(){
263
+ ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
264
+ }).load();
265
+ });
266
+
267
+ test("trigger() bubbling", function() {
268
+ expect(14);
269
+
270
+ var doc = 0, html = 0, body = 0, main = 0, ap = 0;
271
+
272
+ jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
273
+ jQuery("html").bind("click", function(e){ html++; });
274
+ jQuery("body").bind("click", function(e){ body++; });
275
+ jQuery("#main").bind("click", function(e){ main++; });
276
+ jQuery("#ap").bind("click", function(){ ap++; return false; });
277
+
278
+ jQuery("html").trigger("click");
279
+ equals( doc, 1, "HTML bubble" );
280
+ equals( html, 1, "HTML bubble" );
281
+
282
+ jQuery("body").trigger("click");
283
+ equals( doc, 2, "Body bubble" );
284
+ equals( html, 2, "Body bubble" );
285
+ equals( body, 1, "Body bubble" );
286
+
287
+ jQuery("#main").trigger("click");
288
+ equals( doc, 3, "Main bubble" );
289
+ equals( html, 3, "Main bubble" );
290
+ equals( body, 2, "Main bubble" );
291
+ equals( main, 1, "Main bubble" );
292
+
293
+ jQuery("#ap").trigger("click");
294
+ equals( doc, 3, "ap bubble" );
295
+ equals( html, 3, "ap bubble" );
296
+ equals( body, 2, "ap bubble" );
297
+ equals( main, 1, "ap bubble" );
298
+ equals( ap, 1, "ap bubble" );
299
+ });
300
+
301
+ test("trigger(type, [data], [fn])", function() {
302
+ expect(11);
303
+
304
+ var handler = function(event, a, b, c) {
305
+ equals( event.type, "click", "check passed data" );
306
+ equals( a, 1, "check passed data" );
307
+ equals( b, "2", "check passed data" );
308
+ equals( c, "abc", "check passed data" );
309
+ return "test";
310
+ };
311
+
312
+ var $elem = jQuery("#firstp");
313
+
314
+ // Simulate a "native" click
315
+ $elem[0].click = function(){
316
+ ok( true, "Native call was triggered" );
317
+ };
318
+
319
+ // Triggers handlrs and native
320
+ // Trigger 5
321
+ $elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
322
+
323
+ // Simulate a "native" click
324
+ $elem[0].click = function(){
325
+ ok( false, "Native call was triggered" );
326
+ };
327
+
328
+ // Trigger only the handlers (no native)
329
+ // Triggers 5
330
+ equals( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
331
+
332
+ var pass = true;
333
+ try {
334
+ jQuery('#form input:first').hide().trigger('focus');
335
+ } catch(e) {
336
+ pass = false;
337
+ }
338
+ ok( pass, "Trigger focus on hidden element" );
339
+ });
340
+
341
+ test("trigger(eventObject, [data], [fn])", function() {
342
+ expect(25);
343
+
344
+ var $parent = jQuery('<div id="par" />').hide().appendTo('body'),
345
+ $child = jQuery('<p id="child">foo</p>').appendTo( $parent );
346
+
347
+ var event = jQuery.Event("noNew");
348
+ ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
349
+ equals( event.type, "noNew", "Verify its type" );
350
+
351
+ equals( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
352
+ equals( event.isPropagationStopped(), false, "Verify isPropagationStopped" );
353
+ equals( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
354
+
355
+ event.preventDefault();
356
+ equals( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" );
357
+ event.stopPropagation();
358
+ equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
359
+
360
+ event.isPropagationStopped = function(){ return false };
361
+ event.stopImmediatePropagation();
362
+ equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
363
+ equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
364
+
365
+ $parent.bind('foo',function(e){
366
+ // Tries bubbling
367
+ equals( e.type, 'foo', 'Verify event type when passed passing an event object' );
368
+ equals( e.target.id, 'child', 'Verify event.target when passed passing an event object' );
369
+ equals( e.currentTarget.id, 'par', 'Verify event.target when passed passing an event object' );
370
+ equals( e.secret, 'boo!', 'Verify event object\'s custom attribute when passed passing an event object' );
371
+ });
372
+
373
+ // test with an event object
374
+ event = new jQuery.Event("foo");
375
+ event.secret = 'boo!';
376
+ $child.trigger(event);
377
+
378
+ // test with a literal object
379
+ $child.trigger({type:'foo', secret:'boo!'});
380
+
381
+ $parent.unbind();
382
+
383
+ function error(){
384
+ ok( false, "This assertion shouldn't be reached");
385
+ }
386
+
387
+ $parent.bind('foo', error );
388
+
389
+ $child.bind('foo',function(e, a, b, c ){
390
+ equals( arguments.length, 4, "Check arguments length");
391
+ equals( a, 1, "Check first custom argument");
392
+ equals( b, 2, "Check second custom argument");
393
+ equals( c, 3, "Check third custom argument");
394
+
395
+ equals( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
396
+ equals( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
397
+ equals( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
398
+
399
+ // Skips both errors
400
+ e.stopImmediatePropagation();
401
+
402
+ return "result";
403
+ });
404
+
405
+ // We should add this back in when we want to test the order
406
+ // in which event handlers are iterated.
407
+ //$child.bind('foo', error );
408
+
409
+ event = new jQuery.Event("foo");
410
+ $child.trigger( event, [1,2,3] ).unbind();
411
+ equals( event.result, "result", "Check event.result attribute");
412
+
413
+ // Will error if it bubbles
414
+ $child.triggerHandler('foo');
415
+
416
+ $child.unbind();
417
+ $parent.unbind().remove();
418
+ });
419
+
420
+ test("jQuery.Event.currentTarget", function(){
421
+ expect(1);
422
+
423
+ var counter = 0,
424
+ $elem = jQuery('<button>a</button>').click(function(e){
425
+ equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" );
426
+ });
427
+
428
+ // Fake event
429
+ $elem.trigger('click');
430
+
431
+ // Cleanup
432
+ $elem.unbind();
433
+ });
434
+
435
+ test("toggle(Function, Function, ...)", function() {
436
+ expect(11);
437
+
438
+ var count = 0,
439
+ fn1 = function(e) { count++; },
440
+ fn2 = function(e) { count--; },
441
+ preventDefault = function(e) { e.preventDefault() },
442
+ link = jQuery('#mark');
443
+ link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
444
+ equals( count, 1, "Check for toggle(fn, fn)" );
445
+
446
+ jQuery("#firstp").toggle(function () {
447
+ equals(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" )
448
+ }, function() {}).trigger("click", [ 1, 2, 3 ]);
449
+
450
+ var first = 0;
451
+ jQuery("#simon1").one("click", function() {
452
+ ok( true, "Execute event only once" );
453
+ jQuery(this).toggle(function() {
454
+ equals( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
455
+ }, function() {
456
+ equals( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
457
+ });
458
+ return false;
459
+ }).click().click().click();
460
+
461
+ var turn = 0;
462
+ var fns = [
463
+ function(){
464
+ turn = 1;
465
+ },
466
+ function(){
467
+ turn = 2;
468
+ },
469
+ function(){
470
+ turn = 3;
471
+ }
472
+ ];
473
+
474
+ var $div = jQuery("<div>&nbsp;</div>").toggle( fns[0], fns[1], fns[2] );
475
+ $div.click();
476
+ equals( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1");
477
+ $div.click();
478
+ equals( turn, 2, "Trying toggle with 3 functions, attempt 2 yields 2");
479
+ $div.click();
480
+ equals( turn, 3, "Trying toggle with 3 functions, attempt 3 yields 3");
481
+ $div.click();
482
+ equals( turn, 1, "Trying toggle with 3 functions, attempt 4 yields 1");
483
+ $div.click();
484
+ equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
485
+
486
+ $div.unbind('click',fns[0]);
487
+ var data = jQuery.data( $div[0], 'events' );
488
+ ok( !data, "Unbinding one function from toggle unbinds them all");
489
+ });
490
+
491
+ test(".live()/.die()", function() {
492
+ expect(46);
493
+
494
+ var submit = 0, div = 0, livea = 0, liveb = 0;
495
+
496
+ jQuery("div").live("submit", function(){ submit++; return false; });
497
+ jQuery("div").live("click", function(){ div++; });
498
+ jQuery("div#nothiddendiv").live("click", function(){ livea++; });
499
+ jQuery("div#nothiddendivchild").live("click", function(){ liveb++; });
500
+
501
+ // Nothing should trigger on the body
502
+ jQuery("body").trigger("click");
503
+ equals( submit, 0, "Click on body" );
504
+ equals( div, 0, "Click on body" );
505
+ equals( livea, 0, "Click on body" );
506
+ equals( liveb, 0, "Click on body" );
507
+
508
+ // This should trigger two events
509
+ jQuery("div#nothiddendiv").trigger("click");
510
+ equals( submit, 0, "Click on div" );
511
+ equals( div, 1, "Click on div" );
512
+ equals( livea, 1, "Click on div" );
513
+ equals( liveb, 0, "Click on div" );
514
+
515
+ // This should trigger three events (w/ bubbling)
516
+ jQuery("div#nothiddendivchild").trigger("click");
517
+ equals( submit, 0, "Click on inner div" );
518
+ equals( div, 2, "Click on inner div" );
519
+ equals( livea, 2, "Click on inner div" );
520
+ equals( liveb, 1, "Click on inner div" );
521
+
522
+ // This should trigger one submit
523
+ jQuery("div#nothiddendivchild").trigger("submit");
524
+ equals( submit, 1, "Submit on div" );
525
+ equals( div, 2, "Submit on div" );
526
+ equals( livea, 2, "Submit on div" );
527
+ equals( liveb, 1, "Submit on div" );
528
+
529
+ // Make sure no other events were removed in the process
530
+ jQuery("div#nothiddendivchild").trigger("click");
531
+ equals( submit, 1, "die Click on inner div" );
532
+ equals( div, 3, "die Click on inner div" );
533
+ equals( livea, 3, "die Click on inner div" );
534
+ equals( liveb, 2, "die Click on inner div" );
535
+
536
+ // Now make sure that the removal works
537
+ jQuery("div#nothiddendivchild").die("click");
538
+ jQuery("div#nothiddendivchild").trigger("click");
539
+ equals( submit, 1, "die Click on inner div" );
540
+ equals( div, 4, "die Click on inner div" );
541
+ equals( livea, 4, "die Click on inner div" );
542
+ equals( liveb, 2, "die Click on inner div" );
543
+
544
+ // Make sure that the click wasn't removed too early
545
+ jQuery("div#nothiddendiv").trigger("click");
546
+ equals( submit, 1, "die Click on inner div" );
547
+ equals( div, 5, "die Click on inner div" );
548
+ equals( livea, 5, "die Click on inner div" );
549
+ equals( liveb, 2, "die Click on inner div" );
550
+
551
+ // Make sure that stopPropgation doesn't stop live events
552
+ jQuery("div#nothiddendivchild").live("click", function(e){ liveb++; e.stopPropagation(); });
553
+ jQuery("div#nothiddendivchild").trigger("click");
554
+ equals( submit, 1, "stopPropagation Click on inner div" );
555
+ equals( div, 6, "stopPropagation Click on inner div" );
556
+ equals( livea, 6, "stopPropagation Click on inner div" );
557
+ equals( liveb, 3, "stopPropagation Click on inner div" );
558
+
559
+ jQuery("div#nothiddendivchild").die("click");
560
+ jQuery("div#nothiddendiv").die("click");
561
+ jQuery("div").die("click");
562
+ jQuery("div").die("submit");
563
+
564
+ // Verify that return false prevents default action
565
+ jQuery("#anchor2").live("click", function(){ return false; });
566
+ var hash = window.location.hash;
567
+ jQuery("#anchor2").trigger("click");
568
+ equals( window.location.hash, hash, "return false worked" );
569
+ jQuery("#anchor2").die("click");
570
+
571
+ // Verify that .preventDefault() prevents default action
572
+ jQuery("#anchor2").live("click", function(e){ e.preventDefault(); });
573
+ var hash = window.location.hash;
574
+ jQuery("#anchor2").trigger("click");
575
+ equals( window.location.hash, hash, "e.preventDefault() worked" );
576
+ jQuery("#anchor2").die("click");
577
+
578
+ // Test binding the same handler to multiple points
579
+ var called = 0;
580
+ function callback(){ called++; return false; }
581
+
582
+ jQuery("#nothiddendiv").live("click", callback);
583
+ jQuery("#anchor2").live("click", callback);
584
+
585
+ jQuery("#nothiddendiv").trigger("click");
586
+ equals( called, 1, "Verify that only one click occurred." );
587
+
588
+ jQuery("#anchor2").trigger("click");
589
+ equals( called, 2, "Verify that only one click occurred." );
590
+
591
+ // Make sure that only one callback is removed
592
+ jQuery("#anchor2").die("click", callback);
593
+
594
+ jQuery("#nothiddendiv").trigger("click");
595
+ equals( called, 3, "Verify that only one click occurred." );
596
+
597
+ jQuery("#anchor2").trigger("click");
598
+ equals( called, 3, "Verify that no click occurred." );
599
+
600
+ // Make sure that it still works if the selector is the same,
601
+ // but the event type is different
602
+ jQuery("#nothiddendiv").live("foo", callback);
603
+
604
+ // Cleanup
605
+ jQuery("#nothiddendiv").die("click", callback);
606
+
607
+ jQuery("#nothiddendiv").trigger("click");
608
+ equals( called, 3, "Verify that no click occurred." );
609
+
610
+ jQuery("#nothiddendiv").trigger("foo");
611
+ equals( called, 4, "Verify that one foo occurred." );
612
+
613
+ // Cleanup
614
+ jQuery("#nothiddendiv").die("foo", callback);
615
+
616
+ // Make sure we don't loose the target by DOM modifications
617
+ // after the bubble already reached the liveHandler
618
+ var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0);
619
+
620
+ jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(''); });
621
+ jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} });
622
+
623
+ jQuery("#nothiddendiv span").click();
624
+ equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
625
+ equals( livec, 1, "Verify that second handler occurred even with nuked target." );
626
+
627
+ // Cleanup
628
+ jQuery("#nothiddendivchild").die("click");
629
+
630
+ // Verify that .live() ocurs and cancel buble in the same order as
631
+ // we would expect .bind() and .click() without delegation
632
+ var lived = 0, livee = 0;
633
+
634
+ // bind one pair in one order
635
+ jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; });
636
+ jQuery('span#liveSpan1').live('click', function(){ livee++; });
637
+
638
+ jQuery('span#liveSpan1 a').click();
639
+ equals( lived, 1, "Verify that only one first handler occurred." );
640
+ equals( livee, 0, "Verify that second handler don't." );
641
+
642
+ // and one pair in inverse
643
+ jQuery('#liveHandlerOrder span#liveSpan2').live('click', function(){ livee++; });
644
+ jQuery('#liveHandlerOrder span#liveSpan2 a').live('click', function(){ lived++; return false; });
645
+
646
+ jQuery('span#liveSpan2 a').click();
647
+ equals( lived, 2, "Verify that only one first handler occurred." );
648
+ equals( livee, 0, "Verify that second handler don't." );
649
+
650
+ // Cleanup
651
+ jQuery("span#liveSpan1 a, span#liveSpan1, span#liveSpan2 a, span#liveSpan2").die("click");
652
+ });
653
+
654
+ /*
655
+ test("jQuery(function($) {})", function() {
656
+ stop();
657
+ jQuery(function($) {
658
+ 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");
659
+ start();
660
+ });
661
+ });
662
+
663
+ test("event properties", function() {
664
+ stop();
665
+ jQuery("#simon1").click(function(event) {
666
+ ok( event.timeStamp, "assert event.timeStamp is present" );
667
+ start();
668
+ }).click();
669
+ });
670
+ */