upjs-rails 0.12.4 → 0.12.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -3
- data/dist/up.js +495 -300
- data/dist/up.min.js +2 -2
- data/lib/assets/javascripts/up.js.coffee +3 -1
- data/lib/assets/javascripts/up/browser.js.coffee +8 -8
- data/lib/assets/javascripts/up/bus.js.coffee +77 -37
- data/lib/assets/javascripts/up/flow.js.coffee +40 -6
- data/lib/assets/javascripts/up/form.js.coffee +5 -7
- data/lib/assets/javascripts/up/history.js.coffee +8 -10
- data/lib/assets/javascripts/up/layout.js.coffee +22 -20
- data/lib/assets/javascripts/up/link.js.coffee +10 -15
- data/lib/assets/javascripts/up/modal.js.coffee +92 -72
- data/lib/assets/javascripts/up/motion.js.coffee +16 -17
- data/lib/assets/javascripts/up/navigation.js.coffee +3 -6
- data/lib/assets/javascripts/up/popup.js.coffee +55 -27
- data/lib/assets/javascripts/up/proxy.js.coffee +71 -20
- data/lib/assets/javascripts/up/syntax.js.coffee +30 -15
- data/lib/assets/javascripts/up/tooltip.js.coffee +5 -8
- data/lib/assets/javascripts/up/util.js.coffee +39 -22
- data/lib/upjs/rails/version.rb +1 -1
- data/spec_app/spec/javascripts/up/flow_spec.js.coffee +30 -0
- data/spec_app/spec/javascripts/up/link_spec.js.coffee +6 -0
- data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +8 -8
- metadata +2 -3
- data/lib/assets/javascripts/up/boot.js.coffee +0 -3
@@ -18,8 +18,7 @@ up.navigation = (($) ->
|
|
18
18
|
###*
|
19
19
|
Sets default options for this module.
|
20
20
|
|
21
|
-
@
|
22
|
-
@property
|
21
|
+
@property up.navigation.config
|
23
22
|
@param {Number} [config.currentClasses]
|
24
23
|
An array of classes to set on [links that point the current location](/up-current).
|
25
24
|
###
|
@@ -126,8 +125,7 @@ up.navigation = (($) ->
|
|
126
125
|
|
127
126
|
<a href="/foo" up-follow up-current>Foo</a>
|
128
127
|
|
129
|
-
@
|
130
|
-
@method [up-active]
|
128
|
+
@selector [up-active]
|
131
129
|
###
|
132
130
|
sectionClicked = ($section) ->
|
133
131
|
unmarkActive()
|
@@ -189,8 +187,7 @@ up.navigation = (($) ->
|
|
189
187
|
|
190
188
|
<a href="/reports" up-alias="/reports/*">Reports</a>
|
191
189
|
|
192
|
-
@
|
193
|
-
@ujs
|
190
|
+
@selector [up-current]
|
194
191
|
###
|
195
192
|
up.on 'up:fragment:inserted', ->
|
196
193
|
# If a new fragment is inserted, it's likely to be the result
|
@@ -2,22 +2,46 @@
|
|
2
2
|
Pop-up overlays
|
3
3
|
===============
|
4
4
|
|
5
|
-
Instead of linking to
|
6
|
-
to
|
7
|
-
|
8
|
-
popup
|
9
|
-
|
5
|
+
Instead of [linking to a page fragment](/up.link), you can choose
|
6
|
+
to show a fragment in a popup overlay.
|
7
|
+
|
8
|
+
To open a popup, add an [`up-popup` attribute](/a-up-popup) to a link,
|
9
|
+
or call the Javascript function [`up.popup.attach`](/up.popup.attach).
|
10
|
+
|
10
11
|
For modal dialogs see [up.modal](/up.modal) instead.
|
11
|
-
|
12
|
-
\#\#\# Incomplete documentation!
|
13
|
-
|
14
|
-
We need to work on this page:
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
|
14
|
+
\#\#\#\# Customizing the popup design
|
15
|
+
|
16
|
+
Loading the Up.js stylesheet will give you a minimal popup design:
|
17
|
+
|
18
|
+
- Popup contents are displayed in a white box
|
19
|
+
- There is a a subtle box shadow around the popup
|
20
|
+
- The box will grow to fit the popup contents
|
21
|
+
|
22
|
+
The easiest way to change how the popup looks is by overriding the [default CSS styles](https://github.com/makandra/upjs/blob/master/lib/assets/stylesheets/up/popup.css.sass).
|
23
|
+
|
24
|
+
By default the popup uses the following DOM structure:
|
25
|
+
|
26
|
+
<div class="up-popup">
|
27
|
+
...
|
28
|
+
</div>
|
29
|
+
|
30
|
+
|
31
|
+
\#\#\#\# Closing behavior
|
32
|
+
|
33
|
+
The popup closes when the user clicks anywhere outside the popup area.
|
34
|
+
|
35
|
+
By default the popup also closes
|
36
|
+
*whenever a page fragment below the popup is updated*.
|
37
|
+
This is useful to have the popup interact with the page that
|
38
|
+
opened it, e.g. by updating parts of a larger form or by signing in a user
|
39
|
+
and revealing additional information.
|
40
|
+
|
41
|
+
To disable this behavior, give the opening link an `up-sticky` attribute:
|
42
|
+
|
43
|
+
<a href="/settings" up-popup=".options" up-sticky>Settings</a>
|
44
|
+
|
21
45
|
|
22
46
|
@class up.popup
|
23
47
|
###
|
@@ -29,7 +53,7 @@ up.popup = (($) ->
|
|
29
53
|
Returns the source URL for the fragment displayed
|
30
54
|
in the current popup, or `undefined` if no popup is open.
|
31
55
|
|
32
|
-
@
|
56
|
+
@function up.popup.url
|
33
57
|
@return {String}
|
34
58
|
the source URL
|
35
59
|
###
|
@@ -38,7 +62,7 @@ up.popup = (($) ->
|
|
38
62
|
###*
|
39
63
|
Returns the URL of the page or modal below the popup.
|
40
64
|
|
41
|
-
@
|
65
|
+
@function up.popup.coveredUrl
|
42
66
|
@return {String}
|
43
67
|
@protected
|
44
68
|
###
|
@@ -47,11 +71,17 @@ up.popup = (($) ->
|
|
47
71
|
$popup.attr('up-covered-url')
|
48
72
|
|
49
73
|
###*
|
50
|
-
|
51
|
-
|
52
|
-
@
|
53
|
-
@param {String} [config.
|
54
|
-
|
74
|
+
Sets default options for future popups.
|
75
|
+
|
76
|
+
@property up.popup.config
|
77
|
+
@param {String} [config.openAnimation='fade-in']
|
78
|
+
The animation used to open a popup.
|
79
|
+
@param {String} [config.closeAnimation='fade-out']
|
80
|
+
The animation used to close a popup.
|
81
|
+
@param {String} [config.position='bottom-right']
|
82
|
+
Defines where the popup is attached to the opening element.
|
83
|
+
|
84
|
+
Valid values are `bottom-right`, `bottom-left`, `top-right` and `top-left`.
|
55
85
|
###
|
56
86
|
config = u.config
|
57
87
|
openAnimation: 'fade-in'
|
@@ -137,7 +167,7 @@ up.popup = (($) ->
|
|
137
167
|
###*
|
138
168
|
Attaches a popup overlay to the given element or selector.
|
139
169
|
|
140
|
-
@
|
170
|
+
@function up.popup.attach
|
141
171
|
@param {Element|jQuery|String} elementOrSelector
|
142
172
|
@param {String} [options.url]
|
143
173
|
@param {String} [options.position='bottom-right']
|
@@ -178,7 +208,7 @@ up.popup = (($) ->
|
|
178
208
|
Closes a currently opened popup overlay.
|
179
209
|
Does nothing if no popup is currently open.
|
180
210
|
|
181
|
-
@
|
211
|
+
@function up.popup.close
|
182
212
|
@param {Object} options
|
183
213
|
See options for [`up.animate`](/up.animate).
|
184
214
|
###
|
@@ -223,8 +253,7 @@ up.popup = (($) ->
|
|
223
253
|
<a href="/decks" up-popup=".deck_list">Switch deck</a>
|
224
254
|
<a href="/settings" up-popup=".options" up-sticky>Settings</a>
|
225
255
|
|
226
|
-
@
|
227
|
-
@ujs
|
256
|
+
@selector a[up-popup]
|
228
257
|
@param [up-sticky]
|
229
258
|
@param [up-position]
|
230
259
|
###
|
@@ -259,8 +288,7 @@ up.popup = (($) ->
|
|
259
288
|
When an element with this attribute is clicked,
|
260
289
|
a currently open popup is closed.
|
261
290
|
|
262
|
-
@
|
263
|
-
@ujs
|
291
|
+
@selector [up-close]
|
264
292
|
###
|
265
293
|
up.on('click', '[up-close]', (event, $element) ->
|
266
294
|
if $element.closest('.up-popup').length
|
@@ -18,8 +18,9 @@ the user performs the click.
|
|
18
18
|
Spinners
|
19
19
|
--------
|
20
20
|
|
21
|
-
You can listen
|
22
|
-
(
|
21
|
+
You can [listen](/up.on) to the [`up:proxy:busy`](/up:proxy:busy)
|
22
|
+
and [`up:proxy:idle`](/up:proxy:idle) events to implement a spinner
|
23
|
+
that appears during a long-running request,
|
23
24
|
and disappears once the response has been received:
|
24
25
|
|
25
26
|
<div class="spinner">Please wait!</div>
|
@@ -31,8 +32,8 @@ Here is the Javascript to make it alive:
|
|
31
32
|
show = function() { $element.show() };
|
32
33
|
hide = function() { $element.hide() };
|
33
34
|
|
34
|
-
showOff = up.on('proxy:busy', show);
|
35
|
-
hideOff = up.on('proxy:idle', hide);
|
35
|
+
showOff = up.on('up:proxy:busy', show);
|
36
|
+
hideOff = up.on('up:proxy:idle', hide);
|
36
37
|
|
37
38
|
hide();
|
38
39
|
|
@@ -44,9 +45,9 @@ Here is the Javascript to make it alive:
|
|
44
45
|
|
45
46
|
});
|
46
47
|
|
47
|
-
The `proxy:busy` event will be emitted after a delay of 300 ms
|
48
|
+
The `up:proxy:busy` event will be emitted after a delay of 300 ms
|
48
49
|
to prevent the spinner from flickering on and off.
|
49
|
-
You can change (or remove) this delay like this:
|
50
|
+
You can change (or remove) this delay by [configuring `up.proxy`](/up.proxy.config) like this:
|
50
51
|
|
51
52
|
up.proxy.config.busyDelay = 150;
|
52
53
|
|
@@ -63,8 +64,7 @@ up.proxy = (($) ->
|
|
63
64
|
busyEventEmitted = undefined
|
64
65
|
|
65
66
|
###*
|
66
|
-
@
|
67
|
-
@property
|
67
|
+
@property up.proxy.config
|
68
68
|
@param {Number} [config.preloadDelay=75]
|
69
69
|
The number of milliseconds to wait before [`[up-preload]`](/up-preload)
|
70
70
|
starts preloading.
|
@@ -100,25 +100,26 @@ up.proxy = (($) ->
|
|
100
100
|
|
101
101
|
###*
|
102
102
|
@protected
|
103
|
-
@
|
103
|
+
@function up.proxy.get
|
104
104
|
###
|
105
105
|
get = cache.get
|
106
106
|
|
107
107
|
###*
|
108
108
|
@protected
|
109
|
-
@
|
109
|
+
@function up.proxy.set
|
110
110
|
###
|
111
111
|
set = cache.set
|
112
112
|
|
113
113
|
###*
|
114
114
|
@protected
|
115
|
-
@
|
115
|
+
@function up.proxy.remove
|
116
116
|
###
|
117
117
|
remove = cache.remove
|
118
118
|
|
119
119
|
###*
|
120
|
-
|
121
|
-
|
120
|
+
Removes all cache entries.
|
121
|
+
|
122
|
+
@function up.proxy.clear
|
122
123
|
###
|
123
124
|
clear = cache.clear
|
124
125
|
|
@@ -165,7 +166,7 @@ up.proxy = (($) ->
|
|
165
166
|
Once the response is received, a `proxy:receive` event will
|
166
167
|
be emitted.
|
167
168
|
|
168
|
-
@
|
169
|
+
@function up.proxy.ajax
|
169
170
|
@param {String} request.url
|
170
171
|
@param {String} [request.method='GET']
|
171
172
|
@param {String} [request.selector]
|
@@ -222,7 +223,7 @@ up.proxy = (($) ->
|
|
222
223
|
The proxy will also emit an `proxy:idle` [event](/up.bus) if it
|
223
224
|
used to busy, but is now idle.
|
224
225
|
|
225
|
-
@
|
226
|
+
@function up.proxy.idle
|
226
227
|
@return {Boolean} Whether the proxy is idle
|
227
228
|
###
|
228
229
|
idle = ->
|
@@ -235,7 +236,7 @@ up.proxy = (($) ->
|
|
235
236
|
The proxy will also emit an `proxy:busy` [event](/up.bus) if it
|
236
237
|
used to idle, but is now busy.
|
237
238
|
|
238
|
-
@
|
239
|
+
@function up.proxy.busy
|
239
240
|
@return {Boolean} Whether the proxy is busy
|
240
241
|
###
|
241
242
|
busy = ->
|
@@ -245,6 +246,8 @@ up.proxy = (($) ->
|
|
245
246
|
wasIdle = idle()
|
246
247
|
pendingCount += 1
|
247
248
|
if wasIdle
|
249
|
+
# Since the emission of up:proxy:busy might be delayed by config.busyDelay,
|
250
|
+
# we wrap the mission in a function for scheduling below.
|
248
251
|
emission = ->
|
249
252
|
if busy() # a fast response might have beaten the delay
|
250
253
|
up.emit('up:proxy:busy')
|
@@ -254,19 +257,66 @@ up.proxy = (($) ->
|
|
254
257
|
else
|
255
258
|
emission()
|
256
259
|
|
260
|
+
###*
|
261
|
+
This event is [emitted]/(up.emit) when [AJAX requests](/up.proxy.ajax)
|
262
|
+
are taking long to finish.
|
263
|
+
|
264
|
+
By default Up.js will wait 300 ms for an AJAX request to finish
|
265
|
+
before emitting `up:proxy:busy`. You can configure this time like this:
|
266
|
+
|
267
|
+
up.proxy.config.busyDelay = 150;
|
268
|
+
|
269
|
+
Once all responses have been received, an [`up:proxy:idle`](/up:proxy:idle)
|
270
|
+
will be emitted.
|
271
|
+
|
272
|
+
Note that if additional requests are made while Up.js is already busy
|
273
|
+
waiting, **no** additional `up:proxy:busy` events will be triggered.
|
274
|
+
|
275
|
+
@event up:proxy:busy
|
276
|
+
###
|
277
|
+
|
257
278
|
loadEnded = ->
|
258
279
|
pendingCount -= 1
|
259
280
|
if idle() && busyEventEmitted
|
260
281
|
up.emit('up:proxy:idle')
|
261
282
|
busyEventEmitted = false
|
262
283
|
|
284
|
+
###*
|
285
|
+
This event is [emitted]/(up.emit) when [AJAX requests](/up.proxy.ajax)
|
286
|
+
have [taken long to finish](/up:proxy:busy), but have finished now.
|
287
|
+
|
288
|
+
@event up:proxy:busy
|
289
|
+
###
|
290
|
+
|
263
291
|
load = (request) ->
|
264
292
|
u.debug('Loading URL %o', request.url)
|
265
293
|
up.emit('up:proxy:load', request)
|
266
294
|
promise = u.ajax(request)
|
267
|
-
promise.always -> up.emit('up:proxy:
|
295
|
+
promise.always -> up.emit('up:proxy:received', request)
|
268
296
|
promise
|
269
297
|
|
298
|
+
###*
|
299
|
+
This event is [emitted]/(up.emit) before an [AJAX request](/up.proxy.ajax)
|
300
|
+
is starting to load.
|
301
|
+
|
302
|
+
@event up:proxy:load
|
303
|
+
@protected
|
304
|
+
@param event.url
|
305
|
+
@param event.method
|
306
|
+
@param event.selector
|
307
|
+
###
|
308
|
+
|
309
|
+
###*
|
310
|
+
This event is [emitted]/(up.emit) when the response to an [AJAX request](/up.proxy.ajax)
|
311
|
+
has been received.
|
312
|
+
|
313
|
+
@event up:proxy:received
|
314
|
+
@protected
|
315
|
+
@param event.url
|
316
|
+
@param event.method
|
317
|
+
@param event.selector
|
318
|
+
###
|
319
|
+
|
270
320
|
isIdempotent = (request) ->
|
271
321
|
normalizeRequest(request)
|
272
322
|
u.contains(SAFE_HTTP_METHODS, request.method)
|
@@ -286,7 +336,9 @@ up.proxy = (($) ->
|
|
286
336
|
|
287
337
|
###*
|
288
338
|
@protected
|
289
|
-
@
|
339
|
+
@function up.proxy.preload
|
340
|
+
@param {String|Element|jQuery}
|
341
|
+
The element whose destination should be preloaded.
|
290
342
|
@return
|
291
343
|
A promise that will be resolved when the request was loaded and cached
|
292
344
|
###
|
@@ -310,12 +362,11 @@ up.proxy = (($) ->
|
|
310
362
|
response will already be cached when the user performs the click,
|
311
363
|
making the interaction feel instant.
|
312
364
|
|
313
|
-
@
|
365
|
+
@selector [up-preload]
|
314
366
|
@param [up-delay=75]
|
315
367
|
The number of milliseconds to wait between hovering
|
316
368
|
and preloading. Increasing this will lower the load in your server,
|
317
369
|
but will also make the interaction feel less instant.
|
318
|
-
@ujs
|
319
370
|
###
|
320
371
|
up.on 'mouseover mousedown touchstart', '[up-preload]', (event, $element) ->
|
321
372
|
# Don't do anything if we are hovering over the child
|
@@ -155,7 +155,7 @@ up.syntax = (($) ->
|
|
155
155
|
});
|
156
156
|
|
157
157
|
|
158
|
-
@
|
158
|
+
@function up.compiler
|
159
159
|
@param {String} selector
|
160
160
|
The selector to match.
|
161
161
|
@param {Boolean} [options.batch=false]
|
@@ -204,7 +204,7 @@ up.syntax = (($) ->
|
|
204
204
|
else
|
205
205
|
$matches.each -> applyCompiler(compiler, $(this), this)
|
206
206
|
|
207
|
-
|
207
|
+
runDestroyers = ($fragment) ->
|
208
208
|
u.findWithSelf($fragment, ".#{DESTROYABLE_CLASS}").each ->
|
209
209
|
$element = $(this)
|
210
210
|
destroyer = $element.data(DESTROYER_KEY)
|
@@ -220,14 +220,15 @@ up.syntax = (($) ->
|
|
220
220
|
we can support getting or setting individual keys.
|
221
221
|
|
222
222
|
@protected
|
223
|
-
@
|
223
|
+
@function up.syntax.data
|
224
224
|
@param {String|Element|jQuery} elementOrSelector
|
225
|
-
|
225
|
+
@return
|
226
|
+
The JSON-decoded value of the `up-data` attribute.
|
226
227
|
|
228
|
+
Returns an empty object (`{}`) if the element has no (or an empty) `up-data` attribute.
|
227
229
|
###
|
228
|
-
Looks for an `up-data` attribute on the given element, then parses
|
229
|
-
its value as JSON and returns the JSON object.
|
230
230
|
|
231
|
+
###
|
231
232
|
If an element annotated with [`up-data`] is inserted into the DOM,
|
232
233
|
Up will parse the JSON and pass the resulting object to any matching
|
233
234
|
[`up.compiler`](/up.syntax.compiler) handlers.
|
@@ -236,13 +237,9 @@ up.syntax = (($) ->
|
|
236
237
|
[`up-data`], the parsed object will be passed to any matching
|
237
238
|
[`up.on`](/up.on) handlers.
|
238
239
|
|
239
|
-
@
|
240
|
-
@
|
241
|
-
|
242
|
-
@return
|
243
|
-
The JSON-decoded value of the `up-data` attribute.
|
244
|
-
|
245
|
-
Returns an empty object (`{}`) if the element has no (or an empty) `up-data` attribute.
|
240
|
+
@selector [up-data]
|
241
|
+
@param {JSON} up-data
|
242
|
+
A serialized JSON string
|
246
243
|
###
|
247
244
|
data = (elementOrSelector) ->
|
248
245
|
$element = $(elementOrSelector)
|
@@ -284,7 +281,10 @@ up.syntax = (($) ->
|
|
284
281
|
$element = $('<div>...</div>').appendTo(document.body);
|
285
282
|
up.hello($element);
|
286
283
|
|
287
|
-
|
284
|
+
This function emits the [`up:fragment:inserted`](/up:fragment:inserted)
|
285
|
+
event.
|
286
|
+
|
287
|
+
@function up.hello
|
288
288
|
@param {String|Element|jQuery} selectorOrElement
|
289
289
|
###
|
290
290
|
hello = (selectorOrElement) ->
|
@@ -292,9 +292,24 @@ up.syntax = (($) ->
|
|
292
292
|
up.emit('up:fragment:inserted', $element: $element)
|
293
293
|
$element
|
294
294
|
|
295
|
+
###*
|
296
|
+
When a page fragment has been [inserted or updated](/up.replace),
|
297
|
+
this event is [emitted](/up.emit) on the fragment.
|
298
|
+
|
299
|
+
\#\#\#\# Example
|
300
|
+
|
301
|
+
up.on('up:fragment:inserted', function(event, $fragment) {
|
302
|
+
console.log("Looks like we have a new %o!", $fragment);
|
303
|
+
});
|
304
|
+
|
305
|
+
@event up:fragment:inserted
|
306
|
+
@param {jQuery} event.$element
|
307
|
+
The fragment that has been inserted or updated.
|
308
|
+
###
|
309
|
+
|
295
310
|
up.on 'ready', (-> hello(document.body))
|
296
311
|
up.on 'up:fragment:inserted', (event) -> compile(event.$element)
|
297
|
-
up.on 'up:fragment:destroy', (event) ->
|
312
|
+
up.on 'up:fragment:destroy', (event) -> runDestroyers(event.$element)
|
298
313
|
up.on 'up:framework:boot', snapshot
|
299
314
|
up.on 'up:framework:reset', reset
|
300
315
|
|