unpoly-rails 0.26.1 → 0.26.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of unpoly-rails might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/dist/unpoly.js +77 -109
- data/dist/unpoly.min.js +3 -3
- data/lib/assets/javascripts/unpoly/modal.js.coffee +10 -3
- data/lib/assets/javascripts/unpoly/popup.js.coffee +31 -45
- data/lib/assets/javascripts/unpoly/tooltip.js.coffee +18 -10
- data/lib/assets/javascripts/unpoly/util.js.coffee +4 -7
- data/lib/unpoly/rails/version.rb +1 -1
- data/spec_app/app/assets/stylesheets/integration_test.sass +16 -0
- data/spec_app/app/views/css_test/popup.erb +25 -0
- data/spec_app/app/views/css_test/popup_contents.erb +5 -0
- data/spec_app/app/views/css_test/tooltip.erb +7 -0
- data/spec_app/app/views/pages/start.erb +4 -0
- data/spec_app/spec/javascripts/up/modal_spec.js.coffee +19 -5
- data/spec_app/spec/javascripts/up/popup_spec.js.coffee +32 -8
- data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +32 -6
- metadata +4 -2
@@ -57,23 +57,31 @@ up.tooltip = (($) ->
|
|
57
57
|
config.reset()
|
58
58
|
|
59
59
|
setPosition = ($link, $tooltip, position) ->
|
60
|
-
|
60
|
+
css = {}
|
61
61
|
tooltipBox = u.measure($tooltip)
|
62
|
-
|
62
|
+
|
63
|
+
if u.isFixed($link)
|
64
|
+
linkBox = $link.get(0).getBoundingClientRect()
|
65
|
+
css['position'] = 'fixed'
|
66
|
+
else
|
67
|
+
linkBox = u.measure($link)
|
68
|
+
|
69
|
+
switch position
|
63
70
|
when "top"
|
64
|
-
|
65
|
-
|
71
|
+
css['top'] = linkBox.top - tooltipBox.height
|
72
|
+
css['left'] = linkBox.left + 0.5 * (linkBox.width - tooltipBox.width)
|
66
73
|
when "left"
|
67
|
-
|
68
|
-
|
74
|
+
css['top'] = linkBox.top + 0.5 * (linkBox.height - tooltipBox.height)
|
75
|
+
css['left'] = linkBox.left - tooltipBox.width
|
69
76
|
when "right"
|
70
|
-
|
71
|
-
|
77
|
+
css['top'] = linkBox.top + 0.5 * (linkBox.height - tooltipBox.height)
|
78
|
+
css['left'] = linkBox.left + linkBox.width
|
72
79
|
when "bottom"
|
73
|
-
|
74
|
-
|
80
|
+
css['top'] = linkBox.top + linkBox.height
|
81
|
+
css['left'] = linkBox.left + 0.5 * (linkBox.width - tooltipBox.width)
|
75
82
|
else
|
76
83
|
u.error("Unknown position option '%s'", position)
|
84
|
+
|
77
85
|
$tooltip.attr('up-position', position)
|
78
86
|
$tooltip.css(css)
|
79
87
|
|
@@ -886,7 +886,8 @@ up.util = (($) ->
|
|
886
886
|
A function that restores the original CSS when called.
|
887
887
|
@internal
|
888
888
|
###
|
889
|
-
temporaryCss = (
|
889
|
+
temporaryCss = (elementOrSelector, css, block) ->
|
890
|
+
$element = $(elementOrSelector)
|
890
891
|
oldCss = $element.css(Object.keys(css))
|
891
892
|
$element.css(css)
|
892
893
|
memo = -> $element.css(oldCss)
|
@@ -1048,7 +1049,7 @@ up.util = (($) ->
|
|
1048
1049
|
@internal
|
1049
1050
|
###
|
1050
1051
|
measure = ($element, opts) ->
|
1051
|
-
opts = options(opts, relative: false, inner: false
|
1052
|
+
opts = options(opts, relative: false, inner: false)
|
1052
1053
|
|
1053
1054
|
if opts.relative
|
1054
1055
|
if opts.relative == true
|
@@ -1078,11 +1079,7 @@ up.util = (($) ->
|
|
1078
1079
|
else
|
1079
1080
|
box.width = $element.outerWidth()
|
1080
1081
|
box.height = $element.outerHeight()
|
1081
|
-
|
1082
|
-
if opts.full
|
1083
|
-
$viewport = up.layout.viewportOf($element)
|
1084
|
-
box.right = $viewport.width() - (box.left + box.width)
|
1085
|
-
box.bottom = $viewport.height() - (box.top + box.height)
|
1082
|
+
|
1086
1083
|
box
|
1087
1084
|
|
1088
1085
|
###*
|
data/lib/unpoly/rails/version.rb
CHANGED
@@ -5,6 +5,22 @@ body
|
|
5
5
|
background: image-url('grid.png') repeat
|
6
6
|
font-family: arial, sans-serif
|
7
7
|
|
8
|
+
.page
|
9
|
+
min-height: 3000px
|
10
|
+
|
11
|
+
.spacer
|
12
|
+
background-color: transparentize(green, 0.5)
|
13
|
+
height: 150px
|
14
|
+
content: 'Free space'
|
15
|
+
|
16
|
+
.fixed-top-bar
|
17
|
+
position: fixed
|
18
|
+
top: 0
|
19
|
+
left: 0
|
20
|
+
right: 0
|
21
|
+
background-color: transparentize(blue, 0.5)
|
22
|
+
padding: 50px
|
23
|
+
|
8
24
|
.example
|
9
25
|
margin: 50px
|
10
26
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<div class="spacer">
|
2
|
+
</div>
|
3
|
+
|
4
|
+
<div class="example">
|
5
|
+
<a class="button" href="/css_test/popup_contents" up-popup=".contents" up-position="top-left">Top-left popup</a>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<div class="example">
|
9
|
+
<a class="button" href="/css_test/popup_contents" up-popup=".contents" up-position="top-right">Top-right popup</a>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="example">
|
13
|
+
<a class="button" href="/css_test/popup_contents" up-popup=".contents" up-position="bottom-right">Bottom-right popup</a>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="example">
|
17
|
+
<a class="button" href="/css_test/popup_contents" up-popup=".contents" up-position="bottom-left">Bottom-left popup</a>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class="fixed-top-bar">
|
21
|
+
<a class="button" href="/css_test/popup_contents" up-popup=".contents" up-position="top-left">Top-left popup</a>
|
22
|
+
<a class="button" href="/css_test/popup_contents" up-popup=".contents" up-position="top-right">Top-right popup</a>
|
23
|
+
<a class="button" href="/css_test/popup_contents" up-popup=".contents" up-position="bottom-right">Bottom-right popup</a>
|
24
|
+
<a class="button" href="/css_test/popup_contents" up-popup=".contents" up-position="bottom-left">Bottom-left popup</a>
|
25
|
+
</div>
|
@@ -13,3 +13,10 @@
|
|
13
13
|
<div class="example">
|
14
14
|
<a class="button" href="#" up-tooltip="Tooltip text" up-position="right">Right tooltip</a>
|
15
15
|
</div>
|
16
|
+
|
17
|
+
<div class="fixed-top-bar">
|
18
|
+
<a class="button" href="#" up-tooltip="Tooltip text" up-position="top">Top tooltip</a>
|
19
|
+
<a class="button" href="#" up-tooltip="Tooltip text" up-position="bottom">Bottom tooltip</a>
|
20
|
+
<a class="button" href="#" up-tooltip="Tooltip text" up-position="left">Left tooltip</a>
|
21
|
+
<a class="button" href="#" up-tooltip="Tooltip text" up-position="right">Right tooltip</a>
|
22
|
+
</div>
|
@@ -143,7 +143,7 @@ describe 'up.modal', ->
|
|
143
143
|
@respondWith('<div class="container">response1</div>', request: request1)
|
144
144
|
u.setTimer 10, =>
|
145
145
|
@respondWith('<div class="container">response2</div>', request: request2)
|
146
|
-
u.setTimer
|
146
|
+
u.setTimer 110, =>
|
147
147
|
expect($('.up-modal').length).toBe(1)
|
148
148
|
expect($('.up-modal-dialog').length).toBe(1)
|
149
149
|
expect($('.container')).toHaveText('response2')
|
@@ -323,37 +323,44 @@ describe 'up.modal', ->
|
|
323
323
|
describe 'unobtrusive behavior', ->
|
324
324
|
|
325
325
|
describe 'a[up-modal]', ->
|
326
|
-
|
326
|
+
|
327
327
|
beforeEach ->
|
328
|
-
|
329
|
-
|
330
|
-
|
328
|
+
@stubFollow = =>
|
329
|
+
@$link = affix('a[href="/path"][up-modal=".target"]')
|
330
|
+
@followSpy = up.modal.knife.mock('follow').and.returnValue(u.resolvedPromise())
|
331
|
+
@defaultSpy = up.link.knife.mock('allowDefault').and.callFake((event) -> event.preventDefault())
|
331
332
|
|
332
333
|
it 'opens the clicked link in a modal', ->
|
334
|
+
@stubFollow()
|
333
335
|
Trigger.click(@$link)
|
334
336
|
expect(@followSpy).toHaveBeenCalledWith(@$link)
|
335
337
|
|
336
338
|
# IE does not call Javascript and always performs the default action on right clicks
|
337
339
|
unless navigator.userAgent.match(/Trident/)
|
338
340
|
it 'does nothing if the right mouse button is used', ->
|
341
|
+
@stubFollow()
|
339
342
|
Trigger.click(@$link, button: 2)
|
340
343
|
expect(@followSpy).not.toHaveBeenCalled()
|
341
344
|
|
342
345
|
it 'does nothing if shift is pressed during the click', ->
|
346
|
+
@stubFollow()
|
343
347
|
Trigger.click(@$link, shiftKey: true)
|
344
348
|
expect(@followSpy).not.toHaveBeenCalled()
|
345
349
|
|
346
350
|
it 'does nothing if ctrl is pressed during the click', ->
|
351
|
+
@stubFollow()
|
347
352
|
Trigger.click(@$link, ctrlKey: true)
|
348
353
|
expect(@followSpy).not.toHaveBeenCalled()
|
349
354
|
|
350
355
|
it 'does nothing if meta is pressed during the click', ->
|
356
|
+
@stubFollow()
|
351
357
|
Trigger.click(@$link, metaKey: true)
|
352
358
|
expect(@followSpy).not.toHaveBeenCalled()
|
353
359
|
|
354
360
|
describe 'with [up-instant] modifier', ->
|
355
361
|
|
356
362
|
beforeEach ->
|
363
|
+
@stubFollow()
|
357
364
|
@$link.attr('up-instant', '')
|
358
365
|
|
359
366
|
it 'opens the modal on mousedown (instead of on click)', ->
|
@@ -386,6 +393,13 @@ describe 'up.modal', ->
|
|
386
393
|
Trigger.mousedown(@$link, metaKey: true)
|
387
394
|
expect(@followSpy).not.toHaveBeenCalled()
|
388
395
|
|
396
|
+
describe 'with [up-method] modifier', ->
|
397
|
+
|
398
|
+
it 'honours the given method', ->
|
399
|
+
$link = affix('a[href="/path"][up-modal=".target"][up-method="post"]')
|
400
|
+
Trigger.click($link)
|
401
|
+
expect(@lastRequest().method).toEqual 'POST'
|
402
|
+
|
389
403
|
|
390
404
|
describe '[up-close]', ->
|
391
405
|
|
@@ -10,11 +10,16 @@ describe 'up.popup', ->
|
|
10
10
|
jasmine.addMatchers
|
11
11
|
toSitBelow: (util, customEqualityTesters) ->
|
12
12
|
compare: ($popup, $link) ->
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
popupDims = $popup.get(0).getBoundingClientRect()
|
14
|
+
linkDims = $link.get(0).getBoundingClientRect()
|
15
|
+
pass:
|
16
|
+
Math.abs(popupDims.right - linkDims.right) < 1.0 && Math.abs(popupDims.top - linkDims.bottom) < 1.0
|
17
|
+
|
18
|
+
beforeEach ->
|
19
|
+
@restoreBodyHeight = u.temporaryCss('body', 'min-height': '3000px')
|
20
|
+
|
21
|
+
afterEach ->
|
22
|
+
@restoreBodyHeight()
|
18
23
|
|
19
24
|
it "loads this link's destination in a popup positioned under the given link", ->
|
20
25
|
$container = affix('.container')
|
@@ -42,19 +47,24 @@ describe 'up.popup', ->
|
|
42
47
|
expect($popup.find('.after')).not.toExist()
|
43
48
|
|
44
49
|
expect($popup.css('position')).toEqual('absolute')
|
50
|
+
|
45
51
|
expect($popup).toSitBelow($link)
|
46
52
|
|
47
53
|
it 'gives the popup { position: "fixed" } if the given link is fixed', ->
|
54
|
+
# Let's test the harder case where the document is scrolled
|
55
|
+
up.layout.scroll(document, 50)
|
48
56
|
$container = affix('.container')
|
49
57
|
$container.css
|
50
58
|
position: 'fixed'
|
51
59
|
left: '100px'
|
52
60
|
top: '50px'
|
53
61
|
$link = $container.affix('a[href="/path/to"][up-popup=".content"]').text('link')
|
62
|
+
|
54
63
|
up.popup.attach($link)
|
55
64
|
@respondWith('<div class="content">popup-content</div>')
|
56
65
|
$popup = $('.up-popup')
|
57
66
|
expect($popup.css('position')).toEqual('fixed')
|
67
|
+
|
58
68
|
expect($popup).toSitBelow($link)
|
59
69
|
|
60
70
|
it 'does not explode if the popup was closed before the response was received', ->
|
@@ -166,35 +176,42 @@ describe 'up.popup', ->
|
|
166
176
|
describe 'a[up-popup]', ->
|
167
177
|
|
168
178
|
beforeEach ->
|
169
|
-
|
170
|
-
|
171
|
-
|
179
|
+
@stubAttach = =>
|
180
|
+
@$link = affix('a[href="/path"][up-popup=".target"]')
|
181
|
+
@attachSpy = up.popup.knife.mock('attach').and.returnValue(u.resolvedPromise())
|
182
|
+
@defaultSpy = up.link.knife.mock('allowDefault').and.callFake((event) -> event.preventDefault())
|
172
183
|
|
173
184
|
it 'opens the clicked link in a popup', ->
|
185
|
+
@stubAttach()
|
174
186
|
Trigger.click(@$link)
|
175
187
|
expect(@attachSpy).toHaveBeenCalledWith(@$link)
|
176
188
|
|
177
189
|
# IE does not call Javascript and always performs the default action on right clicks
|
178
190
|
unless navigator.userAgent.match(/Trident/)
|
179
191
|
it 'does nothing if the right mouse button is used', ->
|
192
|
+
@stubAttach()
|
180
193
|
Trigger.click(@$link, button: 2)
|
181
194
|
expect(@attachSpy).not.toHaveBeenCalled()
|
182
195
|
|
183
196
|
it 'does nothing if shift is pressed during the click', ->
|
197
|
+
@stubAttach()
|
184
198
|
Trigger.click(@$link, shiftKey: true)
|
185
199
|
expect(@attachSpy).not.toHaveBeenCalled()
|
186
200
|
|
187
201
|
it 'does nothing if ctrl is pressed during the click', ->
|
202
|
+
@stubAttach()
|
188
203
|
Trigger.click(@$link, ctrlKey: true)
|
189
204
|
expect(@attachSpy).not.toHaveBeenCalled()
|
190
205
|
|
191
206
|
it 'does nothing if meta is pressed during the click', ->
|
207
|
+
@stubAttach()
|
192
208
|
Trigger.click(@$link, metaKey: true)
|
193
209
|
expect(@attachSpy).not.toHaveBeenCalled()
|
194
210
|
|
195
211
|
describe 'with [up-instant] modifier', ->
|
196
212
|
|
197
213
|
beforeEach ->
|
214
|
+
@stubAttach()
|
198
215
|
@$link.attr('up-instant', '')
|
199
216
|
|
200
217
|
it 'opens the modal on mousedown (instead of on click)', ->
|
@@ -227,6 +244,13 @@ describe 'up.popup', ->
|
|
227
244
|
Trigger.mousedown(@$link, metaKey: true)
|
228
245
|
expect(@attachSpy).not.toHaveBeenCalled()
|
229
246
|
|
247
|
+
describe 'with [up-method] modifier', ->
|
248
|
+
|
249
|
+
it 'honours the given method', ->
|
250
|
+
$link = affix('a[href="/path"][up-popup=".target"][up-method="post"]')
|
251
|
+
Trigger.click($link)
|
252
|
+
expect(@lastRequest().method).toEqual 'POST'
|
253
|
+
|
230
254
|
describe '[up-close]', ->
|
231
255
|
|
232
256
|
describe 'when clicked inside a popup', ->
|
@@ -1,5 +1,7 @@
|
|
1
1
|
describe 'up.tooltip', ->
|
2
|
-
|
2
|
+
|
3
|
+
u = up.util
|
4
|
+
|
3
5
|
describe 'Javascript functions', ->
|
4
6
|
|
5
7
|
describe 'up.tooltip.attach', ->
|
@@ -33,44 +35,68 @@ describe 'up.tooltip', ->
|
|
33
35
|
width: '50px'
|
34
36
|
height: '50px'
|
35
37
|
)
|
36
|
-
|
38
|
+
|
39
|
+
beforeEach ->
|
40
|
+
@restoreBodyHeight = u.temporaryCss('body', 'min-height': '3000px')
|
41
|
+
|
42
|
+
afterEach ->
|
43
|
+
@restoreBodyHeight()
|
37
44
|
|
38
45
|
describe 'with { position: "top" }', ->
|
39
46
|
|
40
47
|
it 'centers the tooltip above the given element', ->
|
48
|
+
@linkBox = @$link.get(0).getBoundingClientRect()
|
41
49
|
up.tooltip.attach(@$link, html: 'tooltip text', position: 'top')
|
42
50
|
$tooltip = $('.up-tooltip')
|
43
|
-
tooltipBox =
|
51
|
+
tooltipBox = $tooltip.get(0).getBoundingClientRect()
|
44
52
|
expect(tooltipBox.top).toBeAround(@linkBox.top - tooltipBox.height, 15)
|
45
53
|
expect(tooltipBox.left).toBeAround(@linkBox.left + 0.5 * (@linkBox.width - tooltipBox.width), 15)
|
46
54
|
|
47
55
|
describe 'with { position: "right" }', ->
|
48
56
|
|
49
57
|
it 'centers the tooltip at the right side of the given element', ->
|
58
|
+
@linkBox = @$link.get(0).getBoundingClientRect()
|
50
59
|
up.tooltip.attach(@$link, html: 'tooltip text', position: 'right')
|
51
60
|
$tooltip = $('.up-tooltip')
|
52
|
-
tooltipBox =
|
61
|
+
tooltipBox = $tooltip.get(0).getBoundingClientRect()
|
53
62
|
expect(tooltipBox.top).toBeAround(@linkBox.top + 0.5 * (@linkBox.height - tooltipBox.height), 15)
|
54
63
|
expect(tooltipBox.left).toBeAround(@linkBox.left + @linkBox.width, 15)
|
55
64
|
|
56
65
|
describe 'with { position: "bottom" }', ->
|
57
66
|
|
58
67
|
it 'centers the tooltip below the given element', ->
|
68
|
+
@linkBox = @$link.get(0).getBoundingClientRect()
|
59
69
|
up.tooltip.attach(@$link, html: 'tooltip text', position: 'bottom')
|
60
70
|
$tooltip = $('.up-tooltip')
|
61
|
-
tooltipBox =
|
71
|
+
tooltipBox = $tooltip.get(0).getBoundingClientRect()
|
62
72
|
expect(tooltipBox.top).toBeAround(@linkBox.top + @linkBox.height, 15)
|
63
73
|
expect(tooltipBox.left).toBeAround(@linkBox.left + 0.5 * (@linkBox.width - tooltipBox.width), 15)
|
64
74
|
|
65
75
|
describe 'with { position: "left" }', ->
|
66
76
|
|
67
77
|
it 'centers the tooltip at the left side of the given element', ->
|
78
|
+
@linkBox = @$link.get(0).getBoundingClientRect()
|
68
79
|
up.tooltip.attach(@$link, html: 'tooltip text', position: 'left')
|
69
80
|
$tooltip = $('.up-tooltip')
|
70
|
-
tooltipBox =
|
81
|
+
tooltipBox = $tooltip.get(0).getBoundingClientRect()
|
71
82
|
expect(tooltipBox.top).toBeAround(@linkBox.top + 0.5 * (@linkBox.height - tooltipBox.height), 15)
|
72
83
|
expect(tooltipBox.left).toBeAround(@linkBox.left - tooltipBox.width, 15)
|
73
84
|
|
85
|
+
it 'gives the tooltip { position: "fixed" } if the given link is fixed', ->
|
86
|
+
# Let's test the harder case where the document is scrolled
|
87
|
+
up.layout.scroll(document, 50)
|
88
|
+
@$link.css(position: 'fixed')
|
89
|
+
@linkBox = @$link.get(0).getBoundingClientRect()
|
90
|
+
|
91
|
+
up.tooltip.attach(@$link, html: 'tooltip text', position: 'top')
|
92
|
+
$tooltip = $('.up-tooltip')
|
93
|
+
tooltipBox = $tooltip.get(0).getBoundingClientRect()
|
94
|
+
|
95
|
+
expect($tooltip.css('position')).toEqual('fixed')
|
96
|
+
expect(tooltipBox.top).toBeAround(@linkBox.top - tooltipBox.height, 15)
|
97
|
+
expect(tooltipBox.left).toBeAround(@linkBox.left + 0.5 * (@linkBox.width - tooltipBox.width), 15)
|
98
|
+
|
99
|
+
|
74
100
|
it 'closes an existing tooltip'
|
75
101
|
|
76
102
|
describe 'with position option', ->
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unpoly-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.26.
|
4
|
+
version: 0.26.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -150,6 +150,8 @@ files:
|
|
150
150
|
- spec_app/app/helpers/application_helper.rb
|
151
151
|
- spec_app/app/mailers/.keep
|
152
152
|
- spec_app/app/models/concerns/.keep
|
153
|
+
- spec_app/app/views/css_test/popup.erb
|
154
|
+
- spec_app/app/views/css_test/popup_contents.erb
|
153
155
|
- spec_app/app/views/css_test/tooltip.erb
|
154
156
|
- spec_app/app/views/form_test/basics/new.erb
|
155
157
|
- spec_app/app/views/form_test/submission_result.erb
|