upjs-rails 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,7 @@ We need to work on this page:
15
15
  - Demo the built-in animations and transitions
16
16
  - Examples for defining your own animations and transitions
17
17
  - Explain ghosting
18
+ - Explain how many elements accept arguments for animation.
18
19
 
19
20
 
20
21
  @class up.motion
@@ -43,38 +44,76 @@ up.motion = (->
43
44
  u.extend(config, options)
44
45
 
45
46
  ###*
46
- Animates an element.
47
-
48
- If the element is already being animated, the previous animation
49
- will instantly jump to its last frame before the new animation begins.
50
-
51
- The following animations are pre-registered:
52
-
53
- - `fade-in`
54
- - `fade-out`
55
- - `move-to-top`
56
- - `move-from-top`
57
- - `move-to-bottom`
58
- - `move-from-bottom`
59
- - `move-to-left`
60
- - `move-from-left`
61
- - `move-to-right`
62
- - `move-from-right`
63
- - `none`
64
-
47
+ Applies the given animation to the given element:
48
+
49
+ up.animate('.warning', 'fade-in');
50
+
51
+ You can pass additional options:
52
+
53
+ up.animate('warning', '.fade-in', {
54
+ delay: 1000,
55
+ duration: 250,
56
+ easing: 'linear'
57
+ });
58
+
59
+ \#\#\#\# Named animations
60
+
61
+ The following animations are pre-defined:
62
+
63
+ | `fade-in` | Changes the element's opacity from 0% to 100% |
64
+ | `fade-out` | Changes the element's opacity from 100% to 0% |
65
+ | `move-to-top` | Moves the element upwards until it exits the screen at the top edge |
66
+ | `move-from-top` | Moves the element downwards from beyond the top edge of the screen until it reaches its current position |
67
+ | `move-to-bottom` | Moves the element downwards until it exits the screen at the bottom edge |
68
+ | `move-from-bottom` | Moves the element upwards from beyond the bottom edge of the screen until it reaches its current position |
69
+ | `move-to-left` | Moves the element leftwards until it exists the screen at the left edge |
70
+ | `move-from-left` | Moves the element rightwards from beyond the left edge of the screen until it reaches its current position |
71
+ | `move-to-right` | Moves the element rightwards until it exists the screen at the right edge |
72
+ | `move-from-right` | Moves the element leftwards from beyond the right edge of the screen until it reaches its current position |
73
+ | `none` | An animation that has no visible effect. Sounds useless at first, but can save you a lot of `if` statements. |
74
+
75
+ You can define additional named animations using [`up.animation`](#up.animation).
76
+
77
+ \#\#\#\# Animating CSS properties directly
78
+
79
+ By passing an object instead of an animation name, you can animate
80
+ the CSS properties of the given element:
81
+
82
+ var $warning = $('.warning');
83
+ $warning.css({ opacity: 0 });
84
+ up.animate($warning, { opacity: 1 });
85
+
86
+ \#\#\#\# Multiple animations on the same element
87
+
88
+ Up.js doesn't allow more than one concurrent animation on the same element.
89
+
90
+ If you attempt to animate an element that is already being animated,
91
+ the previous animation will instantly jump to its last frame before
92
+ the new animation begins.
93
+
65
94
  @method up.animate
66
95
  @param {Element|jQuery|String} elementOrSelector
96
+ The element to animate.
67
97
  @param {String|Function|Object} animation
68
- @param {Number} [options.duration]
69
- @param {String} [options.easing]
70
- @param {Number} [options.delay]
98
+ Can either be:
99
+ - The animation's name
100
+ - A function performing the animation
101
+ - An object of CSS attributes describing the last frame of the animation
102
+ @param {Number} [opts.duration=300]
103
+ The duration of the animation, in milliseconds.
104
+ @param {Number} [opts.delay=0]
105
+ The delay before the animation starts, in milliseconds.
106
+ @param {String} [opts.easing='ease']
107
+ The timing function that controls the animation's acceleration.
108
+ See [W3C documentation](http://www.w3.org/TR/css3-transitions/#transition-timing-function)
109
+ for a list of pre-defined timing functions.
71
110
  @return {Promise}
72
111
  A promise for the animation's end.
73
112
  ###
74
113
  animate = (elementOrSelector, animation, options) ->
75
114
  $element = $(elementOrSelector)
76
115
  finish($element)
77
- options = u.options(options, config)
116
+ options = animateOptions(options)
78
117
  if u.isFunction(animation)
79
118
  assertIsDeferred(animation($element, options), animation)
80
119
  else if u.isString(animation)
@@ -83,6 +122,22 @@ up.motion = (->
83
122
  u.cssAnimate($element, animation, options)
84
123
  else
85
124
  u.error("Unknown animation type %o", animation)
125
+
126
+ ###*
127
+ Extracts animation-related options from the given options hash.
128
+ If `$element` is given, also inspects the element for animation-related
129
+ attributes like `up-easing` or `up-duration`.
130
+
131
+ @protected
132
+ @method up.motion.animateOptions
133
+ ###
134
+ animateOptions = (allOptions, $element = null) ->
135
+ allOptions = u.options(allOptions)
136
+ options = {}
137
+ options.easing = u.option(allOptions.easing, $element?.attr('up-easing'), config.easing)
138
+ options.duration = Number(u.option(allOptions.duration, $element?.attr('up-duration'), config.duration))
139
+ options.delay = Number(u.option(allOptions.delay, $element?.attr('up-delay'), config.delay))
140
+ options
86
141
 
87
142
  findAnimation = (name) ->
88
143
  animations[name] or u.error("Unknown animation %o", animation)
@@ -99,7 +154,7 @@ up.motion = (->
99
154
  # $old should take up space in the page flow until the transition ends
100
155
  $old.css(visibility: 'hidden')
101
156
 
102
- newCssMemo = u.temporaryCss($new, display: 'none')
157
+ showNew = u.temporaryCss($new, display: 'none')
103
158
  promise = block($oldGhost, $newGhost)
104
159
  $old.data(GHOSTING_PROMISE_KEY, promise)
105
160
  $new.data(GHOSTING_PROMISE_KEY, promise)
@@ -113,7 +168,7 @@ up.motion = (->
113
168
  # Since we expect $old to be removed in a heartbeat,
114
169
  # $new should take up space
115
170
  $old.css(display: 'none')
116
- newCssMemo()
171
+ showNew()
117
172
 
118
173
  promise
119
174
 
@@ -121,7 +176,7 @@ up.motion = (->
121
176
  Completes all animations and transitions for the given element
122
177
  by jumping to the last animation frame instantly. All callbacks chained to
123
178
  the original animation's promise will be called.
124
-
179
+
125
180
  Does nothing if the given element is not currently animating.
126
181
 
127
182
  @method up.motion.finish
@@ -145,18 +200,24 @@ up.motion = (->
145
200
  u.error("Did not return a promise with .then and .resolve methods: %o", origin)
146
201
 
147
202
  ###*
148
- Performs a transition between two elements.
149
-
150
- The following transitions are pre-registered:
151
-
152
- - `cross-fade`
153
- - `move-up`
154
- - `move-down`
155
- - `move-left`
156
- - `move-right`
157
- - `none`
203
+ Performs an animated transition between two elements.
204
+ Transitions are implement by performing two animations in parallel,
205
+ causing one element to disappear and the other to appear.
206
+
207
+ \#\#\#\# Named transitions
208
+
209
+ The following transitions are pre-defined:
210
+
211
+ | `cross-fade` | Fades out the first element. Simultaneously fades in the second element. |
212
+ | `move-up` | Moves the first element upwards until it exits the screen at the top edge. Simultaneously moves the second element upwards from beyond the bottom edge of the screen until it reaches its current position. |
213
+ | `move-down` | Moves the first element downwards until it exits the screen at the bottom edge. Simultaneously moves the second element downwards from beyond the top edge of the screen until it reaches its current position. |
214
+ | `move-left` | Moves the first element leftwards until it exists the screen at the left edge. Simultaneously moves the second element leftwards from beyond the right edge of the screen until it reaches its current position. |
215
+ | `move-right` | Moves the first element rightwards until it exists the screen at the right edge. Simultaneously moves the second element rightwards from beyond the left edge of the screen until it reaches its current position. |
216
+ | `none` | A transition that has no visible effect. Sounds useless at first, but can save you a lot of `if` statements. |
217
+
218
+ You can define additional named transitions using [`up.transition`](#up.transition).
158
219
 
159
- You can also compose a transition from two animation names
220
+ You can also compose a transition from two [named animations](#named-animations).
160
221
  separated by a slash character (`/`):
161
222
 
162
223
  - `move-to-bottom/fade-in`
@@ -166,15 +227,20 @@ up.motion = (->
166
227
  @param {Element|jQuery|String} source
167
228
  @param {Element|jQuery|String} target
168
229
  @param {Function|String} transitionOrName
169
- @param {Number} [options.duration]
170
- @param {String} [options.easing]
171
- @param {Number} [options.delay]
230
+ @param {Number} [opts.duration=300]
231
+ The duration of the animation, in milliseconds.
232
+ @param {Number} [opts.delay=0]
233
+ The delay before the animation starts, in milliseconds.
234
+ @param {String} [opts.easing='ease']
235
+ The timing function that controls the transition's acceleration.
236
+ See [W3C documentation](http://www.w3.org/TR/css3-transitions/#transition-timing-function)
237
+ for a list of pre-defined timing functions.
172
238
  @return {Promise}
173
239
  A promise for the transition's end.
174
240
  ###
175
241
  morph = (source, target, transitionOrName, options) ->
176
242
  if up.browser.canCssAnimation()
177
- options = u.options(config)
243
+ options = animateOptions(options)
178
244
  $old = $(source)
179
245
  $new = $(target)
180
246
  finish($old)
@@ -216,6 +282,29 @@ up.motion = (->
216
282
  ###*
217
283
  Defines a named animation.
218
284
 
285
+ Here is the definition of the pre-defined `fade-in` animation:
286
+
287
+ animation('fade-in', ($ghost, options) ->
288
+ $ghost.css(opacity: 0)
289
+ animate($ghost, { opacity: 1 }, options)
290
+ )
291
+
292
+ It is recommended that your definitions always end by calling
293
+ calling [`up.animate`](#up.animate) with an object argument, passing along
294
+ the `options` that were passed to you.
295
+
296
+ If you choose to *not* use `up.animate` and roll your own
297
+ animation code instead, your code must honor the following contract:
298
+
299
+ 1. It must honor the passed options.
300
+ 2. It must not remove the passed element from the DOM.
301
+ 3. It returns a promise that is resolved when the animation ends
302
+ 4. The returned promise responds to a `resolve()` function that
303
+ instantly jumps to the last animation frame and resolves the promise.
304
+
305
+ Calling [`up.animate`](#up.animate) with an object argument
306
+ will take care of all these points.
307
+
219
308
  @method up.animation
220
309
  @param {String} name
221
310
  @param {Function} animation
@@ -369,6 +458,7 @@ up.motion = (->
369
458
 
370
459
  morph: morph
371
460
  animate: animate
461
+ animateOptions: animateOptions
372
462
  finish: finish
373
463
  transition: transition
374
464
  animation: animation
@@ -105,10 +105,10 @@ up.popup = (->
105
105
  $popup.hide()
106
106
  $popup
107
107
 
108
- updated = ($link, $popup, origin, animation) ->
108
+ updated = ($link, $popup, origin, animation, animateOptions) ->
109
109
  $popup.show()
110
110
  position($link, $popup, origin)
111
- up.animate($popup, animation)
111
+ up.animate($popup, animation, animateOptions)
112
112
 
113
113
  ###*
114
114
  Opens a popup overlay.
@@ -118,6 +118,13 @@ up.popup = (->
118
118
  @param {String} [options.url]
119
119
  @param {String} [options.origin='bottom-right']
120
120
  @param {String} [options.animation]
121
+ The animation to use when opening the popup.
122
+ @param {Number} [opts.duration]
123
+ The duration of the animation. See [`up.animate`](/up.motion#up.animate).
124
+ @param {Number} [opts.delay]
125
+ The delay before the animation starts. See [`up.animate`](/up.motion#up.animate).
126
+ @param {String} [opts.easing]
127
+ The timing function that controls the animation's acceleration. [`up.animate`](/up.motion#up.animate).
121
128
  @param {Boolean} [options.sticky=false]
122
129
  If set to `true`, the popup remains
123
130
  open even if the page changes in the background.
@@ -133,14 +140,14 @@ up.popup = (->
133
140
  animation = u.option(options.animation, $link.attr('up-animation'), config.openAnimation)
134
141
  sticky = u.option(options.sticky, $link.is('[up-sticky]'))
135
142
  history = if up.browser.canPushState() then u.option(options.history, $link.attr('up-history'), false) else false
143
+ animateOptions = up.motion.animateOptions(options, $link)
136
144
 
137
145
  close()
138
146
  $popup = createHiddenPopup($link, selector, sticky)
139
147
 
140
148
  up.replace(selector, url,
141
149
  history: history
142
- # source: true
143
- insert: -> updated($link, $popup, origin, animation)
150
+ insert: -> updated($link, $popup, origin, animation, animateOptions)
144
151
  )
145
152
 
146
153
  ###*
@@ -1,5 +1,5 @@
1
1
  module Upjs
2
2
  module Rails
3
- VERSION = '0.4.4'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails