actionview 4.2.11.3 → 5.2.7.1

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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +115 -245
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +5 -6
  5. data/lib/action_view/base.rb +38 -28
  6. data/lib/action_view/buffers.rb +3 -1
  7. data/lib/action_view/context.rb +3 -3
  8. data/lib/action_view/dependency_tracker.rb +54 -20
  9. data/lib/action_view/digestor.rb +94 -83
  10. data/lib/action_view/flows.rb +11 -11
  11. data/lib/action_view/gem_version.rb +5 -3
  12. data/lib/action_view/helpers/active_model_helper.rb +17 -11
  13. data/lib/action_view/helpers/asset_tag_helper.rb +244 -62
  14. data/lib/action_view/helpers/asset_url_helper.rb +170 -67
  15. data/lib/action_view/helpers/atom_feed_helper.rb +19 -17
  16. data/lib/action_view/helpers/cache_helper.rb +105 -42
  17. data/lib/action_view/helpers/capture_helper.rb +16 -13
  18. data/lib/action_view/helpers/controller_helper.rb +15 -4
  19. data/lib/action_view/helpers/csp_helper.rb +24 -0
  20. data/lib/action_view/helpers/csrf_helper.rb +7 -5
  21. data/lib/action_view/helpers/date_helper.rb +170 -112
  22. data/lib/action_view/helpers/debug_helper.rb +7 -6
  23. data/lib/action_view/helpers/form_helper.rb +521 -127
  24. data/lib/action_view/helpers/form_options_helper.rb +109 -63
  25. data/lib/action_view/helpers/form_tag_helper.rb +110 -67
  26. data/lib/action_view/helpers/javascript_helper.rb +27 -12
  27. data/lib/action_view/helpers/number_helper.rb +77 -58
  28. data/lib/action_view/helpers/output_safety_helper.rb +36 -4
  29. data/lib/action_view/helpers/record_tag_helper.rb +14 -99
  30. data/lib/action_view/helpers/rendering_helper.rb +6 -5
  31. data/lib/action_view/helpers/sanitize_helper.rb +20 -15
  32. data/lib/action_view/helpers/tag_helper.rb +229 -73
  33. data/lib/action_view/helpers/tags/base.rb +134 -97
  34. data/lib/action_view/helpers/tags/check_box.rb +20 -18
  35. data/lib/action_view/helpers/tags/checkable.rb +4 -2
  36. data/lib/action_view/helpers/tags/collection_check_boxes.rb +12 -33
  37. data/lib/action_view/helpers/tags/collection_helpers.rb +70 -36
  38. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +6 -11
  39. data/lib/action_view/helpers/tags/collection_select.rb +4 -2
  40. data/lib/action_view/helpers/tags/color_field.rb +3 -1
  41. data/lib/action_view/helpers/tags/date_field.rb +2 -0
  42. data/lib/action_view/helpers/tags/date_select.rb +38 -36
  43. data/lib/action_view/helpers/tags/datetime_field.rb +4 -2
  44. data/lib/action_view/helpers/tags/datetime_local_field.rb +2 -0
  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 -1
  51. data/lib/action_view/helpers/tags/month_field.rb +2 -0
  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 -5
  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 -9
  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 -7
  62. data/lib/action_view/helpers/tags/time_field.rb +2 -0
  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 +17 -13
  66. data/lib/action_view/helpers/tags/url_field.rb +2 -0
  67. data/lib/action_view/helpers/tags/week_field.rb +2 -0
  68. data/lib/action_view/helpers/tags.rb +3 -1
  69. data/lib/action_view/helpers/text_helper.rb +55 -36
  70. data/lib/action_view/helpers/translation_helper.rb +74 -32
  71. data/lib/action_view/helpers/url_helper.rb +159 -104
  72. data/lib/action_view/helpers.rb +5 -1
  73. data/lib/action_view/layouts.rb +65 -58
  74. data/lib/action_view/log_subscriber.rb +60 -8
  75. data/lib/action_view/lookup_context.rb +80 -65
  76. data/lib/action_view/model_naming.rb +3 -1
  77. data/lib/action_view/path_set.rb +30 -19
  78. data/lib/action_view/railtie.rb +39 -6
  79. data/lib/action_view/record_identifier.rb +53 -25
  80. data/lib/action_view/renderer/abstract_renderer.rb +21 -15
  81. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +57 -0
  82. data/lib/action_view/renderer/partial_renderer.rb +218 -214
  83. data/lib/action_view/renderer/renderer.rb +8 -6
  84. data/lib/action_view/renderer/streaming_template_renderer.rb +50 -48
  85. data/lib/action_view/renderer/template_renderer.rb +67 -66
  86. data/lib/action_view/rendering.rb +19 -14
  87. data/lib/action_view/routing_url_for.rb +27 -17
  88. data/lib/action_view/tasks/cache_digests.rake +25 -0
  89. data/lib/action_view/template/error.rb +16 -16
  90. data/lib/action_view/template/handlers/builder.rb +10 -11
  91. data/lib/action_view/template/handlers/erb/erubi.rb +83 -0
  92. data/lib/action_view/template/handlers/erb.rb +9 -80
  93. data/lib/action_view/template/handlers/html.rb +11 -0
  94. data/lib/action_view/template/handlers/raw.rb +3 -3
  95. data/lib/action_view/template/handlers.rb +11 -7
  96. data/lib/action_view/template/html.rb +5 -5
  97. data/lib/action_view/template/resolver.rb +140 -115
  98. data/lib/action_view/template/text.rb +8 -9
  99. data/lib/action_view/template/types.rb +18 -18
  100. data/lib/action_view/template.rb +54 -33
  101. data/lib/action_view/test_case.rb +50 -29
  102. data/lib/action_view/testing/resolvers.rb +31 -31
  103. data/lib/action_view/version.rb +3 -1
  104. data/lib/action_view/view_paths.rb +28 -34
  105. data/lib/action_view.rb +8 -7
  106. data/lib/assets/compiled/rails-ujs.js +720 -0
  107. metadata +28 -27
  108. data/lib/action_view/tasks/dependencies.rake +0 -23
@@ -0,0 +1,720 @@
1
+ /*
2
+ Unobtrusive JavaScript
3
+ https://github.com/rails/rails/blob/master/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, 'select')) {
324
+ return toArray(input.options).forEach(function(option) {
325
+ if (option.selected) {
326
+ return params.push({
327
+ name: input.name,
328
+ value: option.value
329
+ });
330
+ }
331
+ });
332
+ } else if (input.checked || ['radio', 'checkbox', 'submit'].indexOf(input.type) === -1) {
333
+ return params.push({
334
+ name: input.name,
335
+ value: input.value
336
+ });
337
+ }
338
+ });
339
+ if (additionalParam) {
340
+ params.push(additionalParam);
341
+ }
342
+ return params.map(function(param) {
343
+ if (param.name != null) {
344
+ return (encodeURIComponent(param.name)) + "=" + (encodeURIComponent(param.value));
345
+ } else {
346
+ return param;
347
+ }
348
+ }).join('&');
349
+ };
350
+
351
+ Rails.formElements = function(form, selector) {
352
+ if (matches(form, 'form')) {
353
+ return toArray(form.elements).filter(function(el) {
354
+ return matches(el, selector);
355
+ });
356
+ } else {
357
+ return toArray(form.querySelectorAll(selector));
358
+ }
359
+ };
360
+
361
+ }).call(this);
362
+ (function() {
363
+ var allowAction, fire, stopEverything;
364
+
365
+ fire = Rails.fire, stopEverything = Rails.stopEverything;
366
+
367
+ Rails.handleConfirm = function(e) {
368
+ if (!allowAction(this)) {
369
+ return stopEverything(e);
370
+ }
371
+ };
372
+
373
+ allowAction = function(element) {
374
+ var answer, callback, message;
375
+ message = element.getAttribute('data-confirm');
376
+ if (!message) {
377
+ return true;
378
+ }
379
+ answer = false;
380
+ if (fire(element, 'confirm')) {
381
+ try {
382
+ answer = confirm(message);
383
+ } catch (error) {}
384
+ callback = fire(element, 'confirm:complete', [answer]);
385
+ }
386
+ return answer && callback;
387
+ };
388
+
389
+ }).call(this);
390
+ (function() {
391
+ var disableFormElement, disableFormElements, disableLinkElement, enableFormElement, enableFormElements, enableLinkElement, formElements, getData, matches, setData, stopEverything;
392
+
393
+ matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, stopEverything = Rails.stopEverything, formElements = Rails.formElements;
394
+
395
+ Rails.handleDisabledElement = function(e) {
396
+ var element;
397
+ element = this;
398
+ if (element.disabled) {
399
+ return stopEverything(e);
400
+ }
401
+ };
402
+
403
+ Rails.enableElement = function(e) {
404
+ var element;
405
+ element = e instanceof Event ? e.target : e;
406
+ if (matches(element, Rails.linkDisableSelector)) {
407
+ return enableLinkElement(element);
408
+ } else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formEnableSelector)) {
409
+ return enableFormElement(element);
410
+ } else if (matches(element, Rails.formSubmitSelector)) {
411
+ return enableFormElements(element);
412
+ }
413
+ };
414
+
415
+ Rails.disableElement = function(e) {
416
+ var element;
417
+ element = e instanceof Event ? e.target : e;
418
+ if (matches(element, Rails.linkDisableSelector)) {
419
+ return disableLinkElement(element);
420
+ } else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formDisableSelector)) {
421
+ return disableFormElement(element);
422
+ } else if (matches(element, Rails.formSubmitSelector)) {
423
+ return disableFormElements(element);
424
+ }
425
+ };
426
+
427
+ disableLinkElement = function(element) {
428
+ var replacement;
429
+ replacement = element.getAttribute('data-disable-with');
430
+ if (replacement != null) {
431
+ setData(element, 'ujs:enable-with', element.innerHTML);
432
+ element.innerHTML = replacement;
433
+ }
434
+ element.addEventListener('click', stopEverything);
435
+ return setData(element, 'ujs:disabled', true);
436
+ };
437
+
438
+ enableLinkElement = function(element) {
439
+ var originalText;
440
+ originalText = getData(element, 'ujs:enable-with');
441
+ if (originalText != null) {
442
+ element.innerHTML = originalText;
443
+ setData(element, 'ujs:enable-with', null);
444
+ }
445
+ element.removeEventListener('click', stopEverything);
446
+ return setData(element, 'ujs:disabled', null);
447
+ };
448
+
449
+ disableFormElements = function(form) {
450
+ return formElements(form, Rails.formDisableSelector).forEach(disableFormElement);
451
+ };
452
+
453
+ disableFormElement = function(element) {
454
+ var replacement;
455
+ replacement = element.getAttribute('data-disable-with');
456
+ if (replacement != null) {
457
+ if (matches(element, 'button')) {
458
+ setData(element, 'ujs:enable-with', element.innerHTML);
459
+ element.innerHTML = replacement;
460
+ } else {
461
+ setData(element, 'ujs:enable-with', element.value);
462
+ element.value = replacement;
463
+ }
464
+ }
465
+ element.disabled = true;
466
+ return setData(element, 'ujs:disabled', true);
467
+ };
468
+
469
+ enableFormElements = function(form) {
470
+ return formElements(form, Rails.formEnableSelector).forEach(enableFormElement);
471
+ };
472
+
473
+ enableFormElement = function(element) {
474
+ var originalText;
475
+ originalText = getData(element, 'ujs:enable-with');
476
+ if (originalText != null) {
477
+ if (matches(element, 'button')) {
478
+ element.innerHTML = originalText;
479
+ } else {
480
+ element.value = originalText;
481
+ }
482
+ setData(element, 'ujs:enable-with', null);
483
+ }
484
+ element.disabled = false;
485
+ return setData(element, 'ujs:disabled', null);
486
+ };
487
+
488
+ }).call(this);
489
+ (function() {
490
+ var stopEverything;
491
+
492
+ stopEverything = Rails.stopEverything;
493
+
494
+ Rails.handleMethod = function(e) {
495
+ var csrfParam, csrfToken, form, formContent, href, link, method;
496
+ link = this;
497
+ method = link.getAttribute('data-method');
498
+ if (!method) {
499
+ return;
500
+ }
501
+ href = Rails.href(link);
502
+ csrfToken = Rails.csrfToken();
503
+ csrfParam = Rails.csrfParam();
504
+ form = document.createElement('form');
505
+ formContent = "<input name='_method' value='" + method + "' type='hidden' />";
506
+ if ((csrfParam != null) && (csrfToken != null) && !Rails.isCrossDomain(href)) {
507
+ formContent += "<input name='" + csrfParam + "' value='" + csrfToken + "' type='hidden' />";
508
+ }
509
+ formContent += '<input type="submit" />';
510
+ form.method = 'post';
511
+ form.action = href;
512
+ form.target = link.target;
513
+ form.innerHTML = formContent;
514
+ form.style.display = 'none';
515
+ document.body.appendChild(form);
516
+ form.querySelector('[type="submit"]').click();
517
+ return stopEverything(e);
518
+ };
519
+
520
+ }).call(this);
521
+ (function() {
522
+ var ajax, fire, getData, isCrossDomain, isRemote, matches, serializeElement, setData, stopEverything,
523
+ slice = [].slice;
524
+
525
+ matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, fire = Rails.fire, stopEverything = Rails.stopEverything, ajax = Rails.ajax, isCrossDomain = Rails.isCrossDomain, serializeElement = Rails.serializeElement;
526
+
527
+ isRemote = function(element) {
528
+ var value;
529
+ value = element.getAttribute('data-remote');
530
+ return (value != null) && value !== 'false';
531
+ };
532
+
533
+ Rails.handleRemote = function(e) {
534
+ var button, data, dataType, element, method, url, withCredentials;
535
+ element = this;
536
+ if (!isRemote(element)) {
537
+ return true;
538
+ }
539
+ if (!fire(element, 'ajax:before')) {
540
+ fire(element, 'ajax:stopped');
541
+ return false;
542
+ }
543
+ withCredentials = element.getAttribute('data-with-credentials');
544
+ dataType = element.getAttribute('data-type') || 'script';
545
+ if (matches(element, Rails.formSubmitSelector)) {
546
+ button = getData(element, 'ujs:submit-button');
547
+ method = getData(element, 'ujs:submit-button-formmethod') || element.method;
548
+ url = getData(element, 'ujs:submit-button-formaction') || element.getAttribute('action') || location.href;
549
+ if (method.toUpperCase() === 'GET') {
550
+ url = url.replace(/\?.*$/, '');
551
+ }
552
+ if (element.enctype === 'multipart/form-data') {
553
+ data = new FormData(element);
554
+ if (button != null) {
555
+ data.append(button.name, button.value);
556
+ }
557
+ } else {
558
+ data = serializeElement(element, button);
559
+ }
560
+ setData(element, 'ujs:submit-button', null);
561
+ setData(element, 'ujs:submit-button-formmethod', null);
562
+ setData(element, 'ujs:submit-button-formaction', null);
563
+ } else if (matches(element, Rails.buttonClickSelector) || matches(element, Rails.inputChangeSelector)) {
564
+ method = element.getAttribute('data-method');
565
+ url = element.getAttribute('data-url');
566
+ data = serializeElement(element, element.getAttribute('data-params'));
567
+ } else {
568
+ method = element.getAttribute('data-method');
569
+ url = Rails.href(element);
570
+ data = element.getAttribute('data-params');
571
+ }
572
+ ajax({
573
+ type: method || 'GET',
574
+ url: url,
575
+ data: data,
576
+ dataType: dataType,
577
+ beforeSend: function(xhr, options) {
578
+ if (fire(element, 'ajax:beforeSend', [xhr, options])) {
579
+ return fire(element, 'ajax:send', [xhr]);
580
+ } else {
581
+ fire(element, 'ajax:stopped');
582
+ return false;
583
+ }
584
+ },
585
+ success: function() {
586
+ var args;
587
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
588
+ return fire(element, 'ajax:success', args);
589
+ },
590
+ error: function() {
591
+ var args;
592
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
593
+ return fire(element, 'ajax:error', args);
594
+ },
595
+ complete: function() {
596
+ var args;
597
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
598
+ return fire(element, 'ajax:complete', args);
599
+ },
600
+ crossDomain: isCrossDomain(url),
601
+ withCredentials: (withCredentials != null) && withCredentials !== 'false'
602
+ });
603
+ return stopEverything(e);
604
+ };
605
+
606
+ Rails.formSubmitButtonClick = function(e) {
607
+ var button, form;
608
+ button = this;
609
+ form = button.form;
610
+ if (!form) {
611
+ return;
612
+ }
613
+ if (button.name) {
614
+ setData(form, 'ujs:submit-button', {
615
+ name: button.name,
616
+ value: button.value
617
+ });
618
+ }
619
+ setData(form, 'ujs:formnovalidate-button', button.formNoValidate);
620
+ setData(form, 'ujs:submit-button-formaction', button.getAttribute('formaction'));
621
+ return setData(form, 'ujs:submit-button-formmethod', button.getAttribute('formmethod'));
622
+ };
623
+
624
+ Rails.preventInsignificantClick = function(e) {
625
+ var data, insignificantMetaClick, link, metaClick, method, nonPrimaryMouseClick;
626
+ link = this;
627
+ method = (link.getAttribute('data-method') || 'GET').toUpperCase();
628
+ data = link.getAttribute('data-params');
629
+ metaClick = e.metaKey || e.ctrlKey;
630
+ insignificantMetaClick = metaClick && method === 'GET' && !data;
631
+ nonPrimaryMouseClick = (e.button != null) && e.button !== 0;
632
+ if (nonPrimaryMouseClick || insignificantMetaClick) {
633
+ return e.stopImmediatePropagation();
634
+ }
635
+ };
636
+
637
+ }).call(this);
638
+ (function() {
639
+ var $, CSRFProtection, delegate, disableElement, enableElement, fire, formSubmitButtonClick, getData, handleConfirm, handleDisabledElement, handleMethod, handleRemote, loadCSPNonce, preventInsignificantClick, refreshCSRFTokens;
640
+
641
+ 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;
642
+
643
+ if ((typeof jQuery !== "undefined" && jQuery !== null) && (jQuery.ajax != null)) {
644
+ if (jQuery.rails) {
645
+ throw new Error('If you load both jquery_ujs and rails-ujs, use rails-ujs only.');
646
+ }
647
+ jQuery.rails = Rails;
648
+ jQuery.ajaxPrefilter(function(options, originalOptions, xhr) {
649
+ if (!options.crossDomain) {
650
+ return CSRFProtection(xhr);
651
+ }
652
+ });
653
+ }
654
+
655
+ Rails.start = function() {
656
+ if (window._rails_loaded) {
657
+ throw new Error('rails-ujs has already been loaded!');
658
+ }
659
+ window.addEventListener('pageshow', function() {
660
+ $(Rails.formEnableSelector).forEach(function(el) {
661
+ if (getData(el, 'ujs:disabled')) {
662
+ return enableElement(el);
663
+ }
664
+ });
665
+ return $(Rails.linkDisableSelector).forEach(function(el) {
666
+ if (getData(el, 'ujs:disabled')) {
667
+ return enableElement(el);
668
+ }
669
+ });
670
+ });
671
+ delegate(document, Rails.linkDisableSelector, 'ajax:complete', enableElement);
672
+ delegate(document, Rails.linkDisableSelector, 'ajax:stopped', enableElement);
673
+ delegate(document, Rails.buttonDisableSelector, 'ajax:complete', enableElement);
674
+ delegate(document, Rails.buttonDisableSelector, 'ajax:stopped', enableElement);
675
+ delegate(document, Rails.linkClickSelector, 'click', preventInsignificantClick);
676
+ delegate(document, Rails.linkClickSelector, 'click', handleDisabledElement);
677
+ delegate(document, Rails.linkClickSelector, 'click', handleConfirm);
678
+ delegate(document, Rails.linkClickSelector, 'click', disableElement);
679
+ delegate(document, Rails.linkClickSelector, 'click', handleRemote);
680
+ delegate(document, Rails.linkClickSelector, 'click', handleMethod);
681
+ delegate(document, Rails.buttonClickSelector, 'click', preventInsignificantClick);
682
+ delegate(document, Rails.buttonClickSelector, 'click', handleDisabledElement);
683
+ delegate(document, Rails.buttonClickSelector, 'click', handleConfirm);
684
+ delegate(document, Rails.buttonClickSelector, 'click', disableElement);
685
+ delegate(document, Rails.buttonClickSelector, 'click', handleRemote);
686
+ delegate(document, Rails.inputChangeSelector, 'change', handleDisabledElement);
687
+ delegate(document, Rails.inputChangeSelector, 'change', handleConfirm);
688
+ delegate(document, Rails.inputChangeSelector, 'change', handleRemote);
689
+ delegate(document, Rails.formSubmitSelector, 'submit', handleDisabledElement);
690
+ delegate(document, Rails.formSubmitSelector, 'submit', handleConfirm);
691
+ delegate(document, Rails.formSubmitSelector, 'submit', handleRemote);
692
+ delegate(document, Rails.formSubmitSelector, 'submit', function(e) {
693
+ return setTimeout((function() {
694
+ return disableElement(e);
695
+ }), 13);
696
+ });
697
+ delegate(document, Rails.formSubmitSelector, 'ajax:send', disableElement);
698
+ delegate(document, Rails.formSubmitSelector, 'ajax:complete', enableElement);
699
+ delegate(document, Rails.formInputClickSelector, 'click', preventInsignificantClick);
700
+ delegate(document, Rails.formInputClickSelector, 'click', handleDisabledElement);
701
+ delegate(document, Rails.formInputClickSelector, 'click', handleConfirm);
702
+ delegate(document, Rails.formInputClickSelector, 'click', formSubmitButtonClick);
703
+ document.addEventListener('DOMContentLoaded', refreshCSRFTokens);
704
+ document.addEventListener('DOMContentLoaded', loadCSPNonce);
705
+ return window._rails_loaded = true;
706
+ };
707
+
708
+ if (window.Rails === Rails && fire(document, 'rails:attachBindings')) {
709
+ Rails.start();
710
+ }
711
+
712
+ }).call(this);
713
+ }).call(this);
714
+
715
+ if (typeof module === "object" && module.exports) {
716
+ module.exports = Rails;
717
+ } else if (typeof define === "function" && define.amd) {
718
+ define(Rails);
719
+ }
720
+ }).call(this);