unpoly-rails 0.57.0 → 0.60.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of unpoly-rails might be problematic. Click here for more details.

Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +393 -1
  3. data/Gemfile.lock +5 -2
  4. data/README.md +1 -1
  5. data/README_RAILS.md +1 -1
  6. data/Rakefile +10 -1
  7. data/design/es6.js +32 -0
  8. data/design/ie11.txt +9 -0
  9. data/design/measure_jquery/element_list.js +41 -0
  10. data/design/measure_jquery/up.on_vs_addEventListener.js +56 -0
  11. data/design/todo_jquery.txt +13 -0
  12. data/dist/unpoly-bootstrap3.js +8 -8
  13. data/dist/unpoly-bootstrap3.min.js +1 -1
  14. data/dist/unpoly.css +22 -20
  15. data/dist/unpoly.js +6990 -5336
  16. data/dist/unpoly.min.css +1 -1
  17. data/dist/unpoly.min.js +4 -4
  18. data/lib/assets/javascripts/unpoly-bootstrap3/viewport-ext.coffee +5 -0
  19. data/lib/assets/javascripts/unpoly.coffee +8 -6
  20. data/lib/assets/javascripts/unpoly/browser.coffee.erb +23 -118
  21. data/lib/assets/javascripts/unpoly/classes/body_shifter.coffee +36 -0
  22. data/lib/assets/javascripts/unpoly/classes/cache.coffee +4 -4
  23. data/lib/assets/javascripts/unpoly/classes/compile_pass.coffee +45 -39
  24. data/lib/assets/javascripts/unpoly/classes/config.coffee +9 -0
  25. data/lib/assets/javascripts/unpoly/classes/css_transition.coffee +18 -27
  26. data/lib/assets/javascripts/unpoly/classes/divertible_chain.coffee +39 -0
  27. data/lib/assets/javascripts/unpoly/classes/event_listener.coffee +116 -0
  28. data/lib/assets/javascripts/unpoly/classes/extract_cascade.coffee +8 -8
  29. data/lib/assets/javascripts/unpoly/classes/extract_plan.coffee +19 -19
  30. data/lib/assets/javascripts/unpoly/classes/field_observer.coffee +54 -31
  31. data/lib/assets/javascripts/unpoly/classes/{focus_tracker.coffee → focus_follower.coffee} +2 -2
  32. data/lib/assets/javascripts/unpoly/classes/follow_variant.coffee +25 -25
  33. data/lib/assets/javascripts/unpoly/classes/html_parser.coffee +4 -11
  34. data/lib/assets/javascripts/unpoly/classes/motion_controller.coffee +157 -0
  35. data/lib/assets/javascripts/unpoly/classes/params.coffee.erb +525 -0
  36. data/lib/assets/javascripts/unpoly/classes/record.coffee +8 -2
  37. data/lib/assets/javascripts/unpoly/classes/rect.js +21 -0
  38. data/lib/assets/javascripts/unpoly/classes/request.coffee +41 -35
  39. data/lib/assets/javascripts/unpoly/classes/response.coffee +7 -3
  40. data/lib/assets/javascripts/unpoly/classes/reveal_motion.coffee +102 -0
  41. data/lib/assets/javascripts/unpoly/classes/scroll_motion.coffee +67 -0
  42. data/lib/assets/javascripts/unpoly/classes/selector.coffee +60 -0
  43. data/lib/assets/javascripts/unpoly/classes/tether.coffee +105 -0
  44. data/lib/assets/javascripts/unpoly/classes/url_set.coffee +12 -7
  45. data/lib/assets/javascripts/unpoly/element.coffee.erb +1126 -0
  46. data/lib/assets/javascripts/unpoly/event.coffee.erb +437 -0
  47. data/lib/assets/javascripts/unpoly/feedback.coffee +73 -94
  48. data/lib/assets/javascripts/unpoly/form.coffee.erb +188 -181
  49. data/lib/assets/javascripts/unpoly/{dom.coffee.erb → fragment.coffee.erb} +250 -283
  50. data/lib/assets/javascripts/unpoly/framework.coffee +67 -0
  51. data/lib/assets/javascripts/unpoly/history.coffee +29 -28
  52. data/lib/assets/javascripts/unpoly/legacy.coffee +60 -0
  53. data/lib/assets/javascripts/unpoly/link.coffee.erb +127 -119
  54. data/lib/assets/javascripts/unpoly/log.coffee +99 -19
  55. data/lib/assets/javascripts/unpoly/modal.coffee.erb +95 -118
  56. data/lib/assets/javascripts/unpoly/motion.coffee.erb +158 -138
  57. data/lib/assets/javascripts/unpoly/namespace.coffee.erb +0 -5
  58. data/lib/assets/javascripts/unpoly/popup.coffee.erb +119 -102
  59. data/lib/assets/javascripts/unpoly/protocol.coffee +11 -15
  60. data/lib/assets/javascripts/unpoly/proxy.coffee +62 -65
  61. data/lib/assets/javascripts/unpoly/radio.coffee +3 -5
  62. data/lib/assets/javascripts/unpoly/rails.coffee +8 -9
  63. data/lib/assets/javascripts/unpoly/syntax.coffee.erb +173 -125
  64. data/lib/assets/javascripts/unpoly/toast.coffee +25 -24
  65. data/lib/assets/javascripts/unpoly/tooltip.coffee +89 -79
  66. data/lib/assets/javascripts/unpoly/util.coffee.erb +579 -1074
  67. data/lib/assets/javascripts/unpoly/{layout.coffee.erb → viewport.coffee.erb} +334 -264
  68. data/lib/assets/stylesheets/unpoly/dom.sass +1 -1
  69. data/lib/assets/stylesheets/unpoly/layout.sass +2 -0
  70. data/lib/assets/stylesheets/unpoly/popup.sass +0 -1
  71. data/lib/assets/stylesheets/unpoly/tooltip.sass +17 -12
  72. data/lib/unpoly/rails/version.rb +1 -1
  73. data/package.json +1 -2
  74. data/spec_app/Gemfile +2 -1
  75. data/spec_app/Gemfile.lock +38 -27
  76. data/spec_app/app/assets/javascripts/integration_test.coffee +1 -0
  77. data/spec_app/app/assets/javascripts/jasmine_specs.coffee +1 -2
  78. data/spec_app/app/assets/stylesheets/integration_test.sass +14 -1
  79. data/spec_app/app/controllers/scroll_test_controller.rb +5 -0
  80. data/spec_app/app/views/css_test/modal.erb +6 -6
  81. data/spec_app/app/views/css_test/popup.erb +44 -18
  82. data/spec_app/app/views/css_test/tooltip.erb +23 -4
  83. data/spec_app/app/views/error_test/trigger.erb +1 -1
  84. data/spec_app/app/views/form_test/basics/new.erb +1 -3
  85. data/spec_app/app/views/pages/start.erb +9 -2
  86. data/spec_app/app/views/reveal_test/long1.erb +1 -1
  87. data/spec_app/app/views/reveal_test/long2.erb +1 -1
  88. data/spec_app/app/views/reveal_test/within_document_viewport.erb +24 -0
  89. data/spec_app/app/views/reveal_test/within_overflowing_div_viewport.erb +28 -0
  90. data/spec_app/app/views/scroll_test/long1.erb +30 -0
  91. data/spec_app/config/routes.rb +1 -0
  92. data/spec_app/spec/javascripts/helpers/agent_detector.coffee +3 -0
  93. data/spec_app/spec/javascripts/helpers/async_sequence.js.coffee +1 -0
  94. data/spec_app/spec/javascripts/helpers/browser_switches.js.coffee +17 -5
  95. data/spec_app/spec/javascripts/helpers/enable_logging.js.coffee +1 -1
  96. data/spec_app/spec/javascripts/helpers/fixture.js.coffee +25 -0
  97. data/spec_app/spec/javascripts/helpers/jquery_no_conflict.js +1 -0
  98. data/spec_app/spec/javascripts/helpers/last_request.js.coffee +1 -0
  99. data/spec_app/spec/javascripts/helpers/mock_ajax.js.coffee +1 -1
  100. data/spec_app/spec/javascripts/helpers/parse_form_data.js.coffee +2 -2
  101. data/spec_app/spec/javascripts/helpers/protect_jasmine_runner.coffee +4 -1
  102. data/spec_app/spec/javascripts/helpers/remove_body_margin.js.coffee +3 -0
  103. data/spec_app/spec/javascripts/helpers/reset_history.js.coffee +2 -1
  104. data/spec_app/spec/javascripts/helpers/reset_knife.js.coffee +2 -2
  105. data/spec_app/spec/javascripts/helpers/reset_up.js.coffee +18 -11
  106. data/spec_app/spec/javascripts/helpers/restore_body_scroll.js.coffee +3 -0
  107. data/spec_app/spec/javascripts/helpers/show_lib_versions.coffee +3 -0
  108. data/spec_app/spec/javascripts/helpers/spec_util.coffee +47 -0
  109. data/spec_app/spec/javascripts/helpers/to_be_around.js.coffee +3 -0
  110. data/spec_app/spec/javascripts/helpers/to_be_array.coffee +5 -0
  111. data/spec_app/spec/javascripts/helpers/to_be_attached.coffee +6 -2
  112. data/spec_app/spec/javascripts/helpers/to_be_blank.js.coffee +3 -0
  113. data/spec_app/spec/javascripts/helpers/to_be_detached.coffee +6 -2
  114. data/spec_app/spec/javascripts/helpers/to_be_element.js.coffee +8 -0
  115. data/spec_app/spec/javascripts/helpers/to_be_error.coffee +3 -0
  116. data/spec_app/spec/javascripts/helpers/to_be_given.js.coffee +3 -0
  117. data/spec_app/spec/javascripts/helpers/to_be_hidden.js.coffee +8 -0
  118. data/spec_app/spec/javascripts/helpers/to_be_missing.js.coffee +3 -0
  119. data/spec_app/spec/javascripts/helpers/to_be_present.js.coffee +3 -0
  120. data/spec_app/spec/javascripts/helpers/to_be_scrolled_to.coffee +3 -0
  121. data/spec_app/spec/javascripts/helpers/to_be_visible.js.coffee +9 -0
  122. data/spec_app/spec/javascripts/helpers/to_contain.js.coffee +3 -0
  123. data/spec_app/spec/javascripts/helpers/to_end_with.js.coffee +3 -0
  124. data/spec_app/spec/javascripts/helpers/to_equal_jquery.js.coffee +1 -2
  125. data/spec_app/spec/javascripts/helpers/to_equal_node_list.coffee +7 -0
  126. data/spec_app/spec/javascripts/helpers/to_equal_via_is_equal.js.coffee +7 -0
  127. data/spec_app/spec/javascripts/helpers/to_have_class.js.coffee +10 -0
  128. data/spec_app/spec/javascripts/helpers/to_have_descendant.js.coffee +10 -0
  129. data/spec_app/spec/javascripts/helpers/to_have_length.js.coffee +8 -0
  130. data/spec_app/spec/javascripts/helpers/to_have_opacity.coffee +7 -3
  131. data/spec_app/spec/javascripts/helpers/to_have_own_property.js.coffee +3 -0
  132. data/spec_app/spec/javascripts/helpers/to_have_request_method.js.coffee +1 -0
  133. data/spec_app/spec/javascripts/helpers/to_have_text.js.coffee +9 -0
  134. data/spec_app/spec/javascripts/helpers/to_have_unhandled_rejections.coffee +0 -21
  135. data/spec_app/spec/javascripts/helpers/to_match_list.coffee +14 -0
  136. data/spec_app/spec/javascripts/helpers/to_match_selector.coffee +3 -0
  137. data/spec_app/spec/javascripts/helpers/to_match_text.js.coffee +4 -1
  138. data/spec_app/spec/javascripts/helpers/to_match_url.coffee +1 -0
  139. data/spec_app/spec/javascripts/helpers/trigger.js.coffee +91 -7
  140. data/spec_app/spec/javascripts/helpers/wait_until_dom_ready.js.coffee +3 -0
  141. data/spec_app/spec/javascripts/up/browser_spec.js.coffee +23 -90
  142. data/spec_app/spec/javascripts/up/classes/cache_spec.js.coffee +3 -0
  143. data/spec_app/spec/javascripts/up/classes/config_spec.coffee +24 -0
  144. data/spec_app/spec/javascripts/up/classes/divertible_chain_spec.coffee +45 -0
  145. data/spec_app/spec/javascripts/up/classes/focus_tracker_spec.coffee +5 -2
  146. data/spec_app/spec/javascripts/up/classes/params_spec.coffee +557 -0
  147. data/spec_app/spec/javascripts/up/classes/request_spec.coffee +7 -4
  148. data/spec_app/spec/javascripts/up/classes/scroll_motion_spec.js.coffee +51 -0
  149. data/spec_app/spec/javascripts/up/classes/store/memory_spec.js.coffee +3 -0
  150. data/spec_app/spec/javascripts/up/classes/store/session_spec.js.coffee +3 -2
  151. data/spec_app/spec/javascripts/up/element_spec.coffee +897 -0
  152. data/spec_app/spec/javascripts/up/event_spec.js.coffee +496 -0
  153. data/spec_app/spec/javascripts/up/feedback_spec.js.coffee +69 -48
  154. data/spec_app/spec/javascripts/up/form_spec.js.coffee +252 -194
  155. data/spec_app/spec/javascripts/up/{dom_spec.js.coffee → fragment_spec.js.coffee} +381 -388
  156. data/spec_app/spec/javascripts/up/history_spec.js.coffee +21 -19
  157. data/spec_app/spec/javascripts/up/jquery_spec.js.coffee +4 -0
  158. data/spec_app/spec/javascripts/up/legacy_spec.js.coffee +27 -0
  159. data/spec_app/spec/javascripts/up/link_spec.js.coffee +163 -160
  160. data/spec_app/spec/javascripts/up/log_spec.js.coffee +85 -12
  161. data/spec_app/spec/javascripts/up/modal_spec.js.coffee +141 -123
  162. data/spec_app/spec/javascripts/up/motion_spec.js.coffee +117 -113
  163. data/spec_app/spec/javascripts/up/popup_spec.js.coffee +60 -77
  164. data/spec_app/spec/javascripts/up/protocol_spec.js.coffee +1 -0
  165. data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +85 -78
  166. data/spec_app/spec/javascripts/up/radio_spec.js.coffee +29 -22
  167. data/spec_app/spec/javascripts/up/rails_spec.js.coffee +14 -13
  168. data/spec_app/spec/javascripts/up/spec_spec.js.coffee +9 -0
  169. data/spec_app/spec/javascripts/up/syntax_spec.js.coffee +96 -66
  170. data/spec_app/spec/javascripts/up/toast_spec.js.coffee +37 -0
  171. data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +31 -47
  172. data/spec_app/spec/javascripts/up/util_spec.js.coffee +725 -562
  173. data/spec_app/spec/javascripts/up/{layout_spec.js.coffee → viewport_spec.js.coffee} +175 -149
  174. metadata +57 -19
  175. data/lib/assets/javascripts/unpoly-bootstrap3/layout-ext.coffee +0 -5
  176. data/lib/assets/javascripts/unpoly/bus.coffee.erb +0 -518
  177. data/lib/assets/javascripts/unpoly/classes/extract_step.coffee +0 -4
  178. data/lib/assets/javascripts/unpoly/classes/motion_tracker.coffee +0 -125
  179. data/lib/assets/javascripts/unpoly/params.coffee.erb +0 -522
  180. data/spec_app/spec/javascripts/helpers/append_fixture.js.coffee +0 -8
  181. data/spec_app/spec/javascripts/up/bus_spec.js.coffee +0 -210
  182. data/spec_app/spec/javascripts/up/namespace_spec.js.coffee +0 -9
  183. data/spec_app/spec/javascripts/up/params_spec.coffee +0 -768
  184. data/spec_app/vendor/asset-libs/jasmine-fixture-1.3.4/jasmine-fixture.js +0 -433
  185. data/spec_app/vendor/asset-libs/jasmine-jquery-2.1.1/.bower.json +0 -26
  186. data/spec_app/vendor/asset-libs/jasmine-jquery-2.1.1/jasmine-jquery.js +0 -838
@@ -1,5 +1,9 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toBeDetached: (util, customEqualityTesters) ->
4
- compare: (actual) ->
5
- pass: up.util.isDetached(actual)
7
+ compare: (element) ->
8
+ element = up.element.get(element)
9
+ pass: element && up.specUtil.isDetached(element)
@@ -0,0 +1,8 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
4
+ beforeEach ->
5
+ jasmine.addMatchers
6
+ toBeElement: (util, customEqualityTesters) ->
7
+ compare: (actual) ->
8
+ pass: up.util.isElement(actual)
@@ -1,3 +1,6 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toBeError: (util, customEqualityTesters) ->
@@ -1,3 +1,6 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toBeGiven: (util, customEqualityTesters) ->
@@ -0,0 +1,8 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
4
+ beforeEach ->
5
+ jasmine.addMatchers
6
+ toBeHidden: (util, customEqualityTesters) ->
7
+ compare: (object) ->
8
+ pass: object && up.specUtil.isHidden(object)
@@ -1,3 +1,6 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toBeMissing: (util, customEqualityTesters) ->
@@ -1,3 +1,6 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toBePresent: (util, customEqualityTesters) ->
@@ -1,3 +1,6 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toBeScrolledTo: (util, customEqualityTesters) ->
@@ -0,0 +1,9 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
4
+ beforeEach ->
5
+ jasmine.addMatchers
6
+ toBeVisible: (util, customEqualityTesters) ->
7
+ compare: (object) ->
8
+ pass: object && up.specUtil.isVisible(object)
9
+
@@ -1,3 +1,6 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toContain: (util, customEqualityTesters) ->
@@ -1,3 +1,6 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  endsWith = (string, substring) ->
2
5
  string.indexOf(substring) == string.length - substring.length
3
6
 
@@ -1,6 +1,5 @@
1
- # http://jasmine.github.io/2.0/custom_equality.html
2
-
3
1
  u = up.util
2
+ $ = jQuery
4
3
 
5
4
  beforeEach ->
6
5
  jasmine.addCustomEqualityTester (first, second) ->
@@ -0,0 +1,7 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
4
+ beforeEach ->
5
+ jasmine.addCustomEqualityTester (a, b) ->
6
+ if a instanceof NodeList
7
+ return (a.length == b.length) && u.every(a, (elem, index) -> a[index] == b[index])
@@ -0,0 +1,7 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
4
+ beforeEach ->
5
+ jasmine.addCustomEqualityTester (first, second) ->
6
+ if u.isObject(first) && u.isObject(second) && first[up.util.isEqual.key]
7
+ first[u.isEqual.key](second)
@@ -0,0 +1,10 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
4
+ beforeEach ->
5
+ jasmine.addMatchers
6
+ toHaveClass: (util, customEqualityTesters) ->
7
+ compare: (element, expectedClass) ->
8
+ element = up.element.get(element)
9
+ pass: element && element.classList.contains(expectedClass)
10
+
@@ -0,0 +1,10 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
4
+ beforeEach ->
5
+ jasmine.addMatchers
6
+ toHaveDescendant: (util, customEqualityTesters) ->
7
+ compare: (element, expectedDescendant) ->
8
+ pass: $(element).find(expectedDescendant).length
9
+
10
+
@@ -0,0 +1,8 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
4
+ beforeEach ->
5
+ jasmine.addMatchers
6
+ toHaveLength: (util, customEqualityTesters) ->
7
+ compare: (actualObject, expectedLength) ->
8
+ pass: actualObject && actualObject.length == expectedLength
@@ -1,11 +1,15 @@
1
+ u = up.util
2
+ e = up.element
3
+ $ = jQuery
4
+
1
5
  beforeEach ->
2
6
  jasmine.addMatchers
3
7
  toHaveOpacity: (util, customEqualityTesters) ->
4
8
  compare: (element, expectedOpacity, tolerance = 0.0) ->
5
- element = up.util.element(element)
6
- actualOpacity = up.util.opacity(element)
9
+ element = e.get(element)
10
+ actualOpacity = e.styleNumber(element, 'opacity')
7
11
  result = {}
8
12
  result.pass = Math.abs(expectedOpacity - actualOpacity) <= tolerance
9
13
  unless result.pass
10
- result.message = up.browser.sprintf("Expected %o to have opacity %o, but it was %o", element, expectedOpacity, actualOpacity)
14
+ result.message = up.log.sprintf("Expected %o to have opacity %o, but it was %o", element, expectedOpacity, actualOpacity)
11
15
  return result
@@ -1,3 +1,6 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toHaveOwnProperty: (util, customEqualityTesters) ->
@@ -1,4 +1,5 @@
1
1
  u = up.util
2
+ $ = jQuery
2
3
 
3
4
  beforeEach ->
4
5
  jasmine.addMatchers
@@ -0,0 +1,9 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
4
+ beforeEach ->
5
+ jasmine.addMatchers
6
+ toHaveText: (util, customEqualityTesters) ->
7
+ compare: (element, expectedText) ->
8
+ element = up.element.get(element)
9
+ pass: element && (element.textContent?.trim() == expectedText.trim())
@@ -16,24 +16,3 @@ beforeEach ->
16
16
  # It doesn't really matter what's in actual.
17
17
  # A good way to call this is e.g. `expect(window).not.toHaveUnhandledRejections()
18
18
  pass: UNHANDLED_REJECTIONS.length > 0
19
-
20
- #UnhandledRejectionTracker = do ->
21
- #
22
- #
23
- #
24
- #
25
- #
26
- ##beforeEach (done) ->
27
- ## @unhandledRejections = []
28
- ## @trackUnhandledRejections = (event) =>
29
- ## @unhandledRejections.push(event)
30
- ## window.addEventListener('unhandledrejection', @trackUnhandledRejections)
31
- ## done()
32
- ##
33
- ##afterEach (done) ->
34
- ## hadUnhandledRejections = @unhandledRejections.length > 0
35
- ## @unhandledRejections = []
36
- ## if hadUnhandledRejections
37
- ## done.fail('There were rejected promises without a rejection handler')
38
- ## else
39
- ## done()
@@ -0,0 +1,14 @@
1
+ u = up.util
2
+
3
+ beforeEach ->
4
+ jasmine.addMatchers
5
+ toMatchList: (util, customEqualityTesters) ->
6
+ compare: (actualList, expectedList) ->
7
+ actualList = u.toArray(actualList) if actualList
8
+ expectedList = u.toArray(expectedList) if expectedList
9
+
10
+ pass:
11
+ actualList &&
12
+ expectedList &&
13
+ actualList.length == expectedList.length &&
14
+ u.every(expectedList, (elem) -> u.contains(actualList, elem))
@@ -1,3 +1,6 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toMatchSelector: (util, customEqualityTesters) ->
@@ -1,9 +1,12 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeEach ->
2
5
  jasmine.addMatchers
3
6
  toMatchText: (util, customEqualityTesters) ->
4
7
  compare: (actualString, expectedString) ->
5
8
  normalize = (str) ->
6
- str = up.util.trim(str)
9
+ str = str.trim()
7
10
  str = str.replace(/[\n\r\t ]+/g, ' ')
8
11
  str
9
12
 
@@ -1,4 +1,5 @@
1
1
  u = up.util
2
+ $ = jQuery
2
3
 
3
4
  beforeEach ->
4
5
  jasmine.addMatchers
@@ -1,7 +1,9 @@
1
+ u = up.util
2
+ e = up.element
3
+ $ = jQuery
4
+
1
5
  @Trigger = (->
2
-
3
- u = up.util
4
-
6
+
5
7
  mouseover = (element, options) ->
6
8
  $element = $(element)
7
9
  event = createMouseEvent('mouseover', options)
@@ -41,6 +43,41 @@
41
43
  $element = $(element)
42
44
  $element.focus()
43
45
 
46
+ submit = (form, options) ->
47
+ form = e.get(form)
48
+ options = u.options(options,
49
+ cancelable: true,
50
+ bubbles: true
51
+ )
52
+ event = createEvent('submit', options)
53
+ form.dispatchEvent(event)
54
+
55
+ change = (field, options) ->
56
+ field = e.get(field)
57
+ options = u.options(options,
58
+ cancelable: false,
59
+ bubbles: true
60
+ )
61
+ event = createEvent('change', options)
62
+ field.dispatchEvent(event)
63
+
64
+ input = (field, options) ->
65
+ field = e.get(field)
66
+ options = u.options(options,
67
+ cancelable: false,
68
+ bubbles: true
69
+ )
70
+ event = createEvent('input', options)
71
+ field.dispatchEvent(event)
72
+
73
+ escapeSequence = (element, options) ->
74
+ options = u.options(options,
75
+ key: 'Escape'
76
+ )
77
+ for type in ['keydown', 'keypress', 'keyup']
78
+ event = createKeyboardEvent(type, options)
79
+ element.dispatchEvent(event)
80
+
44
81
  clickSequence = (element, options) ->
45
82
  $element = $(element)
46
83
  mouseover($element, options)
@@ -59,6 +96,17 @@
59
96
  mouseout($element, options)
60
97
  mouseleave($element, options)
61
98
 
99
+ # Can't use the new Event constructor in IE11 because computer.
100
+ # http://www.codeproject.com/Tips/893254/JavaScript-Triggering-Event-Manually-in-Internet-E
101
+ createEvent = (type, options) ->
102
+ options = u.options(options,
103
+ cancelable: true,
104
+ bubbles: true
105
+ )
106
+ event = document.createEvent('Event')
107
+ event.initEvent(type, options.bubbles, options.cancelable)
108
+ event
109
+
62
110
  # Can't use the new MouseEvent constructor in IE11 because computer.
63
111
  # http://www.codeproject.com/Tips/893254/JavaScript-Triggering-Event-Manually-in-Internet-E
64
112
  createMouseEvent = (type, options) ->
@@ -97,9 +145,39 @@
97
145
  )
98
146
  event
99
147
 
100
- dispatch = ($element, event) ->
101
- $element.each ->
102
- this.dispatchEvent(event)
148
+ createKeyboardEvent = (type, options) ->
149
+ options = u.options(options,
150
+ cancelable: true,
151
+ bubbles: true,
152
+ view: window,
153
+ key: null,
154
+ )
155
+
156
+ if canEventConstructors()
157
+ event = new KeyboardEvent(type, options)
158
+ else
159
+ event = document.createEvent('KeyboardEvent')
160
+ # The argument of initKeyboardEvent differs wildly between browsers.
161
+ # In IE 11 it is initKeyboardEvent(type, canBubble, cancelable, view, key, location, modifierList, repeat, locale).
162
+ event.initKeyboardEvent(type,
163
+ options.bubbles,
164
+ options.cancelable,
165
+ options.view,
166
+ options.key,
167
+ null,
168
+ null,
169
+ null,
170
+ null,
171
+ )
172
+
173
+ event
174
+
175
+ canEventConstructors = ->
176
+ typeof window.Event == "function"
177
+
178
+ dispatch = (element, event) ->
179
+ element = e.get(element)
180
+ element.dispatchEvent(event)
103
181
 
104
182
  mouseover: mouseover
105
183
  mouseenter: mouseenter
@@ -111,6 +189,12 @@
111
189
  clickSequence: clickSequence
112
190
  hoverSequence: hoverSequence
113
191
  unhoverSequence: unhoverSequence
192
+ escapeSequence: escapeSequence
193
+ submit: submit
194
+ change: change
195
+ input: input
196
+ createEvent: createEvent
114
197
  createMouseEvent: createMouseEvent
115
-
198
+ createKeyboardEvent: createKeyboardEvent
199
+
116
200
  )()
@@ -1,2 +1,5 @@
1
+ u = up.util
2
+ $ = jQuery
3
+
1
4
  beforeAll (done) ->
2
5
  $(done)
@@ -1,6 +1,7 @@
1
- describe 'up.browser', ->
1
+ u = up.util
2
+ $ = jQuery
2
3
 
3
- u = up.util
4
+ describe 'up.browser', ->
4
5
 
5
6
  describe 'JavaScript functions', ->
6
7
 
@@ -17,25 +18,28 @@ describe 'up.browser', ->
17
18
  submitForm = spyOn(up.browser, 'submitForm')
18
19
  up.browser.navigate('/foo', method: 'GET', params: { param1: 'param1 value', param2: 'param2 value' })
19
20
  expect(submitForm).toHaveBeenCalled()
21
+
20
22
  $form = $('form.up-page-loader')
21
- expect($form).toExist()
23
+
24
+ expect($form).toBeAttached()
22
25
  # GET forms cannot have an URL with a query section in their [action] attribute.
23
26
  # The query section would be overridden by the serialized input values on submission.
24
27
  expect($form.attr('action')).toMatchUrl('/foo')
25
- expect($form.find('input[name="param1"][value="param1 value"]')).toExist()
26
- expect($form.find('input[name="param2"][value="param2 value"]')).toExist()
28
+
29
+ expect($form.find('input[name="param1"][value="param1 value"]')).toBeAttached()
30
+ expect($form.find('input[name="param2"][value="param2 value"]')).toBeAttached()
27
31
 
28
32
  it 'merges params from the given URL and the { params } option', ->
29
33
  submitForm = spyOn(up.browser, 'submitForm')
30
34
  up.browser.navigate('/foo?param1=param1%20value', method: 'GET', params: { param2: 'param2 value' })
31
35
  expect(submitForm).toHaveBeenCalled()
32
36
  $form = $('form.up-page-loader')
33
- expect($form).toExist()
37
+ expect($form).toBeAttached()
34
38
  # GET forms cannot have an URL with a query section in their [action] attribute.
35
39
  # The query section would be overridden by the serialized input values on submission.
36
40
  expect($form.attr('action')).toMatchUrl('/foo')
37
- expect($form.find('input[name="param1"][value="param1 value"]')).toExist()
38
- expect($form.find('input[name="param2"][value="param2 value"]')).toExist()
41
+ expect($form.find('input[name="param1"][value="param1 value"]')).toBeAttached()
42
+ expect($form.find('input[name="param2"][value="param2 value"]')).toBeAttached()
39
43
 
40
44
  describe "for POST requests", ->
41
45
 
@@ -44,22 +48,22 @@ describe 'up.browser', ->
44
48
  up.browser.navigate('/foo', method: 'POST', params: { param1: 'param1 value', param2: 'param2 value' })
45
49
  expect(submitForm).toHaveBeenCalled()
46
50
  $form = $('form.up-page-loader')
47
- expect($form).toExist()
51
+ expect($form).toBeAttached()
48
52
  expect($form.attr('action')).toMatchUrl('/foo')
49
53
  expect($form.attr('method')).toEqual('POST')
50
- expect($form.find('input[name="param1"][value="param1 value"]')).toExist()
51
- expect($form.find('input[name="param2"][value="param2 value"]')).toExist()
54
+ expect($form.find('input[name="param1"][value="param1 value"]')).toBeAttached()
55
+ expect($form.find('input[name="param2"][value="param2 value"]')).toBeAttached()
52
56
 
53
57
  it 'merges params from the given URL and the { params } option', ->
54
58
  submitForm = spyOn(up.browser, 'submitForm')
55
59
  up.browser.navigate('/foo?param1=param1%20value', method: 'POST', params: { param2: 'param2 value' })
56
60
  expect(submitForm).toHaveBeenCalled()
57
61
  $form = $('form.up-page-loader')
58
- expect($form).toExist()
62
+ expect($form).toBeAttached()
59
63
  expect($form.attr('action')).toMatchUrl('/foo')
60
64
  expect($form.attr('method')).toEqual('POST')
61
- expect($form.find('input[name="param1"][value="param1 value"]')).toExist()
62
- expect($form.find('input[name="param2"][value="param2 value"]')).toExist()
65
+ expect($form.find('input[name="param1"][value="param1 value"]')).toBeAttached()
66
+ expect($form.find('input[name="param2"][value="param2 value"]')).toBeAttached()
63
67
 
64
68
  u.each ['PUT', 'PATCH', 'DELETE'], (method) ->
65
69
 
@@ -70,7 +74,7 @@ describe 'up.browser', ->
70
74
  up.browser.navigate('/foo', method: method)
71
75
  expect(submitForm).toHaveBeenCalled()
72
76
  $form = $('form.up-page-loader')
73
- expect($form).toExist()
77
+ expect($form).toBeAttached()
74
78
  expect($form.attr('method')).toEqual('POST')
75
79
  expect($form.find('input[name="_method"]').val()).toEqual(method)
76
80
 
@@ -86,7 +90,7 @@ describe 'up.browser', ->
86
90
  expect(@submitForm).toHaveBeenCalled()
87
91
  $form = $('form.up-page-loader')
88
92
  $tokenInput = $form.find('input[name="csrf-param"]')
89
- expect($tokenInput).toExist()
93
+ expect($tokenInput).toBeAttached()
90
94
  expect($tokenInput.val()).toEqual('csrf-token')
91
95
 
92
96
  it 'does not add a CSRF token if there is none', ->
@@ -95,92 +99,21 @@ describe 'up.browser', ->
95
99
  expect(@submitForm).toHaveBeenCalled()
96
100
  $form = $('form.up-page-loader')
97
101
  $tokenInput = $form.find('input[name="csrf-param"]')
98
- expect($tokenInput).not.toExist()
102
+ expect($tokenInput).not.toBeAttached()
99
103
 
100
104
  it 'does not add a CSRF token for GET requests', ->
101
105
  up.browser.navigate('/foo', method: 'get')
102
106
  expect(@submitForm).toHaveBeenCalled()
103
107
  $form = $('form.up-page-loader')
104
108
  $tokenInput = $form.find('input[name="csrf-param"]')
105
- expect($tokenInput).not.toExist()
109
+ expect($tokenInput).not.toBeAttached()
106
110
 
107
111
  it 'does not add a CSRF token when loading content from another domain', ->
108
112
  up.browser.navigate('http://other-domain.tld/foo', method: 'get')
109
113
  expect(@submitForm).toHaveBeenCalled()
110
114
  $form = $('form.up-page-loader')
111
115
  $tokenInput = $form.find('input[name="csrf-param"]')
112
- expect($tokenInput).not.toExist()
113
-
114
- describe 'up.browser.sprintf', ->
115
-
116
- describe '(string argument)', ->
117
-
118
- it 'serializes with surrounding quotes', ->
119
- formatted = up.browser.sprintf('before %o after', 'argument')
120
- expect(formatted).toEqual('before "argument" after')
121
-
122
- describe '(undefined argument)', ->
123
-
124
- it 'serializes to the word "undefined"', ->
125
- formatted = up.browser.sprintf('before %o after', undefined)
126
- expect(formatted).toEqual('before undefined after')
127
-
128
- describe '(null argument)', ->
129
-
130
- it 'serializes to the word "null"', ->
131
- formatted = up.browser.sprintf('before %o after', null)
132
- expect(formatted).toEqual('before null after')
133
-
134
- describe '(number argument)', ->
135
-
136
- it 'serializes the number as string', ->
137
- formatted = up.browser.sprintf('before %o after', 5)
138
- expect(formatted).toEqual('before 5 after')
139
-
140
- describe '(function argument)', ->
141
-
142
- it 'serializes the function code', ->
143
- formatted = up.browser.sprintf('before %o after', `function foo() {}`)
144
- expect(formatted).toEqual('before function foo() {} after')
145
-
146
- describe '(array argument)', ->
147
-
148
- it 'recursively serializes the elements', ->
149
- formatted = up.browser.sprintf('before %o after', [1, "foo"])
150
- expect(formatted).toEqual('before [1, "foo"] after')
151
-
152
- describe '(element argument)', ->
153
-
154
- it 'serializes the tag name with id, name and class attributes, but ignores other attributes', ->
155
- $element = $('<table id="id-value" name="name-value" class="class-value" title="title-value">')
156
- element = $element.get(0)
157
- formatted = up.browser.sprintf('before %o after', element)
158
- expect(formatted).toEqual('before <table id="id-value" name="name-value" class="class-value"> after')
159
-
160
- describe '(jQuery argument)', ->
161
-
162
- it 'serializes the tag name with id, name and class attributes, but ignores other attributes', ->
163
- $element1 = $('<table id="table-id">')
164
- $element2 = $('<ul id="ul-id">')
165
- formatted = up.browser.sprintf('before %o after', $element1.add($element2))
166
- expect(formatted).toEqual('before $(<table id="table-id">, <ul id="ul-id">) after')
167
-
168
- describe '(object argument)', ->
169
-
170
- it 'serializes to JSON', ->
171
- object = { foo: 'foo-value', bar: 'bar-value' }
172
- formatted = up.browser.sprintf('before %o after', object)
173
- expect(formatted).toEqual('before {"foo":"foo-value","bar":"bar-value"} after')
174
-
175
- it "skips a key if a getter crashes", ->
176
- object = {}
177
- Object.defineProperty(object, 'foo', get: (-> throw "error"))
178
- formatted = up.browser.sprintf('before %o after', object)
179
- expect(formatted).toEqual('before {} after')
180
-
181
- object.bar = 'bar'
182
- formatted = up.browser.sprintf('before %o after', object)
183
- expect(formatted).toEqual('before {"bar":"bar"} after')
116
+ expect($tokenInput).not.toBeAttached()
184
117
 
185
118
  describe 'up.browser.whenConfirmed', ->
186
119