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,18 +1,61 @@
1
- describe 'up.dom', ->
1
+ u = up.util
2
+ e = up.element
3
+ $ = jQuery
4
+
5
+ describe 'up.fragment', ->
2
6
 
3
- u = up.util
4
-
5
7
  describe 'JavaScript functions', ->
6
8
 
9
+ describe 'up.fragment.first', ->
10
+
11
+ it 'returns the first element with the given selector', ->
12
+ match = fixture('.match')
13
+ noMatch = fixture('.no-match')
14
+ result = up.fragment.first('.match')
15
+ expect(result).toBe(match)
16
+
17
+ it 'returns undefined if there are no matches', ->
18
+ result = up.fragment.first('.match')
19
+ expect(result).toBeUndefined()
20
+
21
+ it 'does not return an element that is currently destroying', ->
22
+ match = fixture('.match.up-destroying')
23
+ result = up.fragment.first('.match')
24
+ expect(result).toBeUndefined()
25
+
26
+ describe 'when given a root element for the search', ->
27
+
28
+ it 'only matches descendants of that root', ->
29
+ parent1 = fixture('.parent1')
30
+ parent1Match = e.affix(parent1, '.match')
31
+
32
+ parent2 = fixture('.parent1')
33
+ parent2Match = e.affix(parent2, '.match')
34
+
35
+ expect(up.fragment.first(parent1, '.match')).toBe(parent1Match)
36
+ expect(up.fragment.first(parent2, '.match')).toBe(parent2Match)
37
+
38
+ describe 'with { origin } option', ->
39
+
40
+ it 'resolves an & in the selector string with an selector for the origin'
41
+
42
+ it 'prefers to find an element in the same layer as the origin'
43
+
44
+ it "returns the element in the top-most layer if there are no matches in the origin's layer"
45
+
46
+ describe 'with { layer } option', ->
47
+
48
+ it 'only matches elements in that layer'
49
+
7
50
  describe 'up.replace', ->
8
51
 
9
52
  describeCapability 'canPushState', ->
10
53
 
11
54
  beforeEach ->
12
55
 
13
- @oldBefore = affix('.before').text('old-before')
14
- @oldMiddle = affix('.middle').text('old-middle')
15
- @oldAfter = affix('.after').text('old-after')
56
+ @$oldBefore = $fixture('.before').text('old-before')
57
+ @$oldMiddle = $fixture('.middle').text('old-middle')
58
+ @$oldAfter = $fixture('.after').text('old-after')
16
59
 
17
60
  @responseText =
18
61
  """
@@ -48,6 +91,17 @@ describe 'up.dom', ->
48
91
  expect(resolution).toHaveBeenCalled()
49
92
  expect($('.middle')).toHaveText('new-middle')
50
93
 
94
+ it 'allows to pass an element instead of a selector', asyncSpec (next) ->
95
+ up.replace(@$oldMiddle, '/path')
96
+
97
+ next =>
98
+ @respond()
99
+
100
+ next =>
101
+ expect($('.before')).toHaveText('old-before')
102
+ expect($('.middle')).toHaveText('new-middle')
103
+ expect($('.after')).toHaveText('old-after')
104
+
51
105
  describe 'with { transition } option', ->
52
106
 
53
107
  it 'returns a promise that will be fulfilled once the server response was received and the swap transition has completed', asyncSpec (next) ->
@@ -89,11 +143,11 @@ describe 'up.dom', ->
89
143
  describe 'when the server responds with an error', ->
90
144
 
91
145
  it 'replaces the first fallback instead of the given selector', asyncSpec (next) ->
92
- up.dom.config.fallbacks = ['.fallback']
93
- affix('.fallback')
146
+ up.fragment.config.fallbacks = ['.fallback']
147
+ $fixture('.fallback')
94
148
 
95
149
  # can't have the example replace the Jasmine test runner UI
96
- extractSpy = up.dom.knife.mock('extract').and.returnValue(Promise.resolve())
150
+ extractSpy = up.fragment.knife.mock('extract').and.returnValue(Promise.resolve())
97
151
 
98
152
  next => up.replace('.middle', '/path')
99
153
  next => @respond(status: 500)
@@ -111,16 +165,16 @@ describe 'up.dom', ->
111
165
  expect($('.after')).toHaveText('new-after')
112
166
 
113
167
  it 'rejects the returned promise', (done) ->
114
- affix('.after')
168
+ $fixture('.after')
115
169
  promise = up.replace('.middle', '/path', failTarget: '.after')
116
170
 
117
- u.nextFrame =>
171
+ u.task =>
118
172
  promiseState(promise).then (result) =>
119
173
  expect(result.state).toEqual('pending')
120
174
 
121
175
  @respond(status: 500)
122
176
 
123
- u.nextFrame =>
177
+ u.task =>
124
178
  promiseState(promise).then (result) =>
125
179
  expect(result.state).toEqual('rejected')
126
180
  done()
@@ -129,7 +183,7 @@ describe 'up.dom', ->
129
183
 
130
184
  it "doesn't crash and rejects the returned promise", asyncSpec (next) ->
131
185
  jasmine.clock().install() # required by responseTimeout()
132
- affix('.target')
186
+ $fixture('.target')
133
187
  promise = up.replace('.middle', '/path', timeout: 50)
134
188
 
135
189
  next =>
@@ -149,14 +203,14 @@ describe 'up.dom', ->
149
203
  describe 'when there is a network issue', ->
150
204
 
151
205
  it "doesn't crash and rejects the returned promise", (done) ->
152
- affix('.target')
206
+ $fixture('.target')
153
207
  promise = up.replace('.middle', '/path')
154
208
 
155
- u.nextFrame =>
209
+ u.task =>
156
210
  promiseState(promise).then (result) =>
157
211
  expect(result.state).toEqual('pending')
158
212
  @lastRequest().responseError()
159
- u.nextFrame =>
213
+ u.task =>
160
214
  promiseState(promise).then (result) =>
161
215
  expect(result.state).toEqual('rejected')
162
216
  done()
@@ -233,31 +287,31 @@ describe 'up.dom', ->
233
287
  done()
234
288
 
235
289
  it 'reuses the previous source for a non-GET request (since that is reloadable)', asyncSpec (next) ->
236
- @oldMiddle.attr('up-source', '/previous-source')
290
+ @$oldMiddle.attr('up-source', '/previous-source')
237
291
  up.replace('.middle', '/path', method: 'post')
238
292
  next =>
239
293
  @respond()
240
294
  next =>
241
295
  expect($('.middle')).toHaveText('new-middle')
242
- expect(up.dom.source('.middle')).toMatchUrl('/previous-source')
296
+ expect(up.fragment.source('.middle')).toMatchUrl('/previous-source')
243
297
 
244
298
  describe 'if a URL is given as { source } option', ->
245
299
 
246
300
  it 'uses that URL as the source for a GET request', asyncSpec (next) ->
247
301
  up.replace('.middle', '/path', source: '/given-path')
248
302
  next => @respond()
249
- next => expect(up.dom.source('.middle')).toMatchUrl('/given-path')
303
+ next => expect(up.fragment.source('.middle')).toMatchUrl('/given-path')
250
304
 
251
305
  it 'uses that URL as the source after a non-GET request', asyncSpec (next) ->
252
306
  up.replace('.middle', '/path', method: 'post', source: '/given-path')
253
307
  next => @respond()
254
- next => expect(up.dom.source('.middle')).toMatchUrl('/given-path')
308
+ next => expect(up.fragment.source('.middle')).toMatchUrl('/given-path')
255
309
 
256
310
  it 'ignores the option and reuses the previous source after a failed non-GET request', asyncSpec (next) ->
257
- @oldMiddle.attr('up-source', '/previous-source')
311
+ @$oldMiddle.attr('up-source', '/previous-source')
258
312
  up.replace('.middle', '/path', method: 'post', source: '/given-path', failTarget: '.middle')
259
313
  next => @respond(status: 500)
260
- next => expect(up.dom.source('.middle')).toMatchUrl('/previous-source')
314
+ next => expect(up.fragment.source('.middle')).toMatchUrl('/previous-source')
261
315
 
262
316
  describe 'document title', ->
263
317
 
@@ -265,7 +319,7 @@ describe 'up.dom', ->
265
319
  up.history.config.enabled = true
266
320
 
267
321
  it "sets the document title to the response <title>", asyncSpec (next) ->
268
- affix('.container').text('old container text')
322
+ $fixture('.container').text('old container text')
269
323
  up.replace('.container', '/path')
270
324
 
271
325
  next =>
@@ -287,7 +341,7 @@ describe 'up.dom', ->
287
341
  expect(document.title).toBe('Title from HTML')
288
342
 
289
343
  it "sets the document title to an 'X-Up-Title' header in the response", asyncSpec (next) ->
290
- affix('.container').text('old container text')
344
+ $fixture('.container').text('old container text')
291
345
  up.replace('.container', '/path')
292
346
 
293
347
  next =>
@@ -305,7 +359,7 @@ describe 'up.dom', ->
305
359
  expect(document.title).toBe('Title from header')
306
360
 
307
361
  it "prefers the X-Up-Title header to the response <title>", asyncSpec (next) ->
308
- affix('.container').text('old container text')
362
+ $fixture('.container').text('old container text')
309
363
  up.replace('.container', '/path')
310
364
 
311
365
  next =>
@@ -330,7 +384,7 @@ describe 'up.dom', ->
330
384
  expect(document.title).toBe('Title from header')
331
385
 
332
386
  it "sets the document title to the response <title> with { history: false, title: true } options (bugfix)", asyncSpec (next) ->
333
- affix('.container').text('old container text')
387
+ $fixture('.container').text('old container text')
334
388
  up.replace('.container', '/path', history: false, title: true)
335
389
 
336
390
  next =>
@@ -352,7 +406,7 @@ describe 'up.dom', ->
352
406
  expect(document.title).toBe('Title from HTML')
353
407
 
354
408
  it 'does not update the document title if the response has a <title> tag inside an inline SVG image (bugfix)', asyncSpec (next) ->
355
- affix('.container').text('old container text')
409
+ $fixture('.container').text('old container text')
356
410
  document.title = 'old document title'
357
411
  up.replace('.container', '/path', history: false, title: true)
358
412
 
@@ -375,7 +429,7 @@ describe 'up.dom', ->
375
429
  expect(document.title).toBe('old document title')
376
430
 
377
431
  it "does not extract the title from the response or HTTP header if history isn't updated", asyncSpec (next) ->
378
- affix('.container').text('old container text')
432
+ $fixture('.container').text('old container text')
379
433
  document.title = 'old document title'
380
434
  up.replace('.container', '/path', history: false)
381
435
 
@@ -400,7 +454,7 @@ describe 'up.dom', ->
400
454
  expect(document.title).toBe('old document title')
401
455
 
402
456
  it 'allows to pass an explicit title as { title } option', asyncSpec (next) ->
403
- affix('.container').text('old container text')
457
+ $fixture('.container').text('old container text')
404
458
  up.replace('.container', '/path', title: 'Title from options')
405
459
 
406
460
  next =>
@@ -435,7 +489,7 @@ describe 'up.dom', ->
435
489
  describe 'nested selector merging', ->
436
490
 
437
491
  it 'replaces a single fragment if a selector contains a subsequent selector in the current page', asyncSpec (next) ->
438
- $outer = affix('.outer').text('old outer text')
492
+ $outer = $fixture('.outer').text('old outer text')
439
493
  $inner = $outer.affix('.inner').text('old inner text')
440
494
 
441
495
  replacePromise = up.replace('.outer, .inner', '/path')
@@ -453,9 +507,9 @@ describe 'up.dom', ->
453
507
  """
454
508
 
455
509
  next =>
456
- expect($('.outer')).toExist()
510
+ expect($('.outer')).toBeAttached()
457
511
  expect($('.outer').text()).toContain('new outer text')
458
- expect($('.inner')).toExist()
512
+ expect($('.inner')).toBeAttached()
459
513
  expect($('.inner').text()).toContain('new inner text')
460
514
 
461
515
  next.await =>
@@ -463,7 +517,7 @@ describe 'up.dom', ->
463
517
  promise.then (result) => expect(result.state).toEqual('fulfilled')
464
518
 
465
519
  it 'does not merge selectors if a selector contains a subsequent selector, but prepends instead of replacing', asyncSpec (next) ->
466
- $outer = affix('.outer').text('old outer text')
520
+ $outer = $fixture('.outer').text('old outer text')
467
521
  $inner = $outer.affix('.inner').text('old inner text')
468
522
 
469
523
  replacePromise = up.replace('.outer:before, .inner', '/path')
@@ -481,10 +535,10 @@ describe 'up.dom', ->
481
535
  """
482
536
 
483
537
  next =>
484
- expect($('.outer')).toExist()
538
+ expect($('.outer')).toBeAttached()
485
539
  expect($('.outer').text()).toContain('new outer text')
486
540
  expect($('.outer').text()).toContain('old outer text')
487
- expect($('.inner')).toExist()
541
+ expect($('.inner')).toBeAttached()
488
542
  expect($('.inner').text()).toContain('new inner text')
489
543
 
490
544
  next.await =>
@@ -492,7 +546,7 @@ describe 'up.dom', ->
492
546
  promise.then (result) => expect(result.state).toEqual('fulfilled')
493
547
 
494
548
  it 'does not merge selectors if a selector contains a subsequent selector, but appends instead of replacing', asyncSpec (next) ->
495
- $outer = affix('.outer').text('old outer text')
549
+ $outer = $fixture('.outer').text('old outer text')
496
550
  $inner = $outer.affix('.inner').text('old inner text')
497
551
 
498
552
  replacePromise = up.replace('.outer:after, .inner', '/path')
@@ -510,10 +564,10 @@ describe 'up.dom', ->
510
564
  """
511
565
 
512
566
  next =>
513
- expect($('.outer')).toExist()
567
+ expect($('.outer')).toBeAttached()
514
568
  expect($('.outer').text()).toContain('old outer text')
515
569
  expect($('.outer').text()).toContain('new outer text')
516
- expect($('.inner')).toExist()
570
+ expect($('.inner')).toBeAttached()
517
571
  expect($('.inner').text()).toContain('new inner text')
518
572
 
519
573
  next.await =>
@@ -521,7 +575,7 @@ describe 'up.dom', ->
521
575
  promise.then (result) => expect(result.state).toEqual('fulfilled')
522
576
 
523
577
  it 'does not lose selector pseudo-classes when merging selectors (bugfix)', asyncSpec (next) ->
524
- $outer = affix('.outer').text('old outer text')
578
+ $outer = $fixture('.outer').text('old outer text')
525
579
  $inner = $outer.affix('.inner').text('old inner text')
526
580
 
527
581
  replacePromise = up.replace('.outer:after, .inner', '/path')
@@ -530,7 +584,7 @@ describe 'up.dom', ->
530
584
  expect(@lastRequest().requestHeaders['X-Up-Target']).toEqual('.outer:after, .inner')
531
585
 
532
586
  it 'replaces a single fragment if a selector contains a previous selector in the current page', asyncSpec (next) ->
533
- $outer = affix('.outer').text('old outer text')
587
+ $outer = $fixture('.outer').text('old outer text')
534
588
  $inner = $outer.affix('.inner').text('old inner text')
535
589
 
536
590
  replacePromise = up.replace('.outer, .inner', '/path')
@@ -548,9 +602,9 @@ describe 'up.dom', ->
548
602
  """
549
603
 
550
604
  next =>
551
- expect($('.outer')).toExist()
605
+ expect($('.outer')).toBeAttached()
552
606
  expect($('.outer').text()).toContain('new outer text')
553
- expect($('.inner')).toExist()
607
+ expect($('.inner')).toBeAttached()
554
608
  expect($('.inner').text()).toContain('new inner text')
555
609
 
556
610
  next.await =>
@@ -558,9 +612,9 @@ describe 'up.dom', ->
558
612
  promise.then (result) => expect(result.state).toEqual('fulfilled')
559
613
 
560
614
  it 'does not lose a { reveal: true } option if the first selector was merged into a subsequent selector', asyncSpec (next) ->
561
- revealStub = up.layout.knife.mock('reveal')
615
+ revealStub = up.viewport.knife.mock('reveal')
562
616
 
563
- $outer = affix('.outer').text('old outer text')
617
+ $outer = $fixture('.outer').text('old outer text')
564
618
  $inner = $outer.affix('.inner').text('old inner text')
565
619
 
566
620
  up.replace('.inner, .outer', '/path', reveal: true)
@@ -578,18 +632,18 @@ describe 'up.dom', ->
578
632
  """
579
633
 
580
634
  next =>
581
- expect($('.outer')).toExist()
635
+ expect($('.outer')).toBeAttached()
582
636
  expect($('.outer').text()).toContain('new outer text')
583
- expect($('.inner')).toExist()
637
+ expect($('.inner')).toBeAttached()
584
638
  expect($('.inner').text()).toContain('new inner text')
585
639
 
586
640
  expect(revealStub).toHaveBeenCalled()
587
641
 
588
642
 
589
643
  it 'does not lose a { reveal: string } option if the first selector was merged into a subsequent selector', asyncSpec (next) ->
590
- revealStub = up.layout.knife.mock('reveal')
644
+ revealStub = up.viewport.knife.mock('reveal')
591
645
 
592
- $outer = affix('.outer').text('old outer text')
646
+ $outer = $fixture('.outer').text('old outer text')
593
647
  $inner = $outer.affix('.inner').text('old inner text')
594
648
 
595
649
  up.replace('.inner, .outer', '/path', reveal: '.revealee')
@@ -610,18 +664,18 @@ describe 'up.dom', ->
610
664
  """
611
665
 
612
666
  next =>
613
- expect($('.outer')).toExist()
667
+ expect($('.outer')).toBeAttached()
614
668
  expect($('.outer').text()).toContain('new outer text')
615
- expect($('.inner')).toExist()
669
+ expect($('.inner')).toBeAttached()
616
670
  expect($('.inner').text()).toContain('new inner text')
617
671
 
618
672
  expect(revealStub).toHaveBeenCalled()
619
673
  revealArg = revealStub.calls.mostRecent().args[0]
620
- expect(revealArg).toBeMatchedBy('.revealee')
674
+ expect(revealArg).toMatchSelector('.revealee')
621
675
 
622
676
 
623
677
  it 'replaces a single fragment if the nesting differs in current page and response', asyncSpec (next) ->
624
- $outer = affix('.outer').text('old outer text')
678
+ $outer = $fixture('.outer').text('old outer text')
625
679
  $inner = $outer.affix('.inner').text('old inner text')
626
680
 
627
681
  replacePromise = up.replace('.outer, .inner', '/path')
@@ -637,17 +691,17 @@ describe 'up.dom', ->
637
691
  """
638
692
 
639
693
  next =>
640
- expect($('.outer')).toExist()
694
+ expect($('.outer')).toBeAttached()
641
695
  expect($('.outer').text()).toContain('new outer text')
642
- expect($('.inner')).not.toExist()
696
+ expect($('.inner')).not.toBeAttached()
643
697
 
644
698
  next.await =>
645
699
  promise = promiseState(replacePromise)
646
700
  promise.then (result) => expect(result.state).toEqual('fulfilled')
647
701
 
648
702
  it 'does not crash if two selectors that are siblings in the current page are nested in the response', asyncSpec (next) ->
649
- $outer = affix('.one').text('old one text')
650
- $inner = affix('.two').text('old two text')
703
+ $outer = $fixture('.one').text('old one text')
704
+ $inner = $fixture('.two').text('old two text')
651
705
 
652
706
  replacePromise = up.replace('.one, .two', '/path')
653
707
 
@@ -662,9 +716,9 @@ describe 'up.dom', ->
662
716
  """
663
717
 
664
718
  next =>
665
- expect($('.one')).toExist()
719
+ expect($('.one')).toBeAttached()
666
720
  expect($('.one').text()).toContain('new one text')
667
- expect($('.two')).toExist()
721
+ expect($('.two')).toBeAttached()
668
722
  expect($('.two').text()).toContain('new two text')
669
723
 
670
724
  next.await =>
@@ -672,8 +726,8 @@ describe 'up.dom', ->
672
726
  promise.then (result) => expect(result.state).toEqual('fulfilled')
673
727
 
674
728
  it 'does not crash if selectors that siblings in the current page are inversely nested in the response', asyncSpec (next) ->
675
- $outer = affix('.one').text('old one text')
676
- $inner = affix('.two').text('old two text')
729
+ $outer = $fixture('.one').text('old one text')
730
+ $inner = $fixture('.two').text('old two text')
677
731
 
678
732
  replacePromise = up.replace('.one, .two', '/path')
679
733
 
@@ -688,9 +742,9 @@ describe 'up.dom', ->
688
742
  """
689
743
 
690
744
  next =>
691
- expect($('.one')).toExist()
745
+ expect($('.one')).toBeAttached()
692
746
  expect($('.one').text()).toContain('new one text')
693
- expect($('.two')).toExist()
747
+ expect($('.two')).toBeAttached()
694
748
  expect($('.two').text()).toContain('new two text')
695
749
 
696
750
  next.await =>
@@ -698,7 +752,7 @@ describe 'up.dom', ->
698
752
  promise.then (result) => expect(result.state).toEqual('fulfilled')
699
753
 
700
754
  it 'updates the first selector if the same element is targeted twice in a single replacement', asyncSpec (next) ->
701
- $one = affix('.one.alias').text('old one text')
755
+ $one = $fixture('.one.alias').text('old one text')
702
756
 
703
757
  replacePromise = up.replace('.one, .alias', '/path')
704
758
 
@@ -712,7 +766,7 @@ describe 'up.dom', ->
712
766
  """
713
767
 
714
768
  next =>
715
- expect($('.one')).toExist()
769
+ expect($('.one')).toBeAttached()
716
770
  expect($('.one').text()).toContain('new one text')
717
771
 
718
772
  next.await =>
@@ -720,7 +774,7 @@ describe 'up.dom', ->
720
774
  promise.then (result) => expect(result.state).toEqual('fulfilled')
721
775
 
722
776
  it 'updates the first selector if the same element is prepended or appended twice in a single replacement', asyncSpec (next) ->
723
- $one = affix('.one').text('old one text')
777
+ $one = $fixture('.one').text('old one text')
724
778
 
725
779
  replacePromise = up.replace('.one:before, .one:after', '/path')
726
780
 
@@ -734,7 +788,7 @@ describe 'up.dom', ->
734
788
  """
735
789
 
736
790
  next =>
737
- expect($('.one')).toExist()
791
+ expect($('.one')).toBeAttached()
738
792
  expect($('.one').text()).toMatchText('new one text old one text')
739
793
 
740
794
  next.await =>
@@ -742,7 +796,7 @@ describe 'up.dom', ->
742
796
  promise.then (result) => expect(result.state).toEqual('fulfilled')
743
797
 
744
798
  it "updates the first selector if the same element is prepended, replaced and appended in a single replacement", asyncSpec (next) ->
745
- $elem = affix('.elem.alias1.alias2').text("old text")
799
+ $elem = $fixture('.elem.alias1.alias2').text("old text")
746
800
 
747
801
  replacePromise = up.replace('.elem:before, .alias1, .alias2:after', '/path')
748
802
 
@@ -756,7 +810,7 @@ describe 'up.dom', ->
756
810
  """
757
811
 
758
812
  next =>
759
- expect('.elem').toExist()
813
+ expect('.elem').toBeAttached()
760
814
  expect($('.elem').text()).toMatchText('new text old text')
761
815
 
762
816
  next.await =>
@@ -793,9 +847,9 @@ describe 'up.dom', ->
793
847
  done()
794
848
 
795
849
  it 'understands non-standard CSS selector extensions such as :has(...)', (done) ->
796
- $first = affix('.boxx#first')
850
+ $first = $fixture('.boxx#first')
797
851
  $firstChild = $('<span class="first-child">old first</span>').appendTo($first)
798
- $second = affix('.boxx#second')
852
+ $second = $fixture('.boxx#second')
799
853
  $secondChild = $('<span class="second-child">old second</span>').appendTo($second)
800
854
 
801
855
  promise = up.replace('.boxx:has(.first-child)', '/path')
@@ -813,10 +867,10 @@ describe 'up.dom', ->
813
867
  describe 'when selectors are missing on the page before the request was made', ->
814
868
 
815
869
  beforeEach ->
816
- up.dom.config.fallbacks = []
870
+ up.fragment.config.fallbacks = []
817
871
 
818
872
  it 'tries selectors from options.fallback before making a request', asyncSpec (next) ->
819
- affix('.box').text('old box')
873
+ $fixture('.box').text('old box')
820
874
  up.replace('.unknown', '/path', fallback: '.box')
821
875
 
822
876
  next => @respondWith '<div class="box">new box</div>'
@@ -829,8 +883,8 @@ describe 'up.dom', ->
829
883
  done()
830
884
 
831
885
  it 'considers a union selector to be missing if one of its selector-atoms are missing', asyncSpec (next) ->
832
- affix('.target').text('old target')
833
- affix('.fallback').text('old fallback')
886
+ $fixture('.target').text('old target')
887
+ $fixture('.fallback').text('old fallback')
834
888
  up.replace('.target, .unknown', '/path', fallback: '.fallback')
835
889
 
836
890
  next =>
@@ -843,16 +897,16 @@ describe 'up.dom', ->
843
897
  expect('.target').toHaveText('old target')
844
898
  expect('.fallback').toHaveText('new fallback')
845
899
 
846
- it 'tries a selector from up.dom.config.fallbacks if options.fallback is missing', asyncSpec (next) ->
847
- up.dom.config.fallbacks = ['.existing']
848
- affix('.existing').text('old existing')
900
+ it 'tries a selector from up.fragment.config.fallbacks if options.fallback is missing', asyncSpec (next) ->
901
+ up.fragment.config.fallbacks = ['.existing']
902
+ $fixture('.existing').text('old existing')
849
903
  up.replace('.unknown', '/path')
850
904
  next => @respondWith '<div class="existing">new existing</div>'
851
905
  next => expect('.existing').toHaveText('new existing')
852
906
 
853
- it 'does not try a selector from up.dom.config.fallbacks and rejects the promise if options.fallback is false', (done) ->
854
- up.dom.config.fallbacks = ['.existing']
855
- affix('.existing').text('old existing')
907
+ it 'does not try a selector from up.fragment.config.fallbacks and rejects the promise if options.fallback is false', (done) ->
908
+ up.fragment.config.fallbacks = ['.existing']
909
+ $fixture('.existing').text('old existing')
856
910
  up.replace('.unknown', '/path', fallback: false).catch (e) ->
857
911
  expect(e).toBeError(/Could not find target in current page/i)
858
912
  done()
@@ -860,11 +914,11 @@ describe 'up.dom', ->
860
914
  describe 'when selectors are missing on the page after the request was made', ->
861
915
 
862
916
  beforeEach ->
863
- up.dom.config.fallbacks = []
917
+ up.fragment.config.fallbacks = []
864
918
 
865
919
  it 'tries selectors from options.fallback before swapping elements', asyncSpec (next) ->
866
- $target = affix('.target').text('old target')
867
- $fallback = affix('.fallback').text('old fallback')
920
+ $target = $fixture('.target').text('old target')
921
+ $fallback = $fixture('.fallback').text('old fallback')
868
922
  up.replace('.target', '/path', fallback: '.fallback')
869
923
  $target.remove()
870
924
 
@@ -878,28 +932,28 @@ describe 'up.dom', ->
878
932
  expect('.fallback').toHaveText('new fallback')
879
933
 
880
934
  it 'rejects the promise if all alternatives are exhausted', (done) ->
881
- $target = affix('.target').text('old target')
882
- $fallback = affix('.fallback').text('old fallback')
935
+ $target = $fixture('.target').text('old target')
936
+ $fallback = $fixture('.fallback').text('old fallback')
883
937
  promise = up.replace('.target', '/path', fallback: '.fallback')
884
938
  $target.remove()
885
939
  $fallback.remove()
886
940
 
887
- u.nextFrame =>
941
+ u.task =>
888
942
  @respondWith """
889
943
  <div class="target">new target</div>
890
944
  <div class="fallback">new fallback</div>
891
945
  """
892
946
 
893
- u.nextFrame =>
947
+ u.task =>
894
948
  promiseState(promise).then (result) ->
895
949
  expect(result.state).toEqual('rejected')
896
950
  expect(result.value).toBeError(/Could not find target in current page/i)
897
951
  done()
898
952
 
899
953
  it 'considers a union selector to be missing if one of its selector-atoms are missing', asyncSpec (next) ->
900
- $target = affix('.target').text('old target')
901
- $target2 = affix('.target2').text('old target2')
902
- $fallback = affix('.fallback').text('old fallback')
954
+ $target = $fixture('.target').text('old target')
955
+ $target2 = $fixture('.target2').text('old target2')
956
+ $fallback = $fixture('.fallback').text('old fallback')
903
957
  up.replace('.target, .target2', '/path', fallback: '.fallback')
904
958
  $target2.remove()
905
959
 
@@ -913,10 +967,10 @@ describe 'up.dom', ->
913
967
  expect('.target').toHaveText('old target')
914
968
  expect('.fallback').toHaveText('new fallback')
915
969
 
916
- it 'tries a selector from up.dom.config.fallbacks if options.fallback is missing', asyncSpec (next) ->
917
- up.dom.config.fallbacks = ['.fallback']
918
- $target = affix('.target').text('old target')
919
- $fallback = affix('.fallback').text('old fallback')
970
+ it 'tries a selector from up.fragment.config.fallbacks if options.fallback is missing', asyncSpec (next) ->
971
+ up.fragment.config.fallbacks = ['.fallback']
972
+ $target = $fixture('.target').text('old target')
973
+ $fallback = $fixture('.fallback').text('old fallback')
920
974
  up.replace('.target', '/path')
921
975
  $target.remove()
922
976
 
@@ -929,14 +983,14 @@ describe 'up.dom', ->
929
983
  next =>
930
984
  expect('.fallback').toHaveText('new fallback')
931
985
 
932
- it 'does not try a selector from up.dom.config.fallbacks and rejects the promise if options.fallback is false', (done) ->
933
- up.dom.config.fallbacks = ['.fallback']
934
- $target = affix('.target').text('old target')
935
- $fallback = affix('.fallback').text('old fallback')
986
+ it 'does not try a selector from up.fragment.config.fallbacks and rejects the promise if options.fallback is false', (done) ->
987
+ up.fragment.config.fallbacks = ['.fallback']
988
+ $target = $fixture('.target').text('old target')
989
+ $fallback = $fixture('.fallback').text('old fallback')
936
990
  promise = up.replace('.target', '/path', fallback: false)
937
991
  $target.remove()
938
992
 
939
- u.nextFrame =>
993
+ u.task =>
940
994
  @respondWith """
941
995
  <div class="target">new target</div>
942
996
  <div class="fallback">new fallback</div>
@@ -949,11 +1003,11 @@ describe 'up.dom', ->
949
1003
  describe 'when selectors are missing in the response', ->
950
1004
 
951
1005
  beforeEach ->
952
- up.dom.config.fallbacks = []
1006
+ up.fragment.config.fallbacks = []
953
1007
 
954
1008
  it 'tries selectors from options.fallback before swapping elements', asyncSpec (next) ->
955
- $target = affix('.target').text('old target')
956
- $fallback = affix('.fallback').text('old fallback')
1009
+ $target = $fixture('.target').text('old target')
1010
+ $fallback = $fixture('.fallback').text('old fallback')
957
1011
  up.replace('.target', '/path', fallback: '.fallback')
958
1012
 
959
1013
  next =>
@@ -968,11 +1022,11 @@ describe 'up.dom', ->
968
1022
  describe 'if all alternatives are exhausted', ->
969
1023
 
970
1024
  it 'rejects the promise', (done) ->
971
- $target = affix('.target').text('old target')
972
- $fallback = affix('.fallback').text('old fallback')
1025
+ $target = $fixture('.target').text('old target')
1026
+ $fallback = $fixture('.fallback').text('old fallback')
973
1027
  promise = up.replace('.target', '/path', fallback: '.fallback')
974
1028
 
975
- u.nextFrame =>
1029
+ u.task =>
976
1030
  @respondWith '<div class="unexpected">new unexpected</div>'
977
1031
 
978
1032
  promise.catch (e) ->
@@ -980,31 +1034,31 @@ describe 'up.dom', ->
980
1034
  done()
981
1035
 
982
1036
  it 'shows a link to open the unexpected response', (done) ->
983
- $target = affix('.target').text('old target')
984
- $fallback = affix('.fallback').text('old fallback')
1037
+ $target = $fixture('.target').text('old target')
1038
+ $fallback = $fixture('.fallback').text('old fallback')
985
1039
  promise = up.replace('.target', '/path', fallback: '.fallback')
986
1040
  navigate = spyOn(up.browser, 'navigate')
987
1041
 
988
- u.nextFrame =>
1042
+ u.task =>
989
1043
  @respondWith '<div class="unexpected">new unexpected</div>'
990
1044
 
991
1045
  promise.catch (e) ->
992
1046
  $toast = $('.up-toast')
993
- expect($toast).toExist()
1047
+ expect($toast).toBeAttached()
994
1048
  $inspectLink = $toast.find(".up-toast-action:contains('Open response')")
995
- expect($inspectLink).toExist()
1049
+ expect($inspectLink).toBeAttached()
996
1050
  expect(navigate).not.toHaveBeenCalled()
997
1051
 
998
1052
  Trigger.clickSequence($inspectLink)
999
1053
 
1000
- u.nextFrame =>
1054
+ u.task =>
1001
1055
  expect(navigate).toHaveBeenCalledWith('/path', {})
1002
1056
  done()
1003
1057
 
1004
1058
  it 'considers a union selector to be missing if one of its selector-atoms are missing', asyncSpec (next) ->
1005
- $target = affix('.target').text('old target')
1006
- $target2 = affix('.target2').text('old target2')
1007
- $fallback = affix('.fallback').text('old fallback')
1059
+ $target = $fixture('.target').text('old target')
1060
+ $target2 = $fixture('.target2').text('old target2')
1061
+ $fallback = $fixture('.fallback').text('old fallback')
1008
1062
  up.replace('.target, .target2', '/path', fallback: '.fallback')
1009
1063
 
1010
1064
  next =>
@@ -1018,10 +1072,10 @@ describe 'up.dom', ->
1018
1072
  expect('.target2').toHaveText('old target2')
1019
1073
  expect('.fallback').toHaveText('new fallback')
1020
1074
 
1021
- it 'tries a selector from up.dom.config.fallbacks if options.fallback is missing', asyncSpec (next) ->
1022
- up.dom.config.fallbacks = ['.fallback']
1023
- $target = affix('.target').text('old target')
1024
- $fallback = affix('.fallback').text('old fallback')
1075
+ it 'tries a selector from up.fragment.config.fallbacks if options.fallback is missing', asyncSpec (next) ->
1076
+ up.fragment.config.fallbacks = ['.fallback']
1077
+ $target = $fixture('.target').text('old target')
1078
+ $fallback = $fixture('.fallback').text('old fallback')
1025
1079
  up.replace('.target', '/path')
1026
1080
 
1027
1081
  next =>
@@ -1031,13 +1085,13 @@ describe 'up.dom', ->
1031
1085
  expect('.target').toHaveText('old target')
1032
1086
  expect('.fallback').toHaveText('new fallback')
1033
1087
 
1034
- it 'does not try a selector from up.dom.config.fallbacks and rejects the promise if options.fallback is false', (done) ->
1035
- up.dom.config.fallbacks = ['.fallback']
1036
- $target = affix('.target').text('old target')
1037
- $fallback = affix('.fallback').text('old fallback')
1088
+ it 'does not try a selector from up.fragment.config.fallbacks and rejects the promise if options.fallback is false', (done) ->
1089
+ up.fragment.config.fallbacks = ['.fallback']
1090
+ $target = $fixture('.target').text('old target')
1091
+ $fallback = $fixture('.fallback').text('old fallback')
1038
1092
  promise = up.replace('.target', '/path', fallback: false)
1039
1093
 
1040
- u.nextFrame =>
1094
+ u.task =>
1041
1095
  @respondWith '<div class="fallback">new fallback</div>'
1042
1096
 
1043
1097
  promise.catch (e) ->
@@ -1082,7 +1136,7 @@ describe 'up.dom', ->
1082
1136
  promise = up.replace('.middle', '/path')
1083
1137
  @respond()
1084
1138
 
1085
- u.nextFrame ->
1139
+ u.task ->
1086
1140
  promiseState(promise).then (result) ->
1087
1141
  expect(result.state).toEqual('fulfilled')
1088
1142
  expect(window.scriptTagExecuted).not.toHaveBeenCalled()
@@ -1115,7 +1169,7 @@ describe 'up.dom', ->
1115
1169
 
1116
1170
  # Now wait for jQuery to parse out <script> tags and fetch the linked scripts.
1117
1171
  # This actually happens with jasmine_ajax's fake XHR object.
1118
- u.nextFrame =>
1172
+ u.task =>
1119
1173
  expect(jasmine.Ajax.requests.count()).toEqual(1)
1120
1174
  expect(@lastRequest().url).not.toContain('linked_script')
1121
1175
  expect(window.scriptTagExecuted).not.toHaveBeenCalled()
@@ -1137,7 +1191,7 @@ describe 'up.dom', ->
1137
1191
 
1138
1192
  promise.then ->
1139
1193
  $noscript = $('.middle noscript')
1140
- text = u.trim($noscript.text())
1194
+ text = $noscript.text().trim()
1141
1195
  expect(text).toEqual('<img src="foo.png">')
1142
1196
  done()
1143
1197
 
@@ -1156,7 +1210,7 @@ describe 'up.dom', ->
1156
1210
 
1157
1211
  promise.then ->
1158
1212
  $noscript = $('.middle noscript')
1159
- text = u.trim($noscript.text())
1213
+ text = $noscript.text().trim()
1160
1214
  expect(text).toMatch(/<img src="foo\.png">\s+<img src="bar\.png">/)
1161
1215
  done()
1162
1216
 
@@ -1178,8 +1232,8 @@ describe 'up.dom', ->
1178
1232
  promise.then ->
1179
1233
  $noscripts = $('.middle noscript')
1180
1234
  expect($noscripts.length).toBe(2)
1181
- text0 = u.trim($noscripts[0].textContent)
1182
- text1 = u.trim($noscripts[1].textContent)
1235
+ text0 = $noscripts[0].textContent.trim()
1236
+ text1 = $noscripts[1].textContent.trim()
1183
1237
  expect(text0).toEqual('<img src="foo.png">')
1184
1238
  expect(text1).toEqual('<img src="bar.png">')
1185
1239
  done()
@@ -1244,7 +1298,7 @@ describe 'up.dom', ->
1244
1298
 
1245
1299
  it 'restores the scroll positions of all viewports around the target', asyncSpec (next) ->
1246
1300
 
1247
- $viewport = affix('div[up-viewport] .element').css
1301
+ $viewport = $fixture('div[up-viewport] .element').css
1248
1302
  'height': '100px'
1249
1303
  'width': '100px'
1250
1304
  'overflow-y': 'scroll'
@@ -1275,9 +1329,9 @@ describe 'up.dom', ->
1275
1329
  @revealedText = []
1276
1330
  @revealOptions = {}
1277
1331
 
1278
- @revealMock = up.layout.knife.mock('reveal').and.callFake ($element, options) =>
1279
- @revealedHTML.push $element.get(0).outerHTML
1280
- @revealedText.push $element.text().trim()
1332
+ @revealMock = up.viewport.knife.mock('reveal').and.callFake (element, options) =>
1333
+ @revealedHTML.push element.outerHTML
1334
+ @revealedText.push element.textContent.trim()
1281
1335
  @revealOptions = options
1282
1336
  Promise.resolve()
1283
1337
 
@@ -1288,11 +1342,11 @@ describe 'up.dom', ->
1288
1342
  @respond()
1289
1343
 
1290
1344
  next =>
1291
- expect(@revealMock).not.toHaveBeenCalledWith(@oldMiddle)
1345
+ expect(@revealMock).not.toHaveBeenCalledWith(@$oldMiddle[0])
1292
1346
  expect(@revealedText).toEqual ['new-middle']
1293
1347
 
1294
1348
  it 'allows to pass another selector to reveal', asyncSpec (next)->
1295
- $other = affix('.other').text('other text')
1349
+ $other = $fixture('.other').text('other text')
1296
1350
 
1297
1351
  up.replace('.middle', '/path', reveal: '.other')
1298
1352
 
@@ -1303,7 +1357,7 @@ describe 'up.dom', ->
1303
1357
  expect(@revealedText).toEqual ['other text']
1304
1358
 
1305
1359
  it 'allows to refer to the replacement { origin } as "&" in the { reveal } selector', asyncSpec (next) ->
1306
- $origin = affix('.origin').text('origin text')
1360
+ $origin = $fixture('.origin').text('origin text')
1307
1361
 
1308
1362
  up.replace('.middle', '/path', reveal: '&', origin: '.origin')
1309
1363
 
@@ -1316,7 +1370,7 @@ describe 'up.dom', ->
1316
1370
  describe 'when the server responds with an error code', ->
1317
1371
 
1318
1372
  it 'ignores the { reveal } option', asyncSpec (next) ->
1319
- $failTarget = affix('.fail-target')
1373
+ $failTarget = $fixture('.fail-target')
1320
1374
  up.replace('.middle', '/path', failTarget: '.fail-target', reveal: true)
1321
1375
 
1322
1376
  next =>
@@ -1326,7 +1380,7 @@ describe 'up.dom', ->
1326
1380
  expect(@revealMock).not.toHaveBeenCalled()
1327
1381
 
1328
1382
  it 'accepts a { failReveal } option for error responses', asyncSpec (next) ->
1329
- $failTarget = affix('.fail-target').text('old fail target text')
1383
+ $failTarget = $fixture('.fail-target').text('old fail target text')
1330
1384
  up.replace('.middle', '/path', failTarget: '.fail-target', reveal: false, failReveal: true)
1331
1385
 
1332
1386
  next =>
@@ -1342,8 +1396,8 @@ describe 'up.dom', ->
1342
1396
  expect(@revealedText).toEqual ['new fail target text']
1343
1397
 
1344
1398
  it 'allows to refer to the replacement { origin } as "&" in the { failTarget } selector', asyncSpec (next) ->
1345
- $origin = affix('.origin').text('origin text')
1346
- $failTarget = affix('.fail-target').text('old fail target text')
1399
+ $origin = $fixture('.origin').text('origin text')
1400
+ $failTarget = $fixture('.fail-target').text('old fail target text')
1347
1401
  up.replace('.middle', '/path', failTarget: '.fail-target', reveal: false, failReveal: '&', origin: $origin)
1348
1402
 
1349
1403
  next =>
@@ -1367,7 +1421,7 @@ describe 'up.dom', ->
1367
1421
  @respond()
1368
1422
 
1369
1423
  next =>
1370
- expect(@revealMock).not.toHaveBeenCalledWith(@oldMiddle)
1424
+ expect(@revealMock).not.toHaveBeenCalledWith(@$oldMiddle[0])
1371
1425
  expect(@revealedText).toEqual ['new-middle']
1372
1426
 
1373
1427
  describe 'when there is an anchor #hash in the URL', ->
@@ -1473,26 +1527,26 @@ describe 'up.dom', ->
1473
1527
  promise = up.replace('.middle:after', '/path', reveal: true)
1474
1528
  @respond()
1475
1529
  promise.then =>
1476
- expect(@revealMock).not.toHaveBeenCalledWith(@oldMiddle)
1530
+ expect(@revealMock).not.toHaveBeenCalledWith(@$oldMiddle[0])
1477
1531
  # Text nodes are wrapped in a .up-insertion container so we can
1478
1532
  # animate them and measure their position/size for scrolling.
1479
1533
  # This is not possible for container-less text nodes.
1480
1534
  expect(@revealedHTML).toEqual ['<div class="up-insertion">new-middle</div>']
1481
1535
  # Show that the wrapper is done after the insertion.
1482
- expect($('.up-insertion')).not.toExist()
1536
+ expect($('.up-insertion')).not.toBeAttached()
1483
1537
  done()
1484
1538
 
1485
1539
  it 'reveals a new element that is being prepended', (done) ->
1486
1540
  promise = up.replace('.middle:before', '/path', reveal: true)
1487
1541
  @respond()
1488
1542
  promise.then =>
1489
- expect(@revealMock).not.toHaveBeenCalledWith(@oldMiddle)
1543
+ expect(@revealMock).not.toHaveBeenCalledWith(@$oldMiddle[0])
1490
1544
  # Text nodes are wrapped in a .up-insertion container so we can
1491
1545
  # animate them and measure their position/size for scrolling.
1492
1546
  # This is not possible for container-less text nodes.
1493
1547
  expect(@revealedHTML).toEqual ['<div class="up-insertion">new-middle</div>']
1494
1548
  # Show that the wrapper is done after the insertion.
1495
- expect($('.up-insertion')).not.toExist()
1549
+ expect($('.up-insertion')).not.toBeAttached()
1496
1550
  done()
1497
1551
 
1498
1552
  it 'uses a { failTransition } option if the request failed'
@@ -1510,9 +1564,9 @@ describe 'up.dom', ->
1510
1564
 
1511
1565
  it 'Updates a selector on the current page with the same selector from the given HTML string', asyncSpec (next) ->
1512
1566
 
1513
- affix('.before').text('old-before')
1514
- affix('.middle').text('old-middle')
1515
- affix('.after').text('old-after')
1567
+ $fixture('.before').text('old-before')
1568
+ $fixture('.middle').text('old-middle')
1569
+ $fixture('.after').text('old-after')
1516
1570
 
1517
1571
  html =
1518
1572
  """
@@ -1537,7 +1591,7 @@ describe 'up.dom', ->
1537
1591
  done()
1538
1592
 
1539
1593
  it "throws an error if the selector can't be found in the given HTML string", (done) ->
1540
- affix('.foo-bar')
1594
+ $fixture('.foo-bar')
1541
1595
  promise = up.extract('.foo-bar', '')
1542
1596
  promiseState(promise).then (result) =>
1543
1597
  expect(result.state).toEqual('rejected')
@@ -1546,7 +1600,7 @@ describe 'up.dom', ->
1546
1600
 
1547
1601
  it "ignores an element that matches the selector but also matches .up-destroying", (done) ->
1548
1602
  html = '<div class="foo-bar">text</div>'
1549
- affix('.foo-bar.up-destroying')
1603
+ $fixture('.foo-bar.up-destroying')
1550
1604
  promise = up.extract('.foo-bar', html)
1551
1605
  promiseState(promise).then (result) =>
1552
1606
  expect(result.state).toEqual('rejected')
@@ -1555,8 +1609,8 @@ describe 'up.dom', ->
1555
1609
 
1556
1610
  it "ignores an element that matches the selector but also has a parent matching .up-destroying", (done) ->
1557
1611
  html = '<div class="foo-bar">text</div>'
1558
- $parent = affix('.up-destroying')
1559
- $child = affix('.foo-bar').appendTo($parent)
1612
+ $parent = $fixture('.up-destroying')
1613
+ $child = $fixture('.foo-bar').appendTo($parent)
1560
1614
  promise = up.extract('.foo-bar', html)
1561
1615
  promiseState(promise).then (result) =>
1562
1616
  expect(result.state).toEqual('rejected')
@@ -1565,8 +1619,8 @@ describe 'up.dom', ->
1565
1619
 
1566
1620
  it 'only replaces the first element matching the selector', asyncSpec (next) ->
1567
1621
  html = '<div class="foo-bar">text</div>'
1568
- affix('.foo-bar')
1569
- affix('.foo-bar')
1622
+ $fixture('.foo-bar')
1623
+ $fixture('.foo-bar')
1570
1624
  up.extract('.foo-bar', html)
1571
1625
 
1572
1626
  next =>
@@ -1575,7 +1629,7 @@ describe 'up.dom', ->
1575
1629
  expect($($elements.get(1)).text()).toEqual('')
1576
1630
 
1577
1631
  it 'focuses an [autofocus] element in the new fragment', asyncSpec (next) ->
1578
- affix('.foo-bar')
1632
+ $fixture('.foo-bar')
1579
1633
  up.extract '.foo-bar', """
1580
1634
  <form class='foo-bar'>
1581
1635
  <input class="autofocused-input" autofocus>
@@ -1588,79 +1642,29 @@ describe 'up.dom', ->
1588
1642
  expect(document.activeElement).toBe(input)
1589
1643
 
1590
1644
 
1591
- it 'emits an up:fragment:destroy event while the element is still in the DOM', asyncSpec (next) ->
1592
- $element = affix('.element')
1593
- expect($element).toBeAttached()
1594
-
1595
- listener = jasmine.createSpy('event listener')
1596
- $element.on('up:fragment:destroy', listener)
1597
-
1598
- destroyDone = up.destroy($element, animation: 'fade-out', duration: 30)
1599
-
1600
- next ->
1601
- expect(listener).toHaveBeenCalledWith(jasmine.objectContaining($element: $element))
1602
- expect($element).toBeAttached()
1603
-
1604
- next.await(destroyDone)
1605
-
1606
- next ->
1607
- expect($element).toBeDetached()
1608
-
1609
- it 'emits an up:fragment:destroyed event on the former parent element after the element has been removed from the DOM', asyncSpec (next) ->
1610
- $parent = affix('.parent')
1611
- $element = $parent.affix('.element')
1612
- expect($element).toBeAttached()
1613
-
1614
- listener = jasmine.createSpy('event listener')
1615
-
1616
- $parent.on('up:fragment:destroyed', listener)
1617
-
1618
- destroyDone = up.destroy($element, animation: 'fade-out', duration: 30)
1619
-
1620
- next ->
1621
- expect(listener).not.toHaveBeenCalled()
1622
- expect($element).toBeAttached()
1623
-
1624
- next.await(destroyDone)
1625
-
1626
- next ->
1627
- expect(listener).toHaveBeenCalledWith(jasmine.objectContaining($element: $element, $parent: $parent))
1628
- expect($element).toBeDetached()
1629
-
1630
- it 'emits an up:fragment:destroy event while the element is still in the DOM', (done) ->
1631
- $element = affix('.element.v1').text('v1')
1632
- expect($element).toBeAttached()
1633
-
1634
- listener = jasmine.createSpy('event listener')
1635
- $element.on 'up:fragment:destroy', -> listener(u.isDetached($element))
1636
-
1637
- extractDone = up.extract('.element', '<div class="element v2">v2</div>')
1638
-
1639
- extractDone.then ->
1640
- expect(listener).toHaveBeenCalledWith(false)
1641
- done()
1642
-
1645
+ # up.extract
1643
1646
  it 'emits an up:fragment:destroyed event on the former parent element after the element has been removed from the DOM', (done) ->
1644
- $parent = affix('.parent')
1647
+ $parent = $fixture('.parent')
1645
1648
  $element = $parent.affix('.element.v1').text('v1')
1646
1649
  expect($element).toBeAttached()
1647
1650
 
1648
- listener = jasmine.createSpy('event listener')
1649
- $parent.on 'up:fragment:destroyed', -> listener(u.isDetached($element))
1651
+ spy = jasmine.createSpy('event listener')
1652
+ $parent[0].addEventListener 'up:fragment:destroyed', (event) ->
1653
+ spy(event.target, event.fragment, up.specUtil.isDetached($element))
1650
1654
 
1651
1655
  extractDone = up.extract('.element', '<div class="element v2">v2</div>')
1652
1656
 
1653
1657
  extractDone.then ->
1654
- expect(listener).toHaveBeenCalledWith(true)
1658
+ expect(spy).toHaveBeenCalledWith($parent[0], $element[0], true)
1655
1659
  done()
1656
1660
 
1657
1661
  describe 'cleaning up', ->
1658
1662
 
1659
1663
  it 'calls destructors on the old element', asyncSpec (next) ->
1660
1664
  destructor = jasmine.createSpy('destructor')
1661
- up.compiler '.container', ($element) ->
1665
+ up.$compiler '.container', ($element) ->
1662
1666
  -> destructor($element.text())
1663
- $container = affix('.container').text('old text')
1667
+ $container = $fixture('.container').text('old text')
1664
1668
  up.hello($container)
1665
1669
  up.extract('.container', '<div class="container">new text</div>')
1666
1670
 
@@ -1670,27 +1674,27 @@ describe 'up.dom', ->
1670
1674
 
1671
1675
  it 'calls destructors on the old element after a { transition }', (done) ->
1672
1676
  destructor = jasmine.createSpy('destructor')
1673
- up.compiler '.container', ($element) ->
1677
+ up.$compiler '.container', ($element) ->
1674
1678
  -> destructor($element.text())
1675
- $container = affix('.container').text('old text')
1679
+ $container = $fixture('.container').text('old text')
1676
1680
  up.hello($container)
1677
1681
 
1678
1682
  up.extract('.container', '<div class="container">new text</div>', transition: 'cross-fade', duration: 100)
1679
1683
 
1680
- u.setTimer 50, =>
1684
+ u.timer 50, =>
1681
1685
  expect(destructor).not.toHaveBeenCalled()
1682
1686
 
1683
- u.setTimer 220, =>
1687
+ u.timer 220, =>
1684
1688
  expect('.container').toHaveText('new text')
1685
1689
  expect(destructor).toHaveBeenCalledWith('old text')
1686
1690
  done()
1687
1691
 
1688
1692
  it 'calls destructors when the replaced element is a singleton element like <body> (bugfix)', asyncSpec (next) ->
1689
1693
  # shouldSwapElementsDirectly() is true for body, but can't have the example replace the Jasmine test runner UI
1690
- up.util.knife.mock('isSingletonElement').and.callFake ($element) -> $element.is('.container')
1694
+ up.element.knife.mock('isSingleton').and.callFake (element) -> e.matches(element, '.container')
1691
1695
  destructor = jasmine.createSpy('destructor')
1692
- up.compiler '.container', -> destructor
1693
- $container = affix('.container')
1696
+ up.$compiler '.container', -> destructor
1697
+ $container = $fixture('.container')
1694
1698
  up.hello($container)
1695
1699
  up.extract('.container', '<div class="container">new text</div>')
1696
1700
 
@@ -1700,9 +1704,9 @@ describe 'up.dom', ->
1700
1704
 
1701
1705
  it 'marks the old element as .up-destroying before destructors', (done) ->
1702
1706
  destructor = jasmine.createSpy('destructor')
1703
- up.compiler '.container', ($element) ->
1707
+ up.$compiler '.container', ($element) ->
1704
1708
  -> destructor($element.text(), $element.is('.up-destroying'))
1705
- $container = affix('.container').text('old text')
1709
+ $container = $fixture('.container').text('old text')
1706
1710
  up.hello($container)
1707
1711
 
1708
1712
  extractDone = up.extract('.container', '<div class="container">new text</div>')
@@ -1714,9 +1718,9 @@ describe 'up.dom', ->
1714
1718
 
1715
1719
  it 'marks the old element as .up-destroying before destructors after a { transition }', (done) ->
1716
1720
  destructor = jasmine.createSpy('destructor')
1717
- up.compiler '.container', ($element) ->
1721
+ up.$compiler '.container', ($element) ->
1718
1722
  -> destructor($element.text(), $element.is('.up-destroying'))
1719
- $container = affix('.container').text('old text')
1723
+ $container = $fixture('.container').text('old text')
1720
1724
  up.hello($container)
1721
1725
 
1722
1726
  extractDone = up.extract('.container', '<div class="container">new text</div>', transition: 'cross-fade', duration: 100)
@@ -1728,10 +1732,10 @@ describe 'up.dom', ->
1728
1732
 
1729
1733
  it 'calls destructors while the element is still attached to the DOM, so destructors see ancestry and events bubble up', asyncSpec (next) ->
1730
1734
  spy = jasmine.createSpy('parent spy')
1731
- up.compiler '.element', ($element) ->
1735
+ up.$compiler '.element', ($element) ->
1732
1736
  return -> spy($element.text(), $element.parent())
1733
1737
 
1734
- $parent = affix('.parent')
1738
+ $parent = $fixture('.parent')
1735
1739
  $element = $parent.affix('.element').text('old text')
1736
1740
  up.hello($element)
1737
1741
 
@@ -1742,12 +1746,12 @@ describe 'up.dom', ->
1742
1746
 
1743
1747
  it 'calls destructors while the element is still attached to the DOM when also using a { transition }', (done) ->
1744
1748
  spy = jasmine.createSpy('parent spy')
1745
- up.compiler '.element', ($element) ->
1749
+ up.$compiler '.element', ($element) ->
1746
1750
  return ->
1747
1751
  # We must seek .parent in our ancestry, because our direct parent() is an .up-bounds container
1748
1752
  spy($element.text(), $element.closest('.parent'))
1749
1753
 
1750
- $parent = affix('.parent')
1754
+ $parent = $fixture('.parent')
1751
1755
  $element = $parent.affix('.element').text('old text')
1752
1756
  up.hello($element)
1753
1757
 
@@ -1761,7 +1765,7 @@ describe 'up.dom', ->
1761
1765
  describe 'with { transition } option', ->
1762
1766
 
1763
1767
  it 'morphs between the old and new element', asyncSpec (next) ->
1764
- affix('.element.v1').text('version 1')
1768
+ $fixture('.element.v1').text('version 1')
1765
1769
  up.extract('.element', '<div class="element v2">version 2</div>', transition: 'cross-fade', duration: 200, easing: 'linear')
1766
1770
 
1767
1771
  $old = undefined
@@ -1772,38 +1776,38 @@ describe 'up.dom', ->
1772
1776
  $new = $('.element.v2')
1773
1777
 
1774
1778
  expect($old).toHaveLength(1)
1775
- expect(u.opacity($old)).toBeAround(1.0, 0.15)
1779
+ expect($old).toHaveOpacity(1.0, 0.15)
1776
1780
 
1777
1781
  expect($new).toHaveLength(1)
1778
- expect(u.opacity($new)).toBeAround(0.0, 0.15)
1782
+ expect($new).toHaveOpacity(0.0, 0.15)
1779
1783
 
1780
1784
  next.after 100, =>
1781
- expect(u.opacity($old)).toBeAround(0.5, 0.3)
1782
- expect(u.opacity($new)).toBeAround(0.5, 0.3)
1785
+ expect($old).toHaveOpacity(0.5, 0.3)
1786
+ expect($new).toHaveOpacity(0.5, 0.3)
1783
1787
 
1784
1788
  next.after (100 + 70), =>
1785
- expect(u.opacity($new)).toBeAround(1.0, 0.1)
1789
+ expect($new).toHaveOpacity(1.0, 0.1)
1786
1790
  expect($old).toBeDetached()
1787
1791
 
1788
1792
 
1789
- it 'ignores a { transition } option when replacing a singleton element like <body>', asyncSpec (next) ->
1790
- # shouldSwapElementsDirectly() is true for body, but can't have the example replace the Jasmine test runner UI
1791
- up.util.knife.mock('isSingletonElement').and.callFake ($element) -> $element.is('.container')
1793
+ it 'ignores a { transition } option when replacing a singleton element like <body>', asyncSpec (next) ->
1794
+ # shouldSwapElementsDirectly() is true for body, but can't have the example replace the Jasmine test runner UI
1795
+ spyOn(up.element, 'isSingleton').and.callFake (element) -> e.matches(element, '.container')
1792
1796
 
1793
- affix('.container').text('old text')
1797
+ $fixture('.container').text('old text')
1794
1798
 
1795
- extractDone = jasmine.createSpy()
1796
- promise = up.extract('.container', '<div class="container">new text</div>', transition: 'cross-fade', duration: 200)
1797
- promise.then(extractDone)
1799
+ extractDone = jasmine.createSpy()
1800
+ promise = up.extract('.container', '<div class="container">new text</div>', transition: 'cross-fade', duration: 200)
1801
+ promise.then(extractDone)
1798
1802
 
1799
- next =>
1800
- # See that we've already immediately swapped the element and ignored the duration of 200ms
1801
- expect(extractDone).toHaveBeenCalled()
1802
- expect($('.container').length).toEqual(1)
1803
- expect(u.opacity($('.container'))).toEqual(1.0)
1803
+ next =>
1804
+ # See that we've already immediately swapped the element and ignored the duration of 200ms
1805
+ expect(extractDone).toHaveBeenCalled()
1806
+ expect($('.container').length).toEqual(1)
1807
+ expect($('.container')).toHaveOpacity(1.0)
1804
1808
 
1805
1809
  it 'marks the old fragment as .up-destroying during the transition', asyncSpec (next) ->
1806
- affix('.element').text('version 1')
1810
+ $fixture('.element').text('version 1')
1807
1811
  up.extract('.element', '<div class="element">version 2</div>', transition: 'cross-fade', duration: 200)
1808
1812
 
1809
1813
  next =>
@@ -1815,36 +1819,25 @@ describe 'up.dom', ->
1815
1819
  expect($version2).toHaveLength(1)
1816
1820
  expect($version2).not.toHaveClass('up-destroying')
1817
1821
 
1818
- it 'emits an up:fragment:destroy event while the old element is still in the DOM', (done) ->
1819
- $element = affix('.element.v1').text('v1')
1820
- expect($element).toBeAttached()
1821
-
1822
- listener = jasmine.createSpy('event listener')
1823
- $element.on 'up:fragment:destroy', -> listener(u.isDetached($element))
1824
-
1825
- extractDone = up.extract('.element', '<div class="element v2">v2</div>', transition: 'cross-fade', duration: 50)
1826
-
1827
- extractDone.then ->
1828
- expect(listener).toHaveBeenCalledWith(false)
1829
- done()
1830
-
1822
+ # extract with { transition } option
1831
1823
  it 'emits an up:fragment:destroyed event on the former parent element after the element has been removed from the DOM', (done) ->
1832
- $parent = affix('.parent')
1824
+ $parent = $fixture('.parent')
1833
1825
  $element = $parent.affix('.element.v1').text('v1')
1834
1826
  expect($element).toBeAttached()
1835
1827
 
1836
- listener = jasmine.createSpy('event listener')
1837
- $parent.on 'up:fragment:destroyed', -> listener(u.isDetached($element))
1828
+ spy = jasmine.createSpy('event listener')
1829
+ $parent[0].addEventListener 'up:fragment:destroyed', (event) ->
1830
+ spy(event.target, event.fragment, up.specUtil.isDetached($element))
1838
1831
 
1839
1832
  extractDone = up.extract('.element', '<div class="element v2">v2</div>', transition: 'cross-fade', duration: 50)
1840
1833
 
1841
1834
  extractDone.then ->
1842
- expect(listener).toHaveBeenCalledWith(true)
1835
+ expect(spy).toHaveBeenCalledWith($parent[0], $element[0], true)
1843
1836
  done()
1844
1837
 
1845
1838
 
1846
1839
  it 'cancels an existing transition by instantly jumping to the last frame', asyncSpec (next) ->
1847
- affix('.element.v1').text('version 1')
1840
+ $fixture('.element.v1').text('version 1')
1848
1841
 
1849
1842
  up.extract('.element', '<div class="element v2">version 2</div>', transition: 'cross-fade', duration: 200)
1850
1843
 
@@ -1874,24 +1867,24 @@ describe 'up.dom', ->
1874
1867
 
1875
1868
 
1876
1869
  it 'delays the resolution of the returned promise until the transition is over', (done) ->
1877
- affix('.element').text('version 1')
1870
+ $fixture('.element').text('version 1')
1878
1871
  resolution = jasmine.createSpy()
1879
1872
  promise = up.extract('.element', '<div class="element">version 2</div>', transition: 'cross-fade', duration: 60)
1880
1873
  promise.then(resolution)
1881
1874
  expect(resolution).not.toHaveBeenCalled()
1882
1875
 
1883
- u.setTimer 20, ->
1876
+ u.timer 20, ->
1884
1877
  expect(resolution).not.toHaveBeenCalled()
1885
1878
 
1886
- u.setTimer 200, ->
1879
+ u.timer 200, ->
1887
1880
  expect(resolution).toHaveBeenCalled()
1888
1881
  done()
1889
1882
 
1890
1883
  it 'attaches the new element to the DOM before compilers are called, so they can see their parents and trigger bubbling events', asyncSpec (next)->
1891
- $parent = affix('.parent')
1884
+ $parent = $fixture('.parent')
1892
1885
  $element = $parent.affix('.element').text('old text')
1893
1886
  spy = jasmine.createSpy('parent spy')
1894
- up.compiler '.element', ($element) -> spy($element.text(), $element.parent())
1887
+ up.$compiler '.element', ($element) -> spy($element.text(), $element.parent())
1895
1888
  up.extract '.element', '<div class="element">new text</div>', transition: 'cross-fade', duration: 50
1896
1889
 
1897
1890
  next =>
@@ -1901,13 +1894,11 @@ describe 'up.dom', ->
1901
1894
  describe 'when up.morph() is called from a transition function', ->
1902
1895
 
1903
1896
  it "does not emit multiple replacement events (bugfix)", (done) ->
1904
- $element = affix('.element').text('old content')
1897
+ $element = $fixture('.element').text('old content')
1905
1898
 
1906
- transition = ($old, $new, options) ->
1907
- up.morph($old, $new, 'cross-fade', options)
1899
+ transition = (oldElement, newElement, options) ->
1900
+ up.morph(oldElement, newElement, 'cross-fade', options)
1908
1901
 
1909
- destroyListener = jasmine.createSpy('listener to up:fragment:destroy')
1910
- up.on 'up:fragment:destroy', destroyListener
1911
1902
  destroyedListener = jasmine.createSpy('listener to up:fragment:destroyed')
1912
1903
  up.on 'up:fragment:destroyed', destroyedListener
1913
1904
  insertedListener = jasmine.createSpy('listener to up:fragment:inserted')
@@ -1916,19 +1907,18 @@ describe 'up.dom', ->
1916
1907
  extractDone = up.extract('.element', '<div class="element">new content</div>', transition: transition, duration: 50, easing: 'linear')
1917
1908
 
1918
1909
  extractDone.then ->
1919
- expect(destroyListener.calls.count()).toBe(1)
1920
1910
  expect(destroyedListener.calls.count()).toBe(1)
1921
1911
  expect(insertedListener.calls.count()).toBe(1)
1922
1912
  done()
1923
1913
 
1924
1914
  it "does not compile the element multiple times (bugfix)", (done) ->
1925
- $element = affix('.element').text('old content')
1915
+ $element = $fixture('.element').text('old content')
1926
1916
 
1927
- transition = ($old, $new, options) ->
1928
- up.morph($old, $new, 'cross-fade', options)
1917
+ transition = (oldElement, newElement, options) ->
1918
+ up.morph(oldElement, newElement, 'cross-fade', options)
1929
1919
 
1930
1920
  compiler = jasmine.createSpy('compiler')
1931
- up.compiler '.element', compiler
1921
+ up.$compiler '.element', compiler
1932
1922
 
1933
1923
  extractDone = up.extract('.element', '<div class="element">new content</div>', transition: transition, duration: 50, easing: 'linear')
1934
1924
 
@@ -1937,13 +1927,13 @@ describe 'up.dom', ->
1937
1927
  done()
1938
1928
 
1939
1929
  it "does not call destructors multiple times (bugfix)", (done) ->
1940
- $element = affix('.element').text('old content')
1930
+ $element = $fixture('.element').text('old content')
1941
1931
 
1942
- transition = ($old, $new, options) ->
1943
- up.morph($old, $new, 'cross-fade', options)
1932
+ transition = (oldElement, newElement, options) ->
1933
+ up.morph(oldElement, newElement, 'cross-fade', options)
1944
1934
 
1945
1935
  destructor = jasmine.createSpy('destructor')
1946
- up.compiler '.element', (element) ->
1936
+ up.$compiler '.element', (element) ->
1947
1937
  return destructor
1948
1938
 
1949
1939
  up.hello($element)
@@ -1961,7 +1951,7 @@ describe 'up.dom', ->
1961
1951
  up.motion.config.enabled = false
1962
1952
 
1963
1953
  it 'immediately swaps the old and new elements without creating unnecessary ghosts', asyncSpec (next) ->
1964
- affix('.element').text('version 1')
1954
+ $fixture('.element').text('version 1')
1965
1955
  up.extract('.element', '<div class="element">version 2</div>', transition: 'cross-fade', duration: 200)
1966
1956
  next =>
1967
1957
  expect($('.element')).toHaveText('version 2')
@@ -1969,7 +1959,7 @@ describe 'up.dom', ->
1969
1959
 
1970
1960
  it "replaces the elements directly, since first inserting and then removing would shift scroll positions", asyncSpec (next) ->
1971
1961
  swapDirectlySpy = up.motion.knife.mock('swapElementsDirectly')
1972
- affix('.element').text('version 1')
1962
+ $fixture('.element').text('version 1')
1973
1963
  up.extract('.element', '<div class="element">version 2</div>', transition: false)
1974
1964
 
1975
1965
  next =>
@@ -1989,7 +1979,7 @@ describe 'up.dom', ->
1989
1979
  $('.before, .middle, .after').remove()
1990
1980
 
1991
1981
  it 'keeps an [up-keep] element, but does replace other elements around it', asyncSpec (next) ->
1992
- $container = affix('.container')
1982
+ $container = $fixture('.container')
1993
1983
  $container.affix('.before').text('old-before')
1994
1984
  $container.affix('.middle[up-keep]').text('old-middle')
1995
1985
  $container.affix('.after').text('old-after')
@@ -2008,7 +1998,7 @@ describe 'up.dom', ->
2008
1998
  expect($('.after')).toHaveText('new-after')
2009
1999
 
2010
2000
  it 'keeps an [up-keep] element, but does replace text nodes around it', asyncSpec (next) ->
2011
- $container = affix('.container')
2001
+ $container = $fixture('.container')
2012
2002
  $container.html """
2013
2003
  old-before
2014
2004
  <div class='element' up-keep>old-inside</div>
@@ -2027,7 +2017,7 @@ describe 'up.dom', ->
2027
2017
  expect(squish($('.container').text())).toEqual('new-before old-inside new-after')
2028
2018
 
2029
2019
  it 'updates an [up-keep] element with { keep: false } option', asyncSpec (next) ->
2030
- $container = affix('.container')
2020
+ $container = $fixture('.container')
2031
2021
  $container.html """
2032
2022
  old-before
2033
2023
  <div class='element' up-keep>old-inside</div>
@@ -2049,7 +2039,7 @@ describe 'up.dom', ->
2049
2039
  describe 'if an [up-keep] element is itself a direct replacement target', ->
2050
2040
 
2051
2041
  it "keeps that element", asyncSpec (next) ->
2052
- affix('.keeper[up-keep]').text('old-inside')
2042
+ $fixture('.keeper[up-keep]').text('old-inside')
2053
2043
  up.extract '.keeper', "<div class='keeper' up-keep>new-inside</div>"
2054
2044
 
2055
2045
  next =>
@@ -2059,23 +2049,27 @@ describe 'up.dom', ->
2059
2049
  insertedListener = jasmine.createSpy('subscriber to up:fragment:inserted')
2060
2050
  keptListener = jasmine.createSpy('subscriber to up:fragment:kept')
2061
2051
  up.on('up:fragment:kept', keptListener)
2062
- up.on 'up:fragment:inserted', insertedListener
2063
- $keeper = affix('.keeper[up-keep]').text('old-inside')
2064
- up.extract '.keeper', "<div class='keeper' up-keep>new-inside</div>"
2052
+ up.on('up:fragment:inserted', insertedListener)
2053
+ $keeper = $fixture('.keeper[up-keep]').text('old-inside')
2054
+ up.extract '.keeper', "<div class='keeper new' up-keep>new-inside</div>"
2065
2055
 
2066
2056
  next =>
2067
2057
  expect(insertedListener).not.toHaveBeenCalled()
2068
- expect(keptListener).toHaveBeenCalledWith(jasmine.anything(), $('.keeper'), jasmine.anything())
2058
+ expect(keptListener).toHaveBeenCalledWith(
2059
+ jasmine.objectContaining(newFragment: jasmine.objectContaining(className: 'keeper new')),
2060
+ $keeper[0],
2061
+ jasmine.anything()
2062
+ )
2069
2063
 
2070
2064
  it "removes an [up-keep] element if no matching element is found in the response", asyncSpec (next) ->
2071
2065
  barCompiler = jasmine.createSpy()
2072
2066
  barDestructor = jasmine.createSpy()
2073
- up.compiler '.bar', ($bar) ->
2067
+ up.$compiler '.bar', ($bar) ->
2074
2068
  text = $bar.text()
2075
2069
  barCompiler(text)
2076
2070
  return -> barDestructor(text)
2077
2071
 
2078
- $container = affix('.container')
2072
+ $container = $fixture('.container')
2079
2073
  $container.html """
2080
2074
  <div class='foo'>old-foo</div>
2081
2075
  <div class='bar' up-keep>old-bar</div>
@@ -2092,8 +2086,8 @@ describe 'up.dom', ->
2092
2086
  """
2093
2087
 
2094
2088
  next =>
2095
- expect($('.container .foo')).toExist()
2096
- expect($('.container .bar')).not.toExist()
2089
+ expect($('.container .foo')).toBeAttached()
2090
+ expect($('.container .bar')).not.toBeAttached()
2097
2091
 
2098
2092
  expect(barCompiler.calls.allArgs()).toEqual [['old-bar']]
2099
2093
  expect(barDestructor.calls.allArgs()).toEqual [['old-bar']]
@@ -2101,12 +2095,12 @@ describe 'up.dom', ->
2101
2095
  it "updates an element if a matching element is found in the response, but that other element is no longer [up-keep]", asyncSpec (next) ->
2102
2096
  barCompiler = jasmine.createSpy()
2103
2097
  barDestructor = jasmine.createSpy()
2104
- up.compiler '.bar', ($bar) ->
2098
+ up.$compiler '.bar', ($bar) ->
2105
2099
  text = $bar.text()
2106
2100
  barCompiler(text)
2107
2101
  return -> barDestructor(text)
2108
2102
 
2109
- $container = affix('.container')
2103
+ $container = $fixture('.container')
2110
2104
  $container.html """
2111
2105
  <div class='foo'>old-foo</div>
2112
2106
  <div class='bar' up-keep>old-bar</div>
@@ -2131,7 +2125,7 @@ describe 'up.dom', ->
2131
2125
  expect(barDestructor.calls.allArgs()).toEqual [['old-bar']]
2132
2126
 
2133
2127
  it 'moves a kept element to the ancestry position of the matching element in the response', asyncSpec (next) ->
2134
- $container = affix('.container')
2128
+ $container = $fixture('.container')
2135
2129
  $container.html """
2136
2130
  <div class="parent1">
2137
2131
  <div class="keeper" up-keep>old-inside</div>
@@ -2154,7 +2148,7 @@ describe 'up.dom', ->
2154
2148
  expect($('.keeper').parent()).toEqual($('.parent2'))
2155
2149
 
2156
2150
  it 'lets developers choose a selector to match against as the value of the up-keep attribute', asyncSpec (next) ->
2157
- $container = affix('.container')
2151
+ $container = $fixture('.container')
2158
2152
  $container.html """
2159
2153
  <div class="keeper" up-keep=".stayer"></div>
2160
2154
  """
@@ -2165,12 +2159,12 @@ describe 'up.dom', ->
2165
2159
  """
2166
2160
 
2167
2161
  next =>
2168
- expect('.keeper').toExist()
2162
+ expect('.keeper').toBeAttached()
2169
2163
 
2170
2164
  it 'does not compile a kept element a second time', asyncSpec (next) ->
2171
2165
  compiler = jasmine.createSpy('compiler')
2172
- up.compiler('.keeper', compiler)
2173
- $container = affix('.container')
2166
+ up.$compiler('.keeper', compiler)
2167
+ $container = $fixture('.container')
2174
2168
  $container.html """
2175
2169
  <div class="keeper" up-keep>old-text</div>
2176
2170
  """
@@ -2186,14 +2180,14 @@ describe 'up.dom', ->
2186
2180
 
2187
2181
  next =>
2188
2182
  expect(compiler.calls.count()).toEqual(1)
2189
- expect('.keeper').toExist()
2183
+ expect('.keeper').toBeAttached()
2190
2184
 
2191
2185
  it 'does not lose jQuery event handlers on a kept element (bugfix)', asyncSpec (next) ->
2192
2186
  handler = jasmine.createSpy('event handler')
2193
- up.compiler '.keeper', ($keeper) ->
2187
+ up.$compiler '.keeper', ($keeper) ->
2194
2188
  $keeper.on 'click', handler
2195
2189
 
2196
- $container = affix('.container')
2190
+ $container = $fixture('.container')
2197
2191
  $container.html """
2198
2192
  <div class="keeper" up-keep>old-text</div>
2199
2193
  """
@@ -2216,10 +2210,10 @@ describe 'up.dom', ->
2216
2210
 
2217
2211
  it 'does not call destructors on a kept alement', asyncSpec (next) ->
2218
2212
  destructor = jasmine.createSpy('destructor')
2219
- up.compiler '.keeper', ($keeper) ->
2213
+ up.$compiler '.keeper', ($keeper) ->
2220
2214
  return destructor
2221
2215
 
2222
- $container = affix('.container')
2216
+ $container = $fixture('.container')
2223
2217
  $container.html """
2224
2218
  <div class="keeper" up-keep>old-text</div>
2225
2219
  """
@@ -2239,10 +2233,10 @@ describe 'up.dom', ->
2239
2233
  it 'calls destructors when a kept element is eventually removed from the DOM', asyncSpec (next) ->
2240
2234
  handler = jasmine.createSpy('event handler')
2241
2235
  destructor = jasmine.createSpy('destructor')
2242
- up.compiler '.keeper', ($keeper) ->
2236
+ up.$compiler '.keeper', ($keeper) ->
2243
2237
  return destructor
2244
2238
 
2245
- $container = affix('.container')
2239
+ $container = $fixture('.container')
2246
2240
  $container.html """
2247
2241
  <div class="keeper" up-keep>old-text</div>
2248
2242
  """
@@ -2259,29 +2253,43 @@ describe 'up.dom', ->
2259
2253
  expect($keeper).toHaveText('new-text')
2260
2254
  expect(destructor).toHaveBeenCalled()
2261
2255
 
2256
+ it 'lets listeners inspect a new element before discarding through properties on an up:fragment:keep event', asyncSpec (next) ->
2257
+ $keeper = $fixture('.keeper[up-keep]').text('old-inside')
2258
+ listener = jasmine.createSpy('event listener')
2259
+ $keeper[0].addEventListener('up:fragment:keep', listener)
2260
+ up.extract '.keeper', "<div class='keeper new' up-keep up-data='{ \"key\": \"new-value\" }'>new-inside</div>"
2261
+ next =>
2262
+ expect(listener).toHaveBeenCalledWith(
2263
+ jasmine.objectContaining(
2264
+ newFragment: jasmine.objectContaining(className: 'keeper new')
2265
+ newData: { key: 'new-value' },
2266
+ target: $keeper[0]
2267
+ )
2268
+ )
2269
+
2262
2270
  it 'lets listeners cancel the keeping by preventing default on an up:fragment:keep event', asyncSpec (next) ->
2263
- $keeper = affix('.keeper[up-keep]').text('old-inside')
2271
+ $keeper = $fixture('.keeper[up-keep]').text('old-inside')
2264
2272
  $keeper.on 'up:fragment:keep', (event) -> event.preventDefault()
2265
2273
  up.extract '.keeper', "<div class='keeper' up-keep>new-inside</div>"
2266
2274
  next => expect($('.keeper')).toHaveText('new-inside')
2267
2275
 
2268
2276
  it 'lets listeners prevent up:fragment:keep event if the element was kept before (bugfix)', asyncSpec (next) ->
2269
- $keeper = affix('.keeper[up-keep]').text('version 1')
2270
- $keeper.on 'up:fragment:keep', (event) ->
2271
- event.preventDefault() if event.$newElement.text() == 'version 3'
2277
+ $keeper = $fixture('.keeper[up-keep]').text('version 1')
2278
+ $keeper[0].addEventListener 'up:fragment:keep', (event) ->
2279
+ event.preventDefault() if event.newFragment.textContent.trim() == 'version 3'
2272
2280
 
2273
2281
  next => up.extract '.keeper', "<div class='keeper' up-keep>version 2</div>"
2274
2282
  next => expect($('.keeper')).toHaveText('version 1')
2275
2283
  next => up.extract '.keeper', "<div class='keeper' up-keep>version 3</div>"
2276
2284
  next => expect($('.keeper')).toHaveText('version 3')
2277
2285
 
2278
- it 'emits an up:fragment:kept event on a kept element and up:fragment:inserted on an updated parent', asyncSpec (next) ->
2286
+ it 'emits an up:fragment:kept event on a kept element and up:fragment:inserted on the targeted parent parent', asyncSpec (next) ->
2279
2287
  insertedListener = jasmine.createSpy()
2280
2288
  up.on('up:fragment:inserted', insertedListener)
2281
2289
  keptListener = jasmine.createSpy()
2282
2290
  up.on('up:fragment:kept', keptListener)
2283
2291
 
2284
- $container = affix('.container')
2292
+ $container = $fixture('.container')
2285
2293
  $container.html """
2286
2294
  <div class="keeper" up-keep></div>
2287
2295
  """
@@ -2293,13 +2301,13 @@ describe 'up.dom', ->
2293
2301
  """
2294
2302
 
2295
2303
  next =>
2296
- expect(insertedListener).toHaveBeenCalledWith(jasmine.anything(), $('.container'), jasmine.anything())
2297
- expect(keptListener).toHaveBeenCalledWith(jasmine.anything(), $('.container .keeper'), jasmine.anything())
2304
+ expect(insertedListener).toHaveBeenCalledWith(jasmine.anything(), $('.container')[0], jasmine.anything())
2305
+ expect(keptListener).toHaveBeenCalledWith(jasmine.anything(), $('.container .keeper')[0], jasmine.anything())
2298
2306
 
2299
2307
  it 'emits an up:fragment:kept event on a kept element with a newData property corresponding to the up-data attribute value of the discarded element', asyncSpec (next) ->
2300
2308
  keptListener = jasmine.createSpy()
2301
- up.on 'up:fragment:kept', (event) -> keptListener(event.$element, event.newData)
2302
- $container = affix('.container')
2309
+ up.on 'up:fragment:kept', (event) -> keptListener(event.target, event.newData)
2310
+ $container = $fixture('.container')
2303
2311
  $keeper = $container.affix('.keeper[up-keep]').text('old-inside')
2304
2312
 
2305
2313
  up.extract '.container', """
@@ -2310,12 +2318,12 @@ describe 'up.dom', ->
2310
2318
 
2311
2319
  next =>
2312
2320
  expect($('.keeper')).toHaveText('old-inside')
2313
- expect(keptListener).toHaveBeenCalledWith($keeper, { 'foo': 'bar' })
2321
+ expect(keptListener).toHaveBeenCalledWith($keeper[0], { 'foo': 'bar' })
2314
2322
 
2315
2323
  it 'emits an up:fragment:kept with { newData: {} } if the discarded element had no up-data value', asyncSpec (next) ->
2316
2324
  keptListener = jasmine.createSpy()
2317
2325
  up.on('up:fragment:kept', keptListener)
2318
- $container = affix('.container')
2326
+ $container = $fixture('.container')
2319
2327
  $keeper = $container.affix('.keeper[up-keep]').text('old-inside')
2320
2328
  up.extract '.keeper', """
2321
2329
  <div class='container'>
@@ -2329,8 +2337,8 @@ describe 'up.dom', ->
2329
2337
 
2330
2338
  it 'reuses the same element and emits up:fragment:kept during multiple extractions', asyncSpec (next) ->
2331
2339
  keptListener = jasmine.createSpy()
2332
- up.on 'up:fragment:kept', (event) -> keptListener(event.$element, event.newData)
2333
- $container = affix('.container')
2340
+ up.on 'up:fragment:kept', (event) -> keptListener(event.target, event.newData)
2341
+ $container = $fixture('.container')
2334
2342
  $keeper = $container.affix('.keeper[up-keep]').text('old-inside')
2335
2343
 
2336
2344
  next =>
@@ -2349,17 +2357,17 @@ describe 'up.dom', ->
2349
2357
  next =>
2350
2358
  $keeper = $('.keeper')
2351
2359
  expect($keeper).toHaveText('old-inside')
2352
- expect(keptListener).toHaveBeenCalledWith($keeper, { key: 'value1' })
2353
- expect(keptListener).toHaveBeenCalledWith($keeper, { key: 'value2' })
2360
+ expect(keptListener).toHaveBeenCalledWith($keeper[0], { key: 'value1' })
2361
+ expect(keptListener).toHaveBeenCalledWith($keeper[0], { key: 'value2' })
2354
2362
 
2355
2363
  it "doesn't let the discarded element appear in a transition", (done) ->
2356
2364
  oldTextDuringTransition = undefined
2357
2365
  newTextDuringTransition = undefined
2358
- transition = ($old, $new) ->
2359
- oldTextDuringTransition = squish($old.text())
2360
- newTextDuringTransition = squish($new.text())
2366
+ transition = (oldElement, newElement) ->
2367
+ oldTextDuringTransition = squish(oldElement.innerText)
2368
+ newTextDuringTransition = squish(newElement.innerText)
2361
2369
  Promise.resolve()
2362
- $container = affix('.container')
2370
+ $container = $fixture('.container')
2363
2371
  $container.html """
2364
2372
  <div class='foo'>old-foo</div>
2365
2373
  <div class='bar' up-keep>old-bar</div>
@@ -2381,13 +2389,13 @@ describe 'up.dom', ->
2381
2389
  describe 'up.destroy', ->
2382
2390
 
2383
2391
  it 'removes the element with the given selector', (done) ->
2384
- affix('.element')
2392
+ $fixture('.element')
2385
2393
  up.destroy('.element').then ->
2386
- expect($('.element')).not.toExist()
2394
+ expect($('.element')).not.toBeAttached()
2387
2395
  done()
2388
2396
 
2389
2397
  it 'runs an animation before removal with { animate } option', asyncSpec (next) ->
2390
- $element = affix('.element')
2398
+ $element = $fixture('.element')
2391
2399
  up.destroy($element, animation: 'fade-out', duration: 200, easing: 'linear')
2392
2400
 
2393
2401
  next ->
@@ -2400,18 +2408,18 @@ describe 'up.dom', ->
2400
2408
  expect($element).toBeDetached()
2401
2409
 
2402
2410
  it 'calls destructors for custom elements', (done) ->
2403
- up.compiler('.element', ($element) -> destructor)
2411
+ up.$compiler('.element', ($element) -> destructor)
2404
2412
  destructor = jasmine.createSpy('destructor')
2405
- up.hello(affix('.element'))
2413
+ up.hello(fixture('.element'))
2406
2414
  up.destroy('.element').then ->
2407
2415
  expect(destructor).toHaveBeenCalled()
2408
2416
  done()
2409
2417
 
2410
2418
  it 'marks the old element as .up-destroying before destructors', (done) ->
2411
2419
  destructor = jasmine.createSpy('destructor')
2412
- up.compiler '.container', ($element) ->
2420
+ up.$compiler '.container', ($element) ->
2413
2421
  -> destructor($element.text(), $element.is('.up-destroying'))
2414
- $container = affix('.container').text('old text')
2422
+ $container = $fixture('.container').text('old text')
2415
2423
  up.hello($container)
2416
2424
 
2417
2425
  destroyDone = up.destroy('.container')
@@ -2422,9 +2430,9 @@ describe 'up.dom', ->
2422
2430
 
2423
2431
  it 'marks the old element as .up-destroying before destructors after an { animation }', (done) ->
2424
2432
  destructor = jasmine.createSpy('destructor')
2425
- up.compiler '.container', ($element) ->
2433
+ up.$compiler '.container', ($element) ->
2426
2434
  -> destructor($element.text(), $element.is('.up-destroying'))
2427
- $container = affix('.container').text('old text')
2435
+ $container = $fixture('.container').text('old text')
2428
2436
  up.hello($container)
2429
2437
 
2430
2438
  destroyDone = up.destroy('.container', animation: 'fade-out', duration: 100)
@@ -2435,68 +2443,53 @@ describe 'up.dom', ->
2435
2443
 
2436
2444
  it 'waits until an { animation } is done before calling destructors', asyncSpec (next) ->
2437
2445
  destructor = jasmine.createSpy('destructor')
2438
- up.compiler '.container', ($element) ->
2446
+ up.$compiler '.container', ($element) ->
2439
2447
  -> destructor($element.text())
2440
- $container = affix('.container').text('old text')
2448
+ $container = $fixture('.container').text('old text')
2441
2449
  up.hello($container)
2442
2450
 
2443
- destroyDone = up.destroy('.container', animation: 'fade-out', duration: 100)
2451
+ destroyDone = up.destroy('.container', animation: 'fade-out', duration: 200)
2444
2452
 
2445
- next.after 50, ->
2453
+ next.after 100, ->
2446
2454
  expect(destructor).not.toHaveBeenCalled()
2447
2455
 
2448
- next.after (50 + (tolerance = 70)), ->
2456
+ next.await(destroyDone)
2457
+
2458
+ next ->
2449
2459
  expect(destructor).toHaveBeenCalledWith('old text',)
2450
2460
 
2451
2461
 
2452
2462
  it 'allows to pass a new history entry as { history } option', (done) ->
2453
2463
  up.history.config.enabled = true
2454
- affix('.element')
2464
+ $fixture('.element')
2455
2465
  up.destroy('.element', history: '/new-path').then ->
2456
- u.setTimer 100, ->
2466
+ u.timer 100, ->
2457
2467
  expect(location.href).toMatchUrl('/new-path')
2458
2468
  done()
2459
2469
 
2460
2470
  it 'allows to pass a new document title as { title } option', (done) ->
2461
2471
  up.history.config.enabled = true
2462
- affix('.element')
2472
+ $fixture('.element')
2463
2473
  up.destroy('.element', history: '/new-path', title: 'Title from options').then ->
2464
2474
  expect(document.title).toEqual('Title from options')
2465
2475
  done()
2466
2476
 
2467
2477
  it 'marks the element as .up-destroying while it is animating', asyncSpec (next) ->
2468
- $element = affix('.element')
2478
+ $element = $fixture('.element')
2469
2479
  up.destroy($element, animation: 'fade-out', duration: 80, easing: 'linear')
2470
2480
 
2471
2481
  next ->
2472
2482
  expect($element).toHaveClass('up-destroying')
2473
2483
 
2474
- it 'emits an up:fragment:destroy event while the element is still in the DOM', asyncSpec (next) ->
2475
- $element = affix('.element')
2476
- expect($element).toBeAttached()
2477
-
2478
- listener = jasmine.createSpy('event listener')
2479
- $element.on('up:fragment:destroy', listener)
2480
-
2481
- destroyDone = up.destroy($element, animation: 'fade-out', duration: 30)
2482
-
2483
- next ->
2484
- expect(listener).toHaveBeenCalledWith(jasmine.objectContaining($element: $element))
2485
- expect($element).toBeAttached()
2486
-
2487
- next.await(destroyDone)
2488
-
2489
- next ->
2490
- expect($element).toBeDetached()
2491
-
2484
+ # up.destroy
2492
2485
  it 'emits an up:fragment:destroyed event on the former parent element after the element has been removed from the DOM', asyncSpec (next) ->
2493
- $parent = affix('.parent')
2486
+ $parent = $fixture('.parent')
2494
2487
  $element = $parent.affix('.element')
2495
2488
  expect($element).toBeAttached()
2496
2489
 
2497
2490
  listener = jasmine.createSpy('event listener')
2498
2491
 
2499
- $parent.on('up:fragment:destroyed', listener)
2492
+ $parent[0].addEventListener('up:fragment:destroyed', listener)
2500
2493
 
2501
2494
  destroyDone = up.destroy($element, animation: 'fade-out', duration: 30)
2502
2495
 
@@ -2507,7 +2500,13 @@ describe 'up.dom', ->
2507
2500
  next.await(destroyDone)
2508
2501
 
2509
2502
  next ->
2510
- expect(listener).toHaveBeenCalledWith(jasmine.objectContaining($element: $element, $parent: $parent))
2503
+ expect(listener).toHaveBeenCalledWith(
2504
+ jasmine.objectContaining(
2505
+ target: $parent[0],
2506
+ parent: $parent[0]
2507
+ fragment: $element[0]
2508
+ )
2509
+ )
2511
2510
  expect($element).toBeDetached()
2512
2511
 
2513
2512
  describe 'up.reload', ->
@@ -2515,7 +2514,7 @@ describe 'up.dom', ->
2515
2514
  describeCapability 'canPushState', ->
2516
2515
 
2517
2516
  it 'reloads the given selector from the closest known source URL', asyncSpec (next) ->
2518
- affix('.container[up-source="/source"] .element').find('.element').text('old text')
2517
+ $fixture('.container[up-source="/source"] .element').find('.element').text('old text')
2519
2518
 
2520
2519
  next =>
2521
2520
  up.reload('.element')
@@ -2535,38 +2534,32 @@ describe 'up.dom', ->
2535
2534
  describeFallback 'canPushState', ->
2536
2535
 
2537
2536
  it 'makes a page load from the closest known source URL', asyncSpec (next) ->
2538
- affix('.container[up-source="/source"] .element').find('.element').text('old text')
2537
+ $fixture('.container[up-source="/source"] .element').find('.element').text('old text')
2539
2538
  spyOn(up.browser, 'navigate')
2540
2539
  up.reload('.element')
2541
2540
 
2542
2541
  next =>
2543
2542
  expect(up.browser.navigate).toHaveBeenCalledWith('/source', jasmine.anything())
2544
2543
 
2545
- describe 'up.dom.layerOf', ->
2544
+ describe 'up.fragment.layerOf', ->
2546
2545
 
2547
2546
  it 'returns "popup" for an element in a popup over the page', ->
2548
- $popup = affix('.up-popup')
2547
+ $popup = $fixture('.up-popup')
2549
2548
  $element = $popup.affix('.element')
2550
- expect(up.dom.layerOf($element)).toEqual('popup')
2549
+ expect(up.fragment.layerOf($element[0])).toEqual('popup')
2551
2550
 
2552
2551
  it 'returns "popup" for an element in a popup over a modal', ->
2553
- $modal = affix('.up-modal')
2552
+ $modal = $fixture('.up-modal')
2554
2553
  $popupInModal = $modal.affix('.up-popup')
2555
2554
  $element = $popupInModal.affix('.element')
2556
- expect(up.dom.layerOf($element)).toEqual('popup')
2555
+ expect(up.fragment.layerOf($element[0])).toEqual('popup')
2557
2556
 
2558
2557
  it 'returns "modal" for an element in a modal', ->
2559
- $modal = affix('.up-modal')
2558
+ $modal = $fixture('.up-modal')
2560
2559
  $element = $modal.affix('.element')
2561
- expect(up.dom.layerOf($element)).toEqual('modal')
2560
+ expect(up.fragment.layerOf($element[0])).toEqual('modal')
2562
2561
 
2563
2562
  it 'returns "page" for an element below a modal or popup', ->
2564
- $element = affix('.element')
2565
- expect(up.dom.layerOf($element)).toEqual('page')
2566
-
2567
- it 'returns undefined for an empty jQuery collection', ->
2568
- expect(up.dom.layerOf($())).toBeUndefined()
2569
-
2570
- it 'returns undefined for undefined', ->
2571
- expect(up.dom.layerOf(undefined)).toBeUndefined()
2563
+ $element = $fixture('.element')
2564
+ expect(up.fragment.layerOf($element[0])).toEqual('page')
2572
2565