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
@@ -29,18 +29,19 @@ and [predefined animations](/up.animate#named-animations).
|
|
29
29
|
You can define custom animations using [`up.transition()`](/up.transition) and
|
30
30
|
[`up.animation()`](/up.animation).
|
31
31
|
|
32
|
-
@
|
32
|
+
@module up.motion
|
33
33
|
###
|
34
|
-
up.motion =
|
34
|
+
up.motion = do ->
|
35
35
|
|
36
36
|
u = up.util
|
37
|
+
e = up.element
|
37
38
|
|
38
39
|
namedAnimations = {}
|
39
40
|
defaultNamedAnimations = {}
|
40
41
|
namedTransitions = {}
|
41
42
|
defaultNamedTransitions = {}
|
42
43
|
|
43
|
-
|
44
|
+
motionController = new up.MotionController('motion')
|
44
45
|
|
45
46
|
###**
|
46
47
|
Sets default options for animations and transitions.
|
@@ -65,14 +66,14 @@ up.motion = (($) ->
|
|
65
66
|
that do not support [CSS transitions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions).
|
66
67
|
@stable
|
67
68
|
###
|
68
|
-
config =
|
69
|
+
config = new up.Config
|
69
70
|
duration: 300
|
70
71
|
delay: 0
|
71
72
|
easing: 'ease'
|
72
73
|
enabled: true
|
73
74
|
|
74
75
|
reset = ->
|
75
|
-
|
76
|
+
motionController.reset()
|
76
77
|
namedAnimations = u.copy(defaultNamedAnimations)
|
77
78
|
namedTransitions = u.copy(defaultNamedTransitions)
|
78
79
|
config.reset()
|
@@ -94,7 +95,7 @@ up.motion = (($) ->
|
|
94
95
|
|
95
96
|
\#\#\# Example
|
96
97
|
|
97
|
-
up.animate('.warning', 'fade-in')
|
98
|
+
up.animate('.warning', 'fade-in')
|
98
99
|
|
99
100
|
You can pass additional options:
|
100
101
|
|
@@ -102,7 +103,7 @@ up.motion = (($) ->
|
|
102
103
|
delay: 1000,
|
103
104
|
duration: 250,
|
104
105
|
easing: 'linear'
|
105
|
-
})
|
106
|
+
})
|
106
107
|
|
107
108
|
\#\#\# Named animations
|
108
109
|
|
@@ -127,9 +128,11 @@ up.motion = (($) ->
|
|
127
128
|
By passing an object instead of an animation name, you can animate
|
128
129
|
the CSS properties of the given element:
|
129
130
|
|
130
|
-
var
|
131
|
-
|
132
|
-
up.animate(
|
131
|
+
var warning = document.querySelector('.warning')
|
132
|
+
warning.style.opacity = 0
|
133
|
+
up.animate(warning, { opacity: 1 })
|
134
|
+
|
135
|
+
CSS properties must be given in `kebab-case`, not `camelCase`.
|
133
136
|
|
134
137
|
\#\#\# Multiple animations on the same element
|
135
138
|
|
@@ -142,12 +145,12 @@ up.motion = (($) ->
|
|
142
145
|
@function up.animate
|
143
146
|
@param {Element|jQuery|string} elementOrSelector
|
144
147
|
The element to animate.
|
145
|
-
@param {string|Function|Object} animation
|
148
|
+
@param {string|Function(element, options): Promise|Object} animation
|
146
149
|
Can either be:
|
147
150
|
|
148
151
|
- The animation's name
|
149
152
|
- A function performing the animation
|
150
|
-
- An object of CSS attributes describing the last frame of the animation
|
153
|
+
- An object of CSS attributes describing the last frame of the animation (using kebeb-case property names)
|
151
154
|
@param {number} [options.duration=300]
|
152
155
|
The duration of the animation, in milliseconds.
|
153
156
|
@param {number} [options.delay=0]
|
@@ -162,27 +165,27 @@ up.motion = (($) ->
|
|
162
165
|
@stable
|
163
166
|
###
|
164
167
|
animate = (elementOrSelector, animation, options) ->
|
165
|
-
|
168
|
+
element = e.get(elementOrSelector)
|
166
169
|
options = animateOptions(options)
|
167
170
|
|
168
171
|
animationFn = findAnimationFn(animation)
|
169
|
-
willRun = willAnimate(
|
172
|
+
willRun = willAnimate(element, animation, options)
|
170
173
|
|
171
174
|
if willRun
|
172
|
-
runNow = -> animationFn(
|
173
|
-
|
175
|
+
runNow = -> animationFn(element, options)
|
176
|
+
motionController.startFunction(element, runNow, options)
|
174
177
|
else
|
175
|
-
skipAnimate(
|
178
|
+
skipAnimate(element, animation)
|
176
179
|
|
177
|
-
willAnimate = (
|
180
|
+
willAnimate = (element, animationOrTransition, options) ->
|
178
181
|
options = animateOptions(options)
|
179
|
-
isEnabled() && !isNone(animationOrTransition) && options.duration > 0 && !
|
182
|
+
isEnabled() && !isNone(animationOrTransition) && options.duration > 0 && !e.isSingleton(element)
|
180
183
|
|
181
|
-
skipAnimate = (
|
184
|
+
skipAnimate = (element, animation) ->
|
182
185
|
if u.isOptions(animation)
|
183
186
|
# If we are given the final animation frame as an object of CSS properties,
|
184
187
|
# the best we can do is to set the final frame without animation.
|
185
|
-
|
188
|
+
e.setStyle(element, animation)
|
186
189
|
# Signal that the animation is already done.
|
187
190
|
Promise.resolve()
|
188
191
|
|
@@ -192,7 +195,7 @@ up.motion = (($) ->
|
|
192
195
|
Animates the given element's CSS properties using CSS transitions.
|
193
196
|
|
194
197
|
Does not track the animation, nor does it finishes existing animations
|
195
|
-
(use `up.motion.animate()` for that). It does, however, listen to the
|
198
|
+
(use `up.motion.animate()` for that). It does, however, listen to the motionController's
|
196
199
|
finish event.
|
197
200
|
|
198
201
|
@function animateNow
|
@@ -212,28 +215,32 @@ up.motion = (($) ->
|
|
212
215
|
A promise that fulfills when the animation ends.
|
213
216
|
@internal
|
214
217
|
###
|
215
|
-
animateNow = (
|
216
|
-
options = u.merge(options, finishEvent:
|
217
|
-
cssTransition = new up.CssTransition(
|
218
|
+
animateNow = (element, lastFrame, options) ->
|
219
|
+
options = u.merge(options, finishEvent: motionController.finishEvent)
|
220
|
+
cssTransition = new up.CssTransition(element, lastFrame, options)
|
218
221
|
return cssTransition.start()
|
219
222
|
|
220
223
|
###**
|
221
224
|
Extracts animation-related options from the given options hash.
|
222
|
-
If
|
225
|
+
If `element` is given, also inspects the element for animation-related
|
223
226
|
attributes like `up-easing` or `up-duration`.
|
224
227
|
|
228
|
+
@param {Object} userOptions
|
229
|
+
@param {Element|jQuery} [element]
|
230
|
+
@param {Object} [moduleDefaults]
|
225
231
|
@function up.motion.animateOptions
|
226
232
|
@internal
|
227
233
|
###
|
228
234
|
animateOptions = (args...) ->
|
229
|
-
userOptions = args.shift()
|
230
|
-
|
231
|
-
|
235
|
+
userOptions = args.shift() ? {}
|
236
|
+
moduleDefaults = u.extractOptions(args)
|
237
|
+
element = args.pop() || e.none()
|
238
|
+
|
232
239
|
consolidatedOptions = {}
|
233
|
-
consolidatedOptions.easing =
|
234
|
-
consolidatedOptions.duration =
|
235
|
-
consolidatedOptions.delay =
|
236
|
-
consolidatedOptions.trackMotion = userOptions.trackMotion # required by up.
|
240
|
+
consolidatedOptions.easing = userOptions.easing ? element.getAttribute('up-easing') ? moduleDefaults.easing ? config.easing
|
241
|
+
consolidatedOptions.duration = userOptions.duration ? e.numberAttr(element, 'up-duration') ? moduleDefaults.duration ? config.duration
|
242
|
+
consolidatedOptions.delay = userOptions.delay ? e.numberAttr(element, 'up-delay') ? moduleDefaults.delay ? config.delay
|
243
|
+
consolidatedOptions.trackMotion = userOptions.trackMotion # required by up.MotionController
|
237
244
|
consolidatedOptions
|
238
245
|
|
239
246
|
findNamedAnimation = (name) ->
|
@@ -247,6 +254,9 @@ up.motion = (($) ->
|
|
247
254
|
are completed.
|
248
255
|
|
249
256
|
Animations are completed by jumping to the last animation frame instantly.
|
257
|
+
Promises returned by animation and transition functions instantly settle.
|
258
|
+
|
259
|
+
Emits the `up:motion:finish` event that is already handled by `up.animate()`.
|
250
260
|
|
251
261
|
Does nothing if there are no animation to complete.
|
252
262
|
|
@@ -257,7 +267,21 @@ up.motion = (($) ->
|
|
257
267
|
@stable
|
258
268
|
###
|
259
269
|
finish = (elementOrSelector) ->
|
260
|
-
|
270
|
+
motionController.finish(elementOrSelector)
|
271
|
+
|
272
|
+
###**
|
273
|
+
This event is emitted on an [animating](/up.animating) element by `up.motion.finish()` to
|
274
|
+
request the animation to instantly finish and skip to the last frame.
|
275
|
+
|
276
|
+
Promises returned by completed animation functions are expected to settle.
|
277
|
+
|
278
|
+
Animations started by `up.animate()` already handle this event.
|
279
|
+
|
280
|
+
@event up:motion:finish
|
281
|
+
@param {Element} event.target
|
282
|
+
The animating element.
|
283
|
+
@experimental
|
284
|
+
###
|
261
285
|
|
262
286
|
###**
|
263
287
|
Performs an animated transition between the `source` and `target` elements.
|
@@ -311,7 +335,7 @@ up.motion = (($) ->
|
|
311
335
|
@function up.morph
|
312
336
|
@param {Element|jQuery|string} source
|
313
337
|
@param {Element|jQuery|string} target
|
314
|
-
@param {Function|string}
|
338
|
+
@param {Function(oldElement, newElement)|string} transition
|
315
339
|
@param {number} [options.duration=300]
|
316
340
|
The duration of the animation, in milliseconds.
|
317
341
|
@param {number} [options.delay=0]
|
@@ -325,18 +349,17 @@ up.motion = (($) ->
|
|
325
349
|
Whether to reveal the new element by scrolling its parent viewport.
|
326
350
|
@return {Promise}
|
327
351
|
A promise that fulfills when the transition ends.
|
328
|
-
@
|
352
|
+
@stable
|
329
353
|
###
|
330
|
-
morph = (
|
354
|
+
morph = (oldElement, newElement, transitionObject, options) ->
|
331
355
|
options = u.options(options)
|
332
|
-
|
356
|
+
u.assign(options, animateOptions(options))
|
333
357
|
|
334
|
-
|
335
|
-
|
336
|
-
$both = $old.add($new)
|
358
|
+
oldElement = e.get(oldElement)
|
359
|
+
newElement = e.get(newElement)
|
337
360
|
|
338
361
|
transitionFn = findTransitionFn(transitionObject)
|
339
|
-
willMorph = willAnimate(
|
362
|
+
willMorph = willAnimate(oldElement, transitionFn, options)
|
340
363
|
|
341
364
|
# Remove callbacks from our options hash in case transitionFn calls morph() recursively.
|
342
365
|
# If we passed on these callbacks, we might call destructors, events, etc. multiple times.
|
@@ -348,55 +371,54 @@ up.motion = (($) ->
|
|
348
371
|
beforeStart()
|
349
372
|
|
350
373
|
scrollNew = ->
|
351
|
-
# Don't animate the scrolling.
|
352
|
-
scrollOptions = u.merge(options,
|
353
|
-
# Scroll
|
354
|
-
up.
|
374
|
+
# Don't animate the scrolling.
|
375
|
+
scrollOptions = u.merge(options, behavior: 'instant')
|
376
|
+
# Scroll newElement into position before we start the enter animation.
|
377
|
+
up.viewport.scrollAfterInsertFragment(newElement, scrollOptions)
|
355
378
|
|
356
379
|
if willMorph
|
357
|
-
if
|
358
|
-
return transitionFn(
|
380
|
+
if motionController.isActive(oldElement) && options.trackMotion is false
|
381
|
+
return transitionFn(oldElement, newElement, options)
|
359
382
|
|
360
|
-
up.puts 'Morphing %o to %o with transition %o',
|
383
|
+
up.puts 'Morphing %o to %o with transition %o', oldElement, newElement, transitionObject
|
361
384
|
|
362
|
-
|
363
|
-
scrollTopBeforeReveal =
|
385
|
+
viewport = up.viewport.closest(oldElement)
|
386
|
+
scrollTopBeforeReveal = viewport.scrollTop
|
364
387
|
|
365
|
-
oldRemote = up.
|
388
|
+
oldRemote = up.viewport.absolutize oldElement,
|
366
389
|
# Because the insertion will shift elements visually, we must delay insertion
|
367
390
|
# until absolutize() has measured the bounding box of the old element.
|
368
391
|
afterMeasure: ->
|
369
|
-
|
392
|
+
e.insertBefore(oldElement, newElement)
|
370
393
|
afterInsert()
|
371
394
|
|
372
395
|
trackable = ->
|
373
|
-
# Scroll
|
396
|
+
# Scroll newElement into position before we start the enter animation.
|
374
397
|
promise = scrollNew()
|
375
398
|
|
376
399
|
promise = promise.then ->
|
377
|
-
# Since we have scrolled the viewport (containing both
|
400
|
+
# Since we have scrolled the viewport (containing both oldElement and newElement),
|
378
401
|
# we must shift the old copy so it looks like it it is still sitting
|
379
402
|
# in the same position.
|
380
|
-
scrollTopAfterReveal =
|
381
|
-
oldRemote.
|
403
|
+
scrollTopAfterReveal = viewport.scrollTop
|
404
|
+
oldRemote.moveBounds(0, scrollTopAfterReveal - scrollTopBeforeReveal)
|
382
405
|
|
383
|
-
transitionFn(
|
406
|
+
transitionFn(oldElement, newElement, options)
|
384
407
|
|
385
408
|
promise = promise.then ->
|
386
409
|
beforeDetach()
|
387
|
-
|
388
|
-
oldRemote.$bounds.remove()
|
410
|
+
e.remove(oldRemote.bounds)
|
389
411
|
afterDetach()
|
390
412
|
|
391
413
|
return promise
|
392
414
|
|
393
|
-
|
415
|
+
motionController.startFunction([oldElement, newElement], trackable, options)
|
394
416
|
|
395
417
|
else
|
396
418
|
beforeDetach()
|
397
419
|
# Swapping the elements directly with replaceWith() will cause
|
398
420
|
# jQuery to remove all data attributes, which we use to store destructors
|
399
|
-
swapElementsDirectly(
|
421
|
+
swapElementsDirectly(oldElement, newElement)
|
400
422
|
afterInsert()
|
401
423
|
afterDetach()
|
402
424
|
promise = scrollNew()
|
@@ -425,10 +447,10 @@ up.motion = (($) ->
|
|
425
447
|
else
|
426
448
|
oldAnimationFn = findAnimationFn(oldAnimation) || u.asyncNoop
|
427
449
|
newAnimationFn = findAnimationFn(newAnimation) || u.asyncNoop
|
428
|
-
(
|
450
|
+
(oldElement, newElement, options) ->
|
429
451
|
Promise.all([
|
430
|
-
oldAnimationFn(
|
431
|
-
newAnimationFn(
|
452
|
+
oldAnimationFn(oldElement, options),
|
453
|
+
newAnimationFn(newElement, options)
|
432
454
|
])
|
433
455
|
|
434
456
|
findAnimationFn = (object) ->
|
@@ -439,25 +461,26 @@ up.motion = (($) ->
|
|
439
461
|
else if u.isString(object)
|
440
462
|
findNamedAnimation(object)
|
441
463
|
else if u.isOptions(object)
|
442
|
-
(
|
464
|
+
(element, options) -> animateNow(element, object, options)
|
443
465
|
else
|
444
466
|
up.fail('Unknown animation %o', object)
|
445
467
|
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
$old.replaceWith($new)
|
468
|
+
# Have a separate function so we can mock it in specs.
|
469
|
+
swapElementsDirectly = (oldElement, newElement) ->
|
470
|
+
e.replace(oldElement, newElement)
|
450
471
|
|
451
472
|
###**
|
452
|
-
Defines a named transition.
|
473
|
+
Defines a named transition that [morphs](/up.element) from one element to another.
|
474
|
+
|
475
|
+
\#\#\# Example
|
453
476
|
|
454
477
|
Here is the definition of the pre-defined `cross-fade` animation:
|
455
478
|
|
456
|
-
up.transition('cross-fade', (
|
457
|
-
|
458
|
-
up.animate(
|
459
|
-
up.animate(
|
460
|
-
)
|
479
|
+
up.transition('cross-fade', (oldElement, newElement, options) ->
|
480
|
+
Promise.all([
|
481
|
+
up.animate(oldElement, 'fade-out', options),
|
482
|
+
up.animate(newElement, 'fade-in', options)
|
483
|
+
])
|
461
484
|
)
|
462
485
|
|
463
486
|
It is recommended that your transitions use [`up.animate()`](/up.animate),
|
@@ -466,11 +489,11 @@ up.motion = (($) ->
|
|
466
489
|
If you choose to *not* use `up.animate()` and roll your own
|
467
490
|
logic instead, your code must honor the following contract:
|
468
491
|
|
469
|
-
1. It must honor the options `{ delay, duration, easing }` if given
|
492
|
+
1. It must honor the options `{ delay, duration, easing }` if given.
|
470
493
|
2. It must *not* remove any of the given elements from the DOM.
|
471
|
-
3. It returns a promise that is fulfilled when the transition has ended
|
494
|
+
3. It returns a promise that is fulfilled when the transition has ended.
|
472
495
|
4. If during the animation an event `up:motion:finish` is emitted on
|
473
|
-
|
496
|
+
either element, the transition instantly jumps to the last frame
|
474
497
|
and resolves the returned promise.
|
475
498
|
|
476
499
|
Calling [`up.animate()`](/up.animate) with an object argument
|
@@ -478,7 +501,7 @@ up.motion = (($) ->
|
|
478
501
|
|
479
502
|
@function up.transition
|
480
503
|
@param {string} name
|
481
|
-
@param {Function} transition
|
504
|
+
@param {Function(oldElement, newElement, options): Promise|Array} transition
|
482
505
|
@stable
|
483
506
|
###
|
484
507
|
registerTransition = (name, transition) ->
|
@@ -489,9 +512,9 @@ up.motion = (($) ->
|
|
489
512
|
|
490
513
|
Here is the definition of the pre-defined `fade-in` animation:
|
491
514
|
|
492
|
-
up.animation('fade-in', function(
|
493
|
-
|
494
|
-
up.animate(
|
515
|
+
up.animation('fade-in', function(element, options) {
|
516
|
+
element.style.opacity = 0
|
517
|
+
up.animate(element, { opacity: 1 }, options)
|
495
518
|
})
|
496
519
|
|
497
520
|
It is recommended that your definitions always end by calling
|
@@ -513,7 +536,7 @@ up.motion = (($) ->
|
|
513
536
|
|
514
537
|
@function up.animation
|
515
538
|
@param {string} name
|
516
|
-
@param {Function} animation
|
539
|
+
@param {Function(element, options): Promise} animation
|
517
540
|
@stable
|
518
541
|
###
|
519
542
|
registerAnimation = (name, animation) ->
|
@@ -534,86 +557,86 @@ up.motion = (($) ->
|
|
534
557
|
# false, undefined, '', null and the string "none" are all ways to skip animations
|
535
558
|
!animationOrTransition || animationOrTransition == 'none' || u.isBlank(animationOrTransition)
|
536
559
|
|
537
|
-
registerAnimation('fade-in', (
|
538
|
-
|
539
|
-
animateNow(
|
560
|
+
registerAnimation('fade-in', (element, options) ->
|
561
|
+
e.setStyle(element, opacity: 0)
|
562
|
+
animateNow(element, { opacity: 1 }, options)
|
540
563
|
)
|
541
564
|
|
542
|
-
registerAnimation('fade-out', (
|
543
|
-
|
544
|
-
animateNow(
|
565
|
+
registerAnimation('fade-out', (element, options) ->
|
566
|
+
e.setStyle(element, opacity: 1)
|
567
|
+
animateNow(element, { opacity: 0 }, options)
|
545
568
|
)
|
546
569
|
|
547
570
|
translateCss = (x, y) ->
|
548
571
|
{ transform: "translate(#{x}px, #{y}px)" }
|
549
572
|
|
550
|
-
registerAnimation('move-to-top', (
|
551
|
-
|
552
|
-
box =
|
573
|
+
registerAnimation('move-to-top', (element, options) ->
|
574
|
+
e.setStyle(element, translateCss(0, 0))
|
575
|
+
box = element.getBoundingClientRect()
|
553
576
|
travelDistance = box.top + box.height
|
554
|
-
animateNow(
|
577
|
+
animateNow(element, translateCss(0, -travelDistance), options)
|
555
578
|
)
|
556
579
|
|
557
|
-
registerAnimation('move-from-top', (
|
558
|
-
|
559
|
-
box =
|
580
|
+
registerAnimation('move-from-top', (element, options) ->
|
581
|
+
e.setStyle(element, translateCss(0, 0))
|
582
|
+
box = element.getBoundingClientRect()
|
560
583
|
travelDistance = box.top + box.height
|
561
|
-
|
562
|
-
animateNow(
|
584
|
+
e.setStyle(element, translateCss(0, -travelDistance))
|
585
|
+
animateNow(element, translateCss(0, 0), options)
|
563
586
|
)
|
564
587
|
|
565
|
-
registerAnimation('move-to-bottom', (
|
566
|
-
|
567
|
-
box =
|
568
|
-
travelDistance =
|
569
|
-
animateNow(
|
588
|
+
registerAnimation('move-to-bottom', (element, options) ->
|
589
|
+
e.setStyle(element, translateCss(0, 0))
|
590
|
+
box = element.getBoundingClientRect()
|
591
|
+
travelDistance = e.root().clientHeight - box.top
|
592
|
+
animateNow(element, translateCss(0, travelDistance), options)
|
570
593
|
)
|
571
594
|
|
572
|
-
registerAnimation('move-from-bottom', (
|
573
|
-
|
574
|
-
box =
|
575
|
-
travelDistance =
|
576
|
-
|
577
|
-
animateNow(
|
595
|
+
registerAnimation('move-from-bottom', (element, options) ->
|
596
|
+
e.setStyle(element, translateCss(0, 0))
|
597
|
+
box = element.getBoundingClientRect()
|
598
|
+
travelDistance = up.viewport.rootHeight() - box.top
|
599
|
+
e.setStyle(element, translateCss(0, travelDistance))
|
600
|
+
animateNow(element, translateCss(0, 0), options)
|
578
601
|
)
|
579
602
|
|
580
|
-
registerAnimation('move-to-left', (
|
581
|
-
|
582
|
-
box =
|
603
|
+
registerAnimation('move-to-left', (element, options) ->
|
604
|
+
e.setStyle(element, translateCss(0, 0))
|
605
|
+
box = element.getBoundingClientRect()
|
583
606
|
travelDistance = box.left + box.width
|
584
|
-
animateNow(
|
607
|
+
animateNow(element, translateCss(-travelDistance, 0), options)
|
585
608
|
)
|
586
609
|
|
587
|
-
registerAnimation('move-from-left', (
|
588
|
-
|
589
|
-
box =
|
610
|
+
registerAnimation('move-from-left', (element, options) ->
|
611
|
+
e.setStyle(element, translateCss(0, 0))
|
612
|
+
box = element.getBoundingClientRect()
|
590
613
|
travelDistance = box.left + box.width
|
591
|
-
|
592
|
-
animateNow(
|
614
|
+
e.setStyle(element, translateCss(-travelDistance, 0))
|
615
|
+
animateNow(element, translateCss(0, 0), options)
|
593
616
|
)
|
594
617
|
|
595
|
-
registerAnimation('move-to-right', (
|
596
|
-
|
597
|
-
box =
|
598
|
-
travelDistance =
|
599
|
-
animateNow(
|
618
|
+
registerAnimation('move-to-right', (element, options) ->
|
619
|
+
e.setStyle(element, translateCss(0, 0))
|
620
|
+
box = element.getBoundingClientRect()
|
621
|
+
travelDistance = up.viewport.rootWidth() - box.left
|
622
|
+
animateNow(element, translateCss(travelDistance, 0), options)
|
600
623
|
)
|
601
624
|
|
602
|
-
registerAnimation('move-from-right', (
|
603
|
-
|
604
|
-
box =
|
605
|
-
travelDistance =
|
606
|
-
|
607
|
-
animateNow(
|
625
|
+
registerAnimation('move-from-right', (element, options) ->
|
626
|
+
e.setStyle(element, translateCss(0, 0))
|
627
|
+
box = element.getBoundingClientRect()
|
628
|
+
travelDistance = up.viewport.rootWidth() - box.left
|
629
|
+
e.setStyle(element, translateCss(travelDistance, 0))
|
630
|
+
animateNow(element, translateCss(0, 0), options)
|
608
631
|
)
|
609
632
|
|
610
|
-
registerAnimation('roll-down', (
|
611
|
-
|
612
|
-
styleMemo =
|
633
|
+
registerAnimation('roll-down', (element, options) ->
|
634
|
+
previousHeightStr = e.style(element, 'height')
|
635
|
+
styleMemo = e.setTemporaryStyle(element,
|
613
636
|
height: '0px'
|
614
637
|
overflow: 'hidden'
|
615
638
|
)
|
616
|
-
deferred = animate(
|
639
|
+
deferred = animate(element, { height: previousHeightStr }, options)
|
617
640
|
deferred.then(styleMemo)
|
618
641
|
deferred
|
619
642
|
)
|
@@ -631,17 +654,14 @@ up.motion = (($) ->
|
|
631
654
|
morph: morph
|
632
655
|
animate: animate
|
633
656
|
animateOptions: animateOptions
|
634
|
-
willAnimate: willAnimate
|
635
657
|
finish: finish
|
636
|
-
finishCount: ->
|
658
|
+
finishCount: -> motionController.finishCount
|
637
659
|
transition: registerTransition
|
638
660
|
animation: registerAnimation
|
639
661
|
config: config
|
640
662
|
isEnabled: isEnabled
|
641
663
|
isNone: isNone
|
642
664
|
|
643
|
-
)(jQuery)
|
644
|
-
|
645
665
|
up.transition = up.motion.transition
|
646
666
|
up.animation = up.motion.animation
|
647
667
|
up.morph = up.motion.morph
|