lady_josephine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +32 -0
  4. data/app/assets/fonts/lady_josephine/icons/icons.eot +0 -0
  5. data/app/assets/fonts/lady_josephine/icons/icons.svg +215 -0
  6. data/app/assets/fonts/lady_josephine/icons/icons.ttf +0 -0
  7. data/app/assets/fonts/lady_josephine/icons/icons.woff +0 -0
  8. data/app/assets/javascripts/lady_josephine/blocks/facebook.js +25 -0
  9. data/app/assets/javascripts/lady_josephine/blocks/instagram.js +22 -0
  10. data/app/assets/javascripts/lady_josephine/blocks/soundcloud.js +24 -0
  11. data/app/assets/javascripts/lady_josephine/blocks/twitter.js +25 -0
  12. data/app/assets/javascripts/lady_josephine/blocks/vimeo.js +55 -0
  13. data/app/assets/javascripts/lady_josephine/blocks/youtube.js +64 -0
  14. data/app/assets/javascripts/lady_josephine/editor.js +40 -0
  15. data/app/assets/javascripts/lady_josephine/lady_josephine.js +4 -0
  16. data/app/assets/javascripts/lady_josephine/lady_josephine_view.js +6 -0
  17. data/app/assets/stylesheets/lady_josephine/content.sass +33 -0
  18. data/app/assets/stylesheets/lady_josephine/icons.sass +175 -0
  19. data/app/assets/stylesheets/lady_josephine/lady_josephine.sass +6 -0
  20. data/app/assets/stylesheets/lady_josephine/sir_trevor.sass +619 -0
  21. data/app/assets/stylesheets/lady_josephine/vars.sass +36 -0
  22. data/app/controllers/lady_josephine/application_controller.rb +4 -0
  23. data/app/controllers/lady_josephine/editor_controller.rb +40 -0
  24. data/app/controllers/lady_josephine/images_controller.rb +26 -0
  25. data/app/helpers/lady_josephine/helper.rb +25 -0
  26. data/app/helpers/lady_josephine/sir_trevor_helper.rb +172 -0
  27. data/app/models/lady_josephine/concerns/model.rb +29 -0
  28. data/app/models/lady_josephine/concerns/pingable.rb +28 -0
  29. data/app/models/lady_josephine/concerns/server_uuid.rb +24 -0
  30. data/app/models/lady_josephine/concerns/sir_trevor_images.rb +38 -0
  31. data/app/models/lady_josephine/image.rb +41 -0
  32. data/app/uploader/lady_josephine/base_uploader.rb +47 -0
  33. data/app/uploader/lady_josephine/image_uploader.rb +149 -0
  34. data/app/views/lady_josephine/blocks/_audio_block.haml +2 -0
  35. data/app/views/lady_josephine/blocks/_definition_block.haml +4 -0
  36. data/app/views/lady_josephine/blocks/_divider_block.haml +2 -0
  37. data/app/views/lady_josephine/blocks/_extended_image_block.haml +63 -0
  38. data/app/views/lady_josephine/blocks/_extended_quote_block.haml +5 -0
  39. data/app/views/lady_josephine/blocks/_extended_tweet_block.haml +2 -0
  40. data/app/views/lady_josephine/blocks/_facebook_post_block.haml +2 -0
  41. data/app/views/lady_josephine/blocks/_heading_block.haml +2 -0
  42. data/app/views/lady_josephine/blocks/_html_block.haml +1 -0
  43. data/app/views/lady_josephine/blocks/_instagram_block.haml +2 -0
  44. data/app/views/lady_josephine/blocks/_list_block.haml +3 -0
  45. data/app/views/lady_josephine/blocks/_quote_block.haml +5 -0
  46. data/app/views/lady_josephine/blocks/_text_block.html.haml +2 -0
  47. data/app/views/lady_josephine/blocks/_video_block.haml +9 -0
  48. data/config/routes.rb +9 -0
  49. data/db/migrate/20160222151500_lady_josephine_image.rb +18 -0
  50. data/lib/generators/lady_josephine_migration/USAGE +9 -0
  51. data/lib/generators/lady_josephine_migration/lady_josephine_migration_generator.rb +17 -0
  52. data/lib/generators/lady_josephine_migration/templates/migration.rb +9 -0
  53. data/lib/lady_josephine.rb +18 -0
  54. data/lib/lady_josephine/engine.rb +18 -0
  55. data/lib/lady_josephine/redcarpet/custom_markdown_formatter.rb +63 -0
  56. data/lib/lady_josephine/renderer/sir_trevor_renderer.rb +16 -0
  57. data/lib/lady_josephine/version.rb +3 -0
  58. data/lib/lady_josephine/whitelist.rb +26 -0
  59. data/lib/tasks/lady_josephine_tasks.rake +4 -0
  60. data/spec/controllers/lady_josephine/editor_controller_spec.rb +58 -0
  61. data/spec/dummy/README.rdoc +28 -0
  62. data/spec/dummy/Rakefile +6 -0
  63. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  64. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  65. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  66. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  67. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  68. data/spec/dummy/bin/bundle +3 -0
  69. data/spec/dummy/bin/rails +4 -0
  70. data/spec/dummy/bin/rake +4 -0
  71. data/spec/dummy/bin/setup +29 -0
  72. data/spec/dummy/config.ru +4 -0
  73. data/spec/dummy/config/application.rb +26 -0
  74. data/spec/dummy/config/boot.rb +5 -0
  75. data/spec/dummy/config/database.yml +25 -0
  76. data/spec/dummy/config/environment.rb +5 -0
  77. data/spec/dummy/config/environments/development.rb +41 -0
  78. data/spec/dummy/config/environments/production.rb +79 -0
  79. data/spec/dummy/config/environments/test.rb +42 -0
  80. data/spec/dummy/config/initializers/assets.rb +11 -0
  81. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  82. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  83. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/spec/dummy/config/initializers/inflections.rb +16 -0
  85. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  86. data/spec/dummy/config/initializers/session_store.rb +3 -0
  87. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  88. data/spec/dummy/config/locales/en.yml +23 -0
  89. data/spec/dummy/config/routes.rb +4 -0
  90. data/spec/dummy/config/secrets.yml +22 -0
  91. data/spec/dummy/db/development.sqlite3 +0 -0
  92. data/spec/dummy/db/schema.rb +16 -0
  93. data/spec/dummy/db/test.sqlite3 +0 -0
  94. data/spec/dummy/log/bla +0 -0
  95. data/spec/dummy/public/404.html +67 -0
  96. data/spec/dummy/public/422.html +67 -0
  97. data/spec/dummy/public/500.html +66 -0
  98. data/spec/dummy/public/favicon.ico +0 -0
  99. data/spec/spec_helper.rb +17 -0
  100. data/vendor/assets/components/Eventable/README.md +12 -0
  101. data/vendor/assets/components/Eventable/bower.json +10 -0
  102. data/vendor/assets/components/Eventable/component.json +11 -0
  103. data/vendor/assets/components/Eventable/eventable.js +207 -0
  104. data/vendor/assets/components/Eventable/package.json +15 -0
  105. data/vendor/assets/components/jquery-autosize/bower.json +30 -0
  106. data/vendor/assets/components/jquery-autosize/demo.html +36 -0
  107. data/vendor/assets/components/jquery-autosize/jquery.autosize.js +273 -0
  108. data/vendor/assets/components/jquery-autosize/jquery.autosize.min.js +6 -0
  109. data/vendor/assets/components/jquery-autosize/package.json +32 -0
  110. data/vendor/assets/components/jquery-autosize/readme.md +216 -0
  111. data/vendor/assets/components/jquery/AUTHORS.txt +163 -0
  112. data/vendor/assets/components/jquery/CONTRIBUTING.md +216 -0
  113. data/vendor/assets/components/jquery/Gruntfile.js +496 -0
  114. data/vendor/assets/components/jquery/MIT-LICENSE.txt +21 -0
  115. data/vendor/assets/components/jquery/README.md +415 -0
  116. data/vendor/assets/components/jquery/build/release-notes.js +59 -0
  117. data/vendor/assets/components/jquery/build/release.js +246 -0
  118. data/vendor/assets/components/jquery/component.json +13 -0
  119. data/vendor/assets/components/jquery/composer.json +35 -0
  120. data/vendor/assets/components/jquery/jquery-migrate.js +496 -0
  121. data/vendor/assets/components/jquery/jquery-migrate.min.js +3 -0
  122. data/vendor/assets/components/jquery/jquery.js +9597 -0
  123. data/vendor/assets/components/jquery/jquery.min.js +5 -0
  124. data/vendor/assets/components/jquery/jquery.min.map +1 -0
  125. data/vendor/assets/components/jquery/package.json +39 -0
  126. data/vendor/assets/components/jquery/speed/benchmark.js +15 -0
  127. data/vendor/assets/components/jquery/speed/benchmarker.css +65 -0
  128. data/vendor/assets/components/jquery/speed/benchmarker.js +181 -0
  129. data/vendor/assets/components/jquery/speed/closest.html +39 -0
  130. data/vendor/assets/components/jquery/speed/css.html +82 -0
  131. data/vendor/assets/components/jquery/speed/event.html +58 -0
  132. data/vendor/assets/components/jquery/speed/filter.html +183 -0
  133. data/vendor/assets/components/jquery/speed/find.html +179 -0
  134. data/vendor/assets/components/jquery/speed/index.html +72 -0
  135. data/vendor/assets/components/jquery/speed/jquery-basis.js +6238 -0
  136. data/vendor/assets/components/jquery/speed/slice.vs.concat.html +47 -0
  137. data/vendor/assets/components/jquery/src/ajax.js +851 -0
  138. data/vendor/assets/components/jquery/src/ajax/jsonp.js +80 -0
  139. data/vendor/assets/components/jquery/src/ajax/script.js +86 -0
  140. data/vendor/assets/components/jquery/src/ajax/xhr.js +207 -0
  141. data/vendor/assets/components/jquery/src/attributes.js +661 -0
  142. data/vendor/assets/components/jquery/src/callbacks.js +196 -0
  143. data/vendor/assets/components/jquery/src/core.js +949 -0
  144. data/vendor/assets/components/jquery/src/css.js +679 -0
  145. data/vendor/assets/components/jquery/src/data.js +340 -0
  146. data/vendor/assets/components/jquery/src/deferred.js +141 -0
  147. data/vendor/assets/components/jquery/src/deprecated.js +4 -0
  148. data/vendor/assets/components/jquery/src/dimensions.js +41 -0
  149. data/vendor/assets/components/jquery/src/effects.js +730 -0
  150. data/vendor/assets/components/jquery/src/event-alias.js +15 -0
  151. data/vendor/assets/components/jquery/src/event.js +991 -0
  152. data/vendor/assets/components/jquery/src/exports.js +18 -0
  153. data/vendor/assets/components/jquery/src/intro.js +20 -0
  154. data/vendor/assets/components/jquery/src/manipulation.js +796 -0
  155. data/vendor/assets/components/jquery/src/offset.js +169 -0
  156. data/vendor/assets/components/jquery/src/outro.js +2 -0
  157. data/vendor/assets/components/jquery/src/queue.js +147 -0
  158. data/vendor/assets/components/jquery/src/serialize.js +99 -0
  159. data/vendor/assets/components/jquery/src/sizzle-jquery.js +9 -0
  160. data/vendor/assets/components/jquery/src/support.js +241 -0
  161. data/vendor/assets/components/jquery/src/traversing.js +275 -0
  162. data/vendor/assets/components/jquery/test/csp.php +16 -0
  163. data/vendor/assets/components/jquery/test/data/1x1.jpg +0 -0
  164. data/vendor/assets/components/jquery/test/data/ajax/unreleasedXHR.html +25 -0
  165. data/vendor/assets/components/jquery/test/data/atom+xml.php +4 -0
  166. data/vendor/assets/components/jquery/test/data/badcall.js +1 -0
  167. data/vendor/assets/components/jquery/test/data/badjson.js +1 -0
  168. data/vendor/assets/components/jquery/test/data/cleanScript.html +10 -0
  169. data/vendor/assets/components/jquery/test/data/core/cc_on.html +22 -0
  170. data/vendor/assets/components/jquery/test/data/dashboard.xml +11 -0
  171. data/vendor/assets/components/jquery/test/data/dimensions/documentLarge.html +17 -0
  172. data/vendor/assets/components/jquery/test/data/dimensions/documentSmall.html +21 -0
  173. data/vendor/assets/components/jquery/test/data/echoData.php +1 -0
  174. data/vendor/assets/components/jquery/test/data/echoQuery.php +1 -0
  175. data/vendor/assets/components/jquery/test/data/errorWithText.php +5 -0
  176. data/vendor/assets/components/jquery/test/data/etag.php +21 -0
  177. data/vendor/assets/components/jquery/test/data/evalScript.php +1 -0
  178. data/vendor/assets/components/jquery/test/data/event/longLoadScript.php +4 -0
  179. data/vendor/assets/components/jquery/test/data/event/promiseReady.html +17 -0
  180. data/vendor/assets/components/jquery/test/data/event/syncReady.html +23 -0
  181. data/vendor/assets/components/jquery/test/data/headers.php +18 -0
  182. data/vendor/assets/components/jquery/test/data/if_modified_since.php +20 -0
  183. data/vendor/assets/components/jquery/test/data/iframe.html +8 -0
  184. data/vendor/assets/components/jquery/test/data/jquery-1.8.2.ajax_xhr.min.js +2 -0
  185. data/vendor/assets/components/jquery/test/data/json.php +13 -0
  186. data/vendor/assets/components/jquery/test/data/json_obj.js +1 -0
  187. data/vendor/assets/components/jquery/test/data/jsonp.php +14 -0
  188. data/vendor/assets/components/jquery/test/data/manipulation/iframe-denied.html +36 -0
  189. data/vendor/assets/components/jquery/test/data/name.html +1 -0
  190. data/vendor/assets/components/jquery/test/data/name.php +24 -0
  191. data/vendor/assets/components/jquery/test/data/nocontent.php +5 -0
  192. data/vendor/assets/components/jquery/test/data/offset/absolute.html +41 -0
  193. data/vendor/assets/components/jquery/test/data/offset/body.html +26 -0
  194. data/vendor/assets/components/jquery/test/data/offset/fixed.html +34 -0
  195. data/vendor/assets/components/jquery/test/data/offset/relative.html +31 -0
  196. data/vendor/assets/components/jquery/test/data/offset/scroll.html +39 -0
  197. data/vendor/assets/components/jquery/test/data/offset/static.html +31 -0
  198. data/vendor/assets/components/jquery/test/data/offset/table.html +43 -0
  199. data/vendor/assets/components/jquery/test/data/params_html.php +12 -0
  200. data/vendor/assets/components/jquery/test/data/readywaitasset.js +1 -0
  201. data/vendor/assets/components/jquery/test/data/readywaitloader.js +25 -0
  202. data/vendor/assets/components/jquery/test/data/script.php +11 -0
  203. data/vendor/assets/components/jquery/test/data/selector/html5_selector.html +114 -0
  204. data/vendor/assets/components/jquery/test/data/selector/sizzle_cache.html +21 -0
  205. data/vendor/assets/components/jquery/test/data/statusText.php +5 -0
  206. data/vendor/assets/components/jquery/test/data/support/bodyBackground.html +28 -0
  207. data/vendor/assets/components/jquery/test/data/support/shrinkWrapBlocks.html +23 -0
  208. data/vendor/assets/components/jquery/test/data/support/testElementCrash.html +17 -0
  209. data/vendor/assets/components/jquery/test/data/test.html +7 -0
  210. data/vendor/assets/components/jquery/test/data/test.js +3 -0
  211. data/vendor/assets/components/jquery/test/data/test.php +7 -0
  212. data/vendor/assets/components/jquery/test/data/test2.html +5 -0
  213. data/vendor/assets/components/jquery/test/data/test3.html +3 -0
  214. data/vendor/assets/components/jquery/test/data/testinit.js +269 -0
  215. data/vendor/assets/components/jquery/test/data/testrunner.js +368 -0
  216. data/vendor/assets/components/jquery/test/data/testsuite.css +155 -0
  217. data/vendor/assets/components/jquery/test/data/text.php +12 -0
  218. data/vendor/assets/components/jquery/test/data/ua.txt +272 -0
  219. data/vendor/assets/components/jquery/test/data/with_fries.xml +25 -0
  220. data/vendor/assets/components/jquery/test/data/with_fries_over_jsonp.php +7 -0
  221. data/vendor/assets/components/jquery/test/delegatetest.html +228 -0
  222. data/vendor/assets/components/jquery/test/hovertest.html +158 -0
  223. data/vendor/assets/components/jquery/test/index.html +330 -0
  224. data/vendor/assets/components/jquery/test/localfile.html +75 -0
  225. data/vendor/assets/components/jquery/test/networkerror.html +84 -0
  226. data/vendor/assets/components/jquery/test/polluted.php +110 -0
  227. data/vendor/assets/components/jquery/test/readywait.html +70 -0
  228. data/vendor/assets/components/jquery/test/unit/ajax.js +1971 -0
  229. data/vendor/assets/components/jquery/test/unit/attributes.js +1332 -0
  230. data/vendor/assets/components/jquery/test/unit/callbacks.js +326 -0
  231. data/vendor/assets/components/jquery/test/unit/core.js +1332 -0
  232. data/vendor/assets/components/jquery/test/unit/css.js +1036 -0
  233. data/vendor/assets/components/jquery/test/unit/data.js +636 -0
  234. data/vendor/assets/components/jquery/test/unit/deferred.js +440 -0
  235. data/vendor/assets/components/jquery/test/unit/deprecated.js +1 -0
  236. data/vendor/assets/components/jquery/test/unit/dimensions.js +461 -0
  237. data/vendor/assets/components/jquery/test/unit/effects.js +2050 -0
  238. data/vendor/assets/components/jquery/test/unit/event.js +2690 -0
  239. data/vendor/assets/components/jquery/test/unit/exports.js +7 -0
  240. data/vendor/assets/components/jquery/test/unit/manipulation.js +2242 -0
  241. data/vendor/assets/components/jquery/test/unit/offset.js +549 -0
  242. data/vendor/assets/components/jquery/test/unit/queue.js +316 -0
  243. data/vendor/assets/components/jquery/test/unit/selector.js +185 -0
  244. data/vendor/assets/components/jquery/test/unit/serialize.js +146 -0
  245. data/vendor/assets/components/jquery/test/unit/support.js +384 -0
  246. data/vendor/assets/components/jquery/test/unit/traversing.js +667 -0
  247. data/vendor/assets/components/jquery/test/xhtml.php +5 -0
  248. data/vendor/assets/components/sir-trevor-js/CHANGELOG.md +44 -0
  249. data/vendor/assets/components/sir-trevor-js/Gemfile +3 -0
  250. data/vendor/assets/components/sir-trevor-js/Gemfile.lock +10 -0
  251. data/vendor/assets/components/sir-trevor-js/Gruntfile.js +109 -0
  252. data/vendor/assets/components/sir-trevor-js/MIT-LICENCE +20 -0
  253. data/vendor/assets/components/sir-trevor-js/Readme.md +84 -0
  254. data/vendor/assets/components/sir-trevor-js/bower.json +21 -0
  255. data/vendor/assets/components/sir-trevor-js/component.json +42 -0
  256. data/vendor/assets/components/sir-trevor-js/contributing.md +74 -0
  257. data/vendor/assets/components/sir-trevor-js/examples-component/component.json +14 -0
  258. data/vendor/assets/components/sir-trevor-js/examples-component/index.html +33 -0
  259. data/vendor/assets/components/sir-trevor-js/examples-component/index.js +29 -0
  260. data/vendor/assets/components/sir-trevor-js/examples-component/javascript/example_block.js +203 -0
  261. data/vendor/assets/components/sir-trevor-js/examples-component/javascript/limit_chars.js +46 -0
  262. data/vendor/assets/components/sir-trevor-js/examples-component/sir-trevor.gif +0 -0
  263. data/vendor/assets/components/sir-trevor-js/locales/cn.js +51 -0
  264. data/vendor/assets/components/sir-trevor-js/locales/de.js +51 -0
  265. data/vendor/assets/components/sir-trevor-js/locales/es.js +51 -0
  266. data/vendor/assets/components/sir-trevor-js/locales/fi.js +51 -0
  267. data/vendor/assets/components/sir-trevor-js/locales/fr.js +51 -0
  268. data/vendor/assets/components/sir-trevor-js/locales/pt.js +52 -0
  269. data/vendor/assets/components/sir-trevor-js/package.json +23 -0
  270. data/vendor/assets/components/sir-trevor-js/sir-trevor-icons.css +6 -0
  271. data/vendor/assets/components/sir-trevor-js/sir-trevor.css +393 -0
  272. data/vendor/assets/components/sir-trevor-js/sir-trevor.css.map +7 -0
  273. data/vendor/assets/components/sir-trevor-js/sir-trevor.js +5481 -0
  274. data/vendor/assets/components/sir-trevor-js/sir-trevor.min.js +13 -0
  275. data/vendor/assets/components/underscore/CNAME +1 -0
  276. data/vendor/assets/components/underscore/CONTRIBUTING.md +9 -0
  277. data/vendor/assets/components/underscore/LICENSE +22 -0
  278. data/vendor/assets/components/underscore/README.md +19 -0
  279. data/vendor/assets/components/underscore/Rakefile +10 -0
  280. data/vendor/assets/components/underscore/docs/docco.css +192 -0
  281. data/vendor/assets/components/underscore/docs/favicon.ico +0 -0
  282. data/vendor/assets/components/underscore/docs/images/background.png +0 -0
  283. data/vendor/assets/components/underscore/docs/images/underscore.png +0 -0
  284. data/vendor/assets/components/underscore/docs/underscore.html +823 -0
  285. data/vendor/assets/components/underscore/favicon.ico +0 -0
  286. data/vendor/assets/components/underscore/index.html +2467 -0
  287. data/vendor/assets/components/underscore/index.js +1 -0
  288. data/vendor/assets/components/underscore/package.json +16 -0
  289. data/vendor/assets/components/underscore/test/arrays.js +200 -0
  290. data/vendor/assets/components/underscore/test/chaining.js +59 -0
  291. data/vendor/assets/components/underscore/test/collections.js +453 -0
  292. data/vendor/assets/components/underscore/test/functions.js +265 -0
  293. data/vendor/assets/components/underscore/test/index.html +44 -0
  294. data/vendor/assets/components/underscore/test/objects.js +570 -0
  295. data/vendor/assets/components/underscore/test/speed.js +75 -0
  296. data/vendor/assets/components/underscore/test/utility.js +266 -0
  297. data/vendor/assets/components/underscore/test/vendor/jquery.js +9404 -0
  298. data/vendor/assets/components/underscore/test/vendor/jslitmus.js +670 -0
  299. data/vendor/assets/components/underscore/test/vendor/qunit.css +235 -0
  300. data/vendor/assets/components/underscore/test/vendor/qunit.js +1977 -0
  301. data/vendor/assets/components/underscore/test/vendor/runner.js +98 -0
  302. data/vendor/assets/components/underscore/underscore-min.js +1 -0
  303. data/vendor/assets/components/underscore/underscore.js +1226 -0
  304. metadata +473 -0
@@ -0,0 +1,2690 @@
1
+ module("event", { teardown: moduleTeardown });
2
+
3
+ test("null or undefined handler", function() {
4
+ expect(2);
5
+ // Supports Fixes bug #7229
6
+ try {
7
+ jQuery("#firstp").on( "click", null );
8
+ ok(true, "Passing a null handler will not throw an exception");
9
+ } catch (e) {}
10
+
11
+ try {
12
+ jQuery("#firstp").on( "click", undefined );
13
+ ok(true, "Passing an undefined handler will not throw an exception");
14
+ } catch (e) {}
15
+ });
16
+
17
+ test("bind(),on(),delegate() with non-null,defined data", function() {
18
+
19
+ expect(3);
20
+
21
+ var handler = function( event, data ) {
22
+ equal( data, 0, "non-null, defined data (zero) is correctly passed" );
23
+ };
24
+
25
+ jQuery("#foo").bind("foo.bind", handler);
26
+ jQuery("#foo").on("foo.on", handler);
27
+ jQuery("div").delegate("#foo", "foo.delegate", handler);
28
+
29
+ jQuery("#foo").trigger("foo", 0);
30
+
31
+ jQuery("#foo").unbind("foo.bind", handler);
32
+ jQuery("#foo").off("foo.on", handler);
33
+ jQuery("div").undelegate("#foo", "foo.delegate");
34
+
35
+ });
36
+
37
+ test("Handler changes and .trigger() order", function() {
38
+ expect(1);
39
+
40
+ var markup = jQuery(
41
+ "<div><div><p><span><b class=\"a\">b</b></span></p></div></div>"
42
+ ),
43
+ path = "";
44
+
45
+ markup
46
+ .find( "*" ).andSelf().on( "click", function( e ) {
47
+ path += this.nodeName.toLowerCase() + " ";
48
+ })
49
+ .filter( "b" ).on( "click", function( e ) {
50
+ // Removing span should not stop propagation to original parents
51
+ if ( e.target === this ) {
52
+ jQuery(this).parent().remove();
53
+ }
54
+ });
55
+
56
+ markup.find( "b" ).trigger( "click" );
57
+
58
+ equal( path, "b p div div ", "Delivered all events" );
59
+
60
+ markup.remove();
61
+ });
62
+
63
+ test("bind(), with data", function() {
64
+ expect(4);
65
+ var handler = function(event) {
66
+ ok( event.data, "bind() with data, check passed data exists" );
67
+ equal( event.data["foo"], "bar", "bind() with data, Check value of passed data" );
68
+ };
69
+ jQuery("#firstp").bind("click", {"foo": "bar"}, handler).trigger("click").unbind("click", handler);
70
+
71
+ ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
72
+
73
+ var test = function(){};
74
+ var handler2 = function(event) {
75
+ equal( event.data, test, "bind() with function data, Check value of passed data" );
76
+ };
77
+ jQuery("#firstp").bind("click", test, handler2).trigger("click").unbind("click", handler2);
78
+ });
79
+
80
+ test("click(), with data", function() {
81
+ expect(3);
82
+ var handler = function(event) {
83
+ ok( event.data, "bind() with data, check passed data exists" );
84
+ equal( event.data["foo"], "bar", "bind() with data, Check value of passed data" );
85
+ };
86
+ jQuery("#firstp").on( "click", {"foo": "bar"}, handler).trigger("click").unbind("click", handler);
87
+
88
+ ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
89
+ });
90
+
91
+ test("bind(), with data, trigger with data", function() {
92
+ expect(4);
93
+ var handler = function(event, data) {
94
+ ok( event.data, "check passed data exists" );
95
+ equal( event.data.foo, "bar", "Check value of passed data" );
96
+ ok( data, "Check trigger data" );
97
+ equal( data.bar, "foo", "Check value of trigger data" );
98
+ };
99
+ jQuery("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler);
100
+ });
101
+
102
+ test("bind(), multiple events at once", function() {
103
+ expect(2);
104
+ var clickCounter = 0,
105
+ mouseoverCounter = 0;
106
+ var handler = function(event) {
107
+ if (event.type == "click") {
108
+ clickCounter += 1;
109
+ }
110
+ else if (event.type == "mouseover") {
111
+ mouseoverCounter += 1;
112
+ }
113
+
114
+ };
115
+ jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover");
116
+ equal( clickCounter, 1, "bind() with multiple events at once" );
117
+ equal( mouseoverCounter, 1, "bind() with multiple events at once" );
118
+ });
119
+
120
+ test("bind(), five events at once", function() {
121
+ expect(1);
122
+
123
+ var count = 0,
124
+ handler = function(event) {
125
+ count++;
126
+ };
127
+
128
+ jQuery("#firstp").bind("click mouseover foo bar baz", handler)
129
+ .trigger("click").trigger("mouseover")
130
+ .trigger("foo").trigger("bar")
131
+ .trigger("baz");
132
+
133
+ equal( count, 5, "bind() five events at once" );
134
+ });
135
+
136
+ test("bind(), multiple events at once and namespaces", function() {
137
+ expect(7);
138
+
139
+ var cur, obj = {};
140
+
141
+ var div = jQuery("<div/>").bind("focusin.a", function(e) {
142
+ equal( e.type, cur, "Verify right single event was fired." );
143
+ });
144
+
145
+ cur = "focusin";
146
+ div.trigger("focusin.a");
147
+
148
+ // manually clean up detached elements
149
+ div.remove();
150
+
151
+ div = jQuery("<div/>").bind("click mouseover", obj, function(e) {
152
+ equal( e.type, cur, "Verify right multi event was fired." );
153
+ equal( e.data, obj, "Make sure the data came in correctly." );
154
+ });
155
+
156
+ cur = "click";
157
+ div.trigger("click");
158
+
159
+ cur = "mouseover";
160
+ div.trigger("mouseover");
161
+
162
+ // manually clean up detached elements
163
+ div.remove();
164
+
165
+ div = jQuery("<div/>").bind("focusin.a focusout.b", function(e) {
166
+ equal( e.type, cur, "Verify right multi event was fired." );
167
+ });
168
+
169
+ cur = "focusin";
170
+ div.trigger("focusin.a");
171
+
172
+ cur = "focusout";
173
+ div.trigger("focusout.b");
174
+
175
+ // manually clean up detached elements
176
+ div.remove();
177
+ });
178
+
179
+ test("bind(), namespace with special add", function() {
180
+ expect(27);
181
+
182
+ var div = jQuery("<div/>").bind("test", function(e) {
183
+ ok( true, "Test event fired." );
184
+ });
185
+
186
+ var i = 0;
187
+
188
+ jQuery.event.special["test"] = {
189
+ _default: function(e, data) {
190
+ equal( this, document, "Make sure we're at the top of the chain." );
191
+ equal( e.type, "test", "And that we're still dealing with a test event." );
192
+ equal( e.target, div[0], "And that the target is correct." );
193
+ ok( data !== undefined , "And that trigger data was passed." );
194
+ },
195
+ setup: function(){},
196
+ teardown: function(){
197
+ ok(true, "Teardown called.");
198
+ },
199
+ add: function( handleObj ) {
200
+ var handler = handleObj.handler;
201
+ handleObj.handler = function(e) {
202
+ e.xyz = ++i;
203
+ handler.apply( this, arguments );
204
+ };
205
+ },
206
+ remove: function() {
207
+ ok(true, "Remove called.");
208
+ }
209
+ };
210
+
211
+ div.bind("test.a", {"x": 1}, function(e) {
212
+ ok( !!e.xyz, "Make sure that the data is getting passed through." );
213
+ equal( e.data["x"], 1, "Make sure data is attached properly." );
214
+ });
215
+
216
+ div.bind("test.b", {"x": 2}, function(e) {
217
+ ok( !!e.xyz, "Make sure that the data is getting passed through." );
218
+ equal( e.data["x"], 2, "Make sure data is attached properly." );
219
+ });
220
+
221
+ // Should trigger 5
222
+ div.trigger("test", 33.33);
223
+
224
+ // Should trigger 2
225
+ div.trigger("test.a", "George Harrison");
226
+
227
+ // Should trigger 2
228
+ div.trigger("test.b", { year: 1982 });
229
+
230
+ // Should trigger 4
231
+ div.unbind("test");
232
+
233
+ div = jQuery("<div/>").bind("test", function(e) {
234
+ ok( true, "Test event fired." );
235
+ });
236
+
237
+ // Should trigger 2
238
+ div.appendTo("#qunit-fixture").remove();
239
+
240
+ delete jQuery.event.special["test"];
241
+ });
242
+
243
+ test("bind(), no data", function() {
244
+ expect(1);
245
+ var handler = function(event) {
246
+ ok ( !event.data, "Check that no data is added to the event object" );
247
+ };
248
+ jQuery("#firstp").bind("click", handler).trigger("click");
249
+ });
250
+
251
+ test("bind/one/unbind(Object)", function(){
252
+ expect(6);
253
+
254
+ var clickCounter = 0, mouseoverCounter = 0;
255
+ function handler(event) {
256
+ if (event.type == "click") {
257
+
258
+ clickCounter++;
259
+ }
260
+ else if (event.type == "mouseover") {
261
+ mouseoverCounter++;
262
+ }
263
+
264
+ }
265
+
266
+ function handlerWithData(event) {
267
+ if (event.type == "click") {
268
+ clickCounter += event.data;
269
+ }
270
+ else if (event.type == "mouseover") {
271
+ mouseoverCounter += event.data;
272
+ }
273
+ }
274
+
275
+ function trigger(){
276
+ $elem.trigger("click").trigger("mouseover");
277
+ }
278
+
279
+ var $elem = jQuery("#firstp")
280
+ // Regular bind
281
+ .bind({
282
+ "click":handler,
283
+ "mouseover":handler
284
+ })
285
+ // Bind with data
286
+ .one({
287
+ "click":handlerWithData,
288
+ "mouseover":handlerWithData
289
+ }, 2 );
290
+
291
+ trigger();
292
+
293
+ equal( clickCounter, 3, "bind(Object)" );
294
+ equal( mouseoverCounter, 3, "bind(Object)" );
295
+
296
+ trigger();
297
+ equal( clickCounter, 4, "bind(Object)" );
298
+ equal( mouseoverCounter, 4, "bind(Object)" );
299
+
300
+ jQuery("#firstp").unbind({
301
+ "click":handler,
302
+ "mouseover":handler
303
+ });
304
+
305
+ trigger();
306
+ equal( clickCounter, 4, "bind(Object)" );
307
+ equal( mouseoverCounter, 4, "bind(Object)" );
308
+ });
309
+
310
+ test("on/off(Object), delegate/undelegate(String, Object)", function() {
311
+ expect(6);
312
+
313
+ var clickCounter = 0, mouseoverCounter = 0,
314
+ $p = jQuery("#firstp"), $a = $p.find("a:first");
315
+
316
+ var events = {
317
+ "click": function( event ) {
318
+ clickCounter += ( event.data || 1 );
319
+ },
320
+ "mouseover": function( event ) {
321
+ mouseoverCounter += ( event.data || 1 );
322
+ }
323
+ };
324
+
325
+ function trigger() {
326
+ $a.trigger("click").trigger("mouseover");
327
+ }
328
+
329
+ jQuery( document ).on( events, "#firstp a:first" );
330
+ $p.delegate( "a", events, 2 );
331
+
332
+ trigger();
333
+ equal( clickCounter, 3, "on/delegate" );
334
+ equal( mouseoverCounter, 3, "on/delegate" );
335
+
336
+ $p.undelegate( "a", events );
337
+
338
+ trigger();
339
+ equal( clickCounter, 4, "undelegate" );
340
+ equal( mouseoverCounter, 4, "undelegate" );
341
+
342
+ jQuery( document ).off( events, "#firstp a:first" );
343
+
344
+ trigger();
345
+ equal( clickCounter, 4, "off" );
346
+ equal( mouseoverCounter, 4, "off" );
347
+ });
348
+
349
+ test("on/delegate immediate propagation", function() {
350
+ expect(2);
351
+
352
+ var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick;
353
+
354
+ lastClick = "";
355
+ jQuery( document ).on( "click", "#firstp a:first", function(e) {
356
+ lastClick = "click1";
357
+ e.stopImmediatePropagation();
358
+ });
359
+ jQuery( document ).on( "click", "#firstp a:first", function(e) {
360
+ lastClick = "click2";
361
+ });
362
+ $a.trigger( "click" );
363
+ equal( lastClick, "click1", "on stopImmediatePropagation" );
364
+ jQuery( document ).off( "click", "#firstp a:first" );
365
+
366
+ lastClick = "";
367
+ $p.delegate( "a", "click", function(e) {
368
+ lastClick = "click1";
369
+ e.stopImmediatePropagation();
370
+ });
371
+ $p.delegate( "a", "click", function(e) {
372
+ lastClick = "click2";
373
+ });
374
+ $a.trigger( "click" );
375
+ equal( lastClick, "click1", "delegate stopImmediatePropagation" );
376
+ $p.undelegate( "click" );
377
+ });
378
+
379
+ test("bind/delegate bubbling, isDefaultPrevented", function() {
380
+ expect(2);
381
+ var $anchor2 = jQuery( "#anchor2" ),
382
+ $main = jQuery( "#qunit-fixture" ),
383
+ fakeClick = function($jq) {
384
+ // Use a native click so we don't get jQuery simulated bubbling
385
+ if ( document.createEvent ) {
386
+ var e = document.createEvent( "MouseEvents" );
387
+ e.initEvent( "click", true, true );
388
+ $jq[0].dispatchEvent(e);
389
+ }
390
+ else if ( $jq[0].click ) {
391
+ $jq[0].click(); // IE
392
+ }
393
+ };
394
+ $anchor2.on( "click", function(e) {
395
+ e.preventDefault();
396
+ });
397
+ $main.delegate("#foo", "click", function(e) {
398
+ var orig = e.originalEvent;
399
+
400
+ if ( typeof(orig.defaultPrevented) === "boolean" || typeof(orig.returnValue) === "boolean" || orig["getPreventDefault"] ) {
401
+ equal( e.isDefaultPrevented(), true, "isDefaultPrevented true passed to bubbled event" );
402
+
403
+ } else {
404
+ // Opera < 11 doesn't implement any interface we can use, so give it a pass
405
+ ok( true, "isDefaultPrevented not supported by this browser, test skipped" );
406
+ }
407
+ });
408
+ fakeClick( $anchor2 );
409
+ $anchor2.unbind( "click" );
410
+ $main.undelegate( "click" );
411
+ $anchor2.on( "click", function(e) {
412
+ // Let the default action occur
413
+ });
414
+ $main.delegate("#foo", "click", function(e) {
415
+ equal( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" );
416
+ });
417
+ fakeClick( $anchor2 );
418
+ $anchor2.unbind( "click" );
419
+ $main.undelegate( "click" );
420
+ });
421
+
422
+ test("bind(), iframes", function() {
423
+ expect( 1 );
424
+
425
+ // events don't work with iframes, see #939 - this test fails in IE because of contentDocument
426
+ var doc = jQuery("#loadediframe").contents();
427
+
428
+ jQuery("div", doc).bind("click", function() {
429
+ ok( true, "Binding to element inside iframe" );
430
+ }).trigger("click").unbind("click");
431
+ });
432
+
433
+ test("bind(), trigger change on select", function() {
434
+ expect(5);
435
+ var counter = 0;
436
+ function selectOnChange(event) {
437
+ equal( event.data, counter++, "Event.data is not a global event object" );
438
+ }
439
+ jQuery("#form select").each(function(i){
440
+ jQuery(this).bind("change", i, selectOnChange);
441
+ }).trigger("change");
442
+ });
443
+
444
+ test("bind(), namespaced events, cloned events", 18, function() {
445
+ var firstp = jQuery( "#firstp" );
446
+
447
+ firstp.bind("custom.test",function(e){
448
+ ok(false, "Custom event triggered");
449
+ });
450
+
451
+ firstp.bind("click",function(e){
452
+ ok(true, "Normal click triggered");
453
+ equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" );
454
+ });
455
+
456
+ firstp.bind("click.test",function(e){
457
+ var check = "click";
458
+ ok( true, "Namespaced click triggered" );
459
+ if ( e.namespace ) {
460
+ check += "test";
461
+ }
462
+ equal( e.type + e.namespace, check, "Check that only click/click.test events trigger this fn" );
463
+ });
464
+
465
+ //clone(true) element to verify events are cloned correctly
466
+ firstp = firstp.add( firstp.clone( true ).attr( "id", "firstp2" ).insertBefore( firstp ) );
467
+
468
+ // Trigger both bound fn (8)
469
+ firstp.trigger("click");
470
+
471
+ // Trigger one bound fn (4)
472
+ firstp.trigger("click.test");
473
+
474
+ // Remove only the one fn
475
+ firstp.unbind("click.test");
476
+
477
+ // Trigger the remaining fn (4)
478
+ firstp.trigger("click");
479
+
480
+ // Remove the remaining namespaced fn
481
+ firstp.unbind(".test");
482
+
483
+ // Try triggering the custom event (0)
484
+ firstp.trigger("custom");
485
+
486
+ // using contents will get comments regular, text, and comment nodes
487
+ jQuery("#nonnodes").contents().bind("tester", function () {
488
+ equal(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
489
+ }).trigger("tester");
490
+
491
+ // Make sure events stick with appendTo'd elements (which are cloned) #2027
492
+ jQuery("<a href='#fail' class='test'>test</a>").on( "click", function(){ return false; }).appendTo("#qunit-fixture");
493
+ ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
494
+ });
495
+
496
+ test("bind(), multi-namespaced events", function() {
497
+ expect(6);
498
+
499
+ var order = [
500
+ "click.test.abc",
501
+ "click.test.abc",
502
+ "click.test",
503
+ "click.test.abc",
504
+ "click.test",
505
+ "custom.test2"
506
+ ];
507
+
508
+ function check(name, msg){
509
+ deepEqual(name, order.shift(), msg);
510
+ }
511
+
512
+ jQuery("#firstp").bind("custom.test",function(e){
513
+ check("custom.test", "Custom event triggered");
514
+ });
515
+
516
+ jQuery("#firstp").bind("custom.test2",function(e){
517
+ check("custom.test2", "Custom event triggered");
518
+ });
519
+
520
+ jQuery("#firstp").bind("click.test",function(e){
521
+ check("click.test", "Normal click triggered");
522
+ });
523
+
524
+ jQuery("#firstp").bind("click.test.abc",function(e){
525
+ check("click.test.abc", "Namespaced click triggered");
526
+ });
527
+
528
+ // Those would not trigger/unbind (#5303)
529
+ jQuery("#firstp").trigger("click.a.test");
530
+ jQuery("#firstp").unbind("click.a.test");
531
+
532
+ // Trigger both bound fn (1)
533
+ jQuery("#firstp").trigger("click.test.abc");
534
+
535
+ // Trigger one bound fn (1)
536
+ jQuery("#firstp").trigger("click.abc");
537
+
538
+ // Trigger two bound fn (2)
539
+ jQuery("#firstp").trigger("click.test");
540
+
541
+ // Remove only the one fn
542
+ jQuery("#firstp").unbind("click.abc");
543
+
544
+ // Trigger the remaining fn (1)
545
+ jQuery("#firstp").trigger("click");
546
+
547
+ // Remove the remaining fn
548
+ jQuery("#firstp").unbind(".test");
549
+
550
+ // Trigger the remaining fn (1)
551
+ jQuery("#firstp").trigger("custom");
552
+ });
553
+
554
+ test("bind(), with same function", function() {
555
+ expect(2);
556
+
557
+ var count = 0, func = function(){
558
+ count++;
559
+ };
560
+
561
+ jQuery("#liveHandlerOrder").bind("foo.bar", func).bind("foo.zar", func);
562
+ jQuery("#liveHandlerOrder").trigger("foo.bar");
563
+
564
+ equal(count, 1, "Verify binding function with multiple namespaces." );
565
+
566
+ jQuery("#liveHandlerOrder").unbind("foo.bar", func).unbind("foo.zar", func);
567
+ jQuery("#liveHandlerOrder").trigger("foo.bar");
568
+
569
+ equal(count, 1, "Verify that removing events still work." );
570
+ });
571
+
572
+ test("bind(), make sure order is maintained", function() {
573
+ expect(1);
574
+
575
+ var elem = jQuery("#firstp"), log = [], check = [];
576
+
577
+ jQuery.each( new Array(100), function( i ) {
578
+ elem.bind( "click", function(){
579
+ log.push( i );
580
+ });
581
+
582
+ check.push( i );
583
+
584
+ });
585
+
586
+ elem.trigger("click");
587
+
588
+ equal( log.join(","), check.join(","), "Make sure order was maintained." );
589
+
590
+ elem.unbind("click");
591
+ });
592
+
593
+ test("bind(), with different this object", function() {
594
+ expect(4);
595
+ var thisObject = { myThis: true },
596
+ data = { myData: true },
597
+ handler1 = function( event ) {
598
+ equal( this, thisObject, "bind() with different this object" );
599
+ },
600
+ handler2 = function( event ) {
601
+ equal( this, thisObject, "bind() with different this object and data" );
602
+ equal( event.data, data, "bind() with different this object and data" );
603
+ };
604
+
605
+ jQuery("#firstp")
606
+ .bind("click", jQuery.proxy(handler1, thisObject)).trigger("click").unbind("click", handler1)
607
+ .bind("click", data, jQuery.proxy(handler2, thisObject)).trigger("click").unbind("click", handler2);
608
+
609
+ ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
610
+ });
611
+
612
+ test("bind(name, false), unbind(name, false)", function() {
613
+ expect(3);
614
+
615
+ var main = 0;
616
+ jQuery("#qunit-fixture").bind("click", function(e){ main++; });
617
+ jQuery("#ap").trigger("click");
618
+ equal( main, 1, "Verify that the trigger happened correctly." );
619
+
620
+ main = 0;
621
+ jQuery("#ap").bind("click", false);
622
+ jQuery("#ap").trigger("click");
623
+ equal( main, 0, "Verify that no bubble happened." );
624
+
625
+ main = 0;
626
+ jQuery("#ap").unbind("click", false);
627
+ jQuery("#ap").trigger("click");
628
+ equal( main, 1, "Verify that the trigger happened correctly." );
629
+
630
+ // manually clean up events from elements outside the fixture
631
+ jQuery("#qunit-fixture").unbind("click");
632
+ });
633
+
634
+ test("delegate(selector, name, false), undelegate(selector, name, false)", function() {
635
+ expect(3);
636
+
637
+ var main = 0;
638
+
639
+ jQuery("#qunit-fixture").delegate("#ap", "click", function(e){ main++; });
640
+ jQuery("#ap").trigger("click");
641
+ equal( main, 1, "Verify that the trigger happened correctly." );
642
+
643
+ main = 0;
644
+ jQuery("#ap").delegate("#groups", "click", false);
645
+ jQuery("#groups").trigger("click");
646
+ equal( main, 0, "Verify that no bubble happened." );
647
+
648
+ main = 0;
649
+ jQuery("#ap").undelegate("#groups", "click", false);
650
+ jQuery("#groups").trigger("click");
651
+ equal( main, 1, "Verify that the trigger happened correctly." );
652
+ jQuery("#qunit-fixture").undelegate("#ap", "click");
653
+ });
654
+
655
+ test("bind()/trigger()/unbind() on plain object", function() {
656
+ expect( 7 );
657
+
658
+ var obj = {};
659
+
660
+ // Make sure it doesn't complain when no events are found
661
+ jQuery(obj).trigger("test");
662
+
663
+ // Make sure it doesn't complain when no events are found
664
+ jQuery(obj).unbind("test");
665
+
666
+ jQuery(obj).bind({
667
+ "test": function() {
668
+ ok( true, "Custom event run." );
669
+ },
670
+ "submit": function() {
671
+ ok( true, "Custom submit event run." );
672
+ }
673
+ });
674
+
675
+ var events = jQuery._data(obj, "events");
676
+ ok( events, "Object has events bound." );
677
+ equal( obj["events"], undefined, "Events object on plain objects is not events" );
678
+ equal( obj["test"], undefined, "Make sure that test event is not on the plain object." );
679
+ equal( obj["handle"], undefined, "Make sure that the event handler is not on the plain object." );
680
+
681
+ // Should trigger 1
682
+ jQuery(obj).trigger("test");
683
+ jQuery(obj).trigger("submit");
684
+
685
+ jQuery(obj).unbind("test");
686
+ jQuery(obj).unbind("submit");
687
+
688
+ // Should trigger 0
689
+ jQuery(obj).trigger("test");
690
+
691
+ // Make sure it doesn't complain when no events are found
692
+ jQuery(obj).unbind("test");
693
+
694
+ equal( obj && obj[ jQuery.expando ] &&
695
+ obj[ jQuery.expando ][ jQuery.expando ] &&
696
+ obj[ jQuery.expando ][ jQuery.expando ]["events"], undefined, "Make sure events object is removed" );
697
+ });
698
+
699
+ test("unbind(type)", function() {
700
+ expect( 1 );
701
+
702
+ var $elem = jQuery("#firstp"),
703
+ message;
704
+
705
+ function error(){
706
+ ok( false, message );
707
+ }
708
+
709
+ message = "unbind passing function";
710
+ $elem.bind("error1", error).unbind("error1", error).triggerHandler("error1");
711
+
712
+ message = "unbind all from event";
713
+ $elem.bind("error1", error).unbind("error1").triggerHandler("error1");
714
+
715
+ message = "unbind all";
716
+ $elem.bind("error1", error).unbind().triggerHandler("error1");
717
+
718
+ message = "unbind many with function";
719
+ $elem.bind("error1 error2",error)
720
+ .unbind("error1 error2", error )
721
+ .trigger("error1").triggerHandler("error2");
722
+
723
+ message = "unbind many"; // #3538
724
+ $elem.bind("error1 error2", error)
725
+ .unbind("error1 error2")
726
+ .trigger("error1").triggerHandler("error2");
727
+
728
+ message = "unbind without a type or handler";
729
+ $elem.bind("error1 error2.test",error)
730
+ .unbind()
731
+ .trigger("error1").triggerHandler("error2");
732
+
733
+ // Should only unbind the specified function
734
+ jQuery( document ).bind( "click", function(){
735
+ ok( true, "called handler after selective removal");
736
+ });
737
+ var func = function(){ };
738
+ jQuery( document )
739
+ .bind( "click", func )
740
+ .unbind( "click", func )
741
+ .trigger("click")
742
+ .unbind( "click" );
743
+ });
744
+
745
+ test("unbind(eventObject)", function() {
746
+ expect(4);
747
+
748
+ var $elem = jQuery("#firstp"),
749
+ num;
750
+
751
+ function assert( expected ){
752
+ num = 0;
753
+ $elem.trigger("foo").triggerHandler("bar");
754
+ equal( num, expected, "Check the right handlers are triggered" );
755
+ }
756
+
757
+ $elem
758
+ // This handler shouldn't be unbound
759
+ .bind("foo", function(){
760
+ num += 1;
761
+ })
762
+ .bind("foo", function(e){
763
+ $elem.unbind( e );
764
+ num += 2;
765
+ })
766
+ // Neither this one
767
+ .bind("bar", function(){
768
+ num += 4;
769
+ });
770
+
771
+ assert( 7 );
772
+ assert( 5 );
773
+
774
+ $elem.unbind("bar");
775
+ assert( 1 );
776
+
777
+ $elem.unbind();
778
+ assert( 0 );
779
+ });
780
+
781
+ if ( jQuery.fn.hover ) {
782
+ test("hover() mouseenter mouseleave", function() {
783
+ expect(1);
784
+
785
+ var times = 0,
786
+ handler1 = function( event ) { ++times; },
787
+ handler2 = function( event ) { ++times; };
788
+
789
+ jQuery("#firstp")
790
+ .hover(handler1, handler2)
791
+ .mouseenter().mouseleave()
792
+ .unbind("mouseenter", handler1)
793
+ .unbind("mouseleave", handler2)
794
+ .hover(handler1)
795
+ .mouseenter().mouseleave()
796
+ .unbind("mouseenter mouseleave", handler1)
797
+ .mouseenter().mouseleave();
798
+
799
+ equal( times, 4, "hover handlers fired" );
800
+
801
+ });
802
+ }
803
+
804
+ test("mouseover triggers mouseenter", function() {
805
+ expect(1);
806
+
807
+ var count = 0,
808
+ elem = jQuery("<a />");
809
+ elem.on( "mouseenter", function () {
810
+ count++;
811
+ });
812
+ elem.trigger("mouseover");
813
+ equal(count, 1, "make sure mouseover triggers a mouseenter" );
814
+
815
+ elem.remove();
816
+ });
817
+
818
+ test("withinElement implemented with jQuery.contains()", function() {
819
+
820
+ expect(1);
821
+
822
+ jQuery("#qunit-fixture").append("<div id='jc-outer'><div id='jc-inner'></div></div>");
823
+
824
+ jQuery("#jc-outer").bind("mouseenter mouseleave", function( event ) {
825
+
826
+ equal( this.id, "jc-outer", this.id + " " + event.type );
827
+
828
+ }).trigger("mouseenter");
829
+
830
+ jQuery("#jc-inner").trigger("mousenter");
831
+
832
+ jQuery("#jc-outer").unbind("mouseenter mouseleave").remove();
833
+ jQuery("#jc-inner").remove();
834
+
835
+ });
836
+
837
+ test("mouseenter, mouseleave don't catch exceptions", function() {
838
+ expect(2);
839
+
840
+ var elem = jQuery("#firstp").on( "mouseenter mouseleave", function() {
841
+ throw "an Exception";
842
+ });
843
+
844
+ try {
845
+ elem.trigger("mouseenter");
846
+ } catch (e) {
847
+ equal( e, "an Exception", "mouseenter doesn't catch exceptions" );
848
+ }
849
+
850
+ try {
851
+ elem.trigger("mouseleave");
852
+ } catch (e) {
853
+ equal( e, "an Exception", "mouseleave doesn't catch exceptions" );
854
+ }
855
+ });
856
+
857
+ if ( jQuery.fn.click ) {
858
+
859
+ test("trigger() shortcuts", function() {
860
+ expect(6);
861
+
862
+ var elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL");
863
+ elem.find("a").bind("click", function() {
864
+ var close = jQuery("spanx", this); // same with jQuery(this).find("span");
865
+ equal( close.length, 0, "Context element does not exist, length must be zero" );
866
+ ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
867
+ return false;
868
+ }).click();
869
+
870
+ // manually clean up detached elements
871
+ elem.remove();
872
+
873
+ jQuery("#check1").click(function() {
874
+ ok( true, "click event handler for checkbox gets fired twice, see #815" );
875
+ }).click();
876
+
877
+ var counter = 0;
878
+ jQuery("#firstp")[0].onclick = function(event) {
879
+ counter++;
880
+ };
881
+ jQuery("#firstp").click();
882
+ equal( counter, 1, "Check that click, triggers onclick event handler also" );
883
+
884
+ var clickCounter = 0;
885
+ jQuery("#simon1")[0].onclick = function(event) {
886
+ clickCounter++;
887
+ };
888
+ jQuery("#simon1").click();
889
+ equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
890
+
891
+ elem = jQuery("<img />").load(function(){
892
+ ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
893
+ }).load();
894
+
895
+ // manually clean up detached elements
896
+ elem.remove();
897
+
898
+ // test that special handlers do not blow up with VML elements (#7071)
899
+ jQuery("<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />").appendTo("head");
900
+ jQuery("<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>").appendTo("#form");
901
+ jQuery("#oval").click().keydown();
902
+ });
903
+
904
+ }
905
+
906
+ test("trigger() bubbling", function() {
907
+ expect(18);
908
+
909
+ var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
910
+
911
+ jQuery(window).bind("click", function(e){ win++; });
912
+ jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
913
+ jQuery("html").bind("click", function(e){ html++; });
914
+ jQuery("body").bind("click", function(e){ body++; });
915
+ jQuery("#qunit-fixture").bind("click", function(e){ main++; });
916
+ jQuery("#ap").bind("click", function(){ ap++; return false; });
917
+
918
+ jQuery("html").trigger("click");
919
+ equal( win, 1, "HTML bubble" );
920
+ equal( doc, 1, "HTML bubble" );
921
+ equal( html, 1, "HTML bubble" );
922
+
923
+ jQuery("body").trigger("click");
924
+ equal( win, 2, "Body bubble" );
925
+ equal( doc, 2, "Body bubble" );
926
+ equal( html, 2, "Body bubble" );
927
+ equal( body, 1, "Body bubble" );
928
+
929
+ jQuery("#qunit-fixture").trigger("click");
930
+ equal( win, 3, "Main bubble" );
931
+ equal( doc, 3, "Main bubble" );
932
+ equal( html, 3, "Main bubble" );
933
+ equal( body, 2, "Main bubble" );
934
+ equal( main, 1, "Main bubble" );
935
+
936
+ jQuery("#ap").trigger("click");
937
+ equal( doc, 3, "ap bubble" );
938
+ equal( html, 3, "ap bubble" );
939
+ equal( body, 2, "ap bubble" );
940
+ equal( main, 1, "ap bubble" );
941
+ equal( ap, 1, "ap bubble" );
942
+
943
+ jQuery( document ).trigger("click");
944
+ equal( win, 4, "doc bubble" );
945
+
946
+ // manually clean up events from elements outside the fixture
947
+ jQuery(document).unbind("click");
948
+ jQuery("html, body, #qunit-fixture").unbind("click");
949
+ });
950
+
951
+ test("trigger(type, [data], [fn])", function() {
952
+ expect(16);
953
+
954
+ var handler = function(event, a, b, c) {
955
+ equal( event.type, "click", "check passed data" );
956
+ equal( a, 1, "check passed data" );
957
+ equal( b, "2", "check passed data" );
958
+ equal( c, "abc", "check passed data" );
959
+ return "test";
960
+ };
961
+
962
+ var $elem = jQuery("#firstp");
963
+
964
+ // Simulate a "native" click
965
+ $elem[0].click = function(){
966
+ ok( true, "Native call was triggered" );
967
+ };
968
+
969
+
970
+ jQuery( document ).on("mouseenter", "#firstp", function(){
971
+ ok( true, "Trigger mouseenter bound by on" );
972
+ });
973
+
974
+ jQuery( document ).on("mouseleave", "#firstp", function(){
975
+ ok( true, "Trigger mouseleave bound by on" );
976
+ });
977
+
978
+ $elem.trigger("mouseenter");
979
+
980
+ $elem.trigger("mouseleave");
981
+
982
+ jQuery( document ).off( "mouseenter mouseleave", "#firstp");
983
+
984
+ // Triggers handlrs and native
985
+ // Trigger 5
986
+ $elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
987
+
988
+ // Simulate a "native" click
989
+ $elem[0].click = function(){
990
+ ok( false, "Native call was triggered" );
991
+ };
992
+
993
+ // Trigger only the handlers (no native)
994
+ // Triggers 5
995
+ equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
996
+
997
+ var pass = true, elem2;
998
+ try {
999
+ elem2 = jQuery("#form input:first");
1000
+ elem2.get(0).style.display = "none";
1001
+ elem2.trigger("focus");
1002
+ } catch(e) {
1003
+ pass = false;
1004
+ }
1005
+ ok( pass, "Trigger focus on hidden element" );
1006
+
1007
+ pass = true;
1008
+ try {
1009
+ jQuery("#qunit-fixture table:first").bind("test:test", function(){}).trigger("test:test");
1010
+ } catch (e) {
1011
+ pass = false;
1012
+ }
1013
+ ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
1014
+
1015
+ var form = jQuery("<form action=''></form>").appendTo("body");
1016
+
1017
+ // Make sure it can be prevented locally
1018
+ form.on( "submit", function(){
1019
+ ok( true, "Local bind still works." );
1020
+ return false;
1021
+ });
1022
+
1023
+ // Trigger 1
1024
+ form.trigger("submit");
1025
+
1026
+ form.unbind("submit");
1027
+
1028
+ jQuery(document).on( "submit", function(){
1029
+ ok( true, "Make sure bubble works up to document." );
1030
+ return false;
1031
+ });
1032
+
1033
+ // Trigger 1
1034
+ form.trigger("submit");
1035
+
1036
+ jQuery(document).unbind("submit");
1037
+
1038
+ form.remove();
1039
+ });
1040
+
1041
+ test( "submit event bubbles on copied forms (#11649)", function() {
1042
+ expect( 3 );
1043
+
1044
+ var $formByClone, $formByHTML,
1045
+ $testForm = jQuery("#testForm"),
1046
+ $fixture = jQuery("#qunit-fixture"),
1047
+ $wrapperDiv = jQuery("<div/>").appendTo( $fixture );
1048
+
1049
+ function noSubmit( e ) {
1050
+ e.preventDefault();
1051
+ }
1052
+ function delegatedSubmit() {
1053
+ ok( true, "Make sure submit event bubbles up." );
1054
+ return false;
1055
+ }
1056
+
1057
+ // Attach a delegated submit handler to the parent element
1058
+ $fixture.on( "submit", "form", delegatedSubmit );
1059
+
1060
+ // Trigger form submission to introduce the _submit_attached property
1061
+ $testForm.on( "submit", noSubmit ).find("input[name=sub1]").trigger("click");
1062
+
1063
+ // Copy the form via .clone() and .html()
1064
+ $formByClone = $testForm.clone( true, true ).removeAttr("id");
1065
+ $formByHTML = jQuery( jQuery.parseHTML($fixture.html()) ).filter("#testForm").removeAttr("id");
1066
+ $wrapperDiv.append( $formByClone, $formByHTML );
1067
+
1068
+ // Check submit bubbling on the copied forms
1069
+ $wrapperDiv.find("form").on( "submit", noSubmit ).find("input[name=sub1]").trigger("click");
1070
+
1071
+ // Clean up
1072
+ $wrapperDiv.remove();
1073
+ $fixture.off( "submit", "form", delegatedSubmit );
1074
+ $testForm.off( "submit", noSubmit );
1075
+ });
1076
+
1077
+ test( "change event bubbles on copied forms (#11796)", function(){
1078
+ expect( 3 );
1079
+
1080
+ var $formByClone, $formByHTML,
1081
+ $form = jQuery("#form"),
1082
+ $fixture = jQuery("#qunit-fixture"),
1083
+ $wrapperDiv = jQuery("<div/>").appendTo( $fixture );
1084
+
1085
+ function delegatedChange() {
1086
+ ok( true, "Make sure change event bubbles up." );
1087
+ return false;
1088
+ }
1089
+
1090
+ // Attach a delegated change handler to the form
1091
+ $fixture.on( "change", "form", delegatedChange );
1092
+
1093
+ // Trigger change event to introduce the _change_attached property
1094
+ $form.find("select[name=select1]").val("1").trigger("change");
1095
+
1096
+ // Copy the form via .clone() and .html()
1097
+ $formByClone = $form.clone( true, true ).removeAttr("id");
1098
+ $formByHTML = jQuery( jQuery.parseHTML($fixture.html()) ).filter("#form").removeAttr("id");
1099
+ $wrapperDiv.append( $formByClone, $formByHTML );
1100
+
1101
+ // Check change bubbling on the copied forms
1102
+ $wrapperDiv.find("form select[name=select1]").val("2").trigger("change");
1103
+
1104
+ // Clean up
1105
+ $wrapperDiv.remove();
1106
+ $fixture.off( "change", "form", delegatedChange );
1107
+ });
1108
+
1109
+ test("trigger(eventObject, [data], [fn])", function() {
1110
+ expect(28);
1111
+
1112
+ var $parent = jQuery("<div id='par' />").appendTo("body"),
1113
+ $child = jQuery("<p id='child'>foo</p>").appendTo( $parent );
1114
+
1115
+ $parent.get( 0 ).style.display = "none";
1116
+
1117
+ var event = jQuery.Event("noNew");
1118
+ ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
1119
+ equal( event.type, "noNew", "Verify its type" );
1120
+
1121
+ equal( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
1122
+ equal( event.isPropagationStopped(), false, "Verify isPropagationStopped" );
1123
+ equal( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
1124
+
1125
+ event.preventDefault();
1126
+ equal( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" );
1127
+ event.stopPropagation();
1128
+ equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
1129
+
1130
+ event.isPropagationStopped = function(){ return false; };
1131
+ event.stopImmediatePropagation();
1132
+ equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
1133
+ equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
1134
+
1135
+ $parent.bind("foo",function(e){
1136
+ // Tries bubbling
1137
+ equal( e.type, "foo", "Verify event type when passed passing an event object" );
1138
+ equal( e.target.id, "child", "Verify event.target when passed passing an event object" );
1139
+ equal( e.currentTarget.id, "par", "Verify event.currentTarget when passed passing an event object" );
1140
+ equal( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" );
1141
+ });
1142
+
1143
+ // test with an event object
1144
+ event = new jQuery.Event("foo");
1145
+ event.secret = "boo!";
1146
+ $child.trigger(event);
1147
+
1148
+ // test with a literal object
1149
+ $child.trigger({"type": "foo", "secret": "boo!"});
1150
+
1151
+ $parent.unbind();
1152
+
1153
+ function error(){
1154
+ ok( false, "This assertion shouldn't be reached");
1155
+ }
1156
+
1157
+ $parent.bind("foo", error );
1158
+
1159
+ $child.bind("foo",function(e, a, b, c ){
1160
+ equal( arguments.length, 4, "Check arguments length");
1161
+ equal( a, 1, "Check first custom argument");
1162
+ equal( b, 2, "Check second custom argument");
1163
+ equal( c, 3, "Check third custom argument");
1164
+
1165
+ equal( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
1166
+ equal( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
1167
+ equal( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
1168
+
1169
+ // Skips both errors
1170
+ e.stopImmediatePropagation();
1171
+
1172
+ return "result";
1173
+ });
1174
+
1175
+ // We should add this back in when we want to test the order
1176
+ // in which event handlers are iterated.
1177
+ //$child.bind("foo", error );
1178
+
1179
+ event = new jQuery.Event("foo");
1180
+ $child.trigger( event, [1,2,3] ).unbind();
1181
+ equal( event.result, "result", "Check event.result attribute");
1182
+
1183
+ // Will error if it bubbles
1184
+ $child.triggerHandler("foo");
1185
+
1186
+ $child.unbind();
1187
+ $parent.unbind().remove();
1188
+
1189
+ // Ensure triggerHandler doesn't molest its event object (#xxx)
1190
+ event = jQuery.Event( "zowie" );
1191
+ jQuery( document ).triggerHandler( event );
1192
+ equal( event.type, "zowie", "Verify its type" );
1193
+ equal( event.isPropagationStopped(), false, "propagation not stopped" );
1194
+ equal( event.isDefaultPrevented(), false, "default not prevented" );
1195
+ });
1196
+
1197
+ // Explicitly introduce global variable for oldIE so QUnit doesn't complain if checking globals
1198
+ window.onclick = undefined;
1199
+ test(".trigger() bubbling on disconnected elements (#10489)", function() {
1200
+ expect(2);
1201
+
1202
+ jQuery( window ).on( "click", function(){
1203
+ ok( false, "click fired on window" );
1204
+ });
1205
+
1206
+ jQuery( "<div><p>hi</p></div>" )
1207
+ .on( "click", function() {
1208
+ ok( true, "click fired on div" );
1209
+ })
1210
+ .find( "p" )
1211
+ .on( "click", function() {
1212
+ ok( true, "click fired on p" );
1213
+ })
1214
+ .trigger("click")
1215
+ .off( "click" )
1216
+ .end()
1217
+ .off( "click" )
1218
+ .remove();
1219
+
1220
+ jQuery( window ).off( "click" );
1221
+ });
1222
+
1223
+ test(".trigger() doesn't bubble load event (#10717)", function() {
1224
+ expect(1);
1225
+
1226
+ jQuery( window ).on( "load", function(){
1227
+ ok( false, "load fired on window" );
1228
+ });
1229
+
1230
+ // It's not an image, but as long as it fires load...
1231
+ jQuery("<img src='index.html' />")
1232
+ .appendTo( "body" )
1233
+ .on( "load", function() {
1234
+ ok( true, "load fired on img" );
1235
+ })
1236
+ .trigger( "load" )
1237
+ .remove();
1238
+
1239
+ jQuery( window ).off( "load" );
1240
+ });
1241
+
1242
+ test("Delegated events in SVG (#10791; #13180)", function() {
1243
+ expect(2);
1244
+
1245
+ var useElem, e,
1246
+ svg = jQuery(
1247
+ "<svg height='1' version='1.1' width='1' xmlns='http://www.w3.org/2000/svg'>" +
1248
+ "<defs><rect id='ref' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect></defs>" +
1249
+ "<rect class='svg-by-class' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect>" +
1250
+ "<rect id='svg-by-id' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect>" +
1251
+ "<use id='use' xlink:href='#ref'></use>" +
1252
+ "</svg>"
1253
+ );
1254
+
1255
+ jQuery("#qunit-fixture")
1256
+ .append( svg )
1257
+ .on( "click", "#svg-by-id", function() {
1258
+ ok( true, "delegated id selector" );
1259
+ })
1260
+ .on( "click", "[class~='svg-by-class']", function() {
1261
+ ok( true, "delegated class selector" );
1262
+ })
1263
+ .find( "#svg-by-id, [class~='svg-by-class']" )
1264
+ .trigger("click")
1265
+ .end();
1266
+
1267
+ // Fire a native click on an SVGElementInstance (the instance tree of an SVG <use>)
1268
+ // to confirm that it doesn't break our event delegation handling (#13180)
1269
+ useElem = svg.find("#use")[0];
1270
+ if ( document.createEvent && useElem && useElem.instanceRoot ) {
1271
+ e = document.createEvent("MouseEvents");
1272
+ e.initEvent( "click", true, true );
1273
+ useElem.instanceRoot.dispatchEvent( e );
1274
+ }
1275
+
1276
+ jQuery("#qunit-fixture").off("click");
1277
+ });
1278
+
1279
+ test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", function() {
1280
+ expect(5);
1281
+
1282
+ // Alias names like "id" cause havoc
1283
+ var form = jQuery(
1284
+ "<form id='myform'>" +
1285
+ "<input type='text' name='id' value='secret agent man' />" +
1286
+ "</form>"
1287
+ )
1288
+ .on( "submit", function( event ) {
1289
+ event.preventDefault();
1290
+ })
1291
+ .appendTo("body");
1292
+
1293
+ jQuery("body")
1294
+ .on( "submit", "#myform", function() {
1295
+ ok( true, "delegated id selector with aliased id" );
1296
+ })
1297
+ .find("#myform")
1298
+ .trigger("submit")
1299
+ .end()
1300
+ .off("submit");
1301
+
1302
+ form.append("<input type='text' name='disabled' value='differently abled' />");
1303
+ jQuery("body")
1304
+ .on( "submit", "#myform", function() {
1305
+ ok( true, "delegated id selector with aliased disabled" );
1306
+ })
1307
+ .find("#myform")
1308
+ .trigger("submit")
1309
+ .end()
1310
+ .off("submit");
1311
+
1312
+ form
1313
+ .append( "<button id='nestyDisabledBtn'><span>Zing</span></button>" )
1314
+ .on( "click", "#nestyDisabledBtn", function() {
1315
+ ok( true, "click on enabled/disabled button with nesty elements" );
1316
+ })
1317
+ .on( "mouseover", "#nestyDisabledBtn", function() {
1318
+ ok( true, "mouse on enabled/disabled button with nesty elements" );
1319
+ })
1320
+ .find( "span" )
1321
+ .trigger( "click" ) // yep
1322
+ .trigger( "mouseover" ) // yep
1323
+ .end()
1324
+ .find( "#nestyDisabledBtn" ).prop( "disabled", true ).end()
1325
+ .find( "span" )
1326
+ .trigger( "click" ) // nope
1327
+ .trigger( "mouseover" ) // yep
1328
+ .end()
1329
+ .off( "click" );
1330
+
1331
+ form.remove();
1332
+ });
1333
+
1334
+ test("Submit event can be stopped (#11049)", function() {
1335
+ expect(1);
1336
+
1337
+ // Since we manually bubble in IE, make sure inner handlers get a chance to cancel
1338
+ var form = jQuery(
1339
+ "<form id='myform'>" +
1340
+ "<input type='text' name='sue' value='bawls' />" +
1341
+ "<input type='submit' />" +
1342
+ "</form>"
1343
+ )
1344
+ .appendTo("body");
1345
+
1346
+ jQuery( "body" )
1347
+ .on( "submit", function() {
1348
+ ok( true, "submit bubbled on first handler" );
1349
+ return false;
1350
+ })
1351
+ .find( "#myform input[type=submit]" )
1352
+ .each( function(){ this.click(); } )
1353
+ .end()
1354
+ .on( "submit", function() {
1355
+ ok( false, "submit bubbled on second handler" );
1356
+ return false;
1357
+ })
1358
+ .find( "#myform input[type=submit]" )
1359
+ .each( function(){
1360
+ jQuery( this.form ).on( "submit", function( e ) {
1361
+ e.preventDefault();
1362
+ e.stopPropagation();
1363
+ });
1364
+ this.click();
1365
+ })
1366
+ .end()
1367
+ .off( "submit" );
1368
+
1369
+ form.remove();
1370
+ });
1371
+
1372
+ // Test beforeunload event only if it supported (i.e. not Opera)
1373
+ if ( window.onbeforeunload === null ) {
1374
+ asyncTest("on(beforeunload)", 4, function() {
1375
+ var win,
1376
+ forIE6 = 0,
1377
+ fired = false,
1378
+ iframe = jQuery("<iframe src='data/iframe.html' />");
1379
+
1380
+ iframe.appendTo("#qunit-fixture").one( "load", function() {
1381
+ win = this.contentWindow || this.contentDocument;
1382
+
1383
+ jQuery( win ).on( "beforeunload", function() {
1384
+ fired = true;
1385
+ ok( true, "beforeunload event is fired" );
1386
+ });
1387
+
1388
+ strictEqual( win.onbeforeunload, null, "onbeforeunload property on window object still equals null" );
1389
+
1390
+ // In old Safari beforeunload event will not fire on iframes
1391
+ jQuery( win ).on( "unload", function() {
1392
+ if ( !fired ) {
1393
+ ok( true, "This is suppose to be true only in old Safari" );
1394
+ checker();
1395
+ }
1396
+ });
1397
+
1398
+ jQuery( win ).on( "beforeunload", function() {
1399
+
1400
+ // On iframe in IE6 beforeunload event will not fire if event is binded through window object,
1401
+ // nevertheless, test should continue
1402
+ window.setTimeout(function() {
1403
+ if ( !forIE6 ) {
1404
+ checker();
1405
+ }
1406
+ });
1407
+ });
1408
+
1409
+ win.onbeforeunload = function() {
1410
+ if ( !forIE6 ) {
1411
+ forIE6++;
1412
+ checker();
1413
+ }
1414
+ };
1415
+
1416
+ function checker() {
1417
+ ok( true, "window.onbeforeunload handler is called" );
1418
+ iframe = jQuery("<iframe src='data/iframe.html' />");
1419
+
1420
+ iframe.appendTo("#qunit-fixture").one( "load", function() {
1421
+ win = iframe[ 0 ].contentWindow || iframe[ 0 ].contentDocument;
1422
+
1423
+ jQuery( win ).on( "beforeunload", function() {
1424
+ strictEqual( win.onbeforeunload, null, "Event handler is fired, even when onbeforeunload property on window is nulled" );
1425
+
1426
+ start();
1427
+ });
1428
+
1429
+ jQuery( win ).on( "unload", function() {
1430
+ if ( !fired ) {
1431
+ jQuery( win ).trigger("beforeunload");
1432
+ }
1433
+ });
1434
+
1435
+ win.onbeforeunload = null;
1436
+
1437
+ win.location.reload();
1438
+ });
1439
+ }
1440
+
1441
+ win.location.reload();
1442
+ });
1443
+ });
1444
+ }
1445
+
1446
+ test("jQuery.Event( type, props )", function() {
1447
+
1448
+ expect(5);
1449
+
1450
+ var event = jQuery.Event( "keydown", { keyCode: 64 }),
1451
+ handler = function( event ) {
1452
+ ok( "keyCode" in event, "Special property 'keyCode' exists" );
1453
+ equal( event.keyCode, 64, "event.keyCode has explicit value '64'" );
1454
+ };
1455
+
1456
+ // Supports jQuery.Event implementation
1457
+ equal( event.type, "keydown", "Verify type" );
1458
+
1459
+ // ensure "type" in props won't clobber the one set by constructor
1460
+ equal( jQuery.inArray("type", jQuery.event.props), -1, "'type' property not in props (#10375)" );
1461
+
1462
+ ok( "keyCode" in event, "Special 'keyCode' property exists" );
1463
+
1464
+ jQuery("body").bind( "keydown", handler ).trigger( event );
1465
+
1466
+ jQuery("body").unbind( "keydown" );
1467
+
1468
+ });
1469
+
1470
+ test("jQuery.Event.currentTarget", function(){
1471
+ expect(2);
1472
+
1473
+ jQuery("<div><p><button>shiny</button></p></div>")
1474
+ .on( "click", "p", function( e ){
1475
+ equal( e.currentTarget, this, "Check delegated currentTarget on event" );
1476
+ })
1477
+ .find( "button" )
1478
+ .on( "click", function( e ){
1479
+ equal( e.currentTarget, this, "Check currentTarget on event" );
1480
+ })
1481
+ .trigger("click")
1482
+ .off( "click" )
1483
+ .end()
1484
+ .off( "click" );
1485
+ });
1486
+
1487
+ test(".delegate()/.undelegate()", function() {
1488
+ expect(65);
1489
+
1490
+ var submit = 0, div = 0, livea = 0, liveb = 0;
1491
+
1492
+ jQuery("#body").delegate("#qunit-fixture div", "submit", function(){ submit++; return false; });
1493
+ jQuery("#body").delegate("#qunit-fixture div", "click", function(){ div++; });
1494
+ jQuery("#body").delegate("div#nothiddendiv", "click", function(){ livea++; });
1495
+ jQuery("#body").delegate("div#nothiddendivchild", "click", function(){ liveb++; });
1496
+
1497
+ // Nothing should trigger on the body
1498
+ jQuery("body").trigger("click");
1499
+ equal( submit, 0, "Click on body" );
1500
+ equal( div, 0, "Click on body" );
1501
+ equal( livea, 0, "Click on body" );
1502
+ equal( liveb, 0, "Click on body" );
1503
+
1504
+ // This should trigger two events
1505
+ submit = 0; div = 0; livea = 0; liveb = 0;
1506
+ jQuery("div#nothiddendiv").trigger("click");
1507
+ equal( submit, 0, "Click on div" );
1508
+ equal( div, 1, "Click on div" );
1509
+ equal( livea, 1, "Click on div" );
1510
+ equal( liveb, 0, "Click on div" );
1511
+
1512
+ // This should trigger three events (w/ bubbling)
1513
+ submit = 0; div = 0; livea = 0; liveb = 0;
1514
+ jQuery("div#nothiddendivchild").trigger("click");
1515
+ equal( submit, 0, "Click on inner div" );
1516
+ equal( div, 2, "Click on inner div" );
1517
+ equal( livea, 1, "Click on inner div" );
1518
+ equal( liveb, 1, "Click on inner div" );
1519
+
1520
+ // This should trigger one submit
1521
+ submit = 0; div = 0; livea = 0; liveb = 0;
1522
+ jQuery("div#nothiddendivchild").trigger("submit");
1523
+ equal( submit, 1, "Submit on div" );
1524
+ equal( div, 0, "Submit on div" );
1525
+ equal( livea, 0, "Submit on div" );
1526
+ equal( liveb, 0, "Submit on div" );
1527
+
1528
+ // Make sure no other events were removed in the process
1529
+ submit = 0; div = 0; livea = 0; liveb = 0;
1530
+ jQuery("div#nothiddendivchild").trigger("click");
1531
+ equal( submit, 0, "undelegate Click on inner div" );
1532
+ equal( div, 2, "undelegate Click on inner div" );
1533
+ equal( livea, 1, "undelegate Click on inner div" );
1534
+ equal( liveb, 1, "undelegate Click on inner div" );
1535
+
1536
+ // Now make sure that the removal works
1537
+ submit = 0; div = 0; livea = 0; liveb = 0;
1538
+ jQuery("#body").undelegate("div#nothiddendivchild", "click");
1539
+ jQuery("div#nothiddendivchild").trigger("click");
1540
+ equal( submit, 0, "undelegate Click on inner div" );
1541
+ equal( div, 2, "undelegate Click on inner div" );
1542
+ equal( livea, 1, "undelegate Click on inner div" );
1543
+ equal( liveb, 0, "undelegate Click on inner div" );
1544
+
1545
+ // Make sure that the click wasn't removed too early
1546
+ submit = 0; div = 0; livea = 0; liveb = 0;
1547
+ jQuery("div#nothiddendiv").trigger("click");
1548
+ equal( submit, 0, "undelegate Click on inner div" );
1549
+ equal( div, 1, "undelegate Click on inner div" );
1550
+ equal( livea, 1, "undelegate Click on inner div" );
1551
+ equal( liveb, 0, "undelegate Click on inner div" );
1552
+
1553
+ // Make sure that stopPropgation doesn't stop live events
1554
+ submit = 0; div = 0; livea = 0; liveb = 0;
1555
+ jQuery("#body").delegate("div#nothiddendivchild", "click", function(e){ liveb++; e.stopPropagation(); });
1556
+ jQuery("div#nothiddendivchild").trigger("click");
1557
+ equal( submit, 0, "stopPropagation Click on inner div" );
1558
+ equal( div, 1, "stopPropagation Click on inner div" );
1559
+ equal( livea, 0, "stopPropagation Click on inner div" );
1560
+ equal( liveb, 1, "stopPropagation Click on inner div" );
1561
+
1562
+ // Make sure click events only fire with primary click
1563
+ submit = 0; div = 0; livea = 0; liveb = 0;
1564
+ var event = jQuery.Event("click");
1565
+ event.button = 1;
1566
+ jQuery("div#nothiddendiv").trigger(event);
1567
+
1568
+ equal( livea, 0, "delegate secondary click" );
1569
+
1570
+ jQuery("#body").undelegate("div#nothiddendivchild", "click");
1571
+ jQuery("#body").undelegate("div#nothiddendiv", "click");
1572
+ jQuery("#body").undelegate("#qunit-fixture div", "click");
1573
+ jQuery("#body").undelegate("#qunit-fixture div", "submit");
1574
+
1575
+ // Test binding with a different context
1576
+ var clicked = 0, container = jQuery("#qunit-fixture")[0];
1577
+ jQuery("#qunit-fixture").delegate("#foo", "click", function(e){ clicked++; });
1578
+ jQuery("#qunit-fixture div").trigger("click");
1579
+ jQuery("#foo").trigger("click");
1580
+ jQuery("#qunit-fixture").trigger("click");
1581
+ jQuery("body").trigger("click");
1582
+ equal( clicked, 2, "delegate with a context" );
1583
+
1584
+ // Test unbinding with a different context
1585
+ jQuery("#qunit-fixture").undelegate("#foo", "click");
1586
+ jQuery("#foo").trigger("click");
1587
+ equal( clicked, 2, "undelegate with a context");
1588
+
1589
+ // Test binding with event data
1590
+ jQuery("#body").delegate("#foo", "click", true, function(e){ equal( e.data, true, "delegate with event data" ); });
1591
+ jQuery("#foo").trigger("click");
1592
+ jQuery("#body").undelegate("#foo", "click");
1593
+
1594
+ // Test binding with trigger data
1595
+ jQuery("#body").delegate("#foo", "click", function(e, data){ equal( data, true, "delegate with trigger data" ); });
1596
+ jQuery("#foo").trigger("click", true);
1597
+ jQuery("#body").undelegate("#foo", "click");
1598
+
1599
+ // Test binding with different this object
1600
+ jQuery("#body").delegate("#foo", "click", jQuery.proxy(function(e){ equal( this["foo"], "bar", "delegate with event scope" ); }, { "foo": "bar" }));
1601
+ jQuery("#foo").trigger("click");
1602
+ jQuery("#body").undelegate("#foo", "click");
1603
+
1604
+ // Test binding with different this object, event data, and trigger data
1605
+ jQuery("#body").delegate("#foo", "click", true, jQuery.proxy(function(e, data){
1606
+ equal( e.data, true, "delegate with with different this object, event data, and trigger data" );
1607
+ equal( this.foo, "bar", "delegate with with different this object, event data, and trigger data" );
1608
+ equal( data, true, "delegate with with different this object, event data, and trigger data");
1609
+ }, { "foo": "bar" }));
1610
+ jQuery("#foo").trigger("click", true);
1611
+ jQuery("#body").undelegate("#foo", "click");
1612
+
1613
+ // Verify that return false prevents default action
1614
+ jQuery("#body").delegate("#anchor2", "click", function(){ return false; });
1615
+ var hash = window.location.hash;
1616
+ jQuery("#anchor2").trigger("click");
1617
+ equal( window.location.hash, hash, "return false worked" );
1618
+ jQuery("#body").undelegate("#anchor2", "click");
1619
+
1620
+ // Verify that .preventDefault() prevents default action
1621
+ jQuery("#body").delegate("#anchor2", "click", function(e){ e.preventDefault(); });
1622
+ hash = window.location.hash;
1623
+ jQuery("#anchor2").trigger("click");
1624
+ equal( window.location.hash, hash, "e.preventDefault() worked" );
1625
+ jQuery("#body").undelegate("#anchor2", "click");
1626
+
1627
+ // Test binding the same handler to multiple points
1628
+ var called = 0;
1629
+ function callback(){ called++; return false; }
1630
+
1631
+ jQuery("#body").delegate("#nothiddendiv", "click", callback);
1632
+ jQuery("#body").delegate("#anchor2", "click", callback);
1633
+
1634
+ jQuery("#nothiddendiv").trigger("click");
1635
+ equal( called, 1, "Verify that only one click occurred." );
1636
+
1637
+ called = 0;
1638
+ jQuery("#anchor2").trigger("click");
1639
+ equal( called, 1, "Verify that only one click occurred." );
1640
+
1641
+ // Make sure that only one callback is removed
1642
+ jQuery("#body").undelegate("#anchor2", "click", callback);
1643
+
1644
+ called = 0;
1645
+ jQuery("#nothiddendiv").trigger("click");
1646
+ equal( called, 1, "Verify that only one click occurred." );
1647
+
1648
+ called = 0;
1649
+ jQuery("#anchor2").trigger("click");
1650
+ equal( called, 0, "Verify that no click occurred." );
1651
+
1652
+ // Make sure that it still works if the selector is the same,
1653
+ // but the event type is different
1654
+ jQuery("#body").delegate("#nothiddendiv", "foo", callback);
1655
+
1656
+ // Cleanup
1657
+ jQuery("#body").undelegate("#nothiddendiv", "click", callback);
1658
+
1659
+ called = 0;
1660
+ jQuery("#nothiddendiv").trigger("click");
1661
+ equal( called, 0, "Verify that no click occurred." );
1662
+
1663
+ called = 0;
1664
+ jQuery("#nothiddendiv").trigger("foo");
1665
+ equal( called, 1, "Verify that one foo occurred." );
1666
+
1667
+ // Cleanup
1668
+ jQuery("#body").undelegate("#nothiddendiv", "foo", callback);
1669
+
1670
+ // Make sure we don't loose the target by DOM modifications
1671
+ // after the bubble already reached the liveHandler
1672
+ var livec = 0, elemDiv = jQuery("#nothiddendivchild").html("<span></span>").get(0);
1673
+
1674
+ jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ jQuery("#nothiddendivchild").html(""); });
1675
+ jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ if(e.target) {livec++;} });
1676
+
1677
+ jQuery("#nothiddendiv span").trigger("click");
1678
+ equal( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
1679
+ equal( livec, 1, "Verify that second handler occurred even with nuked target." );
1680
+
1681
+ // Cleanup
1682
+ jQuery("#body").undelegate("#nothiddendivchild", "click");
1683
+
1684
+ // Verify that .live() ocurs and cancel buble in the same order as
1685
+ // we would expect .bind() and .click() without delegation
1686
+ var lived = 0, livee = 0;
1687
+
1688
+ // bind one pair in one order
1689
+ jQuery("#body").delegate("span#liveSpan1 a", "click", function(){ lived++; return false; });
1690
+ jQuery("#body").delegate("span#liveSpan1", "click", function(){ livee++; });
1691
+
1692
+ jQuery("span#liveSpan1 a").trigger("click");
1693
+ equal( lived, 1, "Verify that only one first handler occurred." );
1694
+ equal( livee, 0, "Verify that second handler doesn't." );
1695
+
1696
+ // and one pair in inverse
1697
+ jQuery("#body").delegate("span#liveSpan2", "click", function(){ livee++; });
1698
+ jQuery("#body").delegate("span#liveSpan2 a", "click", function(){ lived++; return false; });
1699
+
1700
+ lived = 0;
1701
+ livee = 0;
1702
+ jQuery("span#liveSpan2 a").trigger("click");
1703
+ equal( lived, 1, "Verify that only one first handler occurred." );
1704
+ equal( livee, 0, "Verify that second handler doesn't." );
1705
+
1706
+ // Cleanup
1707
+ jQuery("#body").undelegate("click");
1708
+
1709
+ // Test this, target and currentTarget are correct
1710
+ jQuery("#body").delegate("span#liveSpan1", "click", function(e){
1711
+ equal( this.id, "liveSpan1", "Check the this within a delegate handler" );
1712
+ equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a delegate handler" );
1713
+ equal( e.delegateTarget, document.body, "Check the event.delegateTarget within a delegate handler" );
1714
+ equal( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a delegate handler" );
1715
+ });
1716
+
1717
+ jQuery("span#liveSpan1 a").trigger("click");
1718
+
1719
+ jQuery("#body").undelegate("span#liveSpan1", "click");
1720
+
1721
+ // Work with deep selectors
1722
+ livee = 0;
1723
+
1724
+ function clickB(){ livee++; }
1725
+
1726
+ jQuery("#body").delegate("#nothiddendiv div", "click", function(){ livee++; });
1727
+ jQuery("#body").delegate("#nothiddendiv div", "click", clickB);
1728
+ jQuery("#body").delegate("#nothiddendiv div", "mouseover", function(){ livee++; });
1729
+
1730
+ equal( livee, 0, "No clicks, deep selector." );
1731
+
1732
+ livee = 0;
1733
+ jQuery("#nothiddendivchild").trigger("click");
1734
+ equal( livee, 2, "Click, deep selector." );
1735
+
1736
+ livee = 0;
1737
+ jQuery("#nothiddendivchild").trigger("mouseover");
1738
+ equal( livee, 1, "Mouseover, deep selector." );
1739
+
1740
+ jQuery("#body").undelegate("#nothiddendiv div", "mouseover");
1741
+
1742
+ livee = 0;
1743
+ jQuery("#nothiddendivchild").trigger("click");
1744
+ equal( livee, 2, "Click, deep selector." );
1745
+
1746
+ livee = 0;
1747
+ jQuery("#nothiddendivchild").trigger("mouseover");
1748
+ equal( livee, 0, "Mouseover, deep selector." );
1749
+
1750
+ jQuery("#body").undelegate("#nothiddendiv div", "click", clickB);
1751
+
1752
+ livee = 0;
1753
+ jQuery("#nothiddendivchild").trigger("click");
1754
+ equal( livee, 1, "Click, deep selector." );
1755
+
1756
+ jQuery("#body").undelegate("#nothiddendiv div", "click");
1757
+ });
1758
+
1759
+ test("jQuery.off using dispatched jQuery.Event", function() {
1760
+ expect(1);
1761
+
1762
+ var markup = jQuery("<p><a href='#'>target</a></p>"),
1763
+ count = 0;
1764
+ markup
1765
+ .on( "click.name", "a", function( event ) {
1766
+ equal( ++count, 1, "event called once before removal" );
1767
+ jQuery().off( event );
1768
+ })
1769
+ .find("a").trigger("click").trigger("click").end()
1770
+ .remove();
1771
+ });
1772
+
1773
+ test( "delegated event with delegateTarget-relative selector", function() {
1774
+ expect(3);
1775
+ var markup = jQuery("<ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul>").appendTo("#qunit-fixture");
1776
+
1777
+ // Positional selector (#11315)
1778
+ markup
1779
+ .on( "click", ">li>a", function() {
1780
+ ok( this.id === "a0", "child li was clicked" );
1781
+ })
1782
+ .find("#ul0")
1783
+ .on( "click", "li:first>a", function() {
1784
+ ok( this.id === "a0_0" , "first li under #u10 was clicked" );
1785
+ })
1786
+ .end()
1787
+ .find("a").trigger("click").end()
1788
+ .find("#ul0").off();
1789
+
1790
+ // Non-positional selector (#12383)
1791
+ markup = markup.wrap("<div />").parent();
1792
+ markup
1793
+ .find("#ul0")
1794
+ .on( "click", "div li a", function() {
1795
+ ok( false, "div is ABOVE the delegation point!" );
1796
+ })
1797
+ .on( "click", "ul a", function() {
1798
+ ok( false, "ul is the delegation point!" );
1799
+ })
1800
+ .on( "click", "li.test a", function() {
1801
+ ok( true, "li.test is below the delegation point." );
1802
+ })
1803
+ .find("#a0_0").trigger("click");
1804
+
1805
+ markup.remove();
1806
+ });
1807
+
1808
+ test( "delegated event with selector matching Object.prototype property (#13203)", function() {
1809
+ expect(1);
1810
+
1811
+ var matched = 0;
1812
+
1813
+ jQuery("#foo").on( "click", "toString", function( e ) {
1814
+ matched++;
1815
+ });
1816
+
1817
+ jQuery("#anchor2").trigger("click");
1818
+
1819
+ equal( matched, 0, "Nothing matched 'toString'" );
1820
+ });
1821
+
1822
+ test( "delegated event with intermediate DOM manipulation (#13208)", function() {
1823
+ expect(1);
1824
+
1825
+ jQuery("#foo").on( "click", "#sap", function() {});
1826
+ jQuery("#sap").on( "click", "#anchor2", function() {
1827
+ jQuery( this.parentNode ).remove();
1828
+ ok( true, "Element removed" );
1829
+ });
1830
+ jQuery("#anchor2").trigger("click");
1831
+ });
1832
+
1833
+ test("stopPropagation() stops directly-bound events on delegated target", function() {
1834
+ expect(1);
1835
+
1836
+ var markup = jQuery("<div><p><a href=\"#\">target</a></p></div>");
1837
+ markup
1838
+ .on( "click", function() {
1839
+ ok( false, "directly-bound event on delegate target was called" );
1840
+ })
1841
+ .on( "click", "a", function( e ) {
1842
+ e.stopPropagation();
1843
+ ok( true, "delegated handler was called" );
1844
+ })
1845
+ .find("a").trigger("click").end()
1846
+ .remove();
1847
+ });
1848
+
1849
+ test("undelegate all bound events", function(){
1850
+ expect(2);
1851
+
1852
+ var count = 0,
1853
+ clicks = 0,
1854
+ div = jQuery("#body");
1855
+
1856
+ div.delegate( "div#nothiddendivchild", "click submit", function(){ count++; } );
1857
+ div.bind( "click", function(){ clicks++; } );
1858
+ div.undelegate();
1859
+
1860
+ jQuery("div#nothiddendivchild").trigger("click");
1861
+ jQuery("div#nothiddendivchild").trigger("submit");
1862
+
1863
+ equal( count, 0, "Make sure no events were triggered." );
1864
+
1865
+ div.trigger("click");
1866
+ equal( clicks, 2, "Make sure delegated and directly bound event occurred." );
1867
+ div.unbind("click");
1868
+ });
1869
+
1870
+ test("delegate with multiple events", function(){
1871
+ expect(1);
1872
+
1873
+ var count = 0;
1874
+ var div = jQuery("#body");
1875
+
1876
+ div.delegate("div#nothiddendivchild", "click submit", function(){ count++; });
1877
+
1878
+ jQuery("div#nothiddendivchild").trigger("click");
1879
+ jQuery("div#nothiddendivchild").trigger("submit");
1880
+
1881
+ equal( count, 2, "Make sure both the click and submit were triggered." );
1882
+
1883
+ jQuery("#body").undelegate();
1884
+ });
1885
+
1886
+ test("delegate with change", function(){
1887
+ expect(8);
1888
+
1889
+ var selectChange = 0, checkboxChange = 0;
1890
+
1891
+ var select = jQuery("select[name='S1']");
1892
+ jQuery("#body").delegate("select[name='S1']", "change", function() {
1893
+ selectChange++;
1894
+ });
1895
+
1896
+ var checkbox = jQuery("#check2"),
1897
+ checkboxFunction = function(){
1898
+ checkboxChange++;
1899
+ };
1900
+ jQuery("#body").delegate("#check2", "change", checkboxFunction);
1901
+
1902
+ // test click on select
1903
+
1904
+ // second click that changed it
1905
+ selectChange = 0;
1906
+ select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1907
+ select.trigger("change");
1908
+ equal( selectChange, 1, "Change on click." );
1909
+
1910
+ // test keys on select
1911
+ selectChange = 0;
1912
+ select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1913
+ select.trigger("change");
1914
+ equal( selectChange, 1, "Change on keyup." );
1915
+
1916
+ // test click on checkbox
1917
+ checkbox.trigger("change");
1918
+ equal( checkboxChange, 1, "Change on checkbox." );
1919
+
1920
+ // test blur/focus on text
1921
+ var text = jQuery("#name"), textChange = 0, oldTextVal = text.val();
1922
+ jQuery("#body").delegate("#name", "change", function() {
1923
+ textChange++;
1924
+ });
1925
+
1926
+ text.val(oldTextVal+"foo");
1927
+ text.trigger("change");
1928
+ equal( textChange, 1, "Change on text input." );
1929
+
1930
+ text.val(oldTextVal);
1931
+ jQuery("#body").undelegate("#name", "change");
1932
+
1933
+ // test blur/focus on password
1934
+ var password = jQuery("#name"), passwordChange = 0, oldPasswordVal = password.val();
1935
+ jQuery("#body").delegate("#name", "change", function() {
1936
+ passwordChange++;
1937
+ });
1938
+
1939
+ password.val(oldPasswordVal + "foo");
1940
+ password.trigger("change");
1941
+ equal( passwordChange, 1, "Change on password input." );
1942
+
1943
+ password.val(oldPasswordVal);
1944
+ jQuery("#body").undelegate("#name", "change");
1945
+
1946
+ // make sure die works
1947
+
1948
+ // die all changes
1949
+ selectChange = 0;
1950
+ jQuery("#body").undelegate("select[name='S1']", "change");
1951
+ select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1952
+ select.trigger("change");
1953
+ equal( selectChange, 0, "Die on click works." );
1954
+
1955
+ selectChange = 0;
1956
+ select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1957
+ select.trigger("change");
1958
+ equal( selectChange, 0, "Die on keyup works." );
1959
+
1960
+ // die specific checkbox
1961
+ jQuery("#body").undelegate("#check2", "change", checkboxFunction);
1962
+ checkbox.trigger("change");
1963
+ equal( checkboxChange, 1, "Die on checkbox." );
1964
+ });
1965
+
1966
+ test("delegate with submit", function() {
1967
+ expect( 2 );
1968
+
1969
+ var count1 = 0, count2 = 0;
1970
+
1971
+ jQuery("#body").delegate("#testForm", "submit", function(ev) {
1972
+ count1++;
1973
+ ev.preventDefault();
1974
+ });
1975
+
1976
+ jQuery(document).delegate("body", "submit", function(ev) {
1977
+ count2++;
1978
+ ev.preventDefault();
1979
+ });
1980
+
1981
+ jQuery("#testForm input[name=sub1]").trigger("submit");
1982
+ equal( count1, 1, "Verify form submit." );
1983
+ equal( count2, 1, "Verify body submit." );
1984
+
1985
+ jQuery("#body").undelegate();
1986
+ jQuery(document).undelegate();
1987
+ });
1988
+
1989
+ test("undelegate() with only namespaces", function() {
1990
+ expect(2);
1991
+
1992
+ var $delegate = jQuery("#liveHandlerOrder"),
1993
+ count = 0;
1994
+
1995
+ $delegate.delegate("a", "click.ns", function(e) {
1996
+ count++;
1997
+ });
1998
+
1999
+ jQuery("a", $delegate).eq(0).trigger("click.ns");
2000
+
2001
+ equal( count, 1, "delegated click.ns");
2002
+
2003
+ $delegate.undelegate(".ns");
2004
+
2005
+ jQuery("a", $delegate).eq(1).trigger("click.ns");
2006
+
2007
+ equal( count, 1, "no more .ns after undelegate");
2008
+ });
2009
+
2010
+ test("Non DOM element events", function() {
2011
+ expect(1);
2012
+
2013
+ var o = {};
2014
+
2015
+ jQuery(o).bind("nonelementobj", function(e) {
2016
+ ok( true, "Event on non-DOM object triggered" );
2017
+ });
2018
+
2019
+ jQuery(o).trigger("nonelementobj");
2020
+ });
2021
+
2022
+ test("inline handler returning false stops default", function() {
2023
+ expect(1);
2024
+
2025
+ var markup = jQuery("<div><a href=\"#\" onclick=\"return false\">x</a></div>");
2026
+ markup.on( "click", function(e) {
2027
+ ok( e.isDefaultPrevented(), "inline handler prevented default");
2028
+ return false;
2029
+ });
2030
+ markup.find("a").trigger("click");
2031
+ markup.off("click");
2032
+ });
2033
+
2034
+ test("window resize", function() {
2035
+ expect(2);
2036
+
2037
+ jQuery(window).off();
2038
+
2039
+ jQuery(window).on( "resize", function(){
2040
+ ok( true, "Resize event fired." );
2041
+ }).trigger("resize").off("resize");
2042
+
2043
+ ok( !jQuery._data(window, "events"), "Make sure all the events are gone." );
2044
+ });
2045
+
2046
+ test("focusin bubbles", function() {
2047
+ expect(2);
2048
+
2049
+ var input = jQuery( "<input type='text' />" ).prependTo( "body" ),
2050
+ order = 0;
2051
+
2052
+ // focus the element so DOM focus won't fire
2053
+ input[0].focus();
2054
+
2055
+ jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
2056
+ equal( 1, order++, "focusin on the body second" );
2057
+ });
2058
+
2059
+ input.bind( "focusin.focusinBubblesTest", function(){
2060
+ equal( 0, order++, "focusin on the element first" );
2061
+ });
2062
+
2063
+ // Removed since DOM focus is unreliable on test swarm
2064
+ // DOM focus method
2065
+ // input[0].focus();
2066
+
2067
+ // To make the next focus test work, we need to take focus off the input.
2068
+ // This will fire another focusin event, so set order to reflect that.
2069
+ // order = 1;
2070
+ // jQuery("#text1")[0].focus();
2071
+
2072
+ // jQuery trigger, which calls DOM focus
2073
+ order = 0;
2074
+ input.trigger( "focus" );
2075
+
2076
+ input.remove();
2077
+ jQuery( "body" ).unbind( "focusin.focusinBubblesTest" );
2078
+ });
2079
+
2080
+ test("custom events with colons (#3533, #8272)", function() {
2081
+ expect(1);
2082
+
2083
+ var tab = jQuery("<table><tr><td>trigger</td></tr></table>").appendTo("body");
2084
+ try {
2085
+ tab.trigger("back:forth");
2086
+ ok( true, "colon events don't throw" );
2087
+ } catch ( e ) {
2088
+ ok( false, "colon events die" );
2089
+ }
2090
+ tab.remove();
2091
+
2092
+ });
2093
+
2094
+ test(".on and .off", function() {
2095
+ expect(9);
2096
+ var counter, mixfn;
2097
+
2098
+ var $onandoff = jQuery("<div id=\"onandoff\"><p>on<b>and</b>off</p><div>worked<em>or</em>borked?</div></div>").appendTo("body");
2099
+
2100
+ // Simple case
2101
+ jQuery( "#onandoff" )
2102
+ .on( "whip", function() {
2103
+ ok( true, "whipped it good" );
2104
+ })
2105
+ .trigger( "whip" )
2106
+ .off();
2107
+
2108
+ // Direct events only
2109
+ counter = 0;
2110
+ jQuery( "#onandoff b" )
2111
+ .on( "click", 5, function( e, trig ) {
2112
+ counter += e.data + (trig || 9); // twice, 5+9+5+17=36
2113
+ })
2114
+ .one( "click", 7, function( e, trig ) {
2115
+ counter += e.data + (trig || 11); // once, 7+11=18
2116
+ })
2117
+ .trigger("click")
2118
+ .trigger( "click", 17 )
2119
+ .off( "click" );
2120
+ equal( counter, 54, "direct event bindings with data" );
2121
+
2122
+ // Delegated events only
2123
+ counter = 0;
2124
+ jQuery( "#onandoff" )
2125
+ .on( "click", "em", 5, function( e, trig ) {
2126
+ counter += e.data + (trig || 9); // twice, 5+9+5+17=36
2127
+ })
2128
+ .one( "click", "em", 7, function( e, trig ) {
2129
+ counter += e.data + (trig || 11); // once, 7+11=18
2130
+ })
2131
+ .find("em")
2132
+ .trigger("click")
2133
+ .trigger( "click", 17 )
2134
+ .end()
2135
+ .off( "click", "em" );
2136
+ equal( counter, 54, "delegated event bindings with data" );
2137
+
2138
+
2139
+ // Mixed event bindings and types
2140
+ counter = 0;
2141
+ mixfn = function(e, trig) {
2142
+ counter += (e.data || 0) + (trig || 1);
2143
+ };
2144
+ jQuery( "#onandoff" )
2145
+ .on( " click clack cluck ", "em", 2, mixfn )
2146
+ .on( "cluck", "b", 7, mixfn )
2147
+ .on( "cluck", mixfn )
2148
+ .trigger( "what!" )
2149
+ .each( function() {
2150
+ equal( counter, 0, "nothing triggered yet" );
2151
+ })
2152
+ .find( "em" )
2153
+ .one( "cluck", 3, mixfn )
2154
+ .trigger( "cluck", 8 ) // 3+8 2+8 + 0+8 = 29
2155
+ .off()
2156
+ .trigger( "cluck", 9 ) // 2+9 + 0+9 = 20
2157
+ .end()
2158
+ .each( function() {
2159
+ equal( counter, 49, "after triggering em element" );
2160
+ })
2161
+ .off( "cluck", function(){} ) // shouldn't remove anything
2162
+ .trigger( "cluck", 2 ) // 0+2 = 2
2163
+ .each( function() {
2164
+ equal( counter, 51, "after triggering #onandoff cluck" );
2165
+ })
2166
+ .find( "b" )
2167
+ .on( "click", 95, mixfn )
2168
+ .on( "clack", "p", 97, mixfn )
2169
+ .one( "cluck", 3, mixfn )
2170
+ .trigger( "quack", 19 ) // 0
2171
+ .off( "click clack cluck" )
2172
+ .end()
2173
+ .each( function() {
2174
+ equal( counter, 51, "after triggering b" );
2175
+ })
2176
+ .trigger( "cluck", 3 ) // 0+3 = 3
2177
+ .off( "clack", "em", mixfn )
2178
+ .find( "em" )
2179
+ .trigger( "clack" ) // 0
2180
+ .end()
2181
+ .each( function() {
2182
+ equal( counter, 54, "final triggers" );
2183
+ })
2184
+ .off( "click cluck" );
2185
+
2186
+ // We should have removed all the event handlers ... kinda hacky way to check this
2187
+ var data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {};
2188
+ equal( data["events"], undefined, "no events left" );
2189
+
2190
+ $onandoff.remove();
2191
+ });
2192
+
2193
+ test("special bind/delegate name mapping", function() {
2194
+ expect( 7 );
2195
+
2196
+ jQuery.event.special["slap"] = {
2197
+ bindType: "click",
2198
+ delegateType: "swing",
2199
+ handle: function( event ) {
2200
+ equal( event.handleObj.origType, "slap", "slapped your mammy, " + event.type );
2201
+ }
2202
+ };
2203
+
2204
+ var comeback = function( event ) {
2205
+ ok( true, "event " + event.type + " triggered" );
2206
+ };
2207
+
2208
+ jQuery("<div><button id=\"mammy\">Are We Not Men?</button></div>")
2209
+ .on( "slap", "button", jQuery.noop )
2210
+ .on( "swing", "button", comeback )
2211
+ .find( "button" )
2212
+ .on( "slap", jQuery.noop )
2213
+ .on( "click", comeback )
2214
+ .trigger( "click" ) // bindType-slap and click
2215
+ .off( "slap" )
2216
+ .trigger( "click" ) // click
2217
+ .off( "click" )
2218
+ .trigger( "swing" ) // delegateType-slap and swing
2219
+ .end()
2220
+ .off( "slap swing", "button" )
2221
+ .find( "button" ) // everything should be gone
2222
+ .trigger( "slap" )
2223
+ .trigger( "click" )
2224
+ .trigger( "swing" )
2225
+ .end()
2226
+ .remove();
2227
+ delete jQuery.event.special["slap"];
2228
+
2229
+ jQuery.event.special["gutfeeling"] = {
2230
+ bindType: "click",
2231
+ delegateType: "click",
2232
+ handle: function( event ) {
2233
+ equal( event.handleObj.origType, "gutfeeling", "got a gutfeeling" );
2234
+ // Need to call the handler since .one() uses it to unbind
2235
+ return event.handleObj.handler.call( this , event );
2236
+ }
2237
+ };
2238
+
2239
+ // Ensure a special event isn't removed by its mapped type
2240
+ jQuery( "<p>Gut Feeling</p>" )
2241
+ .on( "click", jQuery.noop )
2242
+ .on( "gutfeeling", jQuery.noop )
2243
+ .off( "click" )
2244
+ .trigger( "gutfeeling" )
2245
+ .remove();
2246
+
2247
+ // Ensure special events are removed when only a namespace is provided
2248
+ jQuery( "<p>Gut Feeling</p>" )
2249
+ .on( "gutfeeling.Devo", jQuery.noop )
2250
+ .off( ".Devo" )
2251
+ .trigger( "gutfeeling" )
2252
+ .remove();
2253
+
2254
+ // Ensure .one() events are removed after their maiden voyage
2255
+ jQuery( "<p>Gut Feeling</p>" )
2256
+ .one( "gutfeeling", jQuery.noop )
2257
+ .trigger( "gutfeeling" ) // This one should
2258
+ .trigger( "gutfeeling" ) // This one should not
2259
+ .remove();
2260
+
2261
+ delete jQuery.event.special["gutfeeling"];
2262
+ });
2263
+
2264
+ test(".on and .off, selective mixed removal (#10705)", function() {
2265
+ expect(7);
2266
+
2267
+ var clockout = 0,
2268
+ timingx = function( e ) {
2269
+ ok( true, "triggered " + e.type );
2270
+ };
2271
+
2272
+ jQuery( "<p>Strange Pursuit</p>" )
2273
+ .on( "click", timingx )
2274
+ .on( "click.duty", timingx )
2275
+ .on( "click.now", timingx )
2276
+ .on( "devo", timingx )
2277
+ .on( "future", timingx )
2278
+ .trigger( "click" ) // 3
2279
+ .trigger( "devo" ) // 1
2280
+ .off( ".duty devo " ) // trailing space
2281
+ .trigger( "future" ) // 1
2282
+ .trigger( "click" ) // 2
2283
+ .off( "future click" )
2284
+ .trigger( "click" ); // 0
2285
+ });
2286
+
2287
+ test(".on( event-map, null-selector, data ) #11130", function() {
2288
+
2289
+ expect( 1 );
2290
+
2291
+ var $p = jQuery("<p>Strange Pursuit</p>"),
2292
+ data = "bar",
2293
+ map = {
2294
+ "foo": function( event ) {
2295
+ equal( event.data, "bar", "event.data correctly relayed with null selector" );
2296
+ $p.remove();
2297
+ }
2298
+ };
2299
+
2300
+ $p.on( map, null, data ).trigger("foo");
2301
+ });
2302
+
2303
+ test("clone() delegated events (#11076)", function() {
2304
+ expect(3);
2305
+
2306
+ var counter = { "center": 0, "fold": 0, "centerfold": 0 },
2307
+ clicked = function( event ) {
2308
+ counter[ jQuery(this).text().replace(/\s+/, "") ]++;
2309
+ },
2310
+ table =
2311
+ jQuery( "<table><tr><td>center</td><td>fold</td></tr></table>" )
2312
+ .on( "click", "tr", clicked )
2313
+ .on( "click", "td:first-child", clicked )
2314
+ .on( "click", "td:last-child", clicked ),
2315
+ clone = table.clone( true );
2316
+
2317
+ clone.find("td").trigger("click");
2318
+ equal( counter["center"], 1, "first child" );
2319
+ equal( counter["fold"], 1, "last child" );
2320
+ equal( counter["centerfold"], 2, "all children" );
2321
+
2322
+ table.remove();
2323
+ clone.remove();
2324
+ });
2325
+
2326
+ test("checkbox state (#3827)", function() {
2327
+ expect( 9 );
2328
+
2329
+ var markup = jQuery("<div><input type=checkbox><div>").appendTo("#qunit-fixture"),
2330
+ cb = markup.find("input")[0];
2331
+
2332
+ jQuery(cb).on( "click", function(){
2333
+ equal( this.checked, false, "just-clicked checkbox is not checked" );
2334
+ });
2335
+ markup.on( "click", function(){
2336
+ equal( cb.checked, false, "checkbox is not checked in bubbled event" );
2337
+ });
2338
+
2339
+ // Native click
2340
+ cb.checked = true;
2341
+ equal( cb.checked, true, "native - checkbox is initially checked" );
2342
+ cb.click();
2343
+ equal( cb.checked, false, "native - checkbox is no longer checked" );
2344
+
2345
+ // jQuery click
2346
+ cb.checked = true;
2347
+ equal( cb.checked, true, "jQuery - checkbox is initially checked" );
2348
+ jQuery( cb ).trigger("click");
2349
+ equal( cb.checked, false, "jQuery - checkbox is no longer checked" );
2350
+
2351
+ // Handlers only; checkbox state remains false
2352
+ jQuery( cb ).triggerHandler( "click" );
2353
+ });
2354
+
2355
+ test("focus-blur order (#12868)", function() {
2356
+ expect( 5 );
2357
+
2358
+ var $text = jQuery("#text1"),
2359
+ $radio = jQuery("#radio1").trigger("focus"),
2360
+ order;
2361
+
2362
+ // IE6-10 fire focus/blur events asynchronously; this is the resulting mess.
2363
+ // IE's browser window must be topmost for this to work properly!!
2364
+ stop();
2365
+ $radio[0].focus();
2366
+
2367
+ setTimeout( function() {
2368
+
2369
+ $text
2370
+ .on( "focus", function(){
2371
+ equal( order++, 1, "text focus" );
2372
+ })
2373
+ .on( "blur", function(){
2374
+ equal( order++, 0, "text blur" );
2375
+ });
2376
+ $radio
2377
+ .on( "focus", function(){
2378
+ equal( order++, 1, "radio focus" );
2379
+ })
2380
+ .on( "blur", function(){
2381
+ equal( order++, 0, "radio blur" );
2382
+ });
2383
+
2384
+ // Enabled input getting focus
2385
+ order = 0;
2386
+ equal( document.activeElement, $radio[0], "radio has focus" );
2387
+ $text.trigger("focus");
2388
+ setTimeout( function() {
2389
+ equal( document.activeElement, $text[0], "text has focus" );
2390
+
2391
+ // Run handlers without native method on an input
2392
+ order = 1;
2393
+ $radio.triggerHandler( "focus" );
2394
+ start();
2395
+ }, 50 );
2396
+ }, 50 );
2397
+ });
2398
+
2399
+ test("hover event no longer special since 1.9", function() {
2400
+ expect( 1 );
2401
+
2402
+ jQuery("<div>craft</div>")
2403
+ .on( "hover", function( e ) {
2404
+ equal( e.type, "hover", "I am hovering!" );
2405
+ })
2406
+ .trigger("hover")
2407
+ .off("hover");
2408
+ });
2409
+
2410
+ test("fixHooks extensions", function() {
2411
+ expect( 2 );
2412
+
2413
+ // IE requires focusable elements to be visible, so append to body
2414
+ var $fixture = jQuery( "<input type='text' id='hook-fixture' />" ).appendTo( "body" ),
2415
+ saved = jQuery.event.fixHooks.click;
2416
+
2417
+ // Ensure the property doesn't exist
2418
+ $fixture.bind( "click", function( event ) {
2419
+ ok( !("blurrinessLevel" in event), "event.blurrinessLevel does not exist" );
2420
+ });
2421
+ fireNative( $fixture[0], "click" );
2422
+ $fixture.unbind( "click" );
2423
+
2424
+ jQuery.event.fixHooks.click = {
2425
+ filter: function( event, originalEvent ) {
2426
+ event.blurrinessLevel = 42;
2427
+ return event;
2428
+ }
2429
+ };
2430
+
2431
+ // Trigger a native click and ensure the property is set
2432
+ $fixture.bind( "click", function( event ) {
2433
+ equal( event.blurrinessLevel, 42, "event.blurrinessLevel was set" );
2434
+ });
2435
+ fireNative( $fixture[0], "click" );
2436
+
2437
+ delete jQuery.event.fixHooks.click;
2438
+ $fixture.unbind( "click" ).remove();
2439
+ jQuery.event.fixHooks.click = saved;
2440
+ });
2441
+
2442
+ testIframeWithCallback( "jQuery.ready promise", "event/promiseReady.html", function( isOk ) {
2443
+ expect(1);
2444
+ ok( isOk, "$.when( $.ready ) works" );
2445
+ });
2446
+
2447
+ // need PHP here to make the incepted IFRAME hang
2448
+ if ( hasPHP ) {
2449
+ testIframeWithCallback( "jQuery.ready synchronous load with long loading subresources", "event/syncReady.html", function( isOk ) {
2450
+ expect(1);
2451
+ ok( isOk, "jQuery loaded synchronously fires ready when the DOM can truly be interacted with" );
2452
+ });
2453
+ }
2454
+
2455
+ (function(){
2456
+ // This code must be run before DOM ready!
2457
+ var notYetReady, noEarlyExecution,
2458
+ order = [],
2459
+ args = {};
2460
+
2461
+ notYetReady = !jQuery.isReady;
2462
+
2463
+ test("jQuery.isReady", function() {
2464
+ expect(2);
2465
+
2466
+ equal(notYetReady, true, "jQuery.isReady should not be true before DOM ready");
2467
+ equal(jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready");
2468
+ });
2469
+
2470
+ // Create an event handler.
2471
+ function makeHandler( testId ) {
2472
+ // When returned function is executed, push testId onto `order` array
2473
+ // to ensure execution order. Also, store event handler arg to ensure
2474
+ // the correct arg is being passed into the event handler.
2475
+ return function( arg ) {
2476
+ order.push(testId);
2477
+ args[testId] = arg;
2478
+ };
2479
+ }
2480
+
2481
+ // Bind to the ready event in every possible way.
2482
+ jQuery(makeHandler("a"));
2483
+ jQuery(document).ready(makeHandler("b"));
2484
+ jQuery(document).bind("ready.readytest", makeHandler("c"));
2485
+
2486
+ // Do it twice, just to be sure.
2487
+ jQuery(makeHandler("d"));
2488
+ jQuery(document).ready(makeHandler("e"));
2489
+ jQuery(document).bind("ready.readytest", makeHandler("f"));
2490
+
2491
+ noEarlyExecution = order.length === 0;
2492
+
2493
+ // This assumes that QUnit tests are run on DOM ready!
2494
+ test("jQuery ready", function() {
2495
+ expect(10);
2496
+
2497
+ ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready");
2498
+
2499
+ // Ensure execution order.
2500
+ deepEqual(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in bind-order, but those bound with jQuery(document).bind( 'ready', fn ) will always execute last");
2501
+
2502
+ // Ensure handler argument is correct.
2503
+ equal(args["a"], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
2504
+ equal(args["b"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
2505
+ ok(args["c"] instanceof jQuery.Event, "Argument passed to fn in jQuery(document).bind( 'ready', fn ) should be an event object");
2506
+
2507
+ order = [];
2508
+
2509
+ // Now that the ready event has fired, again bind to the ready event
2510
+ // in every possible way. These event handlers should execute immediately.
2511
+ jQuery(makeHandler("g"));
2512
+ equal(order.pop(), "g", "Event handler should execute immediately");
2513
+ equal(args["g"], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
2514
+
2515
+ jQuery(document).ready(makeHandler("h"));
2516
+ equal(order.pop(), "h", "Event handler should execute immediately");
2517
+ equal(args["h"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
2518
+
2519
+ jQuery(document).bind("ready.readytest", makeHandler("never"));
2520
+ equal(order.length, 0, "Event handler should never execute since DOM ready has already passed");
2521
+
2522
+ // Cleanup.
2523
+ jQuery(document).unbind("ready.readytest");
2524
+ });
2525
+
2526
+ })();
2527
+
2528
+ test("change handler should be detached from element", function() {
2529
+ expect( 2 );
2530
+
2531
+ var $fixture = jQuery( "<input type='text' id='change-ie-leak' />" ).appendTo( "body" );
2532
+
2533
+ var originRemoveEvent = jQuery.removeEvent;
2534
+
2535
+ var wrapperRemoveEvent = function(elem, type, handle){
2536
+ equal("change", type, "Event handler for 'change' event should be removed");
2537
+ equal("change-ie-leak", jQuery(elem).attr("id"), "Event handler for 'change' event should be removed from appropriate element");
2538
+ originRemoveEvent(elem, type, handle);
2539
+ };
2540
+
2541
+ jQuery.removeEvent = wrapperRemoveEvent ;
2542
+
2543
+ $fixture.bind( "change", function( event ) {});
2544
+ $fixture.unbind( "change" );
2545
+
2546
+ $fixture.remove();
2547
+
2548
+ jQuery.removeEvent = originRemoveEvent;
2549
+ });
2550
+
2551
+ asyncTest("trigger click on checkbox, fires change event", function() {
2552
+ expect(1);
2553
+
2554
+ var check = jQuery("#check2");
2555
+
2556
+ check.on( "change", function() {
2557
+ // get it?
2558
+ check.off("change");
2559
+ ok( true, "Change event fired as a result of triggered click" );
2560
+ start();
2561
+ }).trigger("click");
2562
+ });
2563
+
2564
+ test( "Namespace preserved when passed an Event (#12739)", function() {
2565
+ expect( 4 );
2566
+
2567
+ var markup = jQuery(
2568
+ "<div id='parent'><div id='child'></div></div>"
2569
+ ),
2570
+ triggered = 0,
2571
+ fooEvent;
2572
+
2573
+ markup.find("div")
2574
+ .addBack()
2575
+ .on( "foo.bar", function( e ) {
2576
+ if ( !e.handled ) {
2577
+ triggered++;
2578
+ e.handled = true;
2579
+ equal( e.namespace, "bar", "namespace is bar" );
2580
+ jQuery( e.target ).find("div").each(function() {
2581
+ jQuery( this ).triggerHandler( e );
2582
+ });
2583
+ }
2584
+ })
2585
+ .on( "foo.bar2", function( e ) {
2586
+ ok( false, "foo.bar2 called on trigger " + triggered + " id " + this.id );
2587
+ });
2588
+
2589
+ markup.trigger("foo.bar");
2590
+ markup.trigger( jQuery.Event("foo.bar") );
2591
+ fooEvent = jQuery.Event("foo");
2592
+ fooEvent.namespace = "bar";
2593
+ markup.trigger( fooEvent );
2594
+ markup.remove();
2595
+
2596
+ equal( triggered, 3, "foo.bar triggered" );
2597
+ });
2598
+
2599
+ test( "make sure events cloned correctly", 18, function() {
2600
+ var clone,
2601
+ fixture = jQuery("#qunit-fixture"),
2602
+ checkbox = jQuery("#check1"),
2603
+ p = jQuery("#firstp");
2604
+
2605
+ fixture.on( "click change", function( event, result ) {
2606
+ ok( result, event.type + " on original element is fired" );
2607
+
2608
+ }).on( "click", "#firstp", function( event, result ) {
2609
+ ok( result, "Click on original child element though delegation is fired" );
2610
+
2611
+ }).on( "change", "#check1", function( event, result ) {
2612
+ ok( result, "Change on original child element though delegation is fired" );
2613
+ });
2614
+
2615
+ p.on("click", function( event, result ) {
2616
+ ok( true, "Click on original child element is fired" );
2617
+ });
2618
+
2619
+ checkbox.on("change", function( event, result ) {
2620
+ ok( true, "Change on original child element is fired" );
2621
+ });
2622
+
2623
+ fixture.clone().trigger("click").trigger("change"); // 0 events should be fired
2624
+
2625
+ clone = fixture.clone( true );
2626
+
2627
+ clone.find("p:first").trigger( "click", true ); // 3 events should fire
2628
+ clone.find("#check1").trigger( "change", true ); // 3 events should fire
2629
+ clone.remove();
2630
+
2631
+ clone = fixture.clone( true, true );
2632
+ clone.find("p:first").trigger( "click", true ); // 3 events should fire
2633
+ clone.find("#check1").trigger( "change", true ); // 3 events should fire
2634
+
2635
+ fixture.off();
2636
+ p.off();
2637
+ checkbox.off();
2638
+
2639
+ p.trigger("click"); // 0 should be fired
2640
+ checkbox.trigger("change"); // 0 should be fired
2641
+
2642
+ clone.find("p:first").trigger( "click", true ); // 3 events should fire
2643
+ clone.find("#check1").trigger( "change", true ); // 3 events should fire
2644
+ clone.remove();
2645
+
2646
+ clone.find("p:first").trigger("click"); // 0 should be fired
2647
+ clone.find("#check1").trigger("change"); // 0 events should fire
2648
+ });
2649
+
2650
+ test( "Check order of focusin/focusout events", 2, function() {
2651
+ var focus, blur,
2652
+ input = jQuery("#name");
2653
+
2654
+ input.on("focus", function() {
2655
+ focus = true;
2656
+
2657
+ }).on("focusin", function() {
2658
+ ok( !focus, "Focusin event should fire before focus does" );
2659
+
2660
+ }).on("blur", function() {
2661
+ blur = true;
2662
+
2663
+ }).on("focusout", function() {
2664
+ ok( !blur, "Focusout event should fire before blur does" );
2665
+ });
2666
+
2667
+ // gain focus
2668
+ input.trigger("focus");
2669
+
2670
+ // then lose it
2671
+ jQuery("#search").trigger("focus");
2672
+
2673
+ // cleanup
2674
+ input.off();
2675
+ });
2676
+
2677
+ test( "String.prototype.namespace does not cause trigger() to throw (#13360)", function() {
2678
+ expect( 1 );
2679
+ var errored = false;
2680
+
2681
+ String.prototype.namespace = function() {};
2682
+
2683
+ try {
2684
+ jQuery("<p>").trigger("foo.bar");
2685
+ } catch( e ) {
2686
+ errored = true;
2687
+ }
2688
+ equal( errored, false, "trigger() did not throw exception" );
2689
+ delete String.prototype.namespace;
2690
+ });