unpoly-rails 0.37.0 → 0.50.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.

Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +127 -25
  3. data/LICENSE +1 -1
  4. data/README_RAILS.md +4 -2
  5. data/Rakefile +6 -1
  6. data/dist/unpoly.js +3192 -2198
  7. data/dist/unpoly.min.js +4 -3
  8. data/lib/assets/javascripts/unpoly/browser.coffee +51 -63
  9. data/lib/assets/javascripts/unpoly/bus.coffee +58 -33
  10. data/lib/assets/javascripts/unpoly/classes/cache.coffee +117 -0
  11. data/lib/assets/javascripts/unpoly/{dom → classes}/extract_cascade.coffee +3 -3
  12. data/lib/assets/javascripts/unpoly/{dom → classes}/extract_plan.coffee +1 -1
  13. data/lib/assets/javascripts/unpoly/classes/field_observer.coffee +57 -0
  14. data/lib/assets/javascripts/unpoly/classes/follow_variant.coffee +52 -0
  15. data/lib/assets/javascripts/unpoly/classes/motion_tracker.coffee +95 -0
  16. data/lib/assets/javascripts/unpoly/classes/record.coffee +16 -0
  17. data/lib/assets/javascripts/unpoly/classes/request.coffee +228 -0
  18. data/lib/assets/javascripts/unpoly/classes/response.coffee +138 -0
  19. data/lib/assets/javascripts/unpoly/dom.coffee +151 -142
  20. data/lib/assets/javascripts/unpoly/feedback.coffee +67 -38
  21. data/lib/assets/javascripts/unpoly/form.coffee +156 -139
  22. data/lib/assets/javascripts/unpoly/history.coffee +22 -19
  23. data/lib/assets/javascripts/unpoly/layout.coffee +108 -90
  24. data/lib/assets/javascripts/unpoly/link.coffee +159 -158
  25. data/lib/assets/javascripts/unpoly/log.coffee +5 -5
  26. data/lib/assets/javascripts/unpoly/modal.coffee +93 -81
  27. data/lib/assets/javascripts/unpoly/motion.coffee +291 -250
  28. data/lib/assets/javascripts/unpoly/popup.coffee +67 -53
  29. data/lib/assets/javascripts/unpoly/protocol.coffee +67 -16
  30. data/lib/assets/javascripts/unpoly/proxy.coffee +282 -211
  31. data/lib/assets/javascripts/unpoly/rails.coffee +3 -14
  32. data/lib/assets/javascripts/unpoly/syntax.coffee +54 -49
  33. data/lib/assets/javascripts/unpoly/tooltip.coffee +18 -25
  34. data/lib/assets/javascripts/unpoly/util.coffee +236 -477
  35. data/lib/assets/javascripts/unpoly.coffee +1 -1
  36. data/lib/unpoly/rails/inspector.rb +67 -22
  37. data/lib/unpoly/rails/version.rb +1 -1
  38. data/package.json +1 -1
  39. data/spec_app/Gemfile.lock +13 -13
  40. data/spec_app/app/assets/javascripts/integration_test.coffee +1 -0
  41. data/spec_app/app/assets/javascripts/jasmine_specs.coffee +1 -1
  42. data/spec_app/app/assets/stylesheets/jasmine_specs.sass +10 -0
  43. data/spec_app/app/controllers/binding_test_controller.rb +19 -2
  44. data/spec_app/app/controllers/method_test_controller.rb +16 -0
  45. data/spec_app/app/views/layouts/jasmine_rails/spec_runner.html.erb +20 -0
  46. data/spec_app/app/views/method_test/form_target.erb +17 -0
  47. data/spec_app/app/views/method_test/page1.erb +11 -0
  48. data/spec_app/app/views/method_test/page2.erb +6 -0
  49. data/spec_app/app/views/pages/start.erb +33 -19
  50. data/spec_app/config/initializers/assets.rb +5 -0
  51. data/spec_app/config/routes.rb +3 -0
  52. data/spec_app/spec/controllers/binding_test_controller_spec.rb +82 -27
  53. data/spec_app/spec/javascripts/helpers/agent_detector.coffee +17 -0
  54. data/spec_app/spec/javascripts/helpers/async_sequence.js.coffee +102 -0
  55. data/spec_app/spec/javascripts/helpers/last_request.js.coffee +1 -1
  56. data/spec_app/spec/javascripts/helpers/mock_ajax.js.coffee +5 -2
  57. data/spec_app/spec/javascripts/helpers/promise_state.js +18 -0
  58. data/spec_app/spec/javascripts/helpers/protect_jasmine_runner.coffee +9 -0
  59. data/spec_app/spec/javascripts/helpers/reset_history.js.coffee +22 -0
  60. data/spec_app/spec/javascripts/helpers/reset_up.js.coffee +11 -3
  61. data/spec_app/spec/javascripts/helpers/show_lib_versions.coffee +10 -0
  62. data/spec_app/spec/javascripts/helpers/to_be_error.coffee +5 -0
  63. data/spec_app/spec/javascripts/helpers/to_match_url.coffee +13 -0
  64. data/spec_app/spec/javascripts/helpers/trigger.js.coffee +13 -6
  65. data/spec_app/spec/javascripts/up/browser_spec.js.coffee +92 -33
  66. data/spec_app/spec/javascripts/up/bus_spec.js.coffee +64 -15
  67. data/spec_app/spec/javascripts/up/classes/.keep +0 -0
  68. data/spec_app/spec/javascripts/up/classes/cache_spec.js.coffee +1 -0
  69. data/spec_app/spec/javascripts/up/dom_spec.js.coffee +759 -551
  70. data/spec_app/spec/javascripts/up/feedback_spec.js.coffee +155 -82
  71. data/spec_app/spec/javascripts/up/form_spec.js.coffee +490 -349
  72. data/spec_app/spec/javascripts/up/history_spec.js.coffee +226 -179
  73. data/spec_app/spec/javascripts/up/layout_spec.js.coffee +253 -185
  74. data/spec_app/spec/javascripts/up/link_spec.js.coffee +416 -270
  75. data/spec_app/spec/javascripts/up/modal_spec.js.coffee +459 -330
  76. data/spec_app/spec/javascripts/up/motion_spec.js.coffee +198 -153
  77. data/spec_app/spec/javascripts/up/namespace_spec.js.coffee +9 -0
  78. data/spec_app/spec/javascripts/up/popup_spec.js.coffee +240 -175
  79. data/spec_app/spec/javascripts/up/protocol_spec.js.coffee +38 -0
  80. data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +777 -303
  81. data/spec_app/spec/javascripts/up/rails_spec.js.coffee +24 -8
  82. data/spec_app/spec/javascripts/up/syntax_spec.js.coffee +40 -23
  83. data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +80 -66
  84. data/spec_app/spec/javascripts/up/util_spec.js.coffee +227 -201
  85. data/spec_app/vendor/asset-libs/es6-promise-4.1.6/es6-promise.auto.js +1159 -0
  86. metadata +30 -7
  87. data/spec_app/spec/javascripts/helpers/reset_path.js.coffee +0 -7
  88. data/spec_app/spec/javascripts/helpers/to_equal_url.coffee +0 -11
@@ -3,8 +3,8 @@ Navigation feedback
3
3
  ===================
4
4
 
5
5
  Unpoly automatically adds CSS classes to links while they are
6
- currently loading ([`.up-active`](/up-active)) or
7
- pointing to the current location ([`.up-current`](/up-current)).
6
+ currently loading ([`.up-active`](/a.up-active)) or
7
+ pointing to the current location ([`.up-current`](/a.up-current)).
8
8
 
9
9
  By styling these classes with CSS you can provide instant feedback to user interactions.
10
10
  This improves the perceived speed of your interface.
@@ -16,12 +16,12 @@ Let's say we have an navigation bar with two links, pointing to `/foo` and `/bar
16
16
  <a href="/foo" up-follow>Foo</a>
17
17
  <a href="/bar" up-follow>Bar</a>
18
18
 
19
- If the current URL is `/foo`, the first link is automatically marked with an [`up-current`](/up-current) class:
19
+ If the current URL is `/foo`, the first link is automatically marked with an [`up-current`](/a.up-current) class:
20
20
 
21
21
  <a href="/foo" up-follow class="up-current">Foo</a>
22
22
  <a href="/bar" up-follow>Bar</a>
23
23
 
24
- When the user clicks on the `/bar` link, the link will receive the [`up-active`](/up-active) class while it is waiting
24
+ When the user clicks on the `/bar` link, the link will receive the [`up-active`](/a.up-active) class while it is waiting
25
25
  for the server to respond:
26
26
 
27
27
  <a href="/foo" up-follow class="up-current">Foo</a>
@@ -43,8 +43,8 @@ up.feedback = (($) ->
43
43
  Sets default options for this module.
44
44
 
45
45
  @property up.feedback.config
46
- @param {Number} [config.currentClasses]
47
- An array of classes to set on [links that point the current location](/up-current).
46
+ @param {Array<string>} [config.currentClasses]
47
+ An array of classes to set on [links that point the current location](/a.up-current).
48
48
  @stable
49
49
  ###
50
50
  config = u.config
@@ -78,6 +78,7 @@ up.feedback = (($) ->
78
78
  urls
79
79
 
80
80
  urlSet = (urls) ->
81
+ urls = u.map(urls, normalizeUrl)
81
82
  urls = u.compact(urls)
82
83
 
83
84
  matches = (testUrl) ->
@@ -100,11 +101,11 @@ up.feedback = (($) ->
100
101
 
101
102
  locationChanged = ->
102
103
  currentUrls = urlSet([
103
- normalizeUrl(up.browser.url()),
104
- normalizeUrl(up.modal.url()),
105
- normalizeUrl(up.modal.coveredUrl()),
106
- normalizeUrl(up.popup.url()),
107
- normalizeUrl(up.popup.coveredUrl())
104
+ up.browser.url(),
105
+ up.modal.url(),
106
+ up.modal.coveredUrl(),
107
+ up.popup.url(),
108
+ up.popup.coveredUrl()
108
109
  ])
109
110
 
110
111
  klass = currentClass()
@@ -115,14 +116,14 @@ up.feedback = (($) ->
115
116
  # the actual link might be a child element.
116
117
  urls = sectionUrls($section)
117
118
 
118
- if currentUrls.matchesAny(urls)
119
+ if up.link.isSafe($section) && currentUrls.matchesAny(urls)
119
120
  $section.addClass(klass)
120
121
  else if $section.hasClass(klass) && $section.closest('.up-destroying').length == 0
121
122
  $section.removeClass(klass)
122
123
 
123
124
  ###*
124
125
  @function findActionableArea
125
- @param {String|Element|jQuery} elementOrSelector
126
+ @param {string|Element|jQuery} elementOrSelector
126
127
  @internal
127
128
  ###
128
129
  findActionableArea = (elementOrSelector) ->
@@ -133,7 +134,7 @@ up.feedback = (($) ->
133
134
  $area
134
135
 
135
136
  ###*
136
- Marks the given element as currently loading, by assigning the CSS class [`up-active`](/up-active).
137
+ Marks the given element as currently loading, by assigning the CSS class [`up-active`](/a.up-active).
137
138
 
138
139
  This happens automatically when following links or submitting forms through the Unpoly API.
139
140
  Use this function if you make custom network calls from your own JavaScript code.
@@ -143,50 +144,47 @@ up.feedback = (($) ->
143
144
 
144
145
  \#\#\# Example
145
146
 
146
- var $button = $('button');
147
- $button.on('click', function() {
148
- up.feedback.start($button);
149
- up.ajax(...).always(function() {
150
- up.feedback.stop($button);
151
- });
152
- });
153
-
154
- Or shorter:
155
-
156
147
  var $button = $('button');
157
148
  $button.on('click', function() {
158
149
  up.feedback.start($button, function() {
159
- up.ajax(...);
150
+ // the .up-active class will be removed when this promise resolves:
151
+ return up.request(...);
160
152
  });
161
153
  });
162
154
 
163
155
  @method up.feedback.start
164
- @param {Element|jQuery|String} elementOrSelector
156
+ @param {Element|jQuery|string} elementOrSelector
165
157
  The element to mark as active
158
+ @param {Object} [options.preload]
159
+ If set to `false`, the element will not be marked as loading.
166
160
  @param {Function} [action]
167
161
  An optional function to run while the element is marked as loading.
168
162
  The function must return a promise.
169
163
  Once the promise resolves, the element will be [marked as no longer loading](/up.feedback.stop).
170
164
  @internal
171
165
  ###
172
- start = (elementOrSelector, action) ->
166
+ start = (args...) ->
167
+ elementOrSelector = args.shift()
168
+ action = args.pop()
169
+ options = u.options(args[0])
173
170
  $element = findActionableArea(elementOrSelector)
174
- $element.addClass(CLASS_ACTIVE)
171
+ unless options.preload
172
+ $element.addClass(CLASS_ACTIVE)
175
173
  if action
176
174
  promise = action()
177
175
  if u.isPromise(promise)
178
- promise.always -> stop($element)
176
+ u.always promise, -> stop($element)
179
177
  else
180
178
  up.warn('Expected block to return a promise, but got %o', promise)
181
179
  promise
182
180
 
183
181
  ###*
184
- Links that are currently loading are assigned the `up-active`
185
- class automatically. Style `.up-active` in your CSS to improve the
186
- perceived responsiveness of your user interface.
182
+ Links that are currently [loading through Unpoly](/form-up-target)
183
+ are assigned the `up-active` class automatically.
184
+ Style `.up-active` in your CSS to improve the perceived responsiveness
185
+ of your user interface.
187
186
 
188
- The `up-active` class will be removed as soon as another
189
- page fragment is added or updated through Unpoly.
187
+ The `up-active` class will be removed when the link is done loading.
190
188
 
191
189
  \#\#\# Example
192
190
 
@@ -200,16 +198,47 @@ up.feedback = (($) ->
200
198
  <a href="/foo" up-follow class="up-active">Foo</a>
201
199
 
202
200
  Once the link destination has loaded and rendered, the `up-active` class
203
- is removed and the [`up-current`](/up-current) class is added:
201
+ is removed and the [`up-current`](/a.up-current) class is added:
204
202
 
205
203
  <a href="/foo" up-follow class="up-current">Foo</a>
206
204
 
207
- @selector .up-active
205
+ @selector a.up-active
206
+ @stable
207
+ ###
208
+
209
+ ###*
210
+ Forms that are currently [loading through Unpoly](/a-up-target)
211
+ are assigned the `up-active` class automatically.
212
+ Style `.up-active` in your CSS to improve the perceived responsiveness
213
+ of your user interface.
214
+
215
+ The `up-active` class will be removed as soon as the response to the
216
+ form submission has been received.
217
+
218
+ \#\#\# Example
219
+
220
+ We have a form:
221
+
222
+ <form up-target=".foo">
223
+ <button type="submit">Submit</button>
224
+ </form>
225
+
226
+ The user clicks on the submit button. While the form is being submitted
227
+ and waiting for the server to respond, the form has the `up-active` class:
228
+
229
+ <form up-target=".foo" class="up-active">
230
+ <button type="submit">Submit</button>
231
+ </form>
232
+
233
+ Once the link destination has loaded and rendered, the `up-active` class
234
+ is removed.
235
+
236
+ @selector form.up-active
208
237
  @stable
209
238
  ###
210
239
 
211
240
  ###*
212
- Marks the given element as no longer loading, by removing the CSS class [`up-active`](/up-active).
241
+ Marks the given element as no longer loading, by removing the CSS class [`up-active`](/a.up-active).
213
242
 
214
243
  This happens automatically when network requests initiated by the Unpoly API have completed.
215
244
  Use this function if you make custom network calls from your own JavaScript code.
@@ -264,7 +293,7 @@ up.feedback = (($) ->
264
293
 
265
294
  <a href="/reports" up-alias="/reports/*">Reports</a>
266
295
 
267
- @selector .up-current
296
+ @selector a.up-current
268
297
  @stable
269
298
  ###
270
299
  up.on 'up:fragment:inserted', ->