actionview 4.2.11.1 → 6.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionview might be problematic. Click here for more details.

Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +201 -192
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +9 -8
  5. data/lib/action_view/base.rb +144 -37
  6. data/lib/action_view/buffers.rb +18 -1
  7. data/lib/action_view/cache_expiry.rb +53 -0
  8. data/lib/action_view/context.rb +8 -12
  9. data/lib/action_view/dependency_tracker.rb +54 -20
  10. data/lib/action_view/digestor.rb +88 -85
  11. data/lib/action_view/flows.rb +11 -12
  12. data/lib/action_view/gem_version.rb +6 -4
  13. data/lib/action_view/helpers/active_model_helper.rb +16 -11
  14. data/lib/action_view/helpers/asset_tag_helper.rb +241 -82
  15. data/lib/action_view/helpers/asset_url_helper.rb +171 -67
  16. data/lib/action_view/helpers/atom_feed_helper.rb +19 -17
  17. data/lib/action_view/helpers/cache_helper.rb +112 -42
  18. data/lib/action_view/helpers/capture_helper.rb +20 -13
  19. data/lib/action_view/helpers/controller_helper.rb +15 -4
  20. data/lib/action_view/helpers/csp_helper.rb +26 -0
  21. data/lib/action_view/helpers/csrf_helper.rb +8 -6
  22. data/lib/action_view/helpers/date_helper.rb +230 -129
  23. data/lib/action_view/helpers/debug_helper.rb +7 -6
  24. data/lib/action_view/helpers/form_helper.rb +755 -129
  25. data/lib/action_view/helpers/form_options_helper.rb +130 -75
  26. data/lib/action_view/helpers/form_tag_helper.rb +116 -71
  27. data/lib/action_view/helpers/javascript_helper.rb +30 -14
  28. data/lib/action_view/helpers/number_helper.rb +84 -59
  29. data/lib/action_view/helpers/output_safety_helper.rb +36 -4
  30. data/lib/action_view/helpers/rendering_helper.rb +11 -8
  31. data/lib/action_view/helpers/sanitize_helper.rb +30 -31
  32. data/lib/action_view/helpers/tag_helper.rb +201 -75
  33. data/lib/action_view/helpers/tags/base.rb +138 -98
  34. data/lib/action_view/helpers/tags/check_box.rb +20 -19
  35. data/lib/action_view/helpers/tags/checkable.rb +4 -2
  36. data/lib/action_view/helpers/tags/collection_check_boxes.rb +12 -34
  37. data/lib/action_view/helpers/tags/collection_helpers.rb +69 -36
  38. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +6 -12
  39. data/lib/action_view/helpers/tags/collection_select.rb +4 -2
  40. data/lib/action_view/helpers/tags/color_field.rb +4 -3
  41. data/lib/action_view/helpers/tags/date_field.rb +2 -1
  42. data/lib/action_view/helpers/tags/date_select.rb +37 -36
  43. data/lib/action_view/helpers/tags/datetime_field.rb +4 -3
  44. data/lib/action_view/helpers/tags/datetime_local_field.rb +2 -1
  45. data/lib/action_view/helpers/tags/datetime_select.rb +2 -0
  46. data/lib/action_view/helpers/tags/email_field.rb +2 -0
  47. data/lib/action_view/helpers/tags/file_field.rb +2 -0
  48. data/lib/action_view/helpers/tags/grouped_collection_select.rb +4 -2
  49. data/lib/action_view/helpers/tags/hidden_field.rb +2 -0
  50. data/lib/action_view/helpers/tags/label.rb +3 -2
  51. data/lib/action_view/helpers/tags/month_field.rb +2 -1
  52. data/lib/action_view/helpers/tags/number_field.rb +2 -0
  53. data/lib/action_view/helpers/tags/password_field.rb +3 -1
  54. data/lib/action_view/helpers/tags/placeholderable.rb +3 -1
  55. data/lib/action_view/helpers/tags/radio_button.rb +7 -6
  56. data/lib/action_view/helpers/tags/range_field.rb +2 -0
  57. data/lib/action_view/helpers/tags/search_field.rb +14 -9
  58. data/lib/action_view/helpers/tags/select.rb +11 -10
  59. data/lib/action_view/helpers/tags/tel_field.rb +2 -0
  60. data/lib/action_view/helpers/tags/text_area.rb +4 -2
  61. data/lib/action_view/helpers/tags/text_field.rb +8 -8
  62. data/lib/action_view/helpers/tags/time_field.rb +2 -1
  63. data/lib/action_view/helpers/tags/time_select.rb +2 -0
  64. data/lib/action_view/helpers/tags/time_zone_select.rb +3 -1
  65. data/lib/action_view/helpers/tags/translator.rb +15 -16
  66. data/lib/action_view/helpers/tags/url_field.rb +2 -0
  67. data/lib/action_view/helpers/tags/week_field.rb +2 -1
  68. data/lib/action_view/helpers/tags.rb +3 -1
  69. data/lib/action_view/helpers/text_helper.rb +56 -38
  70. data/lib/action_view/helpers/translation_helper.rb +91 -47
  71. data/lib/action_view/helpers/url_helper.rb +160 -105
  72. data/lib/action_view/helpers.rb +5 -3
  73. data/lib/action_view/layouts.rb +65 -61
  74. data/lib/action_view/log_subscriber.rb +61 -10
  75. data/lib/action_view/lookup_context.rb +147 -89
  76. data/lib/action_view/model_naming.rb +3 -1
  77. data/lib/action_view/path_set.rb +28 -23
  78. data/lib/action_view/railtie.rb +62 -6
  79. data/lib/action_view/record_identifier.rb +53 -26
  80. data/lib/action_view/renderer/abstract_renderer.rb +71 -13
  81. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +103 -0
  82. data/lib/action_view/renderer/partial_renderer.rb +239 -225
  83. data/lib/action_view/renderer/renderer.rb +22 -8
  84. data/lib/action_view/renderer/streaming_template_renderer.rb +54 -54
  85. data/lib/action_view/renderer/template_renderer.rb +79 -73
  86. data/lib/action_view/rendering.rb +68 -44
  87. data/lib/action_view/routing_url_for.rb +33 -22
  88. data/lib/action_view/tasks/cache_digests.rake +25 -0
  89. data/lib/action_view/template/error.rb +44 -29
  90. data/lib/action_view/template/handlers/builder.rb +12 -13
  91. data/lib/action_view/template/handlers/erb/erubi.rb +87 -0
  92. data/lib/action_view/template/handlers/erb.rb +24 -86
  93. data/lib/action_view/template/handlers/html.rb +11 -0
  94. data/lib/action_view/template/handlers/raw.rb +4 -4
  95. data/lib/action_view/template/handlers.rb +38 -8
  96. data/lib/action_view/template/html.rb +19 -10
  97. data/lib/action_view/template/inline.rb +22 -0
  98. data/lib/action_view/template/raw_file.rb +28 -0
  99. data/lib/action_view/template/resolver.rb +217 -193
  100. data/lib/action_view/template/sources/file.rb +17 -0
  101. data/lib/action_view/template/sources.rb +13 -0
  102. data/lib/action_view/template/text.rb +11 -10
  103. data/lib/action_view/template/types.rb +18 -18
  104. data/lib/action_view/template.rb +146 -90
  105. data/lib/action_view/test_case.rb +52 -32
  106. data/lib/action_view/testing/resolvers.rb +46 -34
  107. data/lib/action_view/unbound_template.rb +31 -0
  108. data/lib/action_view/version.rb +3 -1
  109. data/lib/action_view/view_paths.rb +48 -31
  110. data/lib/action_view.rb +11 -8
  111. data/lib/assets/compiled/rails-ujs.js +746 -0
  112. metadata +38 -29
  113. data/lib/action_view/helpers/record_tag_helper.rb +0 -108
  114. data/lib/action_view/tasks/dependencies.rake +0 -23
@@ -0,0 +1,746 @@
1
+ /*
2
+ Unobtrusive JavaScript
3
+ https://github.com/rails/rails/blob/main/actionview/app/assets/javascripts
4
+ Released under the MIT license
5
+ */;
6
+
7
+ (function() {
8
+ var context = this;
9
+
10
+ (function() {
11
+ (function() {
12
+ this.Rails = {
13
+ linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]:not([disabled]), a[data-disable-with], a[data-disable]',
14
+ buttonClickSelector: {
15
+ selector: 'button[data-remote]:not([form]), button[data-confirm]:not([form])',
16
+ exclude: 'form button'
17
+ },
18
+ inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
19
+ formSubmitSelector: 'form',
20
+ formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])',
21
+ formDisableSelector: 'input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled',
22
+ formEnableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled',
23
+ fileInputSelector: 'input[name][type=file]:not([disabled])',
24
+ linkDisableSelector: 'a[data-disable-with], a[data-disable]',
25
+ buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]'
26
+ };
27
+
28
+ }).call(this);
29
+ }).call(context);
30
+
31
+ var Rails = context.Rails;
32
+
33
+ (function() {
34
+ (function() {
35
+ var nonce;
36
+
37
+ nonce = null;
38
+
39
+ Rails.loadCSPNonce = function() {
40
+ var ref;
41
+ return nonce = (ref = document.querySelector("meta[name=csp-nonce]")) != null ? ref.content : void 0;
42
+ };
43
+
44
+ Rails.cspNonce = function() {
45
+ return nonce != null ? nonce : Rails.loadCSPNonce();
46
+ };
47
+
48
+ }).call(this);
49
+ (function() {
50
+ var expando, m;
51
+
52
+ m = Element.prototype.matches || Element.prototype.matchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.webkitMatchesSelector;
53
+
54
+ Rails.matches = function(element, selector) {
55
+ if (selector.exclude != null) {
56
+ return m.call(element, selector.selector) && !m.call(element, selector.exclude);
57
+ } else {
58
+ return m.call(element, selector);
59
+ }
60
+ };
61
+
62
+ expando = '_ujsData';
63
+
64
+ Rails.getData = function(element, key) {
65
+ var ref;
66
+ return (ref = element[expando]) != null ? ref[key] : void 0;
67
+ };
68
+
69
+ Rails.setData = function(element, key, value) {
70
+ if (element[expando] == null) {
71
+ element[expando] = {};
72
+ }
73
+ return element[expando][key] = value;
74
+ };
75
+
76
+ Rails.$ = function(selector) {
77
+ return Array.prototype.slice.call(document.querySelectorAll(selector));
78
+ };
79
+
80
+ }).call(this);
81
+ (function() {
82
+ var $, csrfParam, csrfToken;
83
+
84
+ $ = Rails.$;
85
+
86
+ csrfToken = Rails.csrfToken = function() {
87
+ var meta;
88
+ meta = document.querySelector('meta[name=csrf-token]');
89
+ return meta && meta.content;
90
+ };
91
+
92
+ csrfParam = Rails.csrfParam = function() {
93
+ var meta;
94
+ meta = document.querySelector('meta[name=csrf-param]');
95
+ return meta && meta.content;
96
+ };
97
+
98
+ Rails.CSRFProtection = function(xhr) {
99
+ var token;
100
+ token = csrfToken();
101
+ if (token != null) {
102
+ return xhr.setRequestHeader('X-CSRF-Token', token);
103
+ }
104
+ };
105
+
106
+ Rails.refreshCSRFTokens = function() {
107
+ var param, token;
108
+ token = csrfToken();
109
+ param = csrfParam();
110
+ if ((token != null) && (param != null)) {
111
+ return $('form input[name="' + param + '"]').forEach(function(input) {
112
+ return input.value = token;
113
+ });
114
+ }
115
+ };
116
+
117
+ }).call(this);
118
+ (function() {
119
+ var CustomEvent, fire, matches, preventDefault;
120
+
121
+ matches = Rails.matches;
122
+
123
+ CustomEvent = window.CustomEvent;
124
+
125
+ if (typeof CustomEvent !== 'function') {
126
+ CustomEvent = function(event, params) {
127
+ var evt;
128
+ evt = document.createEvent('CustomEvent');
129
+ evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
130
+ return evt;
131
+ };
132
+ CustomEvent.prototype = window.Event.prototype;
133
+ preventDefault = CustomEvent.prototype.preventDefault;
134
+ CustomEvent.prototype.preventDefault = function() {
135
+ var result;
136
+ result = preventDefault.call(this);
137
+ if (this.cancelable && !this.defaultPrevented) {
138
+ Object.defineProperty(this, 'defaultPrevented', {
139
+ get: function() {
140
+ return true;
141
+ }
142
+ });
143
+ }
144
+ return result;
145
+ };
146
+ }
147
+
148
+ fire = Rails.fire = function(obj, name, data) {
149
+ var event;
150
+ event = new CustomEvent(name, {
151
+ bubbles: true,
152
+ cancelable: true,
153
+ detail: data
154
+ });
155
+ obj.dispatchEvent(event);
156
+ return !event.defaultPrevented;
157
+ };
158
+
159
+ Rails.stopEverything = function(e) {
160
+ fire(e.target, 'ujs:everythingStopped');
161
+ e.preventDefault();
162
+ e.stopPropagation();
163
+ return e.stopImmediatePropagation();
164
+ };
165
+
166
+ Rails.delegate = function(element, selector, eventType, handler) {
167
+ return element.addEventListener(eventType, function(e) {
168
+ var target;
169
+ target = e.target;
170
+ while (!(!(target instanceof Element) || matches(target, selector))) {
171
+ target = target.parentNode;
172
+ }
173
+ if (target instanceof Element && handler.call(target, e) === false) {
174
+ e.preventDefault();
175
+ return e.stopPropagation();
176
+ }
177
+ });
178
+ };
179
+
180
+ }).call(this);
181
+ (function() {
182
+ var AcceptHeaders, CSRFProtection, createXHR, cspNonce, fire, prepareOptions, processResponse;
183
+
184
+ cspNonce = Rails.cspNonce, CSRFProtection = Rails.CSRFProtection, fire = Rails.fire;
185
+
186
+ AcceptHeaders = {
187
+ '*': '*/*',
188
+ text: 'text/plain',
189
+ html: 'text/html',
190
+ xml: 'application/xml, text/xml',
191
+ json: 'application/json, text/javascript',
192
+ script: 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript'
193
+ };
194
+
195
+ Rails.ajax = function(options) {
196
+ var xhr;
197
+ options = prepareOptions(options);
198
+ xhr = createXHR(options, function() {
199
+ var ref, response;
200
+ response = processResponse((ref = xhr.response) != null ? ref : xhr.responseText, xhr.getResponseHeader('Content-Type'));
201
+ if (Math.floor(xhr.status / 100) === 2) {
202
+ if (typeof options.success === "function") {
203
+ options.success(response, xhr.statusText, xhr);
204
+ }
205
+ } else {
206
+ if (typeof options.error === "function") {
207
+ options.error(response, xhr.statusText, xhr);
208
+ }
209
+ }
210
+ return typeof options.complete === "function" ? options.complete(xhr, xhr.statusText) : void 0;
211
+ });
212
+ if ((options.beforeSend != null) && !options.beforeSend(xhr, options)) {
213
+ return false;
214
+ }
215
+ if (xhr.readyState === XMLHttpRequest.OPENED) {
216
+ return xhr.send(options.data);
217
+ }
218
+ };
219
+
220
+ prepareOptions = function(options) {
221
+ options.url = options.url || location.href;
222
+ options.type = options.type.toUpperCase();
223
+ if (options.type === 'GET' && options.data) {
224
+ if (options.url.indexOf('?') < 0) {
225
+ options.url += '?' + options.data;
226
+ } else {
227
+ options.url += '&' + options.data;
228
+ }
229
+ }
230
+ if (AcceptHeaders[options.dataType] == null) {
231
+ options.dataType = '*';
232
+ }
233
+ options.accept = AcceptHeaders[options.dataType];
234
+ if (options.dataType !== '*') {
235
+ options.accept += ', */*; q=0.01';
236
+ }
237
+ return options;
238
+ };
239
+
240
+ createXHR = function(options, done) {
241
+ var xhr;
242
+ xhr = new XMLHttpRequest();
243
+ xhr.open(options.type, options.url, true);
244
+ xhr.setRequestHeader('Accept', options.accept);
245
+ if (typeof options.data === 'string') {
246
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
247
+ }
248
+ if (!options.crossDomain) {
249
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
250
+ CSRFProtection(xhr);
251
+ }
252
+ xhr.withCredentials = !!options.withCredentials;
253
+ xhr.onreadystatechange = function() {
254
+ if (xhr.readyState === XMLHttpRequest.DONE) {
255
+ return done(xhr);
256
+ }
257
+ };
258
+ return xhr;
259
+ };
260
+
261
+ processResponse = function(response, type) {
262
+ var parser, script;
263
+ if (typeof response === 'string' && typeof type === 'string') {
264
+ if (type.match(/\bjson\b/)) {
265
+ try {
266
+ response = JSON.parse(response);
267
+ } catch (error) {}
268
+ } else if (type.match(/\b(?:java|ecma)script\b/)) {
269
+ script = document.createElement('script');
270
+ script.setAttribute('nonce', cspNonce());
271
+ script.text = response;
272
+ document.head.appendChild(script).parentNode.removeChild(script);
273
+ } else if (type.match(/\b(xml|html|svg)\b/)) {
274
+ parser = new DOMParser();
275
+ type = type.replace(/;.+/, '');
276
+ try {
277
+ response = parser.parseFromString(response, type);
278
+ } catch (error) {}
279
+ }
280
+ }
281
+ return response;
282
+ };
283
+
284
+ Rails.href = function(element) {
285
+ return element.href;
286
+ };
287
+
288
+ Rails.isCrossDomain = function(url) {
289
+ var e, originAnchor, urlAnchor;
290
+ originAnchor = document.createElement('a');
291
+ originAnchor.href = location.href;
292
+ urlAnchor = document.createElement('a');
293
+ try {
294
+ urlAnchor.href = url;
295
+ return !(((!urlAnchor.protocol || urlAnchor.protocol === ':') && !urlAnchor.host) || (originAnchor.protocol + '//' + originAnchor.host === urlAnchor.protocol + '//' + urlAnchor.host));
296
+ } catch (error) {
297
+ e = error;
298
+ return true;
299
+ }
300
+ };
301
+
302
+ }).call(this);
303
+ (function() {
304
+ var matches, toArray;
305
+
306
+ matches = Rails.matches;
307
+
308
+ toArray = function(e) {
309
+ return Array.prototype.slice.call(e);
310
+ };
311
+
312
+ Rails.serializeElement = function(element, additionalParam) {
313
+ var inputs, params;
314
+ inputs = [element];
315
+ if (matches(element, 'form')) {
316
+ inputs = toArray(element.elements);
317
+ }
318
+ params = [];
319
+ inputs.forEach(function(input) {
320
+ if (!input.name || input.disabled) {
321
+ return;
322
+ }
323
+ if (matches(input, 'fieldset[disabled] *')) {
324
+ return;
325
+ }
326
+ if (matches(input, 'select')) {
327
+ return toArray(input.options).forEach(function(option) {
328
+ if (option.selected) {
329
+ return params.push({
330
+ name: input.name,
331
+ value: option.value
332
+ });
333
+ }
334
+ });
335
+ } else if (input.checked || ['radio', 'checkbox', 'submit'].indexOf(input.type) === -1) {
336
+ return params.push({
337
+ name: input.name,
338
+ value: input.value
339
+ });
340
+ }
341
+ });
342
+ if (additionalParam) {
343
+ params.push(additionalParam);
344
+ }
345
+ return params.map(function(param) {
346
+ if (param.name != null) {
347
+ return (encodeURIComponent(param.name)) + "=" + (encodeURIComponent(param.value));
348
+ } else {
349
+ return param;
350
+ }
351
+ }).join('&');
352
+ };
353
+
354
+ Rails.formElements = function(form, selector) {
355
+ if (matches(form, 'form')) {
356
+ return toArray(form.elements).filter(function(el) {
357
+ return matches(el, selector);
358
+ });
359
+ } else {
360
+ return toArray(form.querySelectorAll(selector));
361
+ }
362
+ };
363
+
364
+ }).call(this);
365
+ (function() {
366
+ var allowAction, fire, stopEverything;
367
+
368
+ fire = Rails.fire, stopEverything = Rails.stopEverything;
369
+
370
+ Rails.handleConfirm = function(e) {
371
+ if (!allowAction(this)) {
372
+ return stopEverything(e);
373
+ }
374
+ };
375
+
376
+ Rails.confirm = function(message, element) {
377
+ return confirm(message);
378
+ };
379
+
380
+ allowAction = function(element) {
381
+ var answer, callback, message;
382
+ message = element.getAttribute('data-confirm');
383
+ if (!message) {
384
+ return true;
385
+ }
386
+ answer = false;
387
+ if (fire(element, 'confirm')) {
388
+ try {
389
+ answer = Rails.confirm(message, element);
390
+ } catch (error) {}
391
+ callback = fire(element, 'confirm:complete', [answer]);
392
+ }
393
+ return answer && callback;
394
+ };
395
+
396
+ }).call(this);
397
+ (function() {
398
+ var disableFormElement, disableFormElements, disableLinkElement, enableFormElement, enableFormElements, enableLinkElement, formElements, getData, isXhrRedirect, matches, setData, stopEverything;
399
+
400
+ matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, stopEverything = Rails.stopEverything, formElements = Rails.formElements;
401
+
402
+ Rails.handleDisabledElement = function(e) {
403
+ var element;
404
+ element = this;
405
+ if (element.disabled) {
406
+ return stopEverything(e);
407
+ }
408
+ };
409
+
410
+ Rails.enableElement = function(e) {
411
+ var element;
412
+ if (e instanceof Event) {
413
+ if (isXhrRedirect(e)) {
414
+ return;
415
+ }
416
+ element = e.target;
417
+ } else {
418
+ element = e;
419
+ }
420
+ if (matches(element, Rails.linkDisableSelector)) {
421
+ return enableLinkElement(element);
422
+ } else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formEnableSelector)) {
423
+ return enableFormElement(element);
424
+ } else if (matches(element, Rails.formSubmitSelector)) {
425
+ return enableFormElements(element);
426
+ }
427
+ };
428
+
429
+ Rails.disableElement = function(e) {
430
+ var element;
431
+ element = e instanceof Event ? e.target : e;
432
+ if (matches(element, Rails.linkDisableSelector)) {
433
+ return disableLinkElement(element);
434
+ } else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formDisableSelector)) {
435
+ return disableFormElement(element);
436
+ } else if (matches(element, Rails.formSubmitSelector)) {
437
+ return disableFormElements(element);
438
+ }
439
+ };
440
+
441
+ disableLinkElement = function(element) {
442
+ var replacement;
443
+ if (getData(element, 'ujs:disabled')) {
444
+ return;
445
+ }
446
+ replacement = element.getAttribute('data-disable-with');
447
+ if (replacement != null) {
448
+ setData(element, 'ujs:enable-with', element.innerHTML);
449
+ element.innerHTML = replacement;
450
+ }
451
+ element.addEventListener('click', stopEverything);
452
+ return setData(element, 'ujs:disabled', true);
453
+ };
454
+
455
+ enableLinkElement = function(element) {
456
+ var originalText;
457
+ originalText = getData(element, 'ujs:enable-with');
458
+ if (originalText != null) {
459
+ element.innerHTML = originalText;
460
+ setData(element, 'ujs:enable-with', null);
461
+ }
462
+ element.removeEventListener('click', stopEverything);
463
+ return setData(element, 'ujs:disabled', null);
464
+ };
465
+
466
+ disableFormElements = function(form) {
467
+ return formElements(form, Rails.formDisableSelector).forEach(disableFormElement);
468
+ };
469
+
470
+ disableFormElement = function(element) {
471
+ var replacement;
472
+ if (getData(element, 'ujs:disabled')) {
473
+ return;
474
+ }
475
+ replacement = element.getAttribute('data-disable-with');
476
+ if (replacement != null) {
477
+ if (matches(element, 'button')) {
478
+ setData(element, 'ujs:enable-with', element.innerHTML);
479
+ element.innerHTML = replacement;
480
+ } else {
481
+ setData(element, 'ujs:enable-with', element.value);
482
+ element.value = replacement;
483
+ }
484
+ }
485
+ element.disabled = true;
486
+ return setData(element, 'ujs:disabled', true);
487
+ };
488
+
489
+ enableFormElements = function(form) {
490
+ return formElements(form, Rails.formEnableSelector).forEach(enableFormElement);
491
+ };
492
+
493
+ enableFormElement = function(element) {
494
+ var originalText;
495
+ originalText = getData(element, 'ujs:enable-with');
496
+ if (originalText != null) {
497
+ if (matches(element, 'button')) {
498
+ element.innerHTML = originalText;
499
+ } else {
500
+ element.value = originalText;
501
+ }
502
+ setData(element, 'ujs:enable-with', null);
503
+ }
504
+ element.disabled = false;
505
+ return setData(element, 'ujs:disabled', null);
506
+ };
507
+
508
+ isXhrRedirect = function(event) {
509
+ var ref, xhr;
510
+ xhr = (ref = event.detail) != null ? ref[0] : void 0;
511
+ return (xhr != null ? xhr.getResponseHeader("X-Xhr-Redirect") : void 0) != null;
512
+ };
513
+
514
+ }).call(this);
515
+ (function() {
516
+ var stopEverything;
517
+
518
+ stopEverything = Rails.stopEverything;
519
+
520
+ Rails.handleMethod = function(e) {
521
+ var csrfParam, csrfToken, form, formContent, href, link, method;
522
+ link = this;
523
+ method = link.getAttribute('data-method');
524
+ if (!method) {
525
+ return;
526
+ }
527
+ href = Rails.href(link);
528
+ csrfToken = Rails.csrfToken();
529
+ csrfParam = Rails.csrfParam();
530
+ form = document.createElement('form');
531
+ formContent = "<input name='_method' value='" + method + "' type='hidden' />";
532
+ if ((csrfParam != null) && (csrfToken != null) && !Rails.isCrossDomain(href)) {
533
+ formContent += "<input name='" + csrfParam + "' value='" + csrfToken + "' type='hidden' />";
534
+ }
535
+ formContent += '<input type="submit" />';
536
+ form.method = 'post';
537
+ form.action = href;
538
+ form.target = link.target;
539
+ form.innerHTML = formContent;
540
+ form.style.display = 'none';
541
+ document.body.appendChild(form);
542
+ form.querySelector('[type="submit"]').click();
543
+ return stopEverything(e);
544
+ };
545
+
546
+ }).call(this);
547
+ (function() {
548
+ var ajax, fire, getData, isCrossDomain, isRemote, matches, serializeElement, setData, stopEverything,
549
+ slice = [].slice;
550
+
551
+ matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, fire = Rails.fire, stopEverything = Rails.stopEverything, ajax = Rails.ajax, isCrossDomain = Rails.isCrossDomain, serializeElement = Rails.serializeElement;
552
+
553
+ isRemote = function(element) {
554
+ var value;
555
+ value = element.getAttribute('data-remote');
556
+ return (value != null) && value !== 'false';
557
+ };
558
+
559
+ Rails.handleRemote = function(e) {
560
+ var button, data, dataType, element, method, url, withCredentials;
561
+ element = this;
562
+ if (!isRemote(element)) {
563
+ return true;
564
+ }
565
+ if (!fire(element, 'ajax:before')) {
566
+ fire(element, 'ajax:stopped');
567
+ return false;
568
+ }
569
+ withCredentials = element.getAttribute('data-with-credentials');
570
+ dataType = element.getAttribute('data-type') || 'script';
571
+ if (matches(element, Rails.formSubmitSelector)) {
572
+ button = getData(element, 'ujs:submit-button');
573
+ method = getData(element, 'ujs:submit-button-formmethod') || element.method;
574
+ url = getData(element, 'ujs:submit-button-formaction') || element.getAttribute('action') || location.href;
575
+ if (method.toUpperCase() === 'GET') {
576
+ url = url.replace(/\?.*$/, '');
577
+ }
578
+ if (element.enctype === 'multipart/form-data') {
579
+ data = new FormData(element);
580
+ if (button != null) {
581
+ data.append(button.name, button.value);
582
+ }
583
+ } else {
584
+ data = serializeElement(element, button);
585
+ }
586
+ setData(element, 'ujs:submit-button', null);
587
+ setData(element, 'ujs:submit-button-formmethod', null);
588
+ setData(element, 'ujs:submit-button-formaction', null);
589
+ } else if (matches(element, Rails.buttonClickSelector) || matches(element, Rails.inputChangeSelector)) {
590
+ method = element.getAttribute('data-method');
591
+ url = element.getAttribute('data-url');
592
+ data = serializeElement(element, element.getAttribute('data-params'));
593
+ } else {
594
+ method = element.getAttribute('data-method');
595
+ url = Rails.href(element);
596
+ data = element.getAttribute('data-params');
597
+ }
598
+ ajax({
599
+ type: method || 'GET',
600
+ url: url,
601
+ data: data,
602
+ dataType: dataType,
603
+ beforeSend: function(xhr, options) {
604
+ if (fire(element, 'ajax:beforeSend', [xhr, options])) {
605
+ return fire(element, 'ajax:send', [xhr]);
606
+ } else {
607
+ fire(element, 'ajax:stopped');
608
+ return false;
609
+ }
610
+ },
611
+ success: function() {
612
+ var args;
613
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
614
+ return fire(element, 'ajax:success', args);
615
+ },
616
+ error: function() {
617
+ var args;
618
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
619
+ return fire(element, 'ajax:error', args);
620
+ },
621
+ complete: function() {
622
+ var args;
623
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
624
+ return fire(element, 'ajax:complete', args);
625
+ },
626
+ crossDomain: isCrossDomain(url),
627
+ withCredentials: (withCredentials != null) && withCredentials !== 'false'
628
+ });
629
+ return stopEverything(e);
630
+ };
631
+
632
+ Rails.formSubmitButtonClick = function(e) {
633
+ var button, form;
634
+ button = this;
635
+ form = button.form;
636
+ if (!form) {
637
+ return;
638
+ }
639
+ if (button.name) {
640
+ setData(form, 'ujs:submit-button', {
641
+ name: button.name,
642
+ value: button.value
643
+ });
644
+ }
645
+ setData(form, 'ujs:formnovalidate-button', button.formNoValidate);
646
+ setData(form, 'ujs:submit-button-formaction', button.getAttribute('formaction'));
647
+ return setData(form, 'ujs:submit-button-formmethod', button.getAttribute('formmethod'));
648
+ };
649
+
650
+ Rails.preventInsignificantClick = function(e) {
651
+ var data, insignificantMetaClick, link, metaClick, method, nonPrimaryMouseClick;
652
+ link = this;
653
+ method = (link.getAttribute('data-method') || 'GET').toUpperCase();
654
+ data = link.getAttribute('data-params');
655
+ metaClick = e.metaKey || e.ctrlKey;
656
+ insignificantMetaClick = metaClick && method === 'GET' && !data;
657
+ nonPrimaryMouseClick = (e.button != null) && e.button !== 0;
658
+ if (nonPrimaryMouseClick || insignificantMetaClick) {
659
+ return e.stopImmediatePropagation();
660
+ }
661
+ };
662
+
663
+ }).call(this);
664
+ (function() {
665
+ var $, CSRFProtection, delegate, disableElement, enableElement, fire, formSubmitButtonClick, getData, handleConfirm, handleDisabledElement, handleMethod, handleRemote, loadCSPNonce, preventInsignificantClick, refreshCSRFTokens;
666
+
667
+ fire = Rails.fire, delegate = Rails.delegate, getData = Rails.getData, $ = Rails.$, refreshCSRFTokens = Rails.refreshCSRFTokens, CSRFProtection = Rails.CSRFProtection, loadCSPNonce = Rails.loadCSPNonce, enableElement = Rails.enableElement, disableElement = Rails.disableElement, handleDisabledElement = Rails.handleDisabledElement, handleConfirm = Rails.handleConfirm, preventInsignificantClick = Rails.preventInsignificantClick, handleRemote = Rails.handleRemote, formSubmitButtonClick = Rails.formSubmitButtonClick, handleMethod = Rails.handleMethod;
668
+
669
+ if ((typeof jQuery !== "undefined" && jQuery !== null) && (jQuery.ajax != null)) {
670
+ if (jQuery.rails) {
671
+ throw new Error('If you load both jquery_ujs and rails-ujs, use rails-ujs only.');
672
+ }
673
+ jQuery.rails = Rails;
674
+ jQuery.ajaxPrefilter(function(options, originalOptions, xhr) {
675
+ if (!options.crossDomain) {
676
+ return CSRFProtection(xhr);
677
+ }
678
+ });
679
+ }
680
+
681
+ Rails.start = function() {
682
+ if (window._rails_loaded) {
683
+ throw new Error('rails-ujs has already been loaded!');
684
+ }
685
+ window.addEventListener('pageshow', function() {
686
+ $(Rails.formEnableSelector).forEach(function(el) {
687
+ if (getData(el, 'ujs:disabled')) {
688
+ return enableElement(el);
689
+ }
690
+ });
691
+ return $(Rails.linkDisableSelector).forEach(function(el) {
692
+ if (getData(el, 'ujs:disabled')) {
693
+ return enableElement(el);
694
+ }
695
+ });
696
+ });
697
+ delegate(document, Rails.linkDisableSelector, 'ajax:complete', enableElement);
698
+ delegate(document, Rails.linkDisableSelector, 'ajax:stopped', enableElement);
699
+ delegate(document, Rails.buttonDisableSelector, 'ajax:complete', enableElement);
700
+ delegate(document, Rails.buttonDisableSelector, 'ajax:stopped', enableElement);
701
+ delegate(document, Rails.linkClickSelector, 'click', preventInsignificantClick);
702
+ delegate(document, Rails.linkClickSelector, 'click', handleDisabledElement);
703
+ delegate(document, Rails.linkClickSelector, 'click', handleConfirm);
704
+ delegate(document, Rails.linkClickSelector, 'click', disableElement);
705
+ delegate(document, Rails.linkClickSelector, 'click', handleRemote);
706
+ delegate(document, Rails.linkClickSelector, 'click', handleMethod);
707
+ delegate(document, Rails.buttonClickSelector, 'click', preventInsignificantClick);
708
+ delegate(document, Rails.buttonClickSelector, 'click', handleDisabledElement);
709
+ delegate(document, Rails.buttonClickSelector, 'click', handleConfirm);
710
+ delegate(document, Rails.buttonClickSelector, 'click', disableElement);
711
+ delegate(document, Rails.buttonClickSelector, 'click', handleRemote);
712
+ delegate(document, Rails.inputChangeSelector, 'change', handleDisabledElement);
713
+ delegate(document, Rails.inputChangeSelector, 'change', handleConfirm);
714
+ delegate(document, Rails.inputChangeSelector, 'change', handleRemote);
715
+ delegate(document, Rails.formSubmitSelector, 'submit', handleDisabledElement);
716
+ delegate(document, Rails.formSubmitSelector, 'submit', handleConfirm);
717
+ delegate(document, Rails.formSubmitSelector, 'submit', handleRemote);
718
+ delegate(document, Rails.formSubmitSelector, 'submit', function(e) {
719
+ return setTimeout((function() {
720
+ return disableElement(e);
721
+ }), 13);
722
+ });
723
+ delegate(document, Rails.formSubmitSelector, 'ajax:send', disableElement);
724
+ delegate(document, Rails.formSubmitSelector, 'ajax:complete', enableElement);
725
+ delegate(document, Rails.formInputClickSelector, 'click', preventInsignificantClick);
726
+ delegate(document, Rails.formInputClickSelector, 'click', handleDisabledElement);
727
+ delegate(document, Rails.formInputClickSelector, 'click', handleConfirm);
728
+ delegate(document, Rails.formInputClickSelector, 'click', formSubmitButtonClick);
729
+ document.addEventListener('DOMContentLoaded', refreshCSRFTokens);
730
+ document.addEventListener('DOMContentLoaded', loadCSPNonce);
731
+ return window._rails_loaded = true;
732
+ };
733
+
734
+ if (window.Rails === Rails && fire(document, 'rails:attachBindings')) {
735
+ Rails.start();
736
+ }
737
+
738
+ }).call(this);
739
+ }).call(this);
740
+
741
+ if (typeof module === "object" && module.exports) {
742
+ module.exports = Rails;
743
+ } else if (typeof define === "function" && define.amd) {
744
+ define(Rails);
745
+ }
746
+ }).call(this);