actionview 5.1.0.rc1 → 5.1.0.rc2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/action_view/digestor.rb +4 -2
- data/lib/action_view/gem_version.rb +1 -1
- data/lib/action_view/helpers/form_helper.rb +11 -7
- data/lib/action_view/helpers/form_tag_helper.rb +1 -1
- data/lib/action_view/helpers/url_helper.rb +0 -5
- data/lib/action_view/railtie.rb +1 -1
- data/lib/assets/compiled/rails-ujs.js +643 -614
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82bc842e6a1cad972a1aea3fa6297953c215188c
|
4
|
+
data.tar.gz: d601a12106a2c0f157cddbbf7a11dd05885fb226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea5f7f2fc5328e585e6b0911bb39a1842909c950dd79e047de9e19e095b239c350a069957386c41256da3c1dee6228d5c318e7041b132c5d6e2f160fec9dc928
|
7
|
+
data.tar.gz: 23eac9774afa65e0bd38900f35f025b38421a3ab081e71a37a16d8688ef9773d89451c10a9b153a601245298d0d823cc2d506d828a060ef30bb763c857b63d83
|
data/CHANGELOG.md
CHANGED
data/lib/action_view/digestor.rb
CHANGED
@@ -62,8 +62,10 @@ module ActionView
|
|
62
62
|
node
|
63
63
|
end
|
64
64
|
else
|
65
|
-
|
66
|
-
|
65
|
+
unless name.include?("#") # Dynamic template partial names can never be tracked
|
66
|
+
logger.error " Couldn't find template for digesting: #{name}"
|
67
|
+
end
|
68
|
+
|
67
69
|
seen[name] ||= Missing.new(name, logical_name, nil)
|
68
70
|
end
|
69
71
|
end
|
@@ -474,6 +474,8 @@ module ActionView
|
|
474
474
|
end
|
475
475
|
private :apply_form_for_options!
|
476
476
|
|
477
|
+
mattr_accessor(:form_with_generates_remote_forms) { true }
|
478
|
+
|
477
479
|
# Creates a form tag based on mixing URLs, scopes, or models.
|
478
480
|
#
|
479
481
|
# # Using just a URL:
|
@@ -1503,7 +1505,7 @@ module ActionView
|
|
1503
1505
|
end
|
1504
1506
|
|
1505
1507
|
private
|
1506
|
-
def html_options_for_form_with(url_for_options = nil, model = nil, html: {}, local:
|
1508
|
+
def html_options_for_form_with(url_for_options = nil, model = nil, html: {}, local: !form_with_generates_remote_forms,
|
1507
1509
|
skip_enforcing_utf8: false, **options)
|
1508
1510
|
html_options = options.slice(:id, :class, :multipart, :method, :data).merge(html)
|
1509
1511
|
html_options[:method] ||= :patch if model.respond_to?(:persisted?) && model.persisted?
|
@@ -1517,12 +1519,14 @@ module ActionView
|
|
1517
1519
|
html_options[:"accept-charset"] = "UTF-8"
|
1518
1520
|
html_options[:"data-remote"] = true unless local
|
1519
1521
|
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
html_options[:authenticity_token] =
|
1524
|
-
|
1525
|
-
|
1522
|
+
html_options[:authenticity_token] = options.delete(:authenticity_token)
|
1523
|
+
|
1524
|
+
if !local && html_options[:authenticity_token].blank?
|
1525
|
+
html_options[:authenticity_token] = embed_authenticity_token_in_remote_forms
|
1526
|
+
end
|
1527
|
+
|
1528
|
+
if html_options[:authenticity_token] == true
|
1529
|
+
# Include the default authenticity_token, which is only generated when it's set to nil,
|
1526
1530
|
# but we needed the true value to override the default of no authenticity_token on data-remote.
|
1527
1531
|
html_options[:authenticity_token] = nil
|
1528
1532
|
end
|
@@ -18,7 +18,7 @@ module ActionView
|
|
18
18
|
include TextHelper
|
19
19
|
|
20
20
|
mattr_accessor :embed_authenticity_token_in_remote_forms
|
21
|
-
self.embed_authenticity_token_in_remote_forms =
|
21
|
+
self.embed_authenticity_token_in_remote_forms = nil
|
22
22
|
|
23
23
|
# Starts a form tag that points the action to a url configured with <tt>url_for_options</tt> just like
|
24
24
|
# ActionController::Base#url_for. The method for the form defaults to POST.
|
@@ -621,11 +621,6 @@ module ActionView
|
|
621
621
|
# # => [{name: 'country[name]', value: 'Denmark'}]
|
622
622
|
def to_form_params(attribute, namespace = nil)
|
623
623
|
attribute = if attribute.respond_to?(:permitted?)
|
624
|
-
unless attribute.permitted?
|
625
|
-
raise ArgumentError, "Attempting to generate a buttom from non-sanitized request parameters!" \
|
626
|
-
" Whitelist and sanitize passed parameters to be secure."
|
627
|
-
end
|
628
|
-
|
629
624
|
attribute.to_h
|
630
625
|
else
|
631
626
|
attribute
|
data/lib/action_view/railtie.rb
CHANGED
@@ -5,7 +5,7 @@ module ActionView
|
|
5
5
|
# = Action View Railtie
|
6
6
|
class Railtie < Rails::Engine # :nodoc:
|
7
7
|
config.action_view = ActiveSupport::OrderedOptions.new
|
8
|
-
config.action_view.embed_authenticity_token_in_remote_forms =
|
8
|
+
config.action_view.embed_authenticity_token_in_remote_forms = nil
|
9
9
|
config.action_view.debug_missing_translation = true
|
10
10
|
|
11
11
|
config.eager_load_namespaces << ActionView
|
@@ -1,648 +1,677 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
|
9
|
-
formSubmitSelector: 'form',
|
10
|
-
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])',
|
11
|
-
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',
|
12
|
-
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',
|
13
|
-
fileInputSelector: 'input[name][type=file]:not([disabled])',
|
14
|
-
linkDisableSelector: 'a[data-disable-with], a[data-disable]',
|
15
|
-
buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]'
|
16
|
-
};
|
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
|
+
;
|
17
8
|
|
18
|
-
}).call(this);
|
19
9
|
(function() {
|
20
|
-
|
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(this);
|
30
|
+
|
31
|
+
var Rails = this.Rails;
|
32
|
+
|
33
|
+
(function() {
|
34
|
+
(function() {
|
35
|
+
var expando, m;
|
36
|
+
|
37
|
+
m = Element.prototype.matches || Element.prototype.matchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.webkitMatchesSelector;
|
38
|
+
|
39
|
+
Rails.matches = function(element, selector) {
|
40
|
+
if (selector.exclude != null) {
|
41
|
+
return m.call(element, selector.selector) && !m.call(element, selector.exclude);
|
42
|
+
} else {
|
43
|
+
return m.call(element, selector);
|
44
|
+
}
|
45
|
+
};
|
21
46
|
|
22
|
-
|
47
|
+
expando = '_ujsData';
|
23
48
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return m.call(element, selector);
|
29
|
-
}
|
30
|
-
};
|
49
|
+
Rails.getData = function(element, key) {
|
50
|
+
var ref;
|
51
|
+
return (ref = element[expando]) != null ? ref[key] : void 0;
|
52
|
+
};
|
31
53
|
|
32
|
-
|
54
|
+
Rails.setData = function(element, key, value) {
|
55
|
+
if (element[expando] == null) {
|
56
|
+
element[expando] = {};
|
57
|
+
}
|
58
|
+
return element[expando][key] = value;
|
59
|
+
};
|
60
|
+
|
61
|
+
Rails.$ = function(selector) {
|
62
|
+
return Array.prototype.slice.call(document.querySelectorAll(selector));
|
63
|
+
};
|
64
|
+
|
65
|
+
}).call(this);
|
66
|
+
(function() {
|
67
|
+
var $, csrfParam, csrfToken;
|
68
|
+
|
69
|
+
$ = Rails.$;
|
70
|
+
|
71
|
+
csrfToken = Rails.csrfToken = function() {
|
72
|
+
var meta;
|
73
|
+
meta = document.querySelector('meta[name=csrf-token]');
|
74
|
+
return meta && meta.content;
|
75
|
+
};
|
76
|
+
|
77
|
+
csrfParam = Rails.csrfParam = function() {
|
78
|
+
var meta;
|
79
|
+
meta = document.querySelector('meta[name=csrf-param]');
|
80
|
+
return meta && meta.content;
|
81
|
+
};
|
82
|
+
|
83
|
+
Rails.CSRFProtection = function(xhr) {
|
84
|
+
var token;
|
85
|
+
token = csrfToken();
|
86
|
+
if (token != null) {
|
87
|
+
return xhr.setRequestHeader('X-CSRF-Token', token);
|
88
|
+
}
|
89
|
+
};
|
90
|
+
|
91
|
+
Rails.refreshCSRFTokens = function() {
|
92
|
+
var param, token;
|
93
|
+
token = csrfToken();
|
94
|
+
param = csrfParam();
|
95
|
+
if ((token != null) && (param != null)) {
|
96
|
+
return $('form input[name="' + param + '"]').forEach(function(input) {
|
97
|
+
return input.value = token;
|
98
|
+
});
|
99
|
+
}
|
100
|
+
};
|
33
101
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
};
|
102
|
+
}).call(this);
|
103
|
+
(function() {
|
104
|
+
var CustomEvent, fire, matches;
|
38
105
|
|
39
|
-
|
40
|
-
if (element[expando] == null) {
|
41
|
-
element[expando] = {};
|
42
|
-
}
|
43
|
-
return element[expando][key] = value;
|
44
|
-
};
|
106
|
+
matches = Rails.matches;
|
45
107
|
|
46
|
-
|
47
|
-
return Array.prototype.slice.call(document.querySelectorAll(selector));
|
48
|
-
};
|
108
|
+
CustomEvent = window.CustomEvent;
|
49
109
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
return meta && meta.content;
|
60
|
-
};
|
61
|
-
|
62
|
-
csrfParam = Rails.csrfParam = function() {
|
63
|
-
var meta;
|
64
|
-
meta = document.querySelector('meta[name=csrf-param]');
|
65
|
-
return meta && meta.content;
|
66
|
-
};
|
67
|
-
|
68
|
-
Rails.CSRFProtection = function(xhr) {
|
69
|
-
var token;
|
70
|
-
token = csrfToken();
|
71
|
-
if (token != null) {
|
72
|
-
return xhr.setRequestHeader('X-CSRF-Token', token);
|
73
|
-
}
|
74
|
-
};
|
75
|
-
|
76
|
-
Rails.refreshCSRFTokens = function() {
|
77
|
-
var param, token;
|
78
|
-
token = csrfToken();
|
79
|
-
param = csrfParam();
|
80
|
-
if ((token != null) && (param != null)) {
|
81
|
-
return $('form input[name="' + param + '"]').forEach(function(input) {
|
82
|
-
return input.value = token;
|
83
|
-
});
|
84
|
-
}
|
85
|
-
};
|
110
|
+
if (typeof CustomEvent !== 'function') {
|
111
|
+
CustomEvent = function(event, params) {
|
112
|
+
var evt;
|
113
|
+
evt = document.createEvent('CustomEvent');
|
114
|
+
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
115
|
+
return evt;
|
116
|
+
};
|
117
|
+
CustomEvent.prototype = window.Event.prototype;
|
118
|
+
}
|
86
119
|
|
87
|
-
|
88
|
-
|
89
|
-
|
120
|
+
fire = Rails.fire = function(obj, name, data) {
|
121
|
+
var event;
|
122
|
+
event = new CustomEvent(name, {
|
123
|
+
bubbles: true,
|
124
|
+
cancelable: true,
|
125
|
+
detail: data
|
126
|
+
});
|
127
|
+
obj.dispatchEvent(event);
|
128
|
+
return !event.defaultPrevented;
|
129
|
+
};
|
90
130
|
|
91
|
-
|
131
|
+
Rails.stopEverything = function(e) {
|
132
|
+
fire(e.target, 'ujs:everythingStopped');
|
133
|
+
e.preventDefault();
|
134
|
+
e.stopPropagation();
|
135
|
+
return e.stopImmediatePropagation();
|
136
|
+
};
|
137
|
+
|
138
|
+
Rails.delegate = function(element, selector, eventType, handler) {
|
139
|
+
return element.addEventListener(eventType, function(e) {
|
140
|
+
var target;
|
141
|
+
target = e.target;
|
142
|
+
while (!(!(target instanceof Element) || matches(target, selector))) {
|
143
|
+
target = target.parentNode;
|
144
|
+
}
|
145
|
+
if (target instanceof Element && handler.call(target, e) === false) {
|
146
|
+
e.preventDefault();
|
147
|
+
return e.stopPropagation();
|
148
|
+
}
|
149
|
+
});
|
150
|
+
};
|
151
|
+
|
152
|
+
}).call(this);
|
153
|
+
(function() {
|
154
|
+
var AcceptHeaders, CSRFProtection, createXHR, fire, prepareOptions, processResponse;
|
155
|
+
|
156
|
+
CSRFProtection = Rails.CSRFProtection, fire = Rails.fire;
|
157
|
+
|
158
|
+
AcceptHeaders = {
|
159
|
+
'*': '*/*',
|
160
|
+
text: 'text/plain',
|
161
|
+
html: 'text/html',
|
162
|
+
xml: 'application/xml, text/xml',
|
163
|
+
json: 'application/json, text/javascript',
|
164
|
+
script: 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript'
|
165
|
+
};
|
166
|
+
|
167
|
+
Rails.ajax = function(options) {
|
168
|
+
var xhr;
|
169
|
+
options = prepareOptions(options);
|
170
|
+
xhr = createXHR(options, function() {
|
171
|
+
var response;
|
172
|
+
response = processResponse(xhr.response, xhr.getResponseHeader('Content-Type'));
|
173
|
+
if (Math.floor(xhr.status / 100) === 2) {
|
174
|
+
if (typeof options.success === "function") {
|
175
|
+
options.success(response, xhr.statusText, xhr);
|
176
|
+
}
|
177
|
+
} else {
|
178
|
+
if (typeof options.error === "function") {
|
179
|
+
options.error(response, xhr.statusText, xhr);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
return typeof options.complete === "function" ? options.complete(xhr, xhr.statusText) : void 0;
|
183
|
+
});
|
184
|
+
if (typeof options.beforeSend === "function") {
|
185
|
+
options.beforeSend(xhr, options);
|
186
|
+
}
|
187
|
+
if (xhr.readyState === XMLHttpRequest.OPENED) {
|
188
|
+
return xhr.send(options.data);
|
189
|
+
} else {
|
190
|
+
return fire(document, 'ajaxStop');
|
191
|
+
}
|
192
|
+
};
|
193
|
+
|
194
|
+
prepareOptions = function(options) {
|
195
|
+
options.url = options.url || location.href;
|
196
|
+
options.type = options.type.toUpperCase();
|
197
|
+
if (options.type === 'GET' && options.data) {
|
198
|
+
if (options.url.indexOf('?') < 0) {
|
199
|
+
options.url += '?' + options.data;
|
200
|
+
} else {
|
201
|
+
options.url += '&' + options.data;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
if (AcceptHeaders[options.dataType] == null) {
|
205
|
+
options.dataType = '*';
|
206
|
+
}
|
207
|
+
options.accept = AcceptHeaders[options.dataType];
|
208
|
+
if (options.dataType !== '*') {
|
209
|
+
options.accept += ', */*; q=0.01';
|
210
|
+
}
|
211
|
+
return options;
|
212
|
+
};
|
213
|
+
|
214
|
+
createXHR = function(options, done) {
|
215
|
+
var xhr;
|
216
|
+
xhr = new XMLHttpRequest();
|
217
|
+
xhr.open(options.type, options.url, true);
|
218
|
+
xhr.setRequestHeader('Accept', options.accept);
|
219
|
+
if (typeof options.data === 'string') {
|
220
|
+
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
221
|
+
}
|
222
|
+
if (!options.crossDomain) {
|
223
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
224
|
+
}
|
225
|
+
CSRFProtection(xhr);
|
226
|
+
xhr.withCredentials = !!options.withCredentials;
|
227
|
+
xhr.onreadystatechange = function() {
|
228
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
229
|
+
return done(xhr);
|
230
|
+
}
|
231
|
+
};
|
232
|
+
return xhr;
|
233
|
+
};
|
234
|
+
|
235
|
+
processResponse = function(response, type) {
|
236
|
+
var parser, script;
|
237
|
+
if (typeof response === 'string' && typeof type === 'string') {
|
238
|
+
if (type.match(/\bjson\b/)) {
|
239
|
+
try {
|
240
|
+
response = JSON.parse(response);
|
241
|
+
} catch (error) {}
|
242
|
+
} else if (type.match(/\b(?:java|ecma)script\b/)) {
|
243
|
+
script = document.createElement('script');
|
244
|
+
script.text = response;
|
245
|
+
document.head.appendChild(script).parentNode.removeChild(script);
|
246
|
+
} else if (type.match(/\b(xml|html|svg)\b/)) {
|
247
|
+
parser = new DOMParser();
|
248
|
+
type = type.replace(/;.+/, '');
|
249
|
+
try {
|
250
|
+
response = parser.parseFromString(response, type);
|
251
|
+
} catch (error) {}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
return response;
|
255
|
+
};
|
256
|
+
|
257
|
+
Rails.href = function(element) {
|
258
|
+
return element.href;
|
259
|
+
};
|
260
|
+
|
261
|
+
Rails.isCrossDomain = function(url) {
|
262
|
+
var e, originAnchor, urlAnchor;
|
263
|
+
originAnchor = document.createElement('a');
|
264
|
+
originAnchor.href = location.href;
|
265
|
+
urlAnchor = document.createElement('a');
|
266
|
+
try {
|
267
|
+
urlAnchor.href = url;
|
268
|
+
return !(((!urlAnchor.protocol || urlAnchor.protocol === ':') && !urlAnchor.host) || (originAnchor.protocol + '//' + originAnchor.host === urlAnchor.protocol + '//' + urlAnchor.host));
|
269
|
+
} catch (error) {
|
270
|
+
e = error;
|
271
|
+
return true;
|
272
|
+
}
|
273
|
+
};
|
92
274
|
|
93
|
-
|
275
|
+
}).call(this);
|
276
|
+
(function() {
|
277
|
+
var matches, toArray;
|
94
278
|
|
95
|
-
|
96
|
-
CustomEvent = function(event, params) {
|
97
|
-
var evt;
|
98
|
-
evt = document.createEvent('CustomEvent');
|
99
|
-
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
100
|
-
return evt;
|
101
|
-
};
|
102
|
-
CustomEvent.prototype = window.Event.prototype;
|
103
|
-
}
|
279
|
+
matches = Rails.matches;
|
104
280
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
bubbles: true,
|
109
|
-
cancelable: true,
|
110
|
-
detail: data
|
111
|
-
});
|
112
|
-
obj.dispatchEvent(event);
|
113
|
-
return !event.defaultPrevented;
|
114
|
-
};
|
115
|
-
|
116
|
-
Rails.stopEverything = function(e) {
|
117
|
-
fire(e.target, 'ujs:everythingStopped');
|
118
|
-
e.preventDefault();
|
119
|
-
e.stopPropagation();
|
120
|
-
return e.stopImmediatePropagation();
|
121
|
-
};
|
122
|
-
|
123
|
-
Rails.delegate = function(element, selector, eventType, handler) {
|
124
|
-
return element.addEventListener(eventType, function(e) {
|
125
|
-
var target;
|
126
|
-
target = e.target;
|
127
|
-
while (!(!(target instanceof Element) || matches(target, selector))) {
|
128
|
-
target = target.parentNode;
|
129
|
-
}
|
130
|
-
if (target instanceof Element && handler.call(target, e) === false) {
|
131
|
-
e.preventDefault();
|
132
|
-
return e.stopPropagation();
|
133
|
-
}
|
134
|
-
});
|
135
|
-
};
|
281
|
+
toArray = function(e) {
|
282
|
+
return Array.prototype.slice.call(e);
|
283
|
+
};
|
136
284
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
AcceptHeaders = {
|
144
|
-
'*': '*/*',
|
145
|
-
text: 'text/plain',
|
146
|
-
html: 'text/html',
|
147
|
-
xml: 'application/xml, text/xml',
|
148
|
-
json: 'application/json, text/javascript',
|
149
|
-
script: 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript'
|
150
|
-
};
|
151
|
-
|
152
|
-
Rails.ajax = function(options) {
|
153
|
-
var xhr;
|
154
|
-
options = prepareOptions(options);
|
155
|
-
xhr = createXHR(options, function() {
|
156
|
-
var response;
|
157
|
-
response = processResponse(xhr.response, xhr.getResponseHeader('Content-Type'));
|
158
|
-
if (Math.floor(xhr.status / 100) === 2) {
|
159
|
-
if (typeof options.success === "function") {
|
160
|
-
options.success(response, xhr.statusText, xhr);
|
161
|
-
}
|
162
|
-
} else {
|
163
|
-
if (typeof options.error === "function") {
|
164
|
-
options.error(response, xhr.statusText, xhr);
|
285
|
+
Rails.serializeElement = function(element, additionalParam) {
|
286
|
+
var inputs, params;
|
287
|
+
inputs = [element];
|
288
|
+
if (matches(element, 'form')) {
|
289
|
+
inputs = toArray(element.elements);
|
165
290
|
}
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
if (options.type === 'GET' && options.data) {
|
182
|
-
if (options.url.indexOf('?') < 0) {
|
183
|
-
options.url += '?' + options.data;
|
184
|
-
} else {
|
185
|
-
options.url += '&' + options.data;
|
186
|
-
}
|
187
|
-
}
|
188
|
-
if (AcceptHeaders[options.dataType] == null) {
|
189
|
-
options.dataType = '*';
|
190
|
-
}
|
191
|
-
options.accept = AcceptHeaders[options.dataType];
|
192
|
-
if (options.dataType !== '*') {
|
193
|
-
options.accept += ', */*; q=0.01';
|
194
|
-
}
|
195
|
-
return options;
|
196
|
-
};
|
197
|
-
|
198
|
-
createXHR = function(options, done) {
|
199
|
-
var xhr;
|
200
|
-
xhr = new XMLHttpRequest();
|
201
|
-
xhr.open(options.type, options.url, true);
|
202
|
-
xhr.setRequestHeader('Accept', options.accept);
|
203
|
-
if (typeof options.data === 'string') {
|
204
|
-
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
205
|
-
}
|
206
|
-
if (!options.crossDomain) {
|
207
|
-
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
208
|
-
}
|
209
|
-
CSRFProtection(xhr);
|
210
|
-
xhr.withCredentials = !!options.withCredentials;
|
211
|
-
xhr.onreadystatechange = function() {
|
212
|
-
if (xhr.readyState === XMLHttpRequest.DONE) {
|
213
|
-
return done(xhr);
|
214
|
-
}
|
215
|
-
};
|
216
|
-
return xhr;
|
217
|
-
};
|
218
|
-
|
219
|
-
processResponse = function(response, type) {
|
220
|
-
var parser, script;
|
221
|
-
if (typeof response === 'string' && typeof type === 'string') {
|
222
|
-
if (type.match(/\bjson\b/)) {
|
223
|
-
try {
|
224
|
-
response = JSON.parse(response);
|
225
|
-
} catch (error) {}
|
226
|
-
} else if (type.match(/\bjavascript\b/)) {
|
227
|
-
script = document.createElement('script');
|
228
|
-
script.innerHTML = response;
|
229
|
-
document.body.appendChild(script);
|
230
|
-
} else if (type.match(/\b(xml|html|svg)\b/)) {
|
231
|
-
parser = new DOMParser();
|
232
|
-
type = type.replace(/;.+/, '');
|
233
|
-
try {
|
234
|
-
response = parser.parseFromString(response, type);
|
235
|
-
} catch (error) {}
|
236
|
-
}
|
237
|
-
}
|
238
|
-
return response;
|
239
|
-
};
|
240
|
-
|
241
|
-
Rails.href = function(element) {
|
242
|
-
return element.href;
|
243
|
-
};
|
244
|
-
|
245
|
-
Rails.isCrossDomain = function(url) {
|
246
|
-
var e, originAnchor, urlAnchor;
|
247
|
-
originAnchor = document.createElement('a');
|
248
|
-
originAnchor.href = location.href;
|
249
|
-
urlAnchor = document.createElement('a');
|
250
|
-
try {
|
251
|
-
urlAnchor.href = url;
|
252
|
-
return !(((!urlAnchor.protocol || urlAnchor.protocol === ':') && !urlAnchor.host) || (originAnchor.protocol + '//' + originAnchor.host === urlAnchor.protocol + '//' + urlAnchor.host));
|
253
|
-
} catch (error) {
|
254
|
-
e = error;
|
255
|
-
return true;
|
256
|
-
}
|
257
|
-
};
|
258
|
-
|
259
|
-
}).call(this);
|
260
|
-
(function() {
|
261
|
-
var matches, toArray;
|
262
|
-
|
263
|
-
matches = Rails.matches;
|
264
|
-
|
265
|
-
toArray = function(e) {
|
266
|
-
return Array.prototype.slice.call(e);
|
267
|
-
};
|
268
|
-
|
269
|
-
Rails.serializeElement = function(element, additionalParam) {
|
270
|
-
var inputs, params;
|
271
|
-
inputs = [element];
|
272
|
-
if (matches(element, 'form')) {
|
273
|
-
inputs = toArray(element.elements);
|
274
|
-
}
|
275
|
-
params = [];
|
276
|
-
inputs.forEach(function(input) {
|
277
|
-
if (!input.name) {
|
278
|
-
return;
|
279
|
-
}
|
280
|
-
if (matches(input, 'select')) {
|
281
|
-
return toArray(input.options).forEach(function(option) {
|
282
|
-
if (option.selected) {
|
291
|
+
params = [];
|
292
|
+
inputs.forEach(function(input) {
|
293
|
+
if (!input.name) {
|
294
|
+
return;
|
295
|
+
}
|
296
|
+
if (matches(input, 'select')) {
|
297
|
+
return toArray(input.options).forEach(function(option) {
|
298
|
+
if (option.selected) {
|
299
|
+
return params.push({
|
300
|
+
name: input.name,
|
301
|
+
value: option.value
|
302
|
+
});
|
303
|
+
}
|
304
|
+
});
|
305
|
+
} else if (input.checked || ['radio', 'checkbox', 'submit'].indexOf(input.type) === -1) {
|
283
306
|
return params.push({
|
284
307
|
name: input.name,
|
285
|
-
value:
|
308
|
+
value: input.value
|
286
309
|
});
|
287
310
|
}
|
288
311
|
});
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
return toArray(form.elements).filter(function(el) {
|
311
|
-
return matches(el, selector);
|
312
|
-
});
|
313
|
-
} else {
|
314
|
-
return toArray(form.querySelectorAll(selector));
|
315
|
-
}
|
316
|
-
};
|
312
|
+
if (additionalParam) {
|
313
|
+
params.push(additionalParam);
|
314
|
+
}
|
315
|
+
return params.map(function(param) {
|
316
|
+
if (param.name != null) {
|
317
|
+
return (encodeURIComponent(param.name)) + "=" + (encodeURIComponent(param.value));
|
318
|
+
} else {
|
319
|
+
return param;
|
320
|
+
}
|
321
|
+
}).join('&');
|
322
|
+
};
|
323
|
+
|
324
|
+
Rails.formElements = function(form, selector) {
|
325
|
+
if (matches(form, 'form')) {
|
326
|
+
return toArray(form.elements).filter(function(el) {
|
327
|
+
return matches(el, selector);
|
328
|
+
});
|
329
|
+
} else {
|
330
|
+
return toArray(form.querySelectorAll(selector));
|
331
|
+
}
|
332
|
+
};
|
317
333
|
|
318
|
-
}).call(this);
|
319
|
-
(function() {
|
320
|
-
|
321
|
-
|
322
|
-
fire = Rails.fire, stopEverything = Rails.stopEverything;
|
323
|
-
|
324
|
-
Rails.handleConfirm = function(e) {
|
325
|
-
if (!allowAction(this)) {
|
326
|
-
return stopEverything(e);
|
327
|
-
}
|
328
|
-
};
|
329
|
-
|
330
|
-
allowAction = function(element) {
|
331
|
-
var answer, callback, message;
|
332
|
-
message = element.getAttribute('data-confirm');
|
333
|
-
if (!message) {
|
334
|
-
return true;
|
335
|
-
}
|
336
|
-
answer = false;
|
337
|
-
if (fire(element, 'confirm')) {
|
338
|
-
try {
|
339
|
-
answer = confirm(message);
|
340
|
-
} catch (error) {}
|
341
|
-
callback = fire(element, 'confirm:complete', [answer]);
|
342
|
-
}
|
343
|
-
return answer && callback;
|
344
|
-
};
|
334
|
+
}).call(this);
|
335
|
+
(function() {
|
336
|
+
var allowAction, fire, stopEverything;
|
345
337
|
|
346
|
-
|
347
|
-
(function() {
|
348
|
-
var disableFormElement, disableFormElements, disableLinkElement, enableFormElement, enableFormElements, enableLinkElement, formElements, getData, matches, setData, stopEverything;
|
349
|
-
|
350
|
-
matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, stopEverything = Rails.stopEverything, formElements = Rails.formElements;
|
351
|
-
|
352
|
-
Rails.enableElement = function(e) {
|
353
|
-
var element;
|
354
|
-
element = e instanceof Event ? e.target : e;
|
355
|
-
if (matches(element, Rails.linkDisableSelector)) {
|
356
|
-
return enableLinkElement(element);
|
357
|
-
} else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formEnableSelector)) {
|
358
|
-
return enableFormElement(element);
|
359
|
-
} else if (matches(element, Rails.formSubmitSelector)) {
|
360
|
-
return enableFormElements(element);
|
361
|
-
}
|
362
|
-
};
|
363
|
-
|
364
|
-
Rails.disableElement = function(e) {
|
365
|
-
var element;
|
366
|
-
element = e instanceof Event ? e.target : e;
|
367
|
-
if (matches(element, Rails.linkDisableSelector)) {
|
368
|
-
return disableLinkElement(element);
|
369
|
-
} else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formDisableSelector)) {
|
370
|
-
return disableFormElement(element);
|
371
|
-
} else if (matches(element, Rails.formSubmitSelector)) {
|
372
|
-
return disableFormElements(element);
|
373
|
-
}
|
374
|
-
};
|
375
|
-
|
376
|
-
disableLinkElement = function(element) {
|
377
|
-
var replacement;
|
378
|
-
replacement = element.getAttribute('data-disable-with');
|
379
|
-
if (replacement != null) {
|
380
|
-
setData(element, 'ujs:enable-with', element.innerHTML);
|
381
|
-
element.innerHTML = replacement;
|
382
|
-
}
|
383
|
-
element.addEventListener('click', stopEverything);
|
384
|
-
return setData(element, 'ujs:disabled', true);
|
385
|
-
};
|
386
|
-
|
387
|
-
enableLinkElement = function(element) {
|
388
|
-
var originalText;
|
389
|
-
originalText = getData(element, 'ujs:enable-with');
|
390
|
-
if (originalText != null) {
|
391
|
-
element.innerHTML = originalText;
|
392
|
-
setData(element, 'ujs:enable-with', null);
|
393
|
-
}
|
394
|
-
element.removeEventListener('click', stopEverything);
|
395
|
-
return setData(element, 'ujs:disabled', null);
|
396
|
-
};
|
397
|
-
|
398
|
-
disableFormElements = function(form) {
|
399
|
-
return formElements(form, Rails.formDisableSelector).forEach(disableFormElement);
|
400
|
-
};
|
401
|
-
|
402
|
-
disableFormElement = function(element) {
|
403
|
-
var replacement;
|
404
|
-
replacement = element.getAttribute('data-disable-with');
|
405
|
-
if (replacement != null) {
|
406
|
-
if (matches(element, 'button')) {
|
407
|
-
setData(element, 'ujs:enable-with', element.innerHTML);
|
408
|
-
element.innerHTML = replacement;
|
409
|
-
} else {
|
410
|
-
setData(element, 'ujs:enable-with', element.value);
|
411
|
-
element.value = replacement;
|
412
|
-
}
|
413
|
-
}
|
414
|
-
element.disabled = true;
|
415
|
-
return setData(element, 'ujs:disabled', true);
|
416
|
-
};
|
417
|
-
|
418
|
-
enableFormElements = function(form) {
|
419
|
-
return formElements(form, Rails.formEnableSelector).forEach(enableFormElement);
|
420
|
-
};
|
421
|
-
|
422
|
-
enableFormElement = function(element) {
|
423
|
-
var originalText;
|
424
|
-
originalText = getData(element, 'ujs:enable-with');
|
425
|
-
if (originalText != null) {
|
426
|
-
if (matches(element, 'button')) {
|
427
|
-
element.innerHTML = originalText;
|
428
|
-
} else {
|
429
|
-
element.value = originalText;
|
430
|
-
}
|
431
|
-
setData(element, 'ujs:enable-with', null);
|
432
|
-
}
|
433
|
-
element.disabled = false;
|
434
|
-
return setData(element, 'ujs:disabled', null);
|
435
|
-
};
|
338
|
+
fire = Rails.fire, stopEverything = Rails.stopEverything;
|
436
339
|
|
437
|
-
|
438
|
-
(
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
Rails.handleMethod = function(e) {
|
444
|
-
var csrfParam, csrfToken, form, formContent, href, link, method;
|
445
|
-
link = this;
|
446
|
-
method = link.getAttribute('data-method');
|
447
|
-
if (!method) {
|
448
|
-
return;
|
449
|
-
}
|
450
|
-
href = Rails.href(link);
|
451
|
-
csrfToken = Rails.csrfToken();
|
452
|
-
csrfParam = Rails.csrfParam();
|
453
|
-
form = document.createElement('form');
|
454
|
-
formContent = "<input name='_method' value='" + method + "' type='hidden' />";
|
455
|
-
if ((csrfParam != null) && (csrfToken != null) && !Rails.isCrossDomain(href)) {
|
456
|
-
formContent += "<input name='" + csrfParam + "' value='" + csrfToken + "' type='hidden' />";
|
457
|
-
}
|
458
|
-
formContent += '<input type="submit" />';
|
459
|
-
form.method = 'post';
|
460
|
-
form.action = href;
|
461
|
-
form.target = link.target;
|
462
|
-
form.innerHTML = formContent;
|
463
|
-
form.style.display = 'none';
|
464
|
-
document.body.appendChild(form);
|
465
|
-
form.querySelector('[type="submit"]').click();
|
466
|
-
return stopEverything(e);
|
467
|
-
};
|
340
|
+
Rails.handleConfirm = function(e) {
|
341
|
+
if (!allowAction(this)) {
|
342
|
+
return stopEverything(e);
|
343
|
+
}
|
344
|
+
};
|
468
345
|
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, fire = Rails.fire, stopEverything = Rails.stopEverything, ajax = Rails.ajax, isCrossDomain = Rails.isCrossDomain, serializeElement = Rails.serializeElement;
|
475
|
-
|
476
|
-
isRemote = function(element) {
|
477
|
-
var value;
|
478
|
-
value = element.getAttribute('data-remote');
|
479
|
-
return (value != null) && value !== 'false';
|
480
|
-
};
|
481
|
-
|
482
|
-
Rails.handleRemote = function(e) {
|
483
|
-
var button, data, dataType, element, method, url, withCredentials;
|
484
|
-
element = this;
|
485
|
-
if (!isRemote(element)) {
|
486
|
-
return true;
|
487
|
-
}
|
488
|
-
if (!fire(element, 'ajax:before')) {
|
489
|
-
fire(element, 'ajax:stopped');
|
490
|
-
return false;
|
491
|
-
}
|
492
|
-
withCredentials = element.getAttribute('data-with-credentials');
|
493
|
-
dataType = element.getAttribute('data-type') || 'script';
|
494
|
-
if (matches(element, Rails.formSubmitSelector)) {
|
495
|
-
button = getData(element, 'ujs:submit-button');
|
496
|
-
method = getData(element, 'ujs:submit-button-formmethod') || element.method;
|
497
|
-
url = getData(element, 'ujs:submit-button-formaction') || element.getAttribute('action') || location.href;
|
498
|
-
if (method.toUpperCase() === 'GET') {
|
499
|
-
url = url.replace(/\?.*$/, '');
|
500
|
-
}
|
501
|
-
if (element.enctype === 'multipart/form-data') {
|
502
|
-
data = new FormData(element);
|
503
|
-
if (button != null) {
|
504
|
-
data.append(button.name, button.value);
|
346
|
+
allowAction = function(element) {
|
347
|
+
var answer, callback, message;
|
348
|
+
message = element.getAttribute('data-confirm');
|
349
|
+
if (!message) {
|
350
|
+
return true;
|
505
351
|
}
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
}
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
if (
|
528
|
-
return
|
529
|
-
} else {
|
352
|
+
answer = false;
|
353
|
+
if (fire(element, 'confirm')) {
|
354
|
+
try {
|
355
|
+
answer = confirm(message);
|
356
|
+
} catch (error) {}
|
357
|
+
callback = fire(element, 'confirm:complete', [answer]);
|
358
|
+
}
|
359
|
+
return answer && callback;
|
360
|
+
};
|
361
|
+
|
362
|
+
}).call(this);
|
363
|
+
(function() {
|
364
|
+
var disableFormElement, disableFormElements, disableLinkElement, enableFormElement, enableFormElements, enableLinkElement, formElements, getData, matches, setData, stopEverything;
|
365
|
+
|
366
|
+
matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, stopEverything = Rails.stopEverything, formElements = Rails.formElements;
|
367
|
+
|
368
|
+
Rails.enableElement = function(e) {
|
369
|
+
var element;
|
370
|
+
element = e instanceof Event ? e.target : e;
|
371
|
+
if (matches(element, Rails.linkDisableSelector)) {
|
372
|
+
return enableLinkElement(element);
|
373
|
+
} else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formEnableSelector)) {
|
374
|
+
return enableFormElement(element);
|
375
|
+
} else if (matches(element, Rails.formSubmitSelector)) {
|
376
|
+
return enableFormElements(element);
|
377
|
+
}
|
378
|
+
};
|
379
|
+
|
380
|
+
Rails.disableElement = function(e) {
|
381
|
+
var element;
|
382
|
+
element = e instanceof Event ? e.target : e;
|
383
|
+
if (matches(element, Rails.linkDisableSelector)) {
|
384
|
+
return disableLinkElement(element);
|
385
|
+
} else if (matches(element, Rails.buttonDisableSelector) || matches(element, Rails.formDisableSelector)) {
|
386
|
+
return disableFormElement(element);
|
387
|
+
} else if (matches(element, Rails.formSubmitSelector)) {
|
388
|
+
return disableFormElements(element);
|
389
|
+
}
|
390
|
+
};
|
391
|
+
|
392
|
+
disableLinkElement = function(element) {
|
393
|
+
var replacement;
|
394
|
+
replacement = element.getAttribute('data-disable-with');
|
395
|
+
if (replacement != null) {
|
396
|
+
setData(element, 'ujs:enable-with', element.innerHTML);
|
397
|
+
element.innerHTML = replacement;
|
398
|
+
}
|
399
|
+
element.addEventListener('click', stopEverything);
|
400
|
+
return setData(element, 'ujs:disabled', true);
|
401
|
+
};
|
402
|
+
|
403
|
+
enableLinkElement = function(element) {
|
404
|
+
var originalText;
|
405
|
+
originalText = getData(element, 'ujs:enable-with');
|
406
|
+
if (originalText != null) {
|
407
|
+
element.innerHTML = originalText;
|
408
|
+
setData(element, 'ujs:enable-with', null);
|
409
|
+
}
|
410
|
+
element.removeEventListener('click', stopEverything);
|
411
|
+
return setData(element, 'ujs:disabled', null);
|
412
|
+
};
|
413
|
+
|
414
|
+
disableFormElements = function(form) {
|
415
|
+
return formElements(form, Rails.formDisableSelector).forEach(disableFormElement);
|
416
|
+
};
|
417
|
+
|
418
|
+
disableFormElement = function(element) {
|
419
|
+
var replacement;
|
420
|
+
replacement = element.getAttribute('data-disable-with');
|
421
|
+
if (replacement != null) {
|
422
|
+
if (matches(element, 'button')) {
|
423
|
+
setData(element, 'ujs:enable-with', element.innerHTML);
|
424
|
+
element.innerHTML = replacement;
|
425
|
+
} else {
|
426
|
+
setData(element, 'ujs:enable-with', element.value);
|
427
|
+
element.value = replacement;
|
428
|
+
}
|
429
|
+
}
|
430
|
+
element.disabled = true;
|
431
|
+
return setData(element, 'ujs:disabled', true);
|
432
|
+
};
|
433
|
+
|
434
|
+
enableFormElements = function(form) {
|
435
|
+
return formElements(form, Rails.formEnableSelector).forEach(enableFormElement);
|
436
|
+
};
|
437
|
+
|
438
|
+
enableFormElement = function(element) {
|
439
|
+
var originalText;
|
440
|
+
originalText = getData(element, 'ujs:enable-with');
|
441
|
+
if (originalText != null) {
|
442
|
+
if (matches(element, 'button')) {
|
443
|
+
element.innerHTML = originalText;
|
444
|
+
} else {
|
445
|
+
element.value = originalText;
|
446
|
+
}
|
447
|
+
setData(element, 'ujs:enable-with', null);
|
448
|
+
}
|
449
|
+
element.disabled = false;
|
450
|
+
return setData(element, 'ujs:disabled', null);
|
451
|
+
};
|
452
|
+
|
453
|
+
}).call(this);
|
454
|
+
(function() {
|
455
|
+
var stopEverything;
|
456
|
+
|
457
|
+
stopEverything = Rails.stopEverything;
|
458
|
+
|
459
|
+
Rails.handleMethod = function(e) {
|
460
|
+
var csrfParam, csrfToken, form, formContent, href, link, method;
|
461
|
+
link = this;
|
462
|
+
method = link.getAttribute('data-method');
|
463
|
+
if (!method) {
|
464
|
+
return;
|
465
|
+
}
|
466
|
+
href = Rails.href(link);
|
467
|
+
csrfToken = Rails.csrfToken();
|
468
|
+
csrfParam = Rails.csrfParam();
|
469
|
+
form = document.createElement('form');
|
470
|
+
formContent = "<input name='_method' value='" + method + "' type='hidden' />";
|
471
|
+
if ((csrfParam != null) && (csrfToken != null) && !Rails.isCrossDomain(href)) {
|
472
|
+
formContent += "<input name='" + csrfParam + "' value='" + csrfToken + "' type='hidden' />";
|
473
|
+
}
|
474
|
+
formContent += '<input type="submit" />';
|
475
|
+
form.method = 'post';
|
476
|
+
form.action = href;
|
477
|
+
form.target = link.target;
|
478
|
+
form.innerHTML = formContent;
|
479
|
+
form.style.display = 'none';
|
480
|
+
document.body.appendChild(form);
|
481
|
+
form.querySelector('[type="submit"]').click();
|
482
|
+
return stopEverything(e);
|
483
|
+
};
|
484
|
+
|
485
|
+
}).call(this);
|
486
|
+
(function() {
|
487
|
+
var ajax, fire, getData, isCrossDomain, isRemote, matches, serializeElement, setData, stopEverything,
|
488
|
+
slice = [].slice;
|
489
|
+
|
490
|
+
matches = Rails.matches, getData = Rails.getData, setData = Rails.setData, fire = Rails.fire, stopEverything = Rails.stopEverything, ajax = Rails.ajax, isCrossDomain = Rails.isCrossDomain, serializeElement = Rails.serializeElement;
|
491
|
+
|
492
|
+
isRemote = function(element) {
|
493
|
+
var value;
|
494
|
+
value = element.getAttribute('data-remote');
|
495
|
+
return (value != null) && value !== 'false';
|
496
|
+
};
|
497
|
+
|
498
|
+
Rails.handleRemote = function(e) {
|
499
|
+
var button, data, dataType, element, method, url, withCredentials;
|
500
|
+
element = this;
|
501
|
+
if (!isRemote(element)) {
|
502
|
+
return true;
|
503
|
+
}
|
504
|
+
if (!fire(element, 'ajax:before')) {
|
530
505
|
fire(element, 'ajax:stopped');
|
531
|
-
return
|
532
|
-
}
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
506
|
+
return false;
|
507
|
+
}
|
508
|
+
withCredentials = element.getAttribute('data-with-credentials');
|
509
|
+
dataType = element.getAttribute('data-type') || 'script';
|
510
|
+
if (matches(element, Rails.formSubmitSelector)) {
|
511
|
+
button = getData(element, 'ujs:submit-button');
|
512
|
+
method = getData(element, 'ujs:submit-button-formmethod') || element.method;
|
513
|
+
url = getData(element, 'ujs:submit-button-formaction') || element.getAttribute('action') || location.href;
|
514
|
+
if (method.toUpperCase() === 'GET') {
|
515
|
+
url = url.replace(/\?.*$/, '');
|
516
|
+
}
|
517
|
+
if (element.enctype === 'multipart/form-data') {
|
518
|
+
data = new FormData(element);
|
519
|
+
if (button != null) {
|
520
|
+
data.append(button.name, button.value);
|
521
|
+
}
|
522
|
+
} else {
|
523
|
+
data = serializeElement(element, button);
|
524
|
+
}
|
525
|
+
setData(element, 'ujs:submit-button', null);
|
526
|
+
setData(element, 'ujs:submit-button-formmethod', null);
|
527
|
+
setData(element, 'ujs:submit-button-formaction', null);
|
528
|
+
} else if (matches(element, Rails.buttonClickSelector) || matches(element, Rails.inputChangeSelector)) {
|
529
|
+
method = element.getAttribute('data-method');
|
530
|
+
url = element.getAttribute('data-url');
|
531
|
+
data = serializeElement(element, element.getAttribute('data-params'));
|
532
|
+
} else {
|
533
|
+
method = element.getAttribute('data-method');
|
534
|
+
url = Rails.href(element);
|
535
|
+
data = element.getAttribute('data-params');
|
536
|
+
}
|
537
|
+
ajax({
|
538
|
+
type: method || 'GET',
|
539
|
+
url: url,
|
540
|
+
data: data,
|
541
|
+
dataType: dataType,
|
542
|
+
beforeSend: function(xhr, options) {
|
543
|
+
if (fire(element, 'ajax:beforeSend', [xhr, options])) {
|
544
|
+
return fire(element, 'ajax:send', [xhr]);
|
545
|
+
} else {
|
546
|
+
fire(element, 'ajax:stopped');
|
547
|
+
return xhr.abort();
|
548
|
+
}
|
549
|
+
},
|
550
|
+
success: function() {
|
551
|
+
var args;
|
552
|
+
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
553
|
+
return fire(element, 'ajax:success', args);
|
554
|
+
},
|
555
|
+
error: function() {
|
556
|
+
var args;
|
557
|
+
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
558
|
+
return fire(element, 'ajax:error', args);
|
559
|
+
},
|
560
|
+
complete: function() {
|
561
|
+
var args;
|
562
|
+
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
563
|
+
return fire(element, 'ajax:complete', args);
|
564
|
+
},
|
565
|
+
crossDomain: isCrossDomain(url),
|
566
|
+
withCredentials: (withCredentials != null) && withCredentials !== 'false'
|
567
|
+
});
|
568
|
+
return stopEverything(e);
|
569
|
+
};
|
570
|
+
|
571
|
+
Rails.formSubmitButtonClick = function(e) {
|
572
|
+
var button, form;
|
573
|
+
button = this;
|
574
|
+
form = button.form;
|
575
|
+
if (!form) {
|
576
|
+
return;
|
577
|
+
}
|
578
|
+
if (button.name) {
|
579
|
+
setData(form, 'ujs:submit-button', {
|
580
|
+
name: button.name,
|
581
|
+
value: button.value
|
582
|
+
});
|
583
|
+
}
|
584
|
+
setData(form, 'ujs:formnovalidate-button', button.formNoValidate);
|
585
|
+
setData(form, 'ujs:submit-button-formaction', button.getAttribute('formaction'));
|
586
|
+
return setData(form, 'ujs:submit-button-formmethod', button.getAttribute('formmethod'));
|
587
|
+
};
|
588
|
+
|
589
|
+
Rails.handleMetaClick = function(e) {
|
590
|
+
var data, link, metaClick, method;
|
591
|
+
link = this;
|
592
|
+
method = (link.getAttribute('data-method') || 'GET').toUpperCase();
|
593
|
+
data = link.getAttribute('data-params');
|
594
|
+
metaClick = e.metaKey || e.ctrlKey;
|
595
|
+
if (metaClick && method === 'GET' && !data) {
|
596
|
+
return e.stopImmediatePropagation();
|
597
|
+
}
|
598
|
+
};
|
583
599
|
|
584
|
-
}).call(this);
|
585
|
-
(function() {
|
586
|
-
|
600
|
+
}).call(this);
|
601
|
+
(function() {
|
602
|
+
var $, CSRFProtection, delegate, disableElement, enableElement, fire, formSubmitButtonClick, getData, handleConfirm, handleDisabledElement, handleMetaClick, handleMethod, handleRemote, refreshCSRFTokens;
|
587
603
|
|
588
|
-
|
604
|
+
fire = Rails.fire, delegate = Rails.delegate, getData = Rails.getData, $ = Rails.$, refreshCSRFTokens = Rails.refreshCSRFTokens, CSRFProtection = Rails.CSRFProtection, enableElement = Rails.enableElement, disableElement = Rails.disableElement, handleDisabledElement = Rails.handleDisabledElement, handleConfirm = Rails.handleConfirm, handleRemote = Rails.handleRemote, formSubmitButtonClick = Rails.formSubmitButtonClick, handleMetaClick = Rails.handleMetaClick, handleMethod = Rails.handleMethod;
|
589
605
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
606
|
+
if ((typeof jQuery !== "undefined" && jQuery !== null) && !jQuery.rails) {
|
607
|
+
jQuery.rails = Rails;
|
608
|
+
jQuery.ajaxPrefilter(function(options, originalOptions, xhr) {
|
609
|
+
if (!options.crossDomain) {
|
610
|
+
return CSRFProtection(xhr);
|
611
|
+
}
|
612
|
+
});
|
595
613
|
}
|
596
|
-
});
|
597
|
-
}
|
598
614
|
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
615
|
+
Rails.start = function() {
|
616
|
+
if (window._rails_loaded) {
|
617
|
+
throw new Error('rails-ujs has already been loaded!');
|
618
|
+
}
|
619
|
+
window.addEventListener('pageshow', function() {
|
620
|
+
$(Rails.formEnableSelector).forEach(function(el) {
|
621
|
+
if (getData(el, 'ujs:disabled')) {
|
622
|
+
return enableElement(el);
|
623
|
+
}
|
624
|
+
});
|
625
|
+
return $(Rails.linkDisableSelector).forEach(function(el) {
|
626
|
+
if (getData(el, 'ujs:disabled')) {
|
627
|
+
return enableElement(el);
|
628
|
+
}
|
629
|
+
});
|
630
|
+
});
|
631
|
+
delegate(document, Rails.linkDisableSelector, 'ajax:complete', enableElement);
|
632
|
+
delegate(document, Rails.linkDisableSelector, 'ajax:stopped', enableElement);
|
633
|
+
delegate(document, Rails.buttonDisableSelector, 'ajax:complete', enableElement);
|
634
|
+
delegate(document, Rails.buttonDisableSelector, 'ajax:stopped', enableElement);
|
635
|
+
delegate(document, Rails.linkClickSelector, 'click', handleDisabledElement);
|
636
|
+
delegate(document, Rails.linkClickSelector, 'click', handleConfirm);
|
637
|
+
delegate(document, Rails.linkClickSelector, 'click', handleMetaClick);
|
638
|
+
delegate(document, Rails.linkClickSelector, 'click', disableElement);
|
639
|
+
delegate(document, Rails.linkClickSelector, 'click', handleRemote);
|
640
|
+
delegate(document, Rails.linkClickSelector, 'click', handleMethod);
|
641
|
+
delegate(document, Rails.buttonClickSelector, 'click', handleDisabledElement);
|
642
|
+
delegate(document, Rails.buttonClickSelector, 'click', handleConfirm);
|
643
|
+
delegate(document, Rails.buttonClickSelector, 'click', disableElement);
|
644
|
+
delegate(document, Rails.buttonClickSelector, 'click', handleRemote);
|
645
|
+
delegate(document, Rails.inputChangeSelector, 'change', handleDisabledElement);
|
646
|
+
delegate(document, Rails.inputChangeSelector, 'change', handleConfirm);
|
647
|
+
delegate(document, Rails.inputChangeSelector, 'change', handleRemote);
|
648
|
+
delegate(document, Rails.formSubmitSelector, 'submit', handleDisabledElement);
|
649
|
+
delegate(document, Rails.formSubmitSelector, 'submit', handleConfirm);
|
650
|
+
delegate(document, Rails.formSubmitSelector, 'submit', handleRemote);
|
651
|
+
delegate(document, Rails.formSubmitSelector, 'submit', function(e) {
|
652
|
+
return setTimeout((function() {
|
653
|
+
return disableElement(e);
|
654
|
+
}), 13);
|
655
|
+
});
|
656
|
+
delegate(document, Rails.formSubmitSelector, 'ajax:send', disableElement);
|
657
|
+
delegate(document, Rails.formSubmitSelector, 'ajax:complete', enableElement);
|
658
|
+
delegate(document, Rails.formInputClickSelector, 'click', handleDisabledElement);
|
659
|
+
delegate(document, Rails.formInputClickSelector, 'click', handleConfirm);
|
660
|
+
delegate(document, Rails.formInputClickSelector, 'click', formSubmitButtonClick);
|
661
|
+
document.addEventListener('DOMContentLoaded', refreshCSRFTokens);
|
662
|
+
return window._rails_loaded = true;
|
663
|
+
};
|
664
|
+
|
665
|
+
if (window.Rails === Rails && fire(document, 'rails:attachBindings')) {
|
666
|
+
Rails.start();
|
667
|
+
}
|
668
|
+
|
669
|
+
}).call(this);
|
670
|
+
}).call(this);
|
647
671
|
|
672
|
+
if (typeof module === "object" && module.exports) {
|
673
|
+
module.exports = Rails;
|
674
|
+
} else if (typeof define === "function" && define.amd) {
|
675
|
+
define(Rails);
|
676
|
+
}
|
648
677
|
}).call(this);
|