upjs-rails 0.14.1 → 0.15.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +80 -0
- data/dist/up.js +388 -123
- data/dist/up.min.js +2 -2
- data/lib/assets/javascripts/up/browser.js.coffee +57 -8
- data/lib/assets/javascripts/up/form.js.coffee +129 -47
- data/lib/assets/javascripts/up/modal.js.coffee +10 -5
- data/lib/assets/javascripts/up/motion.js.coffee +2 -3
- data/lib/assets/javascripts/up/navigation.js.coffee +2 -2
- data/lib/assets/javascripts/up/popup.js.coffee +77 -22
- data/lib/assets/javascripts/up/proxy.js.coffee +0 -1
- data/lib/assets/javascripts/up/syntax.js.coffee +2 -0
- data/lib/assets/javascripts/up/util.js.coffee +15 -13
- data/lib/upjs/rails/version.rb +1 -1
- data/spec_app/Gemfile.lock +1 -1
- data/spec_app/spec/javascripts/up/bus_spec.js.coffee +13 -11
- data/spec_app/spec/javascripts/up/form_spec.js.coffee +87 -3
- data/spec_app/spec/javascripts/up/modal_spec.js.coffee +32 -6
- data/spec_app/spec/javascripts/up/motion_spec.js.coffee +2 -2
- data/spec_app/spec/javascripts/up/popup_spec.js.coffee +45 -2
- metadata +2 -3
- data/design/up-validate.js.coffee +0 -284
@@ -16,6 +16,10 @@ up.form = (($) ->
|
|
16
16
|
Sets default options for form submission and validation.
|
17
17
|
|
18
18
|
@property up.form.config
|
19
|
+
@param {Number} [config.observeDelay=0]
|
20
|
+
The number of miliseconds to wait before [`up.observe`](/up.observe) runs the callback
|
21
|
+
after the input value changes. Use this to limit how often the callback
|
22
|
+
will be invoked for a fast typist.
|
19
23
|
@param {Array} [config.validateTargets=['[up-fieldset]:has(&)', 'fieldset:has(&)', 'label:has(&)', 'form:has(&)']]
|
20
24
|
An array of CSS selectors that are searched around a form field
|
21
25
|
that wants to [validate](/up.validate). The first matching selector
|
@@ -24,10 +28,14 @@ up.form = (($) ->
|
|
24
28
|
By default this looks for a `<fieldset>`, `<label>` or `<form>`
|
25
29
|
around the validating input field, or any element with an
|
26
30
|
`up-fieldset` attribute.
|
31
|
+
@param {String} [config.fields]
|
32
|
+
An array of CSS selectors that represent form fields, such as `input` or `select`.
|
27
33
|
@stable
|
28
34
|
###
|
29
35
|
config = u.config
|
30
36
|
validateTargets: ['[up-fieldset]:has(&)', 'fieldset:has(&)', 'label:has(&)', 'form:has(&)']
|
37
|
+
fields: [':input']
|
38
|
+
observeDelay: 0
|
31
39
|
|
32
40
|
reset = ->
|
33
41
|
config.reset()
|
@@ -106,8 +114,11 @@ up.form = (($) ->
|
|
106
114
|
$form = $(formOrSelector).closest('form')
|
107
115
|
|
108
116
|
options = u.options(options)
|
109
|
-
successSelector =
|
110
|
-
|
117
|
+
successSelector = u.option(options.target, $form.attr('up-target'), 'body')
|
118
|
+
successSelector = up.flow.resolveSelector(successSelector, options)
|
119
|
+
failureSelector = u.option(options.failTarget, $form.attr('up-fail-target')) || u.selectorForElement($form)
|
120
|
+
failureSelector = up.flow.resolveSelector(failureSelector, options)
|
121
|
+
|
111
122
|
historyOption = u.option(options.history, u.castedAttr($form, 'up-history'), true)
|
112
123
|
successTransition = u.option(options.transition, u.castedAttr($form, 'up-transition'))
|
113
124
|
failureTransition = u.option(options.failTransition, u.castedAttr($form, 'up-fail-transition'), successTransition)
|
@@ -174,7 +185,8 @@ up.form = (($) ->
|
|
174
185
|
up.flow.implant(failureSelector, html, failureOptions)
|
175
186
|
|
176
187
|
###*
|
177
|
-
Observes a form
|
188
|
+
Observes a field or form and runs a callback when a value changes.
|
189
|
+
|
178
190
|
This is useful for observing text fields while the user is typing.
|
179
191
|
|
180
192
|
The UJS variant of this is the [`up-observe`](/up-observe) attribute.
|
@@ -184,9 +196,9 @@ up.form = (($) ->
|
|
184
196
|
The following would submit the form whenever the
|
185
197
|
text field value changes:
|
186
198
|
|
187
|
-
up.observe('input[name=query]',
|
199
|
+
up.observe('input[name=query]', function(value, $input) {
|
188
200
|
up.submit($input)
|
189
|
-
}
|
201
|
+
});
|
190
202
|
|
191
203
|
\#\#\#\# Preventing concurrency
|
192
204
|
|
@@ -204,43 +216,56 @@ up.form = (($) ->
|
|
204
216
|
load on your server, you can use a `delay` option to wait
|
205
217
|
a few miliseconds before executing the callback:
|
206
218
|
|
207
|
-
up.observe('input', {
|
208
|
-
|
209
|
-
change: function(value, $input) { up.submit($input) }
|
219
|
+
up.observe('input', { delay: 100 }, function(value, $input) {
|
220
|
+
up.submit($input)
|
210
221
|
});
|
211
222
|
|
212
223
|
@function up.observe
|
213
224
|
@param {Element|jQuery|String} fieldOrSelector
|
214
|
-
@param {
|
225
|
+
@param {Number} [options.delay=up.form.config.observeDelay]
|
226
|
+
The number of miliseconds to wait before executing the callback
|
227
|
+
after the input value changes. Use this to limit how often the callback
|
228
|
+
will be invoked for a fast typist.
|
229
|
+
@param {Function(value, $field)|String} onChange
|
215
230
|
The callback to execute when the field's value changes.
|
216
231
|
If given as a function, it must take two arguments (`value`, `$field`).
|
217
232
|
If given as a string, it will be evaled as Javascript code in a context where
|
218
233
|
(`value`, `$field`) are set.
|
219
|
-
@
|
220
|
-
|
221
|
-
after the input value changes. Use this to limit how often the callback
|
222
|
-
will be invoked for a fast typist.
|
234
|
+
@return {Function}
|
235
|
+
A destructor function that removes the observe watch when called.
|
223
236
|
@stable
|
224
237
|
###
|
225
|
-
observe = (
|
238
|
+
observe = (selectorOrElement, args...) ->
|
226
239
|
|
227
|
-
|
240
|
+
options = {}
|
241
|
+
callbackArg = undefined
|
242
|
+
if args.length == 1
|
243
|
+
callbackArg = args[0]
|
244
|
+
if args.length > 1
|
245
|
+
options = u.options(args[0])
|
246
|
+
callbackArg = args[1]
|
247
|
+
|
248
|
+
$element = $(selectorOrElement)
|
228
249
|
options = u.options(options)
|
229
|
-
delay = u.option($
|
250
|
+
delay = u.option($element.attr('up-delay'), options.delay, config.observeDelay)
|
230
251
|
delay = parseInt(delay)
|
231
252
|
|
232
|
-
knownValue = null
|
233
253
|
callback = null
|
234
|
-
callbackTimer = null
|
235
254
|
|
236
|
-
if
|
237
|
-
callback
|
238
|
-
|
239
|
-
|
240
|
-
|
255
|
+
if u.isGiven(options.change)
|
256
|
+
up.error('up.observe now takes the change callback as the last argument')
|
257
|
+
|
258
|
+
rawCallback = u.option(u.presentAttr($element, 'op-observe'), callbackArg)
|
259
|
+
if u.isString(rawCallback)
|
260
|
+
callback = (value, $field) -> eval(rawCallback)
|
241
261
|
else
|
242
|
-
u.error('up.observe: No change callback given')
|
262
|
+
callback = rawCallback or u.error('up.observe: No change callback given')
|
263
|
+
|
264
|
+
if $element.is('form')
|
265
|
+
return observeForm($element, options, callback)
|
243
266
|
|
267
|
+
knownValue = null
|
268
|
+
callbackTimer = null
|
244
269
|
callbackPromise = u.resolvedPromise()
|
245
270
|
|
246
271
|
# This holds the next callback function, curried with `value` and `$field`.
|
@@ -256,14 +281,14 @@ up.form = (($) ->
|
|
256
281
|
returnValue
|
257
282
|
|
258
283
|
check = ->
|
259
|
-
value = $
|
284
|
+
value = $element.val()
|
260
285
|
# don't run the callback for the check during initialization
|
261
286
|
skipCallback = u.isNull(knownValue)
|
262
287
|
if knownValue != value
|
263
288
|
knownValue = value
|
264
289
|
unless skipCallback
|
265
290
|
clearTimer()
|
266
|
-
nextCallback = -> callback.apply($
|
291
|
+
nextCallback = -> callback.apply($element.get(0), [value, $element])
|
267
292
|
callbackTimer = setTimeout(
|
268
293
|
->
|
269
294
|
# Only run the callback once the previous callback's
|
@@ -288,15 +313,53 @@ up.form = (($) ->
|
|
288
313
|
'input change'
|
289
314
|
else
|
290
315
|
# Actually we won't ever get `input` from the user in this browser,
|
291
|
-
# but we want to notice if another script
|
316
|
+
# but we want to notice if another script manually triggers `input`
|
292
317
|
# on the element.
|
293
318
|
'input change keypress paste cut click propertychange'
|
294
|
-
$
|
319
|
+
$element.on(changeEvents, check)
|
295
320
|
|
296
321
|
check()
|
297
322
|
|
298
323
|
# return destructor
|
299
|
-
return
|
324
|
+
return ->
|
325
|
+
$element.off(changeEvents, check)
|
326
|
+
clearTimer()
|
327
|
+
|
328
|
+
###*
|
329
|
+
@function observeForm
|
330
|
+
@internal
|
331
|
+
###
|
332
|
+
observeForm = ($form, options, callback) ->
|
333
|
+
$fields = u.multiSelector(config.fields).find($form)
|
334
|
+
destructors = u.map $fields, ($field) ->
|
335
|
+
observe($field, callback)
|
336
|
+
->
|
337
|
+
destructor() for destructor in destructors
|
338
|
+
|
339
|
+
###*
|
340
|
+
[Observes](/up.observe) a field or form and submits the form when a value changes.
|
341
|
+
|
342
|
+
The changed form field will be assigned a CSS class [`up-active`](/up-active)
|
343
|
+
while the autosubmitted form is processing.
|
344
|
+
|
345
|
+
The UJS variant of this is the [`up-autosubmit`](/up-autosubmit) attribute.
|
346
|
+
|
347
|
+
@function up.autosubmit
|
348
|
+
@param {String|Element|jQuery} selectorOrElement
|
349
|
+
The form field to observe.
|
350
|
+
@param {Object} [options]
|
351
|
+
See options for [`up.observe`](/up.observe)
|
352
|
+
@return {Function}
|
353
|
+
A destructor function that removes the observe watch when called.
|
354
|
+
@stable
|
355
|
+
###
|
356
|
+
autosubmit = (selectorOrElement, options) ->
|
357
|
+
console.log("autosubmit %o", selectorOrElement)
|
358
|
+
observe(selectorOrElement, options, (value, $field) ->
|
359
|
+
$form = $field.closest('form')
|
360
|
+
$field.addClass('up-active')
|
361
|
+
submit($form).always -> $field.removeClass('up-active')
|
362
|
+
)
|
300
363
|
|
301
364
|
resolveValidateTarget = ($field, options) ->
|
302
365
|
target = u.option(options.target, $field.attr('up-validate'))
|
@@ -564,7 +627,6 @@ up.form = (($) ->
|
|
564
627
|
<input type="text" name="email" up-validate=".email-errors">
|
565
628
|
<span class="email-errors"></span>
|
566
629
|
|
567
|
-
|
568
630
|
\#\#\#\# Updating dependent fields
|
569
631
|
|
570
632
|
The `[up-validate]` behavior is also a great way to partially update a form
|
@@ -599,21 +661,23 @@ up.form = (($) ->
|
|
599
661
|
validate($field)
|
600
662
|
|
601
663
|
###*
|
602
|
-
Observes this form
|
603
|
-
|
604
|
-
while the user is typing.
|
664
|
+
Observes this field or form and runs a callback when a value changes.
|
665
|
+
|
666
|
+
This is useful for observing text fields while the user is typing.
|
605
667
|
|
606
668
|
The programmatic variant of this is the [`up.observe`](/up.observe) function.
|
607
669
|
|
608
670
|
\#\#\#\# Example
|
609
671
|
|
610
|
-
|
611
|
-
|
672
|
+
The following would run a global `showSuggestions(value)` function
|
673
|
+
whenever the `<input>` changes:
|
612
674
|
|
613
|
-
<form
|
614
|
-
<input type="query" up-observe="
|
675
|
+
<form>
|
676
|
+
<input type="query" up-observe="showSuggestions(value)">
|
615
677
|
</form>
|
616
678
|
|
679
|
+
\#\#\#\# Callback context
|
680
|
+
|
617
681
|
The script given to `up-observe` runs with the following context:
|
618
682
|
|
619
683
|
| Name | Type | Description |
|
@@ -625,21 +689,39 @@ up.form = (($) ->
|
|
625
689
|
@selector [up-observe]
|
626
690
|
@param {String} up-observe
|
627
691
|
The code to run when the field's value changes.
|
692
|
+
@param {String} up-delay
|
693
|
+
The number of miliseconds to wait after a change before the code is run.
|
628
694
|
@stable
|
629
695
|
###
|
630
|
-
up.compiler '[up-observe]', ($
|
631
|
-
|
696
|
+
up.compiler '[up-observe]', ($formOrField) -> observe($formOrField)
|
697
|
+
|
698
|
+
###*
|
699
|
+
[Observes](/up.observe) this field or form and submits the form when a value changes.
|
632
700
|
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
701
|
+
The form field will be assigned a CSS class [`up-active`](/up-active)
|
702
|
+
while the autosubmitted form is processing.
|
703
|
+
|
704
|
+
The programmatic variant of this is the [`up.autosubmit`](/up.autosubmit) function.
|
705
|
+
|
706
|
+
\#\#\#\# Example
|
707
|
+
|
708
|
+
The following would submit the form whenever the
|
709
|
+
text field value changes:
|
710
|
+
|
711
|
+
<form method="GET" action="/search" up-autosubmit>
|
712
|
+
<input type="query">
|
713
|
+
</form>
|
714
|
+
|
715
|
+
@selector [up-autosubmit]
|
716
|
+
@param {String} up-delay
|
717
|
+
The number of miliseconds to wait after the change before the form is submitted.
|
718
|
+
@stable
|
719
|
+
###
|
720
|
+
up.compiler '[up-autosubmit]', ($formOrField) -> autosubmit($formOrField)
|
640
721
|
|
641
722
|
up.on 'up:framework:reset', reset
|
642
723
|
|
724
|
+
knife: eval(Knife?.point)
|
643
725
|
submit: submit
|
644
726
|
observe: observe
|
645
727
|
validate: validate
|
@@ -648,5 +730,5 @@ up.form = (($) ->
|
|
648
730
|
|
649
731
|
up.submit = up.form.submit
|
650
732
|
up.observe = up.form.observe
|
733
|
+
up.autosubmit = up.form.autosubmit
|
651
734
|
up.validate = up.form.validate
|
652
|
-
|
@@ -3,7 +3,8 @@ Modal dialogs
|
|
3
3
|
=============
|
4
4
|
|
5
5
|
Instead of [linking to a page fragment](/up.link), you can choose
|
6
|
-
to show a fragment in a modal dialog.
|
6
|
+
to show a fragment in a modal dialog. The existing page will remain
|
7
|
+
open in the background and reappear once the modal is closed.
|
7
8
|
|
8
9
|
To open a modal, add an [`up-modal` attribute](/a-up-modal) to a link,
|
9
10
|
or call the Javascript functions [`up.modal.follow`](/up.modal.follow)
|
@@ -312,7 +313,7 @@ up.modal = (($) ->
|
|
312
313
|
else
|
313
314
|
# Although someone prevented the destruction, keep a uniform API for
|
314
315
|
# callers by returning a Deferred that will never be resolved.
|
315
|
-
|
316
|
+
u.unresolvableDeferred()
|
316
317
|
|
317
318
|
###*
|
318
319
|
This event is [emitted](/up.emit) when a modal dialog is starting to open.
|
@@ -340,6 +341,9 @@ up.modal = (($) ->
|
|
340
341
|
@function up.modal.close
|
341
342
|
@param {Object} options
|
342
343
|
See options for [`up.animate`](/up.animate)
|
344
|
+
@return {Deferred}
|
345
|
+
A promise that will be resolved once the modal's close
|
346
|
+
animation has finished.
|
343
347
|
@stable
|
344
348
|
###
|
345
349
|
close = (options) ->
|
@@ -358,9 +362,10 @@ up.modal = (($) ->
|
|
358
362
|
up.emit('up:modal:closed')
|
359
363
|
deferred
|
360
364
|
else
|
361
|
-
# Although someone prevented the destruction,
|
362
|
-
#
|
363
|
-
|
365
|
+
# Although someone prevented the destruction,
|
366
|
+
# keep a uniform API for callers by returning
|
367
|
+
# a Deferred that will never be resolved.
|
368
|
+
u.unresolvableDeferred()
|
364
369
|
else
|
365
370
|
u.resolvedDeferred()
|
366
371
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Animation
|
3
3
|
=========
|
4
4
|
|
5
|
-
Whenever you
|
5
|
+
Whenever you update a page fragment (through methods like
|
6
6
|
[`up.replace`](/up.replace) or UJS attributes like [`up-target`](/up-target))
|
7
7
|
you can animate the change.
|
8
8
|
|
@@ -26,7 +26,6 @@ and [transitions](/up.morph#named-animation).
|
|
26
26
|
You can also easily [define your own animations](/up.animation)
|
27
27
|
or [transitions](/up.transition) using Javascript or CSS.
|
28
28
|
|
29
|
-
|
30
29
|
@class up.motion
|
31
30
|
###
|
32
31
|
up.motion = (($) ->
|
@@ -325,7 +324,7 @@ up.motion = (($) ->
|
|
325
324
|
parsedOptions = u.only(options, 'reveal', 'restoreScroll', 'source')
|
326
325
|
parsedOptions = u.extend(parsedOptions, animateOptions(options))
|
327
326
|
|
328
|
-
if up.browser.
|
327
|
+
if up.browser.canCssTransition()
|
329
328
|
finish($old)
|
330
329
|
finish($new)
|
331
330
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
###*
|
2
2
|
Fast interaction feedback
|
3
3
|
=========================
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
Up.js automatically marks up link elements with classes indicating that
|
6
6
|
they are currently loading (class `up-active`) or linking
|
7
7
|
to the current location (class `up-current`).
|
8
8
|
|
@@ -3,14 +3,13 @@ Pop-up overlays
|
|
3
3
|
===============
|
4
4
|
|
5
5
|
Instead of [linking to a page fragment](/up.link), you can choose
|
6
|
-
to show a fragment in a popup overlay.
|
6
|
+
to show a fragment in a popup overlay that rolls down from an anchoring element.
|
7
7
|
|
8
8
|
To open a popup, add an [`up-popup` attribute](/a-up-popup) to a link,
|
9
9
|
or call the Javascript function [`up.popup.attach`](/up.popup.attach).
|
10
10
|
|
11
11
|
For modal dialogs see [up.modal](/up.modal) instead.
|
12
12
|
|
13
|
-
|
14
13
|
\#\#\#\# Customizing the popup design
|
15
14
|
|
16
15
|
Loading the Up.js stylesheet will give you a minimal popup design:
|
@@ -27,7 +26,6 @@ By default the popup uses the following DOM structure:
|
|
27
26
|
...
|
28
27
|
</div>
|
29
28
|
|
30
|
-
|
31
29
|
\#\#\#\# Closing behavior
|
32
30
|
|
33
31
|
The popup closes when the user clicks anywhere outside the popup area.
|
@@ -42,7 +40,6 @@ To disable this behavior, give the opening link an `up-sticky` attribute:
|
|
42
40
|
|
43
41
|
<a href="/settings" up-popup=".options" up-sticky>Settings</a>
|
44
42
|
|
45
|
-
|
46
43
|
@class up.popup
|
47
44
|
###
|
48
45
|
up.popup = (($) ->
|
@@ -164,10 +161,14 @@ up.popup = (($) ->
|
|
164
161
|
updated = ($link, $popup, position, animation, animateOptions) ->
|
165
162
|
$popup.show()
|
166
163
|
setPosition($link, $popup, position)
|
167
|
-
up.animate($popup, animation, animateOptions)
|
164
|
+
deferred = up.animate($popup, animation, animateOptions)
|
165
|
+
deferred.then -> up.emit('up:popup:opened')
|
166
|
+
deferred
|
168
167
|
|
169
168
|
###*
|
170
169
|
Attaches a popup overlay to the given element or selector.
|
170
|
+
|
171
|
+
Emits events [`up:popup:open`](/up:popup:open) and [`up:popup:opened`](/up:popup:opened).
|
171
172
|
|
172
173
|
@function up.popup.attach
|
173
174
|
@param {Element|jQuery|String} elementOrSelector
|
@@ -202,35 +203,89 @@ up.popup = (($) ->
|
|
202
203
|
animateOptions = up.motion.animateOptions(options, $link)
|
203
204
|
|
204
205
|
close()
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
206
|
+
|
207
|
+
if up.bus.nobodyPrevents('up:popup:open', url: url)
|
208
|
+
$popup = createHiddenPopup($link, selector, sticky)
|
209
|
+
|
210
|
+
up.replace(selector, url,
|
211
|
+
history: history
|
212
|
+
insert: -> updated($link, $popup, position, animation, animateOptions)
|
213
|
+
)
|
214
|
+
else
|
215
|
+
# Although someone prevented the destruction, keep a uniform API for
|
216
|
+
# callers by returning a Deferred that will never be resolved.
|
217
|
+
u.unresolvableDeferred()
|
218
|
+
|
219
|
+
###*
|
220
|
+
This event is [emitted](/up.emit) when a popup is starting to open.
|
221
|
+
|
222
|
+
@event up:popup:open
|
223
|
+
@param event.preventDefault()
|
224
|
+
Event listeners may call this method to prevent the popup from opening.
|
225
|
+
@stable
|
226
|
+
###
|
227
|
+
|
228
|
+
###*
|
229
|
+
This event is [emitted](/up.emit) when a popup has finished opening.
|
230
|
+
|
231
|
+
@event up:popup:opened
|
232
|
+
@stable
|
233
|
+
###
|
234
|
+
|
212
235
|
###*
|
213
236
|
Closes a currently opened popup overlay.
|
237
|
+
|
214
238
|
Does nothing if no popup is currently open.
|
215
|
-
|
239
|
+
|
240
|
+
Emits events [`up:popup:close`](/up:popup:close) and [`up:popup:closed`](/up:popup:closed).
|
241
|
+
|
216
242
|
@function up.popup.close
|
217
243
|
@param {Object} options
|
218
244
|
See options for [`up.animate`](/up.animate).
|
245
|
+
@return {Deferred}
|
246
|
+
A promise that will be resolved once the modal's close
|
247
|
+
animation has finished.
|
219
248
|
@stable
|
220
249
|
###
|
221
250
|
close = (options) ->
|
222
251
|
$popup = $('.up-popup')
|
223
252
|
if $popup.length
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
253
|
+
if up.bus.nobodyPrevents('up:popup:close', $element: $popup)
|
254
|
+
options = u.options(options,
|
255
|
+
animation: config.closeAnimation,
|
256
|
+
url: $popup.attr('up-covered-url'),
|
257
|
+
title: $popup.attr('up-covered-title')
|
258
|
+
)
|
259
|
+
currentUrl = undefined
|
260
|
+
deferred = up.destroy($popup, options)
|
261
|
+
deferred.then -> up.emit('up:popup:closed')
|
262
|
+
deferred
|
263
|
+
else
|
264
|
+
# Although someone prevented the destruction,
|
265
|
+
# keep a uniform API for callers by returning
|
266
|
+
# a Deferred that will never be resolved.
|
267
|
+
u.unresolvableDeferred()
|
231
268
|
else
|
232
|
-
u.
|
233
|
-
|
269
|
+
u.resolvedDeferred()
|
270
|
+
|
271
|
+
###*
|
272
|
+
This event is [emitted](/up.emit) when a popup dialog
|
273
|
+
is starting to [close](/up.popup.close).
|
274
|
+
|
275
|
+
@event up:popup:close
|
276
|
+
@param event.preventDefault()
|
277
|
+
Event listeners may call this method to prevent the popup from closing.
|
278
|
+
@stable
|
279
|
+
###
|
280
|
+
|
281
|
+
###*
|
282
|
+
This event is [emitted](/up.emit) when a popup dialog
|
283
|
+
is done [closing](/up.popup.close).
|
284
|
+
|
285
|
+
@event up:popup:closed
|
286
|
+
@stable
|
287
|
+
###
|
288
|
+
|
234
289
|
autoclose = ->
|
235
290
|
unless $('.up-popup').is('[up-sticky]')
|
236
291
|
discardHistory()
|
@@ -667,8 +667,7 @@ up.util = (($) ->
|
|
667
667
|
|
668
668
|
###*
|
669
669
|
Returns the first argument that is considered present.
|
670
|
-
|
671
|
-
|
670
|
+
|
672
671
|
This function is useful when you have multiple option sources and the value can be boolean.
|
673
672
|
In that case you cannot change the sources with a `||` operator
|
674
673
|
(since that doesn't short-circuit at `false`).
|
@@ -678,15 +677,7 @@ up.util = (($) ->
|
|
678
677
|
@internal
|
679
678
|
###
|
680
679
|
option = (args...) ->
|
681
|
-
|
682
|
-
match = undefined
|
683
|
-
for arg in args
|
684
|
-
value = arg
|
685
|
-
value = value() if isFunction(value)
|
686
|
-
if isGiven(value)
|
687
|
-
match = value
|
688
|
-
break
|
689
|
-
match
|
680
|
+
detect(args, isGiven)
|
690
681
|
|
691
682
|
###*
|
692
683
|
Passes each element in the given array to the given function.
|
@@ -922,7 +913,7 @@ up.util = (($) ->
|
|
922
913
|
###
|
923
914
|
cssAnimate = (elementOrSelector, lastFrame, opts) ->
|
924
915
|
$element = $(elementOrSelector)
|
925
|
-
if up.browser.
|
916
|
+
if up.browser.canCssTransition()
|
926
917
|
opts = options(opts,
|
927
918
|
duration: 300,
|
928
919
|
delay: 0,
|
@@ -1149,6 +1140,16 @@ up.util = (($) ->
|
|
1149
1140
|
resolvedPromise = ->
|
1150
1141
|
resolvedDeferred().promise()
|
1151
1142
|
|
1143
|
+
###*
|
1144
|
+
Returns a [Deferred object](https://api.jquery.com/category/deferred-object/) that will never be resolved.
|
1145
|
+
|
1146
|
+
@function up.util.unresolvableDeferred
|
1147
|
+
@return {Deferred}
|
1148
|
+
@experimental
|
1149
|
+
###
|
1150
|
+
unresolvableDeferred = ->
|
1151
|
+
$.Deferred()
|
1152
|
+
|
1152
1153
|
###*
|
1153
1154
|
Returns a promise that will never be resolved.
|
1154
1155
|
|
@@ -1156,7 +1157,7 @@ up.util = (($) ->
|
|
1156
1157
|
@experimental
|
1157
1158
|
###
|
1158
1159
|
unresolvablePromise = ->
|
1159
|
-
|
1160
|
+
unresolvableDeferred().promise()
|
1160
1161
|
|
1161
1162
|
###*
|
1162
1163
|
Returns an empty jQuery collection.
|
@@ -1518,6 +1519,7 @@ up.util = (($) ->
|
|
1518
1519
|
clientSize: clientSize
|
1519
1520
|
only: only
|
1520
1521
|
trim: trim
|
1522
|
+
unresolvableDeferred: unresolvableDeferred
|
1521
1523
|
unresolvablePromise: unresolvablePromise
|
1522
1524
|
resolvedPromise: resolvedPromise
|
1523
1525
|
resolvedDeferred: resolvedDeferred
|
data/lib/upjs/rails/version.rb
CHANGED
data/spec_app/Gemfile.lock
CHANGED
@@ -76,19 +76,21 @@ describe 'up.bus', ->
|
|
76
76
|
|
77
77
|
expect(emittedEvent.customField).toEqual('custom-value')
|
78
78
|
|
79
|
-
|
80
|
-
emittedEvent = undefined
|
81
|
-
emitted$Target = undefined
|
79
|
+
describe 'with .$element option', ->
|
82
80
|
|
83
|
-
|
81
|
+
it 'triggers an event on the given element', ->
|
82
|
+
emittedEvent = undefined
|
83
|
+
$emittedTarget = undefined
|
84
84
|
|
85
|
-
|
86
|
-
emittedEvent = event
|
87
|
-
emitted$Target = $target
|
85
|
+
$element = affix('.element').text('foo')
|
88
86
|
|
89
|
-
|
87
|
+
up.on 'foo', (event, $target) ->
|
88
|
+
emittedEvent = event
|
89
|
+
$emittedTarget = $target
|
90
90
|
|
91
|
-
|
92
|
-
|
91
|
+
up.emit('foo', $element: $element)
|
92
|
+
|
93
|
+
expect(emittedEvent).toBeDefined()
|
94
|
+
expect($emittedTarget).toEqual($element)
|
93
95
|
|
94
|
-
|
96
|
+
expect(emittedEvent.$element).toEqual($element)
|