upjs-rails 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ ###*
2
+ Content slots
3
+ =============
4
+
5
+ It can be useful to mark "slots" in your page layout where you expect
6
+ content to appear in the future.
7
+
8
+ For example, you might have
9
+
10
+ <div up-slot class="alerts"></div>
11
+
12
+ <script>
13
+ up.awaken('.alerts', function ($element) {
14
+
15
+ RELOAD SHOULD NOT CACHE
16
+
17
+ setInterval(3000, function() { up.reload('.alerts') });
18
+ });
19
+ </script>
20
+
21
+ Seeing that the `.alerts` container is empty, Up.js will hide it:
22
+
23
+ <div class="alerts" up-slot style="display: none"></div>
24
+
25
+ As soon as you
26
+
27
+ <div class="alerts" up-slot>
28
+ Meeting at 11:30 AM
29
+ </div>
30
+
31
+
32
+ TODO: Write some documentation
33
+
34
+ @class up.slot
35
+ ###
36
+ up.slot = (->
37
+
38
+ u = up.util
39
+
40
+ hasContent = ($slot) ->
41
+ u.trim($slot.html()) != ''
42
+
43
+ check = ($element) ->
44
+ u.findWithSelf($element, '[up-slot]').each ->
45
+ $slot = $(this)
46
+ unless hasContent($slot)
47
+ $slot.hide()
48
+
49
+ ###*
50
+ Use this attribute to mark up empty element containers that
51
+ you plan to update with content in the future.
52
+
53
+ An element with this attribute is automatically hidden
54
+ if it has no content, and is re-shown if it is updated with
55
+ content.
56
+
57
+ This is useful to prevent the element from applying unwanted
58
+ margins to the surrounding page flow.
59
+
60
+ @method [up-slot]
61
+ @ujs
62
+ ###
63
+ up.bus.on 'fragment:ready', check
64
+
65
+ )()
66
+
@@ -1,4 +1,3 @@
1
-
2
1
  ###*
3
2
  Utility functions
4
3
  =================
@@ -328,7 +327,7 @@ up.util = (->
328
327
  for arg in args
329
328
  value = arg
330
329
  value = value() if isFunction(value)
331
- if isPresent(value)
330
+ if isGiven(value)
332
331
  match = value
333
332
  break
334
333
  match
@@ -402,11 +401,11 @@ up.util = (->
402
401
  The element to animate.
403
402
  @param {Object} lastFrame
404
403
  The CSS properties that should be transitioned to.
405
- @param {Number} [opts.duration=300]
404
+ @param {Number} [options.duration=300]
406
405
  The duration of the animation, in milliseconds.
407
- @param {Number} [opts.delay=0]
406
+ @param {Number} [options.delay=0]
408
407
  The delay before the animation starts, in milliseconds.
409
- @param {String} [opts.easing='ease']
408
+ @param {String} [options.easing='ease']
410
409
  The timing function that controls the animation's acceleration.
411
410
  See [W3C documentation](http://www.w3.org/TR/css3-transitions/#transition-timing-function)
412
411
  for a list of pre-defined timing functions.
@@ -517,7 +516,7 @@ up.util = (->
517
516
 
518
517
  contains = (array, element) ->
519
518
  array.indexOf(element) >= 0
520
-
519
+
521
520
  castsToTrue = (object) ->
522
521
  String(object) == "true"
523
522
 
@@ -14,7 +14,7 @@
14
14
  #= require up/modal
15
15
  #= require up/tooltip
16
16
  #= require up/navigation
17
- #= require up/marker
17
+ #= require up/slot
18
18
  #= require_self
19
19
 
20
20
  up.browser.ensureRecentJquery()
@@ -1,5 +1,5 @@
1
1
  module Upjs
2
2
  module Rails
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ @setTimer = (millis, fun) ->
2
+ setTimeout(fun, millis)
3
+
@@ -0,0 +1,5 @@
1
+ beforeEach ->
2
+ jasmine.addMatchers
3
+ toBeAround: (util, customEqualityTesters) ->
4
+ compare: (actual, expected, tolerance) ->
5
+ pass: Math.abs(expected - actual) <= tolerance
@@ -4,12 +4,156 @@ describe 'up.motion', ->
4
4
 
5
5
  describe 'up.animate', ->
6
6
 
7
- it 'should have tests'
8
-
7
+ if up.browser.canCssAnimation()
8
+
9
+ it 'animates the given element', (done) ->
10
+ $element = affix('.element').text('content')
11
+ opacity = -> Number($element.css('opacity'))
12
+ up.animate($element, 'fade-in', duration: 100, easing: 'linear')
13
+
14
+ setTimer 0, ->
15
+ expect(opacity()).toBeAround(0.0, 0.25)
16
+ setTimer 50, ->
17
+ expect(opacity()).toBeAround(0.5, 0.25)
18
+ setTimer 100, ->
19
+ expect(opacity()).toBeAround(1.0, 0.25)
20
+ done()
21
+
22
+ it 'cancels an existing animation on the element by instantly jumping to the last frame', ->
23
+ $element = affix('.element').text('content')
24
+ up.animate($element, { 'font-size': '40px' }, duration: 10000, easing: 'linear')
25
+ up.animate($element, { 'fade-in' }, duration: 100, easing: 'linear')
26
+ expect($element.css('font-size')).toEqual('40px')
27
+
28
+ else
29
+
30
+ it "doesn't animate and directly sets the last frame instead", ->
31
+ $element = affix('.element').text('content')
32
+ up.animate($element, { 'font-size': '40px' }, duration: 10000, easing: 'linear')
33
+ expect($element.css('font-size')).toEqual('40px')
34
+
35
+
9
36
  describe 'up.morph', ->
10
37
 
11
- it 'should have tests'
12
-
38
+ if up.browser.canCssAnimation()
39
+
40
+ it 'transitions between two element using ghosts', (done) ->
41
+
42
+ $old = affix('.old').text('old content').css(
43
+ position: 'absolute'
44
+ top: '10px'
45
+ left: '11px',
46
+ width: '12px',
47
+ height: '13px'
48
+ )
49
+ $new = affix('.new').text('new content').css(
50
+ position: 'absolute'
51
+ top: '20px'
52
+ left: '21px',
53
+ width: '22px',
54
+ height: '23px'
55
+ )
56
+ up.morph($old, $new, 'cross-fade', duration: 100, easing: 'linear')
57
+
58
+ # The actual animation will be performed on Ghosts since
59
+ # two element usually cannot exist in the DOM at the same time
60
+ # without undesired visual effects
61
+ $oldGhost = $('.old.up-ghost')
62
+ $newGhost = $('.new.up-ghost')
63
+ expect($oldGhost).toExist()
64
+ expect($newGhost).toExist()
65
+
66
+ # Ghosts should be inserted before (not after) the element
67
+ # or the browser scroll position will be too low after the
68
+ # transition ends.
69
+ expect($oldGhost.next()).toEqual($old)
70
+ expect($newGhost.next()).toEqual($new)
71
+
72
+ # The actual elements are hidden, but $old will take up its original
73
+ # space until the animation completes.
74
+ expect($old.css(['display', 'visibility'])).toEqual(
75
+ display: 'block',
76
+ visibility: 'hidden'
77
+ )
78
+ expect($new.css(['display', 'visibility'])).toEqual(
79
+ display: 'none',
80
+ visibility: 'visible'
81
+ )
82
+
83
+ # Ghosts will hover over $old and $new using absolute positioning,
84
+ # matching the coordinates of the original elements.
85
+ expect($oldGhost.css(['position', 'top', 'left', 'width', 'height'])).toEqual(
86
+ position: 'absolute'
87
+ top: '10px'
88
+ left: '11px',
89
+ width: '12px',
90
+ height: '13px'
91
+ )
92
+ expect($newGhost.css(['position', 'top', 'left', 'width', 'height'])).toEqual(
93
+ position: 'absolute'
94
+ top: '20px'
95
+ left: '21px',
96
+ width: '22px',
97
+ height: '23px'
98
+ )
99
+
100
+ opacity = ($element) -> Number($element.css('opacity'))
101
+
102
+ setTimer 0, ->
103
+ expect(opacity($newGhost)).toBeAround(0.0, 0.25)
104
+ expect(opacity($oldGhost)).toBeAround(1.0, 0.25)
105
+
106
+ setTimer 40, ->
107
+ expect(opacity($newGhost)).toBeAround(0.4, 0.25)
108
+ expect(opacity($oldGhost)).toBeAround(0.6, 0.25)
109
+
110
+ setTimer 70, ->
111
+ expect(opacity($newGhost)).toBeAround(0.7, 0.25)
112
+ expect(opacity($oldGhost)).toBeAround(0.3, 0.25)
113
+
114
+ setTimer 125, ->
115
+ # Once our two ghosts have rendered their visual effect,
116
+ # we remove them from the DOM.
117
+ expect($newGhost).not.toBeInDOM()
118
+ expect($oldGhost).not.toBeInDOM()
119
+
120
+ # The old element is still in the DOM, but hidden.
121
+ # Morphing does *not* remove the target element.
122
+ expect($old.css(['display', 'visibility'])).toEqual(
123
+ display: 'none',
124
+ visibility: 'hidden'
125
+ )
126
+ expect($new.css(['display', 'visibility'])).toEqual(
127
+ display: 'block',
128
+ visibility: 'visible'
129
+ )
130
+
131
+ done()
132
+
133
+ it 'cancels an existing transition on the element by instantly jumping to the last frame', ->
134
+ $old = affix('.old').text('old content')
135
+ $new = affix('.new').text('new content')
136
+
137
+ up.morph($old, $new, 'cross-fade', duration: 200)
138
+ $ghost1 = $('.old.up-ghost')
139
+ expect($ghost1).toHaveLength(1)
140
+
141
+ up.morph($old, $new, 'cross-fade', duration: 200)
142
+ $ghost2 = $('.old.up-ghost')
143
+ # Check that we didn't create additional ghosts
144
+ expect($ghost2).toHaveLength(1)
145
+ # Check that it's a different ghosts
146
+ expect($ghost2).not.toEqual($ghost1)
147
+
148
+ else
149
+
150
+ it "doesn't animate and hides the first element instead", ->
151
+ $old = affix('.old').text('old content')
152
+ $new = affix('.new').text('new content')
153
+ up.morph($old, $new, 'cross-fade', duration: 1000)
154
+ expect($old).toBeHidden()
155
+ expect($new).toBeVisible()
156
+
13
157
  describe 'up.transition', ->
14
158
 
15
159
  it 'should have tests'
@@ -2,15 +2,15 @@ describe 'up.marker', ->
2
2
 
3
3
  describe 'unobtrusive behavior', ->
4
4
 
5
- describe '[up-marker]', ->
5
+ describe '[up-slot]', ->
6
6
 
7
7
  it 'hides empty containers', ->
8
- $element = affix('.element[up-marker]')
8
+ $element = affix('.element[up-slot]')
9
9
  up.ready($element)
10
10
  expect($element).not.toBeVisible()
11
11
 
12
12
  it 'does not hide empty containers', ->
13
- $element = affix('.element[up-marker]').text('content')
13
+ $element = affix('.element[up-slot]').text('content')
14
14
  up.ready($element)
15
15
  expect($element).toBeVisible()
16
16
 
@@ -19,8 +19,8 @@ describe 'up.tooltip', ->
19
19
  expect($tooltip).toHaveText('tooltip text')
20
20
  tooltipBox = up.util.measure($tooltip, relative: true)
21
21
  linkBox = up.util.measure($link, relative: true)
22
- expect(tooltipBox.top).toBeCloseTo(linkBox.top - tooltipBox.height, 15)
23
- expect(tooltipBox.left).toBeCloseTo(linkBox.left + 0.5 * (linkBox.width - tooltipBox.width), 15)
22
+ expect(tooltipBox.top).toBeAround(linkBox.top - tooltipBox.height, 15)
23
+ expect(tooltipBox.left).toBeAround(linkBox.left + 0.5 * (linkBox.width - tooltipBox.width), 15)
24
24
 
25
25
  it 'allows HTML for the tooltip text'
26
26
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
@@ -125,13 +125,13 @@ files:
125
125
  - lib/assets/javascripts/up/history.js.coffee
126
126
  - lib/assets/javascripts/up/link.js.coffee
127
127
  - lib/assets/javascripts/up/magic.js.coffee
128
- - lib/assets/javascripts/up/marker.js.coffee
129
128
  - lib/assets/javascripts/up/modal.js.coffee
130
129
  - lib/assets/javascripts/up/module.js.coffee
131
130
  - lib/assets/javascripts/up/motion.js.coffee
132
131
  - lib/assets/javascripts/up/navigation.js.coffee
133
132
  - lib/assets/javascripts/up/popup.js.coffee
134
133
  - lib/assets/javascripts/up/proxy.js.coffee
134
+ - lib/assets/javascripts/up/slot.js.coffee
135
135
  - lib/assets/javascripts/up/tooltip.js.coffee
136
136
  - lib/assets/javascripts/up/util.js.coffee
137
137
  - lib/assets/javascripts/up/viewport.js.coffee
@@ -227,6 +227,8 @@ files:
227
227
  - spec_app/spec/javascripts/helpers/index.js.coffee
228
228
  - spec_app/spec/javascripts/helpers/reset_path.js.coffee
229
229
  - spec_app/spec/javascripts/helpers/reset_up.js.coffee
230
+ - spec_app/spec/javascripts/helpers/set_timer.js.coffee
231
+ - spec_app/spec/javascripts/helpers/to_be_around.js.coffee
230
232
  - spec_app/spec/javascripts/helpers/to_equal_jquery.js.coffee
231
233
  - spec_app/spec/javascripts/helpers/trigger.js.coffee
232
234
  - spec_app/spec/javascripts/support/jasmine.yml
@@ -236,12 +238,12 @@ files:
236
238
  - spec_app/spec/javascripts/up/history_spec.js.coffee
237
239
  - spec_app/spec/javascripts/up/link_spec.js.coffee
238
240
  - spec_app/spec/javascripts/up/magic_spec.js.coffee
239
- - spec_app/spec/javascripts/up/marker_spec.js.coffee
240
241
  - spec_app/spec/javascripts/up/modal_spec.js.coffee
241
242
  - spec_app/spec/javascripts/up/motion_spec.js.coffee
242
243
  - spec_app/spec/javascripts/up/navigation_spec.js.coffee
243
244
  - spec_app/spec/javascripts/up/popup_spec.js.coffee
244
245
  - spec_app/spec/javascripts/up/proxy_spec.js.coffee
246
+ - spec_app/spec/javascripts/up/slot_spec.js.coffee
245
247
  - spec_app/spec/javascripts/up/tooltip_spec.js.coffee
246
248
  - spec_app/spec/javascripts/up/util_spec.js.coffee
247
249
  - spec_app/test/controllers/.keep
@@ -1,39 +0,0 @@
1
- ###*
2
- Markers
3
- =======
4
-
5
- TODO: Write some documentation
6
-
7
- @class up.marker
8
- ###
9
- up.marker = (->
10
-
11
- u = up.util
12
-
13
- hasContent = ($marker) ->
14
- u.trim($marker.html()) != ''
15
-
16
- check = ($element) ->
17
- u.findWithSelf($element, '[up-marker]').each ->
18
- $marker = $(this)
19
- unless hasContent($marker)
20
- $marker.hide()
21
-
22
- ###*
23
- Use this attribute to mark up empty element containers that
24
- you plan to update with content in the future.
25
-
26
- An element with this attribute is automatically hidden
27
- if it has no content, and is re-shown if it is updated with
28
- content.
29
-
30
- This is useful to prevent the element from applying unwanted
31
- margins to the surrounding page flow.
32
-
33
- @method [up-marker]
34
- @ujs
35
- ###
36
- up.bus.on 'fragment:ready', check
37
-
38
- )()
39
-