actionview 6.0.0

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 (113) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +271 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.rdoc +40 -0
  5. data/lib/action_view.rb +98 -0
  6. data/lib/action_view/base.rb +312 -0
  7. data/lib/action_view/buffers.rb +67 -0
  8. data/lib/action_view/cache_expiry.rb +54 -0
  9. data/lib/action_view/context.rb +32 -0
  10. data/lib/action_view/dependency_tracker.rb +175 -0
  11. data/lib/action_view/digestor.rb +126 -0
  12. data/lib/action_view/flows.rb +76 -0
  13. data/lib/action_view/gem_version.rb +17 -0
  14. data/lib/action_view/helpers.rb +66 -0
  15. data/lib/action_view/helpers/active_model_helper.rb +55 -0
  16. data/lib/action_view/helpers/asset_tag_helper.rb +488 -0
  17. data/lib/action_view/helpers/asset_url_helper.rb +470 -0
  18. data/lib/action_view/helpers/atom_feed_helper.rb +205 -0
  19. data/lib/action_view/helpers/cache_helper.rb +271 -0
  20. data/lib/action_view/helpers/capture_helper.rb +216 -0
  21. data/lib/action_view/helpers/controller_helper.rb +36 -0
  22. data/lib/action_view/helpers/csp_helper.rb +26 -0
  23. data/lib/action_view/helpers/csrf_helper.rb +35 -0
  24. data/lib/action_view/helpers/date_helper.rb +1200 -0
  25. data/lib/action_view/helpers/debug_helper.rb +36 -0
  26. data/lib/action_view/helpers/form_helper.rb +2569 -0
  27. data/lib/action_view/helpers/form_options_helper.rb +896 -0
  28. data/lib/action_view/helpers/form_tag_helper.rb +920 -0
  29. data/lib/action_view/helpers/javascript_helper.rb +95 -0
  30. data/lib/action_view/helpers/number_helper.rb +456 -0
  31. data/lib/action_view/helpers/output_safety_helper.rb +70 -0
  32. data/lib/action_view/helpers/rendering_helper.rb +101 -0
  33. data/lib/action_view/helpers/sanitize_helper.rb +171 -0
  34. data/lib/action_view/helpers/tag_helper.rb +314 -0
  35. data/lib/action_view/helpers/tags.rb +44 -0
  36. data/lib/action_view/helpers/tags/base.rb +196 -0
  37. data/lib/action_view/helpers/tags/check_box.rb +66 -0
  38. data/lib/action_view/helpers/tags/checkable.rb +18 -0
  39. data/lib/action_view/helpers/tags/collection_check_boxes.rb +36 -0
  40. data/lib/action_view/helpers/tags/collection_helpers.rb +119 -0
  41. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +31 -0
  42. data/lib/action_view/helpers/tags/collection_select.rb +30 -0
  43. data/lib/action_view/helpers/tags/color_field.rb +27 -0
  44. data/lib/action_view/helpers/tags/date_field.rb +15 -0
  45. data/lib/action_view/helpers/tags/date_select.rb +74 -0
  46. data/lib/action_view/helpers/tags/datetime_field.rb +32 -0
  47. data/lib/action_view/helpers/tags/datetime_local_field.rb +21 -0
  48. data/lib/action_view/helpers/tags/datetime_select.rb +10 -0
  49. data/lib/action_view/helpers/tags/email_field.rb +10 -0
  50. data/lib/action_view/helpers/tags/file_field.rb +10 -0
  51. data/lib/action_view/helpers/tags/grouped_collection_select.rb +31 -0
  52. data/lib/action_view/helpers/tags/hidden_field.rb +10 -0
  53. data/lib/action_view/helpers/tags/label.rb +81 -0
  54. data/lib/action_view/helpers/tags/month_field.rb +15 -0
  55. data/lib/action_view/helpers/tags/number_field.rb +20 -0
  56. data/lib/action_view/helpers/tags/password_field.rb +14 -0
  57. data/lib/action_view/helpers/tags/placeholderable.rb +24 -0
  58. data/lib/action_view/helpers/tags/radio_button.rb +33 -0
  59. data/lib/action_view/helpers/tags/range_field.rb +10 -0
  60. data/lib/action_view/helpers/tags/search_field.rb +27 -0
  61. data/lib/action_view/helpers/tags/select.rb +43 -0
  62. data/lib/action_view/helpers/tags/tel_field.rb +10 -0
  63. data/lib/action_view/helpers/tags/text_area.rb +24 -0
  64. data/lib/action_view/helpers/tags/text_field.rb +34 -0
  65. data/lib/action_view/helpers/tags/time_field.rb +15 -0
  66. data/lib/action_view/helpers/tags/time_select.rb +10 -0
  67. data/lib/action_view/helpers/tags/time_zone_select.rb +22 -0
  68. data/lib/action_view/helpers/tags/translator.rb +39 -0
  69. data/lib/action_view/helpers/tags/url_field.rb +10 -0
  70. data/lib/action_view/helpers/tags/week_field.rb +15 -0
  71. data/lib/action_view/helpers/text_helper.rb +486 -0
  72. data/lib/action_view/helpers/translation_helper.rb +145 -0
  73. data/lib/action_view/helpers/url_helper.rb +676 -0
  74. data/lib/action_view/layouts.rb +433 -0
  75. data/lib/action_view/locale/en.yml +56 -0
  76. data/lib/action_view/log_subscriber.rb +96 -0
  77. data/lib/action_view/lookup_context.rb +316 -0
  78. data/lib/action_view/model_naming.rb +14 -0
  79. data/lib/action_view/path_set.rb +95 -0
  80. data/lib/action_view/railtie.rb +105 -0
  81. data/lib/action_view/record_identifier.rb +112 -0
  82. data/lib/action_view/renderer/abstract_renderer.rb +108 -0
  83. data/lib/action_view/renderer/partial_renderer.rb +563 -0
  84. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +103 -0
  85. data/lib/action_view/renderer/renderer.rb +68 -0
  86. data/lib/action_view/renderer/streaming_template_renderer.rb +105 -0
  87. data/lib/action_view/renderer/template_renderer.rb +108 -0
  88. data/lib/action_view/rendering.rb +171 -0
  89. data/lib/action_view/routing_url_for.rb +146 -0
  90. data/lib/action_view/tasks/cache_digests.rake +25 -0
  91. data/lib/action_view/template.rb +393 -0
  92. data/lib/action_view/template/error.rb +161 -0
  93. data/lib/action_view/template/handlers.rb +92 -0
  94. data/lib/action_view/template/handlers/builder.rb +25 -0
  95. data/lib/action_view/template/handlers/erb.rb +84 -0
  96. data/lib/action_view/template/handlers/erb/erubi.rb +87 -0
  97. data/lib/action_view/template/handlers/html.rb +11 -0
  98. data/lib/action_view/template/handlers/raw.rb +11 -0
  99. data/lib/action_view/template/html.rb +43 -0
  100. data/lib/action_view/template/inline.rb +22 -0
  101. data/lib/action_view/template/raw_file.rb +28 -0
  102. data/lib/action_view/template/resolver.rb +394 -0
  103. data/lib/action_view/template/sources.rb +13 -0
  104. data/lib/action_view/template/sources/file.rb +17 -0
  105. data/lib/action_view/template/text.rb +35 -0
  106. data/lib/action_view/template/types.rb +57 -0
  107. data/lib/action_view/test_case.rb +300 -0
  108. data/lib/action_view/testing/resolvers.rb +67 -0
  109. data/lib/action_view/unbound_template.rb +32 -0
  110. data/lib/action_view/version.rb +10 -0
  111. data/lib/action_view/view_paths.rb +129 -0
  112. data/lib/assets/compiled/rails-ujs.js +746 -0
  113. metadata +260 -0
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "concurrent/map"
4
+
5
+ module ActionView
6
+ class UnboundTemplate
7
+ def initialize(source, identifer, handler, options)
8
+ @source = source
9
+ @identifer = identifer
10
+ @handler = handler
11
+ @options = options
12
+
13
+ @templates = Concurrent::Map.new(initial_capacity: 2)
14
+ end
15
+
16
+ def bind_locals(locals)
17
+ @templates[locals] ||= build_template(locals)
18
+ end
19
+
20
+ private
21
+
22
+ def build_template(locals)
23
+ options = @options.merge(locals: locals)
24
+ Template.new(
25
+ @source,
26
+ @identifer,
27
+ @handler,
28
+ options
29
+ )
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "gem_version"
4
+
5
+ module ActionView
6
+ # Returns the version of the currently loaded ActionView as a <tt>Gem::Version</tt>
7
+ def self.version
8
+ gem_version
9
+ end
10
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module ViewPaths
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ ViewPaths.set_view_paths(self, ActionView::PathSet.new.freeze)
9
+ end
10
+
11
+ delegate :template_exists?, :any_templates?, :view_paths, :formats, :formats=,
12
+ :locale, :locale=, to: :lookup_context
13
+
14
+ module ClassMethods
15
+ def _view_paths
16
+ ViewPaths.get_view_paths(self)
17
+ end
18
+
19
+ def _view_paths=(paths)
20
+ ViewPaths.set_view_paths(self, paths)
21
+ end
22
+
23
+ def _prefixes # :nodoc:
24
+ @_prefixes ||= begin
25
+ return local_prefixes if superclass.abstract?
26
+
27
+ local_prefixes + superclass._prefixes
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ # Override this method in your controller if you want to change paths prefixes for finding views.
34
+ # Prefixes defined here will still be added to parents' <tt>._prefixes</tt>.
35
+ def local_prefixes
36
+ [controller_path]
37
+ end
38
+ end
39
+
40
+ # :stopdoc:
41
+ @all_view_paths = {}
42
+
43
+ def self.get_view_paths(klass)
44
+ @all_view_paths[klass] || get_view_paths(klass.superclass)
45
+ end
46
+
47
+ def self.set_view_paths(klass, paths)
48
+ @all_view_paths[klass] = paths
49
+ end
50
+
51
+ def self.all_view_paths
52
+ @all_view_paths.values.uniq
53
+ end
54
+ # :startdoc:
55
+
56
+ # The prefixes used in render "foo" shortcuts.
57
+ def _prefixes # :nodoc:
58
+ self.class._prefixes
59
+ end
60
+
61
+ # <tt>LookupContext</tt> is the object responsible for holding all
62
+ # information required for looking up templates, i.e. view paths and
63
+ # details. Check <tt>ActionView::LookupContext</tt> for more information.
64
+ def lookup_context
65
+ @_lookup_context ||=
66
+ ActionView::LookupContext.new(self.class._view_paths, details_for_lookup, _prefixes)
67
+ end
68
+
69
+ def details_for_lookup
70
+ {}
71
+ end
72
+
73
+ # Append a path to the list of view paths for the current <tt>LookupContext</tt>.
74
+ #
75
+ # ==== Parameters
76
+ # * <tt>path</tt> - If a String is provided, it gets converted into
77
+ # the default view path. You may also provide a custom view path
78
+ # (see ActionView::PathSet for more information)
79
+ def append_view_path(path)
80
+ lookup_context.view_paths.push(*path)
81
+ end
82
+
83
+ # Prepend a path to the list of view paths for the current <tt>LookupContext</tt>.
84
+ #
85
+ # ==== Parameters
86
+ # * <tt>path</tt> - If a String is provided, it gets converted into
87
+ # the default view path. You may also provide a custom view path
88
+ # (see ActionView::PathSet for more information)
89
+ def prepend_view_path(path)
90
+ lookup_context.view_paths.unshift(*path)
91
+ end
92
+
93
+ module ClassMethods
94
+ # Append a path to the list of view paths for this controller.
95
+ #
96
+ # ==== Parameters
97
+ # * <tt>path</tt> - If a String is provided, it gets converted into
98
+ # the default view path. You may also provide a custom view path
99
+ # (see ActionView::PathSet for more information)
100
+ def append_view_path(path)
101
+ self._view_paths = view_paths + Array(path)
102
+ end
103
+
104
+ # Prepend a path to the list of view paths for this controller.
105
+ #
106
+ # ==== Parameters
107
+ # * <tt>path</tt> - If a String is provided, it gets converted into
108
+ # the default view path. You may also provide a custom view path
109
+ # (see ActionView::PathSet for more information)
110
+ def prepend_view_path(path)
111
+ self._view_paths = ActionView::PathSet.new(Array(path) + view_paths)
112
+ end
113
+
114
+ # A list of all of the default view paths for this controller.
115
+ def view_paths
116
+ _view_paths
117
+ end
118
+
119
+ # Set the view paths.
120
+ #
121
+ # ==== Parameters
122
+ # * <tt>paths</tt> - If a PathSet is provided, use that;
123
+ # otherwise, process the parameter into a PathSet.
124
+ def view_paths=(paths)
125
+ self._view_paths = ActionView::PathSet.new(Array(paths))
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,746 @@
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
+ }
251
+ CSRFProtection(xhr);
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 (input.closest('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);