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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +393 -1
- data/Gemfile.lock +5 -2
- data/README.md +1 -1
- data/README_RAILS.md +1 -1
- data/Rakefile +10 -1
- data/design/es6.js +32 -0
- data/design/ie11.txt +9 -0
- data/design/measure_jquery/element_list.js +41 -0
- data/design/measure_jquery/up.on_vs_addEventListener.js +56 -0
- data/design/todo_jquery.txt +13 -0
- data/dist/unpoly-bootstrap3.js +8 -8
- data/dist/unpoly-bootstrap3.min.js +1 -1
- data/dist/unpoly.css +22 -20
- data/dist/unpoly.js +6990 -5336
- data/dist/unpoly.min.css +1 -1
- data/dist/unpoly.min.js +4 -4
- data/lib/assets/javascripts/unpoly-bootstrap3/viewport-ext.coffee +5 -0
- data/lib/assets/javascripts/unpoly.coffee +8 -6
- data/lib/assets/javascripts/unpoly/browser.coffee.erb +23 -118
- data/lib/assets/javascripts/unpoly/classes/body_shifter.coffee +36 -0
- data/lib/assets/javascripts/unpoly/classes/cache.coffee +4 -4
- data/lib/assets/javascripts/unpoly/classes/compile_pass.coffee +45 -39
- data/lib/assets/javascripts/unpoly/classes/config.coffee +9 -0
- data/lib/assets/javascripts/unpoly/classes/css_transition.coffee +18 -27
- data/lib/assets/javascripts/unpoly/classes/divertible_chain.coffee +39 -0
- data/lib/assets/javascripts/unpoly/classes/event_listener.coffee +116 -0
- data/lib/assets/javascripts/unpoly/classes/extract_cascade.coffee +8 -8
- data/lib/assets/javascripts/unpoly/classes/extract_plan.coffee +19 -19
- data/lib/assets/javascripts/unpoly/classes/field_observer.coffee +54 -31
- data/lib/assets/javascripts/unpoly/classes/{focus_tracker.coffee → focus_follower.coffee} +2 -2
- data/lib/assets/javascripts/unpoly/classes/follow_variant.coffee +25 -25
- data/lib/assets/javascripts/unpoly/classes/html_parser.coffee +4 -11
- data/lib/assets/javascripts/unpoly/classes/motion_controller.coffee +157 -0
- data/lib/assets/javascripts/unpoly/classes/params.coffee.erb +525 -0
- data/lib/assets/javascripts/unpoly/classes/record.coffee +8 -2
- data/lib/assets/javascripts/unpoly/classes/rect.js +21 -0
- data/lib/assets/javascripts/unpoly/classes/request.coffee +41 -35
- data/lib/assets/javascripts/unpoly/classes/response.coffee +7 -3
- data/lib/assets/javascripts/unpoly/classes/reveal_motion.coffee +102 -0
- data/lib/assets/javascripts/unpoly/classes/scroll_motion.coffee +67 -0
- data/lib/assets/javascripts/unpoly/classes/selector.coffee +60 -0
- data/lib/assets/javascripts/unpoly/classes/tether.coffee +105 -0
- data/lib/assets/javascripts/unpoly/classes/url_set.coffee +12 -7
- data/lib/assets/javascripts/unpoly/element.coffee.erb +1126 -0
- data/lib/assets/javascripts/unpoly/event.coffee.erb +437 -0
- data/lib/assets/javascripts/unpoly/feedback.coffee +73 -94
- data/lib/assets/javascripts/unpoly/form.coffee.erb +188 -181
- data/lib/assets/javascripts/unpoly/{dom.coffee.erb → fragment.coffee.erb} +250 -283
- data/lib/assets/javascripts/unpoly/framework.coffee +67 -0
- data/lib/assets/javascripts/unpoly/history.coffee +29 -28
- data/lib/assets/javascripts/unpoly/legacy.coffee +60 -0
- data/lib/assets/javascripts/unpoly/link.coffee.erb +127 -119
- data/lib/assets/javascripts/unpoly/log.coffee +99 -19
- data/lib/assets/javascripts/unpoly/modal.coffee.erb +95 -118
- data/lib/assets/javascripts/unpoly/motion.coffee.erb +158 -138
- data/lib/assets/javascripts/unpoly/namespace.coffee.erb +0 -5
- data/lib/assets/javascripts/unpoly/popup.coffee.erb +119 -102
- data/lib/assets/javascripts/unpoly/protocol.coffee +11 -15
- data/lib/assets/javascripts/unpoly/proxy.coffee +62 -65
- data/lib/assets/javascripts/unpoly/radio.coffee +3 -5
- data/lib/assets/javascripts/unpoly/rails.coffee +8 -9
- data/lib/assets/javascripts/unpoly/syntax.coffee.erb +173 -125
- data/lib/assets/javascripts/unpoly/toast.coffee +25 -24
- data/lib/assets/javascripts/unpoly/tooltip.coffee +89 -79
- data/lib/assets/javascripts/unpoly/util.coffee.erb +579 -1074
- data/lib/assets/javascripts/unpoly/{layout.coffee.erb → viewport.coffee.erb} +334 -264
- data/lib/assets/stylesheets/unpoly/dom.sass +1 -1
- data/lib/assets/stylesheets/unpoly/layout.sass +2 -0
- data/lib/assets/stylesheets/unpoly/popup.sass +0 -1
- data/lib/assets/stylesheets/unpoly/tooltip.sass +17 -12
- data/lib/unpoly/rails/version.rb +1 -1
- data/package.json +1 -2
- data/spec_app/Gemfile +2 -1
- data/spec_app/Gemfile.lock +38 -27
- data/spec_app/app/assets/javascripts/integration_test.coffee +1 -0
- data/spec_app/app/assets/javascripts/jasmine_specs.coffee +1 -2
- data/spec_app/app/assets/stylesheets/integration_test.sass +14 -1
- data/spec_app/app/controllers/scroll_test_controller.rb +5 -0
- data/spec_app/app/views/css_test/modal.erb +6 -6
- data/spec_app/app/views/css_test/popup.erb +44 -18
- data/spec_app/app/views/css_test/tooltip.erb +23 -4
- data/spec_app/app/views/error_test/trigger.erb +1 -1
- data/spec_app/app/views/form_test/basics/new.erb +1 -3
- data/spec_app/app/views/pages/start.erb +9 -2
- data/spec_app/app/views/reveal_test/long1.erb +1 -1
- data/spec_app/app/views/reveal_test/long2.erb +1 -1
- data/spec_app/app/views/reveal_test/within_document_viewport.erb +24 -0
- data/spec_app/app/views/reveal_test/within_overflowing_div_viewport.erb +28 -0
- data/spec_app/app/views/scroll_test/long1.erb +30 -0
- data/spec_app/config/routes.rb +1 -0
- data/spec_app/spec/javascripts/helpers/agent_detector.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/async_sequence.js.coffee +1 -0
- data/spec_app/spec/javascripts/helpers/browser_switches.js.coffee +17 -5
- data/spec_app/spec/javascripts/helpers/enable_logging.js.coffee +1 -1
- data/spec_app/spec/javascripts/helpers/fixture.js.coffee +25 -0
- data/spec_app/spec/javascripts/helpers/jquery_no_conflict.js +1 -0
- data/spec_app/spec/javascripts/helpers/last_request.js.coffee +1 -0
- data/spec_app/spec/javascripts/helpers/mock_ajax.js.coffee +1 -1
- data/spec_app/spec/javascripts/helpers/parse_form_data.js.coffee +2 -2
- data/spec_app/spec/javascripts/helpers/protect_jasmine_runner.coffee +4 -1
- data/spec_app/spec/javascripts/helpers/remove_body_margin.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/reset_history.js.coffee +2 -1
- data/spec_app/spec/javascripts/helpers/reset_knife.js.coffee +2 -2
- data/spec_app/spec/javascripts/helpers/reset_up.js.coffee +18 -11
- data/spec_app/spec/javascripts/helpers/restore_body_scroll.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/show_lib_versions.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/spec_util.coffee +47 -0
- data/spec_app/spec/javascripts/helpers/to_be_around.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_array.coffee +5 -0
- data/spec_app/spec/javascripts/helpers/to_be_attached.coffee +6 -2
- data/spec_app/spec/javascripts/helpers/to_be_blank.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_detached.coffee +6 -2
- data/spec_app/spec/javascripts/helpers/to_be_element.js.coffee +8 -0
- data/spec_app/spec/javascripts/helpers/to_be_error.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_given.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_hidden.js.coffee +8 -0
- data/spec_app/spec/javascripts/helpers/to_be_missing.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_present.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_scrolled_to.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_be_visible.js.coffee +9 -0
- data/spec_app/spec/javascripts/helpers/to_contain.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_end_with.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_equal_jquery.js.coffee +1 -2
- data/spec_app/spec/javascripts/helpers/to_equal_node_list.coffee +7 -0
- data/spec_app/spec/javascripts/helpers/to_equal_via_is_equal.js.coffee +7 -0
- data/spec_app/spec/javascripts/helpers/to_have_class.js.coffee +10 -0
- data/spec_app/spec/javascripts/helpers/to_have_descendant.js.coffee +10 -0
- data/spec_app/spec/javascripts/helpers/to_have_length.js.coffee +8 -0
- data/spec_app/spec/javascripts/helpers/to_have_opacity.coffee +7 -3
- data/spec_app/spec/javascripts/helpers/to_have_own_property.js.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_have_request_method.js.coffee +1 -0
- data/spec_app/spec/javascripts/helpers/to_have_text.js.coffee +9 -0
- data/spec_app/spec/javascripts/helpers/to_have_unhandled_rejections.coffee +0 -21
- data/spec_app/spec/javascripts/helpers/to_match_list.coffee +14 -0
- data/spec_app/spec/javascripts/helpers/to_match_selector.coffee +3 -0
- data/spec_app/spec/javascripts/helpers/to_match_text.js.coffee +4 -1
- data/spec_app/spec/javascripts/helpers/to_match_url.coffee +1 -0
- data/spec_app/spec/javascripts/helpers/trigger.js.coffee +91 -7
- data/spec_app/spec/javascripts/helpers/wait_until_dom_ready.js.coffee +3 -0
- data/spec_app/spec/javascripts/up/browser_spec.js.coffee +23 -90
- data/spec_app/spec/javascripts/up/classes/cache_spec.js.coffee +3 -0
- data/spec_app/spec/javascripts/up/classes/config_spec.coffee +24 -0
- data/spec_app/spec/javascripts/up/classes/divertible_chain_spec.coffee +45 -0
- data/spec_app/spec/javascripts/up/classes/focus_tracker_spec.coffee +5 -2
- data/spec_app/spec/javascripts/up/classes/params_spec.coffee +557 -0
- data/spec_app/spec/javascripts/up/classes/request_spec.coffee +7 -4
- data/spec_app/spec/javascripts/up/classes/scroll_motion_spec.js.coffee +51 -0
- data/spec_app/spec/javascripts/up/classes/store/memory_spec.js.coffee +3 -0
- data/spec_app/spec/javascripts/up/classes/store/session_spec.js.coffee +3 -2
- data/spec_app/spec/javascripts/up/element_spec.coffee +897 -0
- data/spec_app/spec/javascripts/up/event_spec.js.coffee +496 -0
- data/spec_app/spec/javascripts/up/feedback_spec.js.coffee +69 -48
- data/spec_app/spec/javascripts/up/form_spec.js.coffee +252 -194
- data/spec_app/spec/javascripts/up/{dom_spec.js.coffee → fragment_spec.js.coffee} +381 -388
- data/spec_app/spec/javascripts/up/history_spec.js.coffee +21 -19
- data/spec_app/spec/javascripts/up/jquery_spec.js.coffee +4 -0
- data/spec_app/spec/javascripts/up/legacy_spec.js.coffee +27 -0
- data/spec_app/spec/javascripts/up/link_spec.js.coffee +163 -160
- data/spec_app/spec/javascripts/up/log_spec.js.coffee +85 -12
- data/spec_app/spec/javascripts/up/modal_spec.js.coffee +141 -123
- data/spec_app/spec/javascripts/up/motion_spec.js.coffee +117 -113
- data/spec_app/spec/javascripts/up/popup_spec.js.coffee +60 -77
- data/spec_app/spec/javascripts/up/protocol_spec.js.coffee +1 -0
- data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +85 -78
- data/spec_app/spec/javascripts/up/radio_spec.js.coffee +29 -22
- data/spec_app/spec/javascripts/up/rails_spec.js.coffee +14 -13
- data/spec_app/spec/javascripts/up/spec_spec.js.coffee +9 -0
- data/spec_app/spec/javascripts/up/syntax_spec.js.coffee +96 -66
- data/spec_app/spec/javascripts/up/toast_spec.js.coffee +37 -0
- data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +31 -47
- data/spec_app/spec/javascripts/up/util_spec.js.coffee +725 -562
- data/spec_app/spec/javascripts/up/{layout_spec.js.coffee → viewport_spec.js.coffee} +175 -149
- metadata +57 -19
- data/lib/assets/javascripts/unpoly-bootstrap3/layout-ext.coffee +0 -5
- data/lib/assets/javascripts/unpoly/bus.coffee.erb +0 -518
- data/lib/assets/javascripts/unpoly/classes/extract_step.coffee +0 -4
- data/lib/assets/javascripts/unpoly/classes/motion_tracker.coffee +0 -125
- data/lib/assets/javascripts/unpoly/params.coffee.erb +0 -522
- data/spec_app/spec/javascripts/helpers/append_fixture.js.coffee +0 -8
- data/spec_app/spec/javascripts/up/bus_spec.js.coffee +0 -210
- data/spec_app/spec/javascripts/up/namespace_spec.js.coffee +0 -9
- data/spec_app/spec/javascripts/up/params_spec.coffee +0 -768
- data/spec_app/vendor/asset-libs/jasmine-fixture-1.3.4/jasmine-fixture.js +0 -433
- data/spec_app/vendor/asset-libs/jasmine-jquery-2.1.1/.bower.json +0 -26
- data/spec_app/vendor/asset-libs/jasmine-jquery-2.1.1/jasmine-jquery.js +0 -838
@@ -1,6 +1,7 @@
|
|
1
|
-
|
1
|
+
u = up.util
|
2
|
+
$ = jQuery
|
2
3
|
|
3
|
-
|
4
|
+
describe 'up.history', ->
|
4
5
|
|
5
6
|
beforeEach ->
|
6
7
|
up.history.config.enabled = true
|
@@ -58,14 +59,14 @@ describe 'up.history', ->
|
|
58
59
|
constructorSpy = jasmine.createSpy('constructor')
|
59
60
|
destructorSpy = jasmine.createSpy('destructor')
|
60
61
|
|
61
|
-
up
|
62
|
+
up.$compiler '.example', ($example) ->
|
62
63
|
constructorSpy()
|
63
64
|
return destructorSpy
|
64
65
|
|
65
66
|
up.history.push('/one')
|
66
67
|
up.history.push('/two')
|
67
68
|
|
68
|
-
$container =
|
69
|
+
$container = $fixture('.container')
|
69
70
|
$example = $container.affix('.example')
|
70
71
|
up.hello($example)
|
71
72
|
|
@@ -88,7 +89,8 @@ describe 'up.history', ->
|
|
88
89
|
it 'sets an [up-href] attribute to the previous URL and sets the up-restore-scroll attribute to "true"', ->
|
89
90
|
up.history.push('/path1')
|
90
91
|
up.history.push('/path2')
|
91
|
-
|
92
|
+
element = up.hello($fixture('a[href="/path3"][up-back]').text('text'))
|
93
|
+
$element = $(element)
|
92
94
|
expect($element.attr('href')).toMatchUrl('/path3')
|
93
95
|
expect($element.attr('up-href')).toMatchUrl('/path1')
|
94
96
|
expect($element.attr('up-restore-scroll')).toBe('')
|
@@ -101,7 +103,7 @@ describe 'up.history', ->
|
|
101
103
|
describeFallback 'canPushState', ->
|
102
104
|
|
103
105
|
it 'does not change the element', ->
|
104
|
-
$element = up.hello(
|
106
|
+
$element = $(up.hello($fixture('a[href="/three"][up-back]').text('text')))
|
105
107
|
expect($element.attr('up-href')).toBeUndefined()
|
106
108
|
|
107
109
|
describe 'scroll restoration', ->
|
@@ -123,7 +125,7 @@ describe 'up.history', ->
|
|
123
125
|
|
124
126
|
$viewport = $(longContentHtml).appendTo(document.body)
|
125
127
|
|
126
|
-
up.
|
128
|
+
up.viewport.config.viewports = ['.viewport']
|
127
129
|
up.history.config.popTargets = ['.viewport']
|
128
130
|
|
129
131
|
up.replace('.content', '/one')
|
@@ -149,33 +151,33 @@ describe 'up.history', ->
|
|
149
151
|
$('.viewport').scrollTop(250)
|
150
152
|
history.back()
|
151
153
|
|
152
|
-
next.after
|
154
|
+
next.after 100, =>
|
153
155
|
respond() # we need to respond since we've never requested /two with the popTarget
|
154
156
|
|
155
157
|
next =>
|
156
158
|
expect($('.viewport').scrollTop()).toBe(150)
|
157
159
|
history.back()
|
158
160
|
|
159
|
-
next.after
|
161
|
+
next.after 100, =>
|
160
162
|
respond() # we need to respond since we've never requested /one with the popTarget
|
161
163
|
|
162
164
|
next =>
|
163
165
|
expect($('.viewport').scrollTop()).toBe(50)
|
164
166
|
history.forward()
|
165
167
|
|
166
|
-
next.after
|
168
|
+
next.after 100, =>
|
167
169
|
# No need to respond since we requested /two with the popTarget
|
168
170
|
# when we went backwards
|
169
171
|
expect($('.viewport').scrollTop()).toBe(150)
|
170
172
|
history.forward()
|
171
173
|
|
172
|
-
next.after
|
174
|
+
next.after 100, =>
|
173
175
|
respond() # we need to respond since we've never requested /three with the popTarget
|
174
176
|
|
175
177
|
next =>
|
176
178
|
expect($('.viewport').scrollTop()).toBe(250)
|
177
179
|
|
178
|
-
it 'restores the scroll position of two viewports marked with [up-viewport], but not configured in up.
|
180
|
+
it 'restores the scroll position of two viewports marked with [up-viewport], but not configured in up.viewport.config (bugfix)', asyncSpec (next) ->
|
179
181
|
up.history.config.popTargets = ['.container']
|
180
182
|
|
181
183
|
html = """
|
@@ -191,7 +193,7 @@ describe 'up.history', ->
|
|
191
193
|
|
192
194
|
respond = => @respondWith(html)
|
193
195
|
|
194
|
-
$screen =
|
196
|
+
$screen = $fixture('.screen')
|
195
197
|
$screen.html(html)
|
196
198
|
|
197
199
|
up.replace('.content1, .content2', '/one', reveal: false)
|
@@ -214,7 +216,7 @@ describe 'up.history', ->
|
|
214
216
|
expect(location.href).toMatchUrl('/two')
|
215
217
|
history.back()
|
216
218
|
|
217
|
-
next.after
|
219
|
+
next.after 100, =>
|
218
220
|
# we need to respond since we've never requested the original URL with the popTarget
|
219
221
|
respond()
|
220
222
|
|
@@ -231,7 +233,7 @@ describe 'up.history', ->
|
|
231
233
|
up.proxy.config.cacheSize = 0
|
232
234
|
up.history.config.popTargets = ['.viewport']
|
233
235
|
|
234
|
-
|
236
|
+
fixture('.viewport .content')
|
235
237
|
respond = =>
|
236
238
|
@respondWith """
|
237
239
|
<div class="viewport">
|
@@ -281,7 +283,7 @@ describe 'up.history', ->
|
|
281
283
|
|
282
284
|
history.back()
|
283
285
|
|
284
|
-
next.after
|
286
|
+
next.after 100, =>
|
285
287
|
respond()
|
286
288
|
|
287
289
|
next =>
|
@@ -294,7 +296,7 @@ describe 'up.history', ->
|
|
294
296
|
|
295
297
|
history.back()
|
296
298
|
|
297
|
-
next.after
|
299
|
+
next.after 100, =>
|
298
300
|
respond()
|
299
301
|
|
300
302
|
next =>
|
@@ -308,7 +310,7 @@ describe 'up.history', ->
|
|
308
310
|
|
309
311
|
history.forward()
|
310
312
|
|
311
|
-
next.after
|
313
|
+
next.after 100, =>
|
312
314
|
respond()
|
313
315
|
|
314
316
|
next =>
|
@@ -323,7 +325,7 @@ describe 'up.history', ->
|
|
323
325
|
|
324
326
|
history.forward()
|
325
327
|
|
326
|
-
next.after
|
328
|
+
next.after 100, =>
|
327
329
|
respond() # we need to respond since we've never requested /baz with the popTarget
|
328
330
|
|
329
331
|
next =>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
u = up.util
|
2
|
+
$ = jQuery
|
3
|
+
|
4
|
+
describe 'up.legacy', ->
|
5
|
+
|
6
|
+
describe 'renamedModule()', ->
|
7
|
+
|
8
|
+
it 'prints a warning and forwards the call to the new module', ->
|
9
|
+
warnSpy = spyOn(up, 'warn')
|
10
|
+
value = up.dom
|
11
|
+
expect(warnSpy).toHaveBeenCalled()
|
12
|
+
expect(value).toBe(up.fragment)
|
13
|
+
|
14
|
+
describe 'warn()', ->
|
15
|
+
|
16
|
+
it 'prepends a deprecation prefix to the given message and prints it to the warning log', ->
|
17
|
+
spy = spyOn(up, 'warn')
|
18
|
+
up.legacy.warn("a legacy warning")
|
19
|
+
expect(spy).toHaveBeenCalledWith('[DEPRECATION] a legacy warning')
|
20
|
+
|
21
|
+
it 'only prints a given message once', ->
|
22
|
+
spy = spyOn(up, 'warn')
|
23
|
+
up.legacy.warn("a very unique legacy warning")
|
24
|
+
up.legacy.warn("a very unique legacy warning")
|
25
|
+
expect(spy.calls.count()).toBe(1)
|
26
|
+
|
27
|
+
it 'allows substitution'
|
@@ -1,3 +1,6 @@
|
|
1
|
+
u = up.util
|
2
|
+
$ = jQuery
|
3
|
+
|
1
4
|
describe 'up.link', ->
|
2
5
|
|
3
6
|
u = up.util
|
@@ -7,7 +10,7 @@ describe 'up.link', ->
|
|
7
10
|
describe 'up.follow', ->
|
8
11
|
|
9
12
|
it 'emits a preventable up:link:follow event', asyncSpec (next) ->
|
10
|
-
$link =
|
13
|
+
$link = $fixture('a[href="/destination"][up-target=".response"]')
|
11
14
|
|
12
15
|
listener = jasmine.createSpy('follow listener').and.callFake (event) ->
|
13
16
|
event.preventDefault()
|
@@ -19,7 +22,7 @@ describe 'up.link', ->
|
|
19
22
|
next =>
|
20
23
|
expect(listener).toHaveBeenCalled()
|
21
24
|
event = listener.calls.mostRecent().args[0]
|
22
|
-
expect(event
|
25
|
+
expect(event.target).toEqual($link[0])
|
23
26
|
|
24
27
|
# No request should be made because we prevented the event
|
25
28
|
expect(jasmine.Ajax.requests.count()).toEqual(0)
|
@@ -27,10 +30,10 @@ describe 'up.link', ->
|
|
27
30
|
describeCapability 'canPushState', ->
|
28
31
|
|
29
32
|
it 'loads the given link via AJAX and replaces the response in the given target', asyncSpec (next) ->
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
$link =
|
33
|
+
$fixture('.before').text('old-before')
|
34
|
+
$fixture('.middle').text('old-middle')
|
35
|
+
$fixture('.after').text('old-after')
|
36
|
+
$link = $fixture('a[href="/path"][up-target=".middle"]')
|
34
37
|
|
35
38
|
up.follow($link)
|
36
39
|
|
@@ -47,7 +50,7 @@ describe 'up.link', ->
|
|
47
50
|
expect($('.after')).toHaveText('old-after')
|
48
51
|
|
49
52
|
it 'uses the method from a data-method attribute', asyncSpec (next) ->
|
50
|
-
$link =
|
53
|
+
$link = $fixture('a[href="/path"][data-method="PUT"]')
|
51
54
|
up.follow($link)
|
52
55
|
|
53
56
|
next =>
|
@@ -55,7 +58,7 @@ describe 'up.link', ->
|
|
55
58
|
expect(request).toHaveRequestMethod('PUT')
|
56
59
|
|
57
60
|
it 'allows to refer to the link itself as "&" in the CSS selector', asyncSpec (next) ->
|
58
|
-
$container =
|
61
|
+
$container = $fixture('div')
|
59
62
|
$link1 = $('<a id="first" href="/path" up-target="&">first-link</a>').appendTo($container)
|
60
63
|
$link2 = $('<a id="second" href="/path" up-target="&">second-link</a>').appendTo($container)
|
61
64
|
up.follow($link2)
|
@@ -66,7 +69,7 @@ describe 'up.link', ->
|
|
66
69
|
it 'adds history entries and allows the user to use the back- and forward-buttons', asyncSpec (next) ->
|
67
70
|
up.history.config.enabled = true
|
68
71
|
|
69
|
-
waitForBrowser =
|
72
|
+
waitForBrowser = 100
|
70
73
|
|
71
74
|
# By default, up.history will replace the <body> tag when
|
72
75
|
# the user presses the back-button. We reconfigure this
|
@@ -85,11 +88,11 @@ describe 'up.link', ->
|
|
85
88
|
# respondWith(html, title)
|
86
89
|
# promise
|
87
90
|
|
88
|
-
$link1 =
|
89
|
-
$link2 =
|
90
|
-
$link3 =
|
91
|
-
$container =
|
92
|
-
$target =
|
91
|
+
$link1 = $fixture('a[href="/one"][up-target=".target"]')
|
92
|
+
$link2 = $fixture('a[href="/two"][up-target=".target"]')
|
93
|
+
$link3 = $fixture('a[href="/three"][up-target=".target"]')
|
94
|
+
$container = $fixture('.container')
|
95
|
+
$target = $fixture('.target').appendTo($container).text('original text')
|
93
96
|
|
94
97
|
up.follow($link1)
|
95
98
|
|
@@ -166,10 +169,10 @@ describe 'up.link', ->
|
|
166
169
|
</div>
|
167
170
|
"""
|
168
171
|
|
169
|
-
$link1 =
|
170
|
-
$link2 =
|
171
|
-
$container =
|
172
|
-
$target =
|
172
|
+
$link1 = $fixture('a[href="/one"][up-target=".target"]')
|
173
|
+
$link2 = $fixture('a[href="/two"][up-target=".target"]')
|
174
|
+
$container = $fixture('.container')
|
175
|
+
$target = $fixture('.target').appendTo($container).text('original text')
|
173
176
|
|
174
177
|
up.follow($link1)
|
175
178
|
|
@@ -200,7 +203,7 @@ describe 'up.link', ->
|
|
200
203
|
|
201
204
|
history.back()
|
202
205
|
|
203
|
-
next.after
|
206
|
+
next.after 100, =>
|
204
207
|
respondWith('restored text from one')
|
205
208
|
|
206
209
|
next =>
|
@@ -209,7 +212,7 @@ describe 'up.link', ->
|
|
209
212
|
|
210
213
|
history.forward()
|
211
214
|
|
212
|
-
next.after
|
215
|
+
next.after 100, =>
|
213
216
|
respondWith('restored text from two')
|
214
217
|
|
215
218
|
next =>
|
@@ -233,11 +236,11 @@ describe 'up.link', ->
|
|
233
236
|
</div>
|
234
237
|
"""
|
235
238
|
|
236
|
-
$link1 =
|
237
|
-
$link2 =
|
238
|
-
$link2WithHash =
|
239
|
-
$container =
|
240
|
-
$target =
|
239
|
+
$link1 = $fixture('a[href="/one"][up-target=".target"]')
|
240
|
+
$link2 = $fixture('a[href="/two"][up-target=".target"]')
|
241
|
+
$link2WithHash = $fixture('a[href="/two#hash"][up-target=".target"]')
|
242
|
+
$container = $fixture('.container')
|
243
|
+
$target = $fixture('.target').appendTo($container).text('original text')
|
241
244
|
|
242
245
|
up.follow($link1)
|
243
246
|
|
@@ -271,7 +274,7 @@ describe 'up.link', ->
|
|
271
274
|
|
272
275
|
history.back()
|
273
276
|
|
274
|
-
next.after
|
277
|
+
next.after 100, =>
|
275
278
|
respondWith('restored text from two')
|
276
279
|
|
277
280
|
next =>
|
@@ -281,7 +284,7 @@ describe 'up.link', ->
|
|
281
284
|
|
282
285
|
history.forward()
|
283
286
|
|
284
|
-
next.after
|
287
|
+
next.after 100, =>
|
285
288
|
respondWith('restored text from two with hash')
|
286
289
|
|
287
290
|
next =>
|
@@ -296,7 +299,7 @@ describe 'up.link', ->
|
|
296
299
|
|
297
300
|
it 'does not reveal, but instead restores the scroll positions of all viewports around the target', asyncSpec (next) ->
|
298
301
|
|
299
|
-
$viewport =
|
302
|
+
$viewport = $fixture('div[up-viewport] .element').css
|
300
303
|
'height': '100px'
|
301
304
|
'width': '100px'
|
302
305
|
'overflow-y': 'scroll'
|
@@ -340,10 +343,10 @@ describe 'up.link', ->
|
|
340
343
|
describe 'revealing', ->
|
341
344
|
|
342
345
|
it 'reaveals the target fragment', asyncSpec (next) ->
|
343
|
-
$link =
|
344
|
-
$target =
|
346
|
+
$link = $fixture('a[href="/action"][up-target=".target"]')
|
347
|
+
$target = $fixture('.target')
|
345
348
|
|
346
|
-
revealStub = up.
|
349
|
+
revealStub = up.viewport.knife.mock('reveal')
|
347
350
|
|
348
351
|
up.follow($link)
|
349
352
|
|
@@ -352,14 +355,14 @@ describe 'up.link', ->
|
|
352
355
|
|
353
356
|
next =>
|
354
357
|
expect(revealStub).toHaveBeenCalled()
|
355
|
-
expect(revealStub.calls.mostRecent().args[0]).
|
358
|
+
expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('.target')
|
356
359
|
|
357
360
|
it 'reveals the { failTarget } if the server responds with an error', asyncSpec (next) ->
|
358
|
-
$link =
|
359
|
-
$target =
|
360
|
-
$failTarget =
|
361
|
+
$link = $fixture('a[href="/action"][up-target=".target"][up-fail-target=".fail-target"]')
|
362
|
+
$target = $fixture('.target')
|
363
|
+
$failTarget = $fixture('.fail-target')
|
361
364
|
|
362
|
-
revealStub = up.
|
365
|
+
revealStub = up.viewport.knife.mock('reveal')
|
363
366
|
|
364
367
|
up.follow($link)
|
365
368
|
|
@@ -374,17 +377,17 @@ describe 'up.link', ->
|
|
374
377
|
|
375
378
|
next =>
|
376
379
|
expect(revealStub).toHaveBeenCalled()
|
377
|
-
expect(revealStub.calls.mostRecent().args[0]).
|
380
|
+
expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('.fail-target')
|
378
381
|
|
379
382
|
|
380
383
|
describe 'with { reveal } option', ->
|
381
384
|
|
382
385
|
it 'allows to reveal a different selector', asyncSpec (next) ->
|
383
|
-
$link =
|
384
|
-
$target =
|
385
|
-
$other =
|
386
|
+
$link = $fixture('a[href="/action"][up-target=".target"]')
|
387
|
+
$target = $fixture('.target')
|
388
|
+
$other = $fixture('.other')
|
386
389
|
|
387
|
-
revealStub = up.
|
390
|
+
revealStub = up.viewport.knife.mock('reveal')
|
388
391
|
|
389
392
|
up.follow($link, reveal: '.other')
|
390
393
|
|
@@ -400,17 +403,17 @@ describe 'up.link', ->
|
|
400
403
|
|
401
404
|
next =>
|
402
405
|
expect(revealStub).toHaveBeenCalled()
|
403
|
-
expect(revealStub.calls.mostRecent().args[0]).
|
406
|
+
expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('.other')
|
404
407
|
|
405
408
|
it 'still reveals the { failTarget } for a failed submission', asyncSpec (next) ->
|
406
|
-
$link =
|
407
|
-
$target =
|
408
|
-
$failTarget =
|
409
|
-
$other =
|
409
|
+
$link = $fixture('a[href="/action"][up-target=".target"][up-fail-target=".fail-target"]')
|
410
|
+
$target = $fixture('.target')
|
411
|
+
$failTarget = $fixture('.fail-target')
|
412
|
+
$other = $fixture('.other')
|
410
413
|
|
411
|
-
revealStub = up.
|
414
|
+
revealStub = up.viewport.knife.mock('reveal')
|
412
415
|
|
413
|
-
up.
|
416
|
+
up.follow($link, reveal: '.other', failTarget: '.fail-target')
|
414
417
|
|
415
418
|
next =>
|
416
419
|
@respondWith
|
@@ -423,18 +426,18 @@ describe 'up.link', ->
|
|
423
426
|
|
424
427
|
next =>
|
425
428
|
expect(revealStub).toHaveBeenCalled()
|
426
|
-
expect(revealStub.calls.mostRecent().args[0]).
|
429
|
+
expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('.fail-target')
|
427
430
|
|
428
431
|
describe 'with { failReveal } option', ->
|
429
432
|
|
430
433
|
it 'reveals the given selector when the server responds with an error', asyncSpec (next) ->
|
431
|
-
$link =
|
432
|
-
$target =
|
433
|
-
$failTarget =
|
434
|
-
$other =
|
435
|
-
$failOther =
|
434
|
+
$link = $fixture('a[href="/action"][up-target=".target"][up-fail-target=".fail-target"]')
|
435
|
+
$target = $fixture('.target')
|
436
|
+
$failTarget = $fixture('.fail-target')
|
437
|
+
$other = $fixture('.other')
|
438
|
+
$failOther = $fixture('.fail-other')
|
436
439
|
|
437
|
-
revealStub = up.
|
440
|
+
revealStub = up.viewport.knife.mock('reveal')
|
438
441
|
|
439
442
|
up.follow($link, reveal: '.other', failReveal: '.fail-other')
|
440
443
|
|
@@ -452,7 +455,7 @@ describe 'up.link', ->
|
|
452
455
|
|
453
456
|
next =>
|
454
457
|
expect(revealStub).toHaveBeenCalled()
|
455
|
-
expect(revealStub.calls.mostRecent().args[0]).
|
458
|
+
expect(revealStub.calls.mostRecent().args[0]).toMatchSelector('.fail-other')
|
456
459
|
|
457
460
|
describe "when the browser is already on the link's destination", ->
|
458
461
|
|
@@ -465,7 +468,7 @@ describe 'up.link', ->
|
|
465
468
|
it 'follows the link after the user OKs a confirmation dialog', asyncSpec (next) ->
|
466
469
|
spyOn(up, 'replace')
|
467
470
|
spyOn(window, 'confirm').and.returnValue(true)
|
468
|
-
$link =
|
471
|
+
$link = $fixture('a[href="/danger"][up-target=".middle"]')
|
469
472
|
up.follow($link, confirm: 'Do you really want to go there?')
|
470
473
|
|
471
474
|
next =>
|
@@ -475,7 +478,7 @@ describe 'up.link', ->
|
|
475
478
|
it 'does not follow the link if the user cancels the confirmation dialog', asyncSpec (next) ->
|
476
479
|
spyOn(up, 'replace')
|
477
480
|
spyOn(window, 'confirm').and.returnValue(false)
|
478
|
-
$link =
|
481
|
+
$link = $fixture('a[href="/danger"][up-target=".middle"]')
|
479
482
|
up.follow($link, confirm: 'Do you really want to go there?')
|
480
483
|
|
481
484
|
next =>
|
@@ -485,7 +488,7 @@ describe 'up.link', ->
|
|
485
488
|
it 'does not show a confirmation dialog if the option is not a present string', asyncSpec (next) ->
|
486
489
|
spyOn(up, 'replace')
|
487
490
|
spyOn(window, 'confirm')
|
488
|
-
$link =
|
491
|
+
$link = $fixture('a[href="/danger"][up-target=".middle"]')
|
489
492
|
up.follow($link, confirm: '')
|
490
493
|
|
491
494
|
next =>
|
@@ -495,7 +498,7 @@ describe 'up.link', ->
|
|
495
498
|
it 'does not show a confirmation dialog when preloading', asyncSpec (next) ->
|
496
499
|
spyOn(up, 'replace')
|
497
500
|
spyOn(window, 'confirm')
|
498
|
-
$link =
|
501
|
+
$link = $fixture('a[href="/danger"][up-target=".middle"]')
|
499
502
|
up.follow($link, confirm: 'Are you sure?', preload: true)
|
500
503
|
|
501
504
|
next =>
|
@@ -505,7 +508,7 @@ describe 'up.link', ->
|
|
505
508
|
describeFallback 'canPushState', ->
|
506
509
|
|
507
510
|
it 'navigates to the given link without JavaScript', asyncSpec (next) ->
|
508
|
-
$link =
|
511
|
+
$link = $fixture('a[href="/path"]')
|
509
512
|
spyOn(up.browser, 'navigate')
|
510
513
|
up.follow($link)
|
511
514
|
|
@@ -513,7 +516,7 @@ describe 'up.link', ->
|
|
513
516
|
expect(up.browser.navigate).toHaveBeenCalledWith('/path', jasmine.anything())
|
514
517
|
|
515
518
|
it 'uses the method from a data-method attribute', asyncSpec (next) ->
|
516
|
-
$link =
|
519
|
+
$link = $fixture('a[href="/path"][data-method="PUT"]')
|
517
520
|
spyOn(up.browser, 'navigate')
|
518
521
|
up.follow($link)
|
519
522
|
|
@@ -522,75 +525,75 @@ describe 'up.link', ->
|
|
522
525
|
|
523
526
|
describe 'up.link.shouldProcessEvent', ->
|
524
527
|
|
525
|
-
buildEvent = (
|
528
|
+
buildEvent = (target, attrs) ->
|
526
529
|
event = Trigger.createMouseEvent('mousedown', attrs)
|
527
|
-
|
528
|
-
event
|
530
|
+
# Cannot change event.target on a native event property, but we can with Object.defineProperty()
|
531
|
+
Object.defineProperty(event, 'target', get: -> target)
|
529
532
|
event
|
530
533
|
|
531
534
|
it "returns true when the given event's target is the given link itself", ->
|
532
|
-
$link =
|
533
|
-
event = buildEvent($link)
|
534
|
-
expect(up.link.shouldProcessEvent(event, $link)).toBe(true)
|
535
|
+
$link = $fixture('a[href="/foo"]')
|
536
|
+
event = buildEvent($link[0])
|
537
|
+
expect(up.link.shouldProcessEvent(event, $link[0])).toBe(true)
|
535
538
|
|
536
539
|
it "returns true when the given event's target is a non-link child of the given link", ->
|
537
|
-
$link =
|
540
|
+
$link = $fixture('a[href="/foo"]')
|
538
541
|
$span = $link.affix('span')
|
539
|
-
event = buildEvent($span)
|
540
|
-
expect(up.link.shouldProcessEvent(event, $link)).toBe(true)
|
542
|
+
event = buildEvent($span[0])
|
543
|
+
expect(up.link.shouldProcessEvent(event, $link[0])).toBe(true)
|
541
544
|
|
542
545
|
it "returns false when the given event's target is a child link of the given link (think [up-expand])", ->
|
543
|
-
$link =
|
546
|
+
$link = $fixture('div[up-href="/foo"]')
|
544
547
|
$childLink = $link.affix('a[href="/bar"]')
|
545
|
-
event = buildEvent($childLink)
|
546
|
-
expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
|
548
|
+
event = buildEvent($childLink[0])
|
549
|
+
expect(up.link.shouldProcessEvent(event, $link[0])).toBe(false)
|
547
550
|
|
548
551
|
it "returns false when the given event's target is a child input of the given link (think [up-expand])", ->
|
549
|
-
$link =
|
552
|
+
$link = $fixture('div[up-href="/foo"]')
|
550
553
|
$childInput = $link.affix('input[type="text"]')
|
551
|
-
event = buildEvent($childInput)
|
552
|
-
expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
|
554
|
+
event = buildEvent($childInput[0])
|
555
|
+
expect(up.link.shouldProcessEvent(event, $link[0])).toBe(false)
|
553
556
|
|
554
557
|
it 'returns false if the right mouse button is used', ->
|
555
|
-
$link =
|
556
|
-
event = buildEvent($link, button: 2)
|
557
|
-
expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
|
558
|
+
$link = $fixture('a[href="/foo"]')
|
559
|
+
event = buildEvent($link[0], button: 2)
|
560
|
+
expect(up.link.shouldProcessEvent(event, $link[0])).toBe(false)
|
558
561
|
|
559
562
|
it 'returns false if shift is pressed during the click', ->
|
560
|
-
$link =
|
561
|
-
event = buildEvent($link, shiftKey: 2)
|
562
|
-
expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
|
563
|
+
$link = $fixture('a[href="/foo"]')
|
564
|
+
event = buildEvent($link[0], shiftKey: 2)
|
565
|
+
expect(up.link.shouldProcessEvent(event, $link[0])).toBe(false)
|
563
566
|
|
564
567
|
it 'returns false if ctrl is pressed during the click', ->
|
565
|
-
$link =
|
566
|
-
event = buildEvent($link, ctrlKey: 2)
|
567
|
-
expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
|
568
|
+
$link = $fixture('a[href="/foo"]')
|
569
|
+
event = buildEvent($link[0], ctrlKey: 2)
|
570
|
+
expect(up.link.shouldProcessEvent(event, $link[0])).toBe(false)
|
568
571
|
|
569
572
|
it 'returns false if meta is pressed during the click', ->
|
570
|
-
$link =
|
571
|
-
event = buildEvent($link, metaKey: 2)
|
572
|
-
expect(up.link.shouldProcessEvent(event, $link)).toBe(false)
|
573
|
+
$link = $fixture('a[href="/foo"]')
|
574
|
+
event = buildEvent($link[0], metaKey: 2)
|
575
|
+
expect(up.link.shouldProcessEvent(event, $link[0])).toBe(false)
|
573
576
|
|
574
577
|
describe 'up.link.makeFollowable', ->
|
575
578
|
|
576
579
|
it "adds [up-follow] to a link that wouldn't otherwise be handled by Unpoly", ->
|
577
|
-
$link =
|
578
|
-
up.link.makeFollowable($link)
|
580
|
+
$link = $fixture('a[href="/path"]').text('label')
|
581
|
+
up.link.makeFollowable($link[0])
|
579
582
|
expect($link.attr('up-follow')).toEqual('')
|
580
583
|
|
581
584
|
it "does not add [up-follow] to a link that is already [up-target]", ->
|
582
|
-
$link =
|
583
|
-
up.link.makeFollowable($link)
|
585
|
+
$link = $fixture('a[href="/path"][up-target=".target"]').text('label')
|
586
|
+
up.link.makeFollowable($link[0])
|
584
587
|
expect($link.attr('up-follow')).toBeMissing()
|
585
588
|
|
586
589
|
it "does not add [up-follow] to a link that is already [up-modal]", ->
|
587
|
-
$link =
|
588
|
-
up.link.makeFollowable($link)
|
590
|
+
$link = $fixture('a[href="/path"][up-modal=".target"]').text('label')
|
591
|
+
up.link.makeFollowable($link[0])
|
589
592
|
expect($link.attr('up-follow')).toBeMissing()
|
590
593
|
|
591
594
|
it "does not add [up-follow] to a link that is already [up-popup]", ->
|
592
|
-
$link =
|
593
|
-
up.link.makeFollowable($link)
|
595
|
+
$link = $fixture('a[href="/path"][up-popup=".target"]').text('label')
|
596
|
+
up.link.makeFollowable($link[0])
|
594
597
|
expect($link.attr('up-follow')).toBeMissing()
|
595
598
|
|
596
599
|
describe 'up.visit', ->
|
@@ -600,42 +603,42 @@ describe 'up.link', ->
|
|
600
603
|
describe 'up.link.isFollowable', ->
|
601
604
|
|
602
605
|
it 'returns true for an [up-target] link', ->
|
603
|
-
$link =
|
606
|
+
$link = $fixture('a[href="/foo"][up-target=".target"]')
|
604
607
|
up.hello $link
|
605
608
|
expect(up.link.isFollowable($link)).toBe(true)
|
606
609
|
|
607
610
|
it 'returns true for an [up-follow] link', ->
|
608
|
-
$link =
|
611
|
+
$link = $fixture('a[href="/foo"][up-follow]')
|
609
612
|
up.hello $link
|
610
613
|
expect(up.link.isFollowable($link)).toBe(true)
|
611
614
|
|
612
615
|
it 'returns true for an [up-modal] link', ->
|
613
|
-
$link =
|
616
|
+
$link = $fixture('a[href="/foo"][up-modal=".target"]')
|
614
617
|
up.hello $link
|
615
618
|
expect(up.link.isFollowable($link)).toBe(true)
|
616
619
|
|
617
620
|
it 'returns true for an [up-popup] link', ->
|
618
|
-
$link =
|
621
|
+
$link = $fixture('a[href="/foo"][up-popup=".target"]')
|
619
622
|
up.hello $link
|
620
623
|
expect(up.link.isFollowable($link)).toBe(true)
|
621
624
|
|
622
625
|
it 'returns true for an [up-drawer] link', ->
|
623
|
-
$link =
|
626
|
+
$link = $fixture('a[href="/foo"][up-drawer=".target"]')
|
624
627
|
up.hello $link
|
625
628
|
expect(up.link.isFollowable($link)).toBe(true)
|
626
629
|
|
627
630
|
it 'returns true for an [up-target] span with [up-href]', ->
|
628
|
-
$link =
|
631
|
+
$link = $fixture('span[up-href="/foo"][up-target=".target"]')
|
629
632
|
up.hello $link
|
630
633
|
expect(up.link.isFollowable($link)).toBe(true)
|
631
634
|
|
632
635
|
it 'returns false if the given link will be handled by the browser', ->
|
633
|
-
$link =
|
636
|
+
$link = $fixture('a[href="/foo"]')
|
634
637
|
up.hello $link
|
635
638
|
expect(up.link.isFollowable($link)).toBe(false)
|
636
639
|
|
637
640
|
it 'returns false if the given link will be handled by Rails UJS', ->
|
638
|
-
$link =
|
641
|
+
$link = $fixture('a[href="/foo"][data-method="put"]')
|
639
642
|
up.hello $link
|
640
643
|
expect(up.link.isFollowable($link)).toBe(false)
|
641
644
|
|
@@ -644,7 +647,7 @@ describe 'up.link', ->
|
|
644
647
|
describe 'a[up-target]', ->
|
645
648
|
|
646
649
|
it 'does not follow a form with up-target attribute (bugfix)', asyncSpec (next) ->
|
647
|
-
$form =
|
650
|
+
$form = $fixture('form[up-target]')
|
648
651
|
up.hello($form)
|
649
652
|
followSpy = up.link.knife.mock('defaultFollow').and.returnValue(Promise.resolve())
|
650
653
|
Trigger.clickSequence($form)
|
@@ -655,8 +658,8 @@ describe 'up.link', ->
|
|
655
658
|
describeCapability 'canPushState', ->
|
656
659
|
|
657
660
|
it 'requests the [href] with AJAX and replaces the [up-target] selector', asyncSpec (next) ->
|
658
|
-
|
659
|
-
$link =
|
661
|
+
$fixture('.target')
|
662
|
+
$link = $fixture('a[href="/path"][up-target=".target"]')
|
660
663
|
Trigger.clickSequence($link)
|
661
664
|
|
662
665
|
next =>
|
@@ -669,8 +672,8 @@ describe 'up.link', ->
|
|
669
672
|
it 'adds a history entry', asyncSpec (next) ->
|
670
673
|
up.history.config.enabled = true
|
671
674
|
|
672
|
-
|
673
|
-
$link =
|
675
|
+
$fixture('.target')
|
676
|
+
$link = $fixture('a[href="/path"][up-target=".target"]')
|
674
677
|
Trigger.clickSequence($link)
|
675
678
|
|
676
679
|
next =>
|
@@ -683,8 +686,8 @@ describe 'up.link', ->
|
|
683
686
|
it 'respects a X-Up-Location header that the server sends in case of a redirect', asyncSpec (next) ->
|
684
687
|
up.history.config.enabled = true
|
685
688
|
|
686
|
-
|
687
|
-
$link =
|
689
|
+
$fixture('.target')
|
690
|
+
$link = $fixture('a[href="/path"][up-target=".target"]')
|
688
691
|
Trigger.clickSequence($link)
|
689
692
|
|
690
693
|
next =>
|
@@ -702,7 +705,7 @@ describe 'up.link', ->
|
|
702
705
|
up.motion.config.enabled = false
|
703
706
|
|
704
707
|
it 'prefers to update a container in the same layer as the clicked link', asyncSpec (next) ->
|
705
|
-
|
708
|
+
$fixture('.document').affix('.target').text('old document text')
|
706
709
|
up.modal.extract('.target', "<div class='target'>old modal text</div>")
|
707
710
|
|
708
711
|
next =>
|
@@ -722,7 +725,7 @@ describe 'up.link', ->
|
|
722
725
|
describe 'with [up-layer] modifier', ->
|
723
726
|
|
724
727
|
it 'allows to name a layer for the update', asyncSpec (next) ->
|
725
|
-
|
728
|
+
$fixture('.document').affix('.target').text('old document text')
|
726
729
|
up.modal.extract('.target', "<div class='target'>old modal text</div>", sticky: true)
|
727
730
|
|
728
731
|
next =>
|
@@ -740,7 +743,7 @@ describe 'up.link', ->
|
|
740
743
|
expect($('.up-modal .target')).toHaveText('old modal text')
|
741
744
|
|
742
745
|
it 'ignores [up-layer] if the server responds with an error', asyncSpec (next) ->
|
743
|
-
|
746
|
+
$fixture('.document').affix('.target').text('old document text')
|
744
747
|
up.modal.extract('.target', "<div class='target'>old modal text</div>", sticky: true)
|
745
748
|
|
746
749
|
next =>
|
@@ -760,7 +763,7 @@ describe 'up.link', ->
|
|
760
763
|
expect($('.up-modal .target')).toHaveText('new failure text from modal link')
|
761
764
|
|
762
765
|
it 'allows to name a layer for a non-200 response using an [up-fail-layer] modifier', asyncSpec (next) ->
|
763
|
-
|
766
|
+
$fixture('.document').affix('.target').text('old document text')
|
764
767
|
up.modal.extract('.target', "<div class='target'>old modal text</div>", sticky: true)
|
765
768
|
|
766
769
|
next =>
|
@@ -782,9 +785,9 @@ describe 'up.link', ->
|
|
782
785
|
describe 'with [up-fail-target] modifier', ->
|
783
786
|
|
784
787
|
beforeEach ->
|
785
|
-
|
786
|
-
|
787
|
-
@$link =
|
788
|
+
$fixture('.success-target').text('old success text')
|
789
|
+
$fixture('.failure-target').text('old failure text')
|
790
|
+
@$link = $fixture('a[href="/path"][up-target=".success-target"][up-fail-target=".failure-target"]')
|
788
791
|
|
789
792
|
it 'uses the [up-fail-target] selector for a failed response', asyncSpec (next) ->
|
790
793
|
Trigger.clickSequence(@$link)
|
@@ -814,8 +817,8 @@ describe 'up.link', ->
|
|
814
817
|
describe 'with [up-transition] modifier', ->
|
815
818
|
|
816
819
|
it 'morphs between the old and new target element', asyncSpec (next) ->
|
817
|
-
|
818
|
-
$link =
|
820
|
+
$fixture('.target.old')
|
821
|
+
$link = $fixture('a[href="/path"][up-target=".target"][up-transition="cross-fade"][up-duration="500"][up-easing="linear"]')
|
819
822
|
Trigger.clickSequence($link)
|
820
823
|
|
821
824
|
next =>
|
@@ -824,20 +827,20 @@ describe 'up.link', ->
|
|
824
827
|
next =>
|
825
828
|
@$oldGhost = $('.target.old')
|
826
829
|
@$newGhost = $('.target.new')
|
827
|
-
expect(@$oldGhost).
|
828
|
-
expect(@$newGhost).
|
829
|
-
expect(
|
830
|
-
expect(
|
830
|
+
expect(@$oldGhost).toBeAttached()
|
831
|
+
expect(@$newGhost).toBeAttached()
|
832
|
+
expect(@$oldGhost).toHaveOpacity(1, 0.15)
|
833
|
+
expect(@$newGhost).toHaveOpacity(0, 0.15)
|
831
834
|
|
832
835
|
next.after 250, =>
|
833
|
-
expect(
|
834
|
-
expect(
|
836
|
+
expect(@$oldGhost).toHaveOpacity(0.5, 0.15)
|
837
|
+
expect(@$newGhost).toHaveOpacity(0.5, 0.15)
|
835
838
|
|
836
839
|
describe 'wih a CSS selector in the [up-fallback] attribute', ->
|
837
840
|
|
838
841
|
it 'uses the fallback selector if the [up-target] CSS does not exist on the page', asyncSpec (next) ->
|
839
|
-
|
840
|
-
$link =
|
842
|
+
$fixture('.fallback').text('old fallback')
|
843
|
+
$link = $fixture('a[href="/path"][up-target=".target"][up-fallback=".fallback"]')
|
841
844
|
Trigger.clickSequence($link)
|
842
845
|
|
843
846
|
next =>
|
@@ -850,9 +853,9 @@ describe 'up.link', ->
|
|
850
853
|
expect('.fallback').toHaveText('new fallback')
|
851
854
|
|
852
855
|
it 'ignores the fallback selector if the [up-target] CSS exists on the page', asyncSpec (next) ->
|
853
|
-
|
854
|
-
|
855
|
-
$link =
|
856
|
+
$fixture('.target').text('old target')
|
857
|
+
$fixture('.fallback').text('old fallback')
|
858
|
+
$link = $fixture('a[href="/path"][up-target=".target"][up-fallback=".fallback"]')
|
856
859
|
Trigger.clickSequence($link)
|
857
860
|
|
858
861
|
next =>
|
@@ -869,8 +872,8 @@ describe 'up.link', ->
|
|
869
872
|
up.history.config.enabled = true
|
870
873
|
|
871
874
|
oldPathname = location.pathname
|
872
|
-
|
873
|
-
$link =
|
875
|
+
$fixture('.target')
|
876
|
+
$link = $fixture('a[href="/path"][up-target=".target"][up-history="false"]')
|
874
877
|
Trigger.clickSequence($link)
|
875
878
|
|
876
879
|
next =>
|
@@ -885,14 +888,14 @@ describe 'up.link', ->
|
|
885
888
|
describe 'a[up-follow]', ->
|
886
889
|
|
887
890
|
beforeEach ->
|
888
|
-
@$link =
|
891
|
+
@$link = $fixture('a[href="/follow-path"][up-follow]')
|
889
892
|
@followSpy = up.link.knife.mock('defaultFollow').and.returnValue(Promise.resolve())
|
890
893
|
@defaultSpy = spyOn(up.link, 'allowDefault').and.callFake((event) -> event.preventDefault())
|
891
894
|
|
892
895
|
it "calls up.follow with the clicked link", asyncSpec (next) ->
|
893
896
|
Trigger.click(@$link)
|
894
897
|
next =>
|
895
|
-
expect(@followSpy).toHaveBeenCalledWith(@$link, {})
|
898
|
+
expect(@followSpy).toHaveBeenCalledWith(@$link[0], {})
|
896
899
|
|
897
900
|
# IE does not call JavaScript and always performs the default action on right clicks
|
898
901
|
unless AgentDetector.isIE() || AgentDetector.isEdge()
|
@@ -919,7 +922,7 @@ describe 'up.link', ->
|
|
919
922
|
|
920
923
|
it 'follows a link on mousedown (instead of on click)', asyncSpec (next)->
|
921
924
|
Trigger.mousedown(@$link)
|
922
|
-
next => expect(@followSpy.calls.mostRecent().args[0]).toEqual(@$link)
|
925
|
+
next => expect(@followSpy.calls.mostRecent().args[0]).toEqual(@$link[0])
|
923
926
|
|
924
927
|
it 'does nothing on mouseup', asyncSpec (next)->
|
925
928
|
Trigger.mouseup(@$link)
|
@@ -950,78 +953,78 @@ describe 'up.link', ->
|
|
950
953
|
describe '[up-dash]', ->
|
951
954
|
|
952
955
|
it "is a shortcut for [up-preload], [up-instant] and [up-target], using [up-dash]'s value as [up-target]", ->
|
953
|
-
$link =
|
956
|
+
$link = $fixture('a[href="/path"][up-dash=".target"]').text('label')
|
954
957
|
up.hello($link)
|
955
958
|
expect($link.attr('up-preload')).toEqual('')
|
956
959
|
expect($link.attr('up-instant')).toEqual('')
|
957
960
|
expect($link.attr('up-target')).toEqual('.target')
|
958
961
|
|
959
962
|
it "adds [up-follow] attribute if [up-dash]'s value is 'true'", ->
|
960
|
-
$link =
|
963
|
+
$link = $fixture('a[href="/path"][up-dash="true"]').text('label')
|
961
964
|
up.hello($link)
|
962
965
|
expect($link.attr('up-follow')).toEqual('')
|
963
966
|
|
964
967
|
it "adds [up-follow] attribute if [up-dash] is present, but has no value", ->
|
965
|
-
$link =
|
968
|
+
$link = $fixture('a[href="/path"][up-dash]').text('label')
|
966
969
|
up.hello($link)
|
967
970
|
expect($link.attr('up-follow')).toEqual('')
|
968
971
|
|
969
972
|
it "does not add an [up-follow] attribute if [up-dash] is 'true', but [up-target] is present", ->
|
970
|
-
$link =
|
973
|
+
$link = $fixture('a[href="/path"][up-dash="true"][up-target=".target"]').text('label')
|
971
974
|
up.hello($link)
|
972
975
|
expect($link.attr('up-follow')).toBeMissing()
|
973
976
|
expect($link.attr('up-target')).toEqual('.target')
|
974
977
|
|
975
978
|
it "does not add an [up-follow] attribute if [up-dash] is 'true', but [up-modal] is present", ->
|
976
|
-
$link =
|
979
|
+
$link = $fixture('a[href="/path"][up-dash="true"][up-modal=".target"]').text('label')
|
977
980
|
up.hello($link)
|
978
981
|
expect($link.attr('up-follow')).toBeMissing()
|
979
982
|
expect($link.attr('up-modal')).toEqual('.target')
|
980
983
|
|
981
984
|
it "does not add an [up-follow] attribute if [up-dash] is 'true', but [up-popup] is present", ->
|
982
|
-
$link =
|
985
|
+
$link = $fixture('a[href="/path"][up-dash="true"][up-popup=".target"]').text('label')
|
983
986
|
up.hello($link)
|
984
987
|
expect($link.attr('up-follow')).toBeMissing()
|
985
988
|
expect($link.attr('up-popup')).toEqual('.target')
|
986
989
|
|
987
990
|
it "removes the [up-dash] attribute when it's done", ->
|
988
|
-
$link =
|
991
|
+
$link = $fixture('a[href="/path"]').text('label')
|
989
992
|
up.hello($link)
|
990
993
|
expect($link.attr('up-dash')).toBeMissing()
|
991
994
|
|
992
995
|
describe '[up-expand]', ->
|
993
996
|
|
994
997
|
it 'copies up-related attributes of a contained link', ->
|
995
|
-
$area =
|
998
|
+
$area = $fixture('div[up-expand] a[href="/path"][up-target="selector"][up-instant][up-preload]')
|
996
999
|
up.hello($area)
|
997
1000
|
expect($area.attr('up-target')).toEqual('selector')
|
998
1001
|
expect($area.attr('up-instant')).toEqual('')
|
999
1002
|
expect($area.attr('up-preload')).toEqual('')
|
1000
1003
|
|
1001
1004
|
it "renames a contained link's href attribute to up-href so the container is considered a link", ->
|
1002
|
-
$area =
|
1005
|
+
$area = $fixture('div[up-expand] a[up-follow][href="/path"]')
|
1003
1006
|
up.hello($area)
|
1004
1007
|
expect($area.attr('up-href')).toEqual('/path')
|
1005
1008
|
|
1006
1009
|
it 'copies attributes from the first link if there are multiple links', ->
|
1007
|
-
$area =
|
1010
|
+
$area = $fixture('div[up-expand]')
|
1008
1011
|
$link1 = $area.affix('a[href="/path1"]')
|
1009
1012
|
$link2 = $area.affix('a[href="/path2"]')
|
1010
1013
|
up.hello($area)
|
1011
1014
|
expect($area.attr('up-href')).toEqual('/path1')
|
1012
1015
|
|
1013
1016
|
it "copies an contained non-link element with up-href attribute", ->
|
1014
|
-
$area =
|
1017
|
+
$area = $fixture('div[up-expand] span[up-follow][up-href="/path"]')
|
1015
1018
|
up.hello($area)
|
1016
1019
|
expect($area.attr('up-href')).toEqual('/path')
|
1017
1020
|
|
1018
1021
|
it 'adds an up-follow attribute if the contained link has neither up-follow nor up-target attributes', ->
|
1019
|
-
$area =
|
1022
|
+
$area = $fixture('div[up-expand] a[href="/path"]')
|
1020
1023
|
up.hello($area)
|
1021
1024
|
expect($area.attr('up-follow')).toEqual('')
|
1022
1025
|
|
1023
1026
|
it 'can be used to enlarge the click area of a link', asyncSpec (next) ->
|
1024
|
-
$area =
|
1027
|
+
$area = $fixture('div[up-expand] a[href="/path"]')
|
1025
1028
|
up.hello($area)
|
1026
1029
|
spyOn(up, 'replace')
|
1027
1030
|
Trigger.clickSequence($area)
|
@@ -1029,7 +1032,7 @@ describe 'up.link', ->
|
|
1029
1032
|
expect(up.replace).toHaveBeenCalled()
|
1030
1033
|
|
1031
1034
|
it 'does nothing when the user clicks another link in the expanded area', asyncSpec (next) ->
|
1032
|
-
$area =
|
1035
|
+
$area = $fixture('div[up-expand]')
|
1033
1036
|
$expandedLink = $area.affix('a[href="/expanded-path"][up-follow]')
|
1034
1037
|
$otherLink = $area.affix('a[href="/other-path"][up-follow]')
|
1035
1038
|
up.hello($area)
|
@@ -1037,10 +1040,10 @@ describe 'up.link', ->
|
|
1037
1040
|
Trigger.clickSequence($otherLink)
|
1038
1041
|
next =>
|
1039
1042
|
expect(followSpy.calls.count()).toEqual(1)
|
1040
|
-
expect(followSpy.calls.mostRecent().args[0]).toEqual($otherLink)
|
1043
|
+
expect(followSpy.calls.mostRecent().args[0]).toEqual($otherLink[0])
|
1041
1044
|
|
1042
1045
|
it 'does nothing when the user clicks on an input in the expanded area', asyncSpec (next) ->
|
1043
|
-
$area =
|
1046
|
+
$area = $fixture('div[up-expand]')
|
1044
1047
|
$expandedLink = $area.affix('a[href="/expanded-path"][up-follow]')
|
1045
1048
|
$input = $area.affix('input[type=text]')
|
1046
1049
|
up.hello($area)
|
@@ -1050,7 +1053,7 @@ describe 'up.link', ->
|
|
1050
1053
|
expect(followSpy).not.toHaveBeenCalled()
|
1051
1054
|
|
1052
1055
|
it 'does not trigger multiple replaces when the user clicks on the expanded area of an [up-instant] link (bugfix)', asyncSpec (next) ->
|
1053
|
-
$area =
|
1056
|
+
$area = $fixture('div[up-expand] a[href="/path"][up-follow][up-instant]')
|
1054
1057
|
up.hello($area)
|
1055
1058
|
spyOn(up, 'replace')
|
1056
1059
|
Trigger.clickSequence($area)
|
@@ -1058,33 +1061,33 @@ describe 'up.link', ->
|
|
1058
1061
|
expect(up.replace.calls.count()).toEqual(1)
|
1059
1062
|
|
1060
1063
|
it 'does not add an up-follow attribute if the expanded link is [up-dash] with a selector (bugfix)', ->
|
1061
|
-
$area =
|
1064
|
+
$area = $fixture('div[up-expand] a[href="/path"][up-dash=".element"]')
|
1062
1065
|
up.hello($area)
|
1063
1066
|
expect($area.attr('up-follow')).toBeMissing()
|
1064
1067
|
|
1065
1068
|
it 'does not an up-follow attribute if the expanded link is [up-dash] without a selector (bugfix)', ->
|
1066
|
-
$area =
|
1069
|
+
$area = $fixture('div[up-expand] a[href="/path"][up-dash]')
|
1067
1070
|
up.hello($area)
|
1068
1071
|
expect($area.attr('up-follow')).toEqual('')
|
1069
1072
|
|
1070
1073
|
describe 'with a CSS selector in the property value', ->
|
1071
1074
|
|
1072
1075
|
it "expands the contained link that matches the selector", ->
|
1073
|
-
$area =
|
1076
|
+
$area = $fixture('div[up-expand=".second"]')
|
1074
1077
|
$link1 = $area.affix('a.first[href="/path1"]')
|
1075
1078
|
$link2 = $area.affix('a.second[href="/path2"]')
|
1076
1079
|
up.hello($area)
|
1077
1080
|
expect($area.attr('up-href')).toEqual('/path2')
|
1078
1081
|
|
1079
1082
|
it 'does nothing if no contained link matches the selector', ->
|
1080
|
-
$area =
|
1083
|
+
$area = $fixture('div[up-expand=".foo"]')
|
1081
1084
|
$link = $area.affix('a[href="/path1"]')
|
1082
1085
|
up.hello($area)
|
1083
1086
|
expect($area.attr('up-href')).toBeUndefined()
|
1084
1087
|
|
1085
1088
|
it 'does not match an element that is not a descendant', ->
|
1086
|
-
$area =
|
1089
|
+
$area = $fixture('div[up-expand=".second"]')
|
1087
1090
|
$link1 = $area.affix('a.first[href="/path1"]')
|
1088
|
-
$link2 =
|
1091
|
+
$link2 = $fixture('a.second[href="/path2"]') # not a child of $area
|
1089
1092
|
up.hello($area)
|
1090
1093
|
expect($area.attr('up-href')).toBeUndefined()
|