better_frame 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/better_frame/jquery-ujs.js +550 -0
- data/lib/better_frame/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 549e7be66adb95f25f3a663c80ac18381c60f1d0
|
4
|
+
data.tar.gz: ace5baea310f70880907a709c209b90d9aaf53b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f36b35c1a3d1d58ad3de68e548d8add5c599c90ff2e566fbec08de2892197eb5eac886ef36d0b9e0922c27d5e6a0d832ed4a06c6d13e22735cfbbfe0f22e64b6
|
7
|
+
data.tar.gz: 5ff9687d6f713b57e7e4ceeeb5835fe453a1c1566ff1b47c21974bdb6149e6cd6920a9c07b8f4a2d330794a2f1fed169079aa1c5555b1ce4d6894ac1781e10c0
|
@@ -0,0 +1,550 @@
|
|
1
|
+
(function($, undefined) {
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Unobtrusive scripting adapter for jQuery
|
5
|
+
* https://github.com/rails/jquery-ujs
|
6
|
+
*
|
7
|
+
* Requires jQuery 1.8.0 or later.
|
8
|
+
*
|
9
|
+
* Released under the MIT license
|
10
|
+
*
|
11
|
+
*/
|
12
|
+
|
13
|
+
// Cut down on the number of issues from people inadvertently including jquery_ujs twice
|
14
|
+
// by detecting and raising an error when it happens.
|
15
|
+
'use strict';
|
16
|
+
|
17
|
+
if ( $.rails !== undefined ) {
|
18
|
+
$.error('jquery-ujs has already been loaded!');
|
19
|
+
}
|
20
|
+
|
21
|
+
// Shorthand to make it a little easier to call public rails functions from within rails.js
|
22
|
+
var rails;
|
23
|
+
var $document = $(document);
|
24
|
+
|
25
|
+
$.rails = rails = {
|
26
|
+
// Link elements bound by jquery-ujs
|
27
|
+
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]:not([disabled]), a[data-disable-with], a[data-disable]',
|
28
|
+
|
29
|
+
// Button elements bound by jquery-ujs
|
30
|
+
buttonClickSelector: 'button[data-remote]:not([form]):not(form button), button[data-confirm]:not([form]):not(form button)',
|
31
|
+
|
32
|
+
// Select elements bound by jquery-ujs
|
33
|
+
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
|
34
|
+
|
35
|
+
// Form elements bound by jquery-ujs
|
36
|
+
formSubmitSelector: 'form',
|
37
|
+
|
38
|
+
// Form input elements bound by jquery-ujs
|
39
|
+
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])',
|
40
|
+
|
41
|
+
// Form input elements disabled during form submission
|
42
|
+
disableSelector: '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',
|
43
|
+
|
44
|
+
// Form input elements re-enabled after form submission
|
45
|
+
enableSelector: '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',
|
46
|
+
|
47
|
+
// Form required input elements
|
48
|
+
requiredInputSelector: 'input[name][required]:not([disabled]), textarea[name][required]:not([disabled])',
|
49
|
+
|
50
|
+
// Form file input elements
|
51
|
+
fileInputSelector: 'input[name][type=file]:not([disabled])',
|
52
|
+
|
53
|
+
// Link onClick disable selector with possible reenable after remote submission
|
54
|
+
linkDisableSelector: 'a[data-disable-with], a[data-disable]',
|
55
|
+
|
56
|
+
// Button onClick disable selector with possible reenable after remote submission
|
57
|
+
buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]',
|
58
|
+
|
59
|
+
// Up-to-date Cross-Site Request Forgery token
|
60
|
+
csrfToken: function() {
|
61
|
+
return $('meta[name=csrf-token]').attr('content');
|
62
|
+
},
|
63
|
+
|
64
|
+
// URL param that must contain the CSRF token
|
65
|
+
csrfParam: function() {
|
66
|
+
return $('meta[name=csrf-param]').attr('content');
|
67
|
+
},
|
68
|
+
|
69
|
+
// Make sure that every Ajax request sends the CSRF token
|
70
|
+
CSRFProtection: function(xhr) {
|
71
|
+
var token = rails.csrfToken();
|
72
|
+
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
|
73
|
+
},
|
74
|
+
|
75
|
+
// Make sure that all forms have actual up-to-date tokens (cached forms contain old ones)
|
76
|
+
refreshCSRFTokens: function(){
|
77
|
+
$('form input[name="' + rails.csrfParam() + '"]').val(rails.csrfToken());
|
78
|
+
},
|
79
|
+
|
80
|
+
// Triggers an event on an element and returns false if the event result is false
|
81
|
+
fire: function(obj, name, data) {
|
82
|
+
var event = $.Event(name);
|
83
|
+
obj.trigger(event, data);
|
84
|
+
return event.result !== false;
|
85
|
+
},
|
86
|
+
|
87
|
+
// Default confirm dialog, may be overridden with custom confirm dialog in $.rails.confirm
|
88
|
+
confirm: function(message) {
|
89
|
+
return confirm(message);
|
90
|
+
},
|
91
|
+
|
92
|
+
// Default ajax function, may be overridden with custom function in $.rails.ajax
|
93
|
+
ajax: function(options) {
|
94
|
+
return $.ajax(options);
|
95
|
+
},
|
96
|
+
|
97
|
+
// Default way to get an element's href. May be overridden at $.rails.href.
|
98
|
+
href: function(element) {
|
99
|
+
return element[0].href;
|
100
|
+
},
|
101
|
+
|
102
|
+
// Checks "data-remote" if true to handle the request through a XHR request.
|
103
|
+
isRemote: function(element) {
|
104
|
+
return element.data('remote') !== undefined && element.data('remote') !== false;
|
105
|
+
},
|
106
|
+
|
107
|
+
// Submits "remote" forms and links with ajax
|
108
|
+
handleRemote: function(element) {
|
109
|
+
var method, url, data, withCredentials, dataType, options;
|
110
|
+
|
111
|
+
if (rails.fire(element, 'ajax:before')) {
|
112
|
+
withCredentials = element.data('with-credentials') || null;
|
113
|
+
dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
|
114
|
+
|
115
|
+
if (element.is('form')) {
|
116
|
+
method = element.data('ujs:submit-button-formmethod') || element.attr('method');
|
117
|
+
url = element.data('ujs:submit-button-formaction') || element.attr('action');
|
118
|
+
data = $(element[0]).serializeArray();
|
119
|
+
// memoized value from clicked submit button
|
120
|
+
var button = element.data('ujs:submit-button');
|
121
|
+
if (button) {
|
122
|
+
data.push(button);
|
123
|
+
element.data('ujs:submit-button', null);
|
124
|
+
}
|
125
|
+
element.data('ujs:submit-button-formmethod', null);
|
126
|
+
element.data('ujs:submit-button-formaction', null);
|
127
|
+
} else if (element.is(rails.inputChangeSelector)) {
|
128
|
+
method = element.data('method');
|
129
|
+
url = element.data('url');
|
130
|
+
data = element.serialize();
|
131
|
+
if (element.data('params')) data = data + '&' + element.data('params');
|
132
|
+
} else if (element.is(rails.buttonClickSelector)) {
|
133
|
+
method = element.data('method') || 'get';
|
134
|
+
url = element.data('url');
|
135
|
+
data = element.serialize();
|
136
|
+
if (element.data('params')) data = data + '&' + element.data('params');
|
137
|
+
} else {
|
138
|
+
method = element.data('method');
|
139
|
+
url = rails.href(element);
|
140
|
+
data = element.data('params') || null;
|
141
|
+
}
|
142
|
+
|
143
|
+
options = {
|
144
|
+
type: method || 'GET', data: data, dataType: dataType,
|
145
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
146
|
+
beforeSend: function(xhr, settings) {
|
147
|
+
if (settings.dataType === undefined) {
|
148
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
149
|
+
}
|
150
|
+
if (rails.fire(element, 'ajax:beforeSend', [xhr, settings])) {
|
151
|
+
element.trigger('ajax:send', xhr);
|
152
|
+
} else {
|
153
|
+
return false;
|
154
|
+
}
|
155
|
+
},
|
156
|
+
success: function(data, status, xhr) {
|
157
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
158
|
+
},
|
159
|
+
complete: function(xhr, status) {
|
160
|
+
element.trigger('ajax:complete', [xhr, status]);
|
161
|
+
},
|
162
|
+
error: function(xhr, status, error) {
|
163
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
164
|
+
},
|
165
|
+
crossDomain: rails.isCrossDomain(url)
|
166
|
+
};
|
167
|
+
|
168
|
+
// There is no withCredentials for IE6-8 when
|
169
|
+
// "Enable native XMLHTTP support" is disabled
|
170
|
+
if (withCredentials) {
|
171
|
+
options.xhrFields = {
|
172
|
+
withCredentials: withCredentials
|
173
|
+
};
|
174
|
+
}
|
175
|
+
|
176
|
+
// If the remote is called with get leave the query string to ?query=...
|
177
|
+
// Else: Send the form as form data, to be able to send files with ajax
|
178
|
+
if (method.toLowerCase() !== "get") {
|
179
|
+
options.processData = false;
|
180
|
+
options.contentType = false;
|
181
|
+
options.data = new FormData(element[0]);
|
182
|
+
}
|
183
|
+
|
184
|
+
// Only pass url to `ajax` options if not blank
|
185
|
+
if (url) { options.url = url; }
|
186
|
+
|
187
|
+
return rails.ajax(options);
|
188
|
+
} else {
|
189
|
+
return false;
|
190
|
+
}
|
191
|
+
},
|
192
|
+
|
193
|
+
// Determines if the request is a cross domain request.
|
194
|
+
isCrossDomain: function(url) {
|
195
|
+
var originAnchor = document.createElement('a');
|
196
|
+
originAnchor.href = location.href;
|
197
|
+
var urlAnchor = document.createElement('a');
|
198
|
+
|
199
|
+
try {
|
200
|
+
urlAnchor.href = url;
|
201
|
+
// This is a workaround to a IE bug.
|
202
|
+
urlAnchor.href = urlAnchor.href;
|
203
|
+
|
204
|
+
// If URL protocol is false or is a string containing a single colon
|
205
|
+
// *and* host are false, assume it is not a cross-domain request
|
206
|
+
// (should only be the case for IE7 and IE compatibility mode).
|
207
|
+
// Otherwise, evaluate protocol and host of the URL against the origin
|
208
|
+
// protocol and host.
|
209
|
+
return !(((!urlAnchor.protocol || urlAnchor.protocol === ':') && !urlAnchor.host) ||
|
210
|
+
(originAnchor.protocol + '//' + originAnchor.host ===
|
211
|
+
urlAnchor.protocol + '//' + urlAnchor.host));
|
212
|
+
} catch (e) {
|
213
|
+
// If there is an error parsing the URL, assume it is crossDomain.
|
214
|
+
return true;
|
215
|
+
}
|
216
|
+
},
|
217
|
+
|
218
|
+
// Handles "data-method" on links such as:
|
219
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
220
|
+
handleMethod: function(link) {
|
221
|
+
var href = rails.href(link),
|
222
|
+
method = link.data('method'),
|
223
|
+
target = link.attr('target'),
|
224
|
+
csrfToken = rails.csrfToken(),
|
225
|
+
csrfParam = rails.csrfParam(),
|
226
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
227
|
+
metadataInput = '<input name="_method" value="' + method + '" type="hidden" />';
|
228
|
+
|
229
|
+
if (csrfParam !== undefined && csrfToken !== undefined && !rails.isCrossDomain(href)) {
|
230
|
+
metadataInput += '<input name="' + csrfParam + '" value="' + csrfToken + '" type="hidden" />';
|
231
|
+
}
|
232
|
+
|
233
|
+
if (target) { form.attr('target', target); }
|
234
|
+
|
235
|
+
form.hide().append(metadataInput).appendTo('body');
|
236
|
+
form.submit();
|
237
|
+
},
|
238
|
+
|
239
|
+
// Helper function that returns form elements that match the specified CSS selector
|
240
|
+
// If form is actually a "form" element this will return associated elements outside the from that have
|
241
|
+
// the html form attribute set
|
242
|
+
formElements: function(form, selector) {
|
243
|
+
return form.is('form') ? $(form[0].elements).filter(selector) : form.find(selector);
|
244
|
+
},
|
245
|
+
|
246
|
+
/* Disables form elements:
|
247
|
+
- Caches element value in 'ujs:enable-with' data store
|
248
|
+
- Replaces element text with value of 'data-disable-with' attribute
|
249
|
+
- Sets disabled property to true
|
250
|
+
*/
|
251
|
+
disableFormElements: function(form) {
|
252
|
+
rails.formElements(form, rails.disableSelector).each(function() {
|
253
|
+
rails.disableFormElement($(this));
|
254
|
+
});
|
255
|
+
},
|
256
|
+
|
257
|
+
disableFormElement: function(element) {
|
258
|
+
var method, replacement;
|
259
|
+
|
260
|
+
method = element.is('button') ? 'html' : 'val';
|
261
|
+
replacement = element.data('disable-with');
|
262
|
+
|
263
|
+
if (replacement !== undefined) {
|
264
|
+
element.data('ujs:enable-with', element[method]());
|
265
|
+
element[method](replacement);
|
266
|
+
}
|
267
|
+
|
268
|
+
element.prop('disabled', true);
|
269
|
+
element.data('ujs:disabled', true);
|
270
|
+
},
|
271
|
+
|
272
|
+
/* Re-enables disabled form elements:
|
273
|
+
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
|
274
|
+
- Sets disabled property to false
|
275
|
+
*/
|
276
|
+
enableFormElements: function(form) {
|
277
|
+
rails.formElements(form, rails.enableSelector).each(function() {
|
278
|
+
rails.enableFormElement($(this));
|
279
|
+
});
|
280
|
+
},
|
281
|
+
|
282
|
+
enableFormElement: function(element) {
|
283
|
+
var method = element.is('button') ? 'html' : 'val';
|
284
|
+
if (element.data('ujs:enable-with') !== undefined) {
|
285
|
+
element[method](element.data('ujs:enable-with'));
|
286
|
+
element.removeData('ujs:enable-with'); // clean up cache
|
287
|
+
}
|
288
|
+
element.prop('disabled', false);
|
289
|
+
element.removeData('ujs:disabled');
|
290
|
+
},
|
291
|
+
|
292
|
+
/* For 'data-confirm' attribute:
|
293
|
+
- Fires `confirm` event
|
294
|
+
- Shows the confirmation dialog
|
295
|
+
- Fires the `confirm:complete` event
|
296
|
+
|
297
|
+
Returns `true` if no function stops the chain and user chose yes; `false` otherwise.
|
298
|
+
Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
|
299
|
+
Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
|
300
|
+
return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
|
301
|
+
*/
|
302
|
+
allowAction: function(element) {
|
303
|
+
var message = element.data('confirm'),
|
304
|
+
answer = false, callback;
|
305
|
+
if (!message) { return true; }
|
306
|
+
|
307
|
+
if (rails.fire(element, 'confirm')) {
|
308
|
+
try {
|
309
|
+
answer = rails.confirm(message);
|
310
|
+
} catch (e) {
|
311
|
+
(console.error || console.log).call(console, e.stack || e);
|
312
|
+
}
|
313
|
+
callback = rails.fire(element, 'confirm:complete', [answer]);
|
314
|
+
}
|
315
|
+
return answer && callback;
|
316
|
+
},
|
317
|
+
|
318
|
+
// Helper function which checks for blank inputs in a form that match the specified CSS selector
|
319
|
+
blankInputs: function(form, specifiedSelector, nonBlank) {
|
320
|
+
var foundInputs = $(),
|
321
|
+
input,
|
322
|
+
valueToCheck,
|
323
|
+
radiosForNameWithNoneSelected,
|
324
|
+
radioName,
|
325
|
+
selector = specifiedSelector || 'input,textarea',
|
326
|
+
requiredInputs = form.find(selector),
|
327
|
+
checkedRadioButtonNames = {};
|
328
|
+
|
329
|
+
requiredInputs.each(function() {
|
330
|
+
input = $(this);
|
331
|
+
if (input.is('input[type=radio]')) {
|
332
|
+
|
333
|
+
// Don't count unchecked required radio as blank if other radio with same name is checked,
|
334
|
+
// regardless of whether same-name radio input has required attribute or not. The spec
|
335
|
+
// states https://www.w3.org/TR/html5/forms.html#the-required-attribute
|
336
|
+
radioName = input.attr('name');
|
337
|
+
|
338
|
+
// Skip if we've already seen the radio with this name.
|
339
|
+
if (!checkedRadioButtonNames[radioName]) {
|
340
|
+
|
341
|
+
// If none checked
|
342
|
+
if (form.find('input[type=radio]:checked[name="' + radioName + '"]').length === 0) {
|
343
|
+
radiosForNameWithNoneSelected = form.find(
|
344
|
+
'input[type=radio][name="' + radioName + '"]');
|
345
|
+
foundInputs = foundInputs.add(radiosForNameWithNoneSelected);
|
346
|
+
}
|
347
|
+
|
348
|
+
// We only need to check each name once.
|
349
|
+
checkedRadioButtonNames[radioName] = radioName;
|
350
|
+
}
|
351
|
+
} else {
|
352
|
+
valueToCheck = input.is('input[type=checkbox],input[type=radio]') ? input.is(':checked') : !!input.val();
|
353
|
+
if (valueToCheck === nonBlank) {
|
354
|
+
foundInputs = foundInputs.add(input);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
});
|
358
|
+
return foundInputs.length ? foundInputs : false;
|
359
|
+
},
|
360
|
+
|
361
|
+
// Helper function which checks for non-blank inputs in a form that match the specified CSS selector
|
362
|
+
nonBlankInputs: function(form, specifiedSelector) {
|
363
|
+
return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
|
364
|
+
},
|
365
|
+
|
366
|
+
// Helper function, needed to provide consistent behavior in IE
|
367
|
+
stopEverything: function(e) {
|
368
|
+
$(e.target).trigger('ujs:everythingStopped');
|
369
|
+
e.stopImmediatePropagation();
|
370
|
+
return false;
|
371
|
+
},
|
372
|
+
|
373
|
+
// Replace element's html with the 'data-disable-with' after storing original html
|
374
|
+
// and prevent clicking on it
|
375
|
+
disableElement: function(element) {
|
376
|
+
var replacement = element.data('disable-with');
|
377
|
+
|
378
|
+
if (replacement !== undefined) {
|
379
|
+
element.data('ujs:enable-with', element.html()); // store enabled state
|
380
|
+
element.html(replacement);
|
381
|
+
}
|
382
|
+
|
383
|
+
element.bind('click.railsDisable', function(e) { // prevent further clicking
|
384
|
+
return rails.stopEverything(e);
|
385
|
+
});
|
386
|
+
element.data('ujs:disabled', true);
|
387
|
+
},
|
388
|
+
|
389
|
+
// Restore element to its original state which was disabled by 'disableElement' above
|
390
|
+
enableElement: function(element) {
|
391
|
+
if (element.data('ujs:enable-with') !== undefined) {
|
392
|
+
element.html(element.data('ujs:enable-with')); // set to old enabled state
|
393
|
+
element.removeData('ujs:enable-with'); // clean up cache
|
394
|
+
}
|
395
|
+
element.unbind('click.railsDisable'); // enable element
|
396
|
+
element.removeData('ujs:disabled');
|
397
|
+
}
|
398
|
+
};
|
399
|
+
|
400
|
+
if (rails.fire($document, 'rails:attachBindings')) {
|
401
|
+
|
402
|
+
$.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
|
403
|
+
|
404
|
+
// This event works the same as the load event, except that it fires every
|
405
|
+
// time the page is loaded.
|
406
|
+
//
|
407
|
+
// See https://github.com/rails/jquery-ujs/issues/357
|
408
|
+
// See https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching
|
409
|
+
$(window).on('pageshow.rails', function () {
|
410
|
+
$($.rails.enableSelector).each(function () {
|
411
|
+
var element = $(this);
|
412
|
+
|
413
|
+
if (element.data('ujs:disabled')) {
|
414
|
+
$.rails.enableFormElement(element);
|
415
|
+
}
|
416
|
+
});
|
417
|
+
|
418
|
+
$($.rails.linkDisableSelector).each(function () {
|
419
|
+
var element = $(this);
|
420
|
+
|
421
|
+
if (element.data('ujs:disabled')) {
|
422
|
+
$.rails.enableElement(element);
|
423
|
+
}
|
424
|
+
});
|
425
|
+
});
|
426
|
+
|
427
|
+
$document.delegate(rails.linkDisableSelector, 'ajax:complete', function() {
|
428
|
+
rails.enableElement($(this));
|
429
|
+
});
|
430
|
+
|
431
|
+
$document.delegate(rails.buttonDisableSelector, 'ajax:complete', function() {
|
432
|
+
rails.enableFormElement($(this));
|
433
|
+
});
|
434
|
+
|
435
|
+
$document.delegate(rails.linkClickSelector, 'click.rails', function(e) {
|
436
|
+
var link = $(this), method = link.data('method'), data = link.data('params'), metaClick = e.metaKey || e.ctrlKey;
|
437
|
+
if (!rails.allowAction(link)) return rails.stopEverything(e);
|
438
|
+
|
439
|
+
if (!metaClick && link.is(rails.linkDisableSelector)) rails.disableElement(link);
|
440
|
+
|
441
|
+
if (rails.isRemote(link)) {
|
442
|
+
if (metaClick && (!method || method === 'GET') && !data) { return true; }
|
443
|
+
|
444
|
+
var handleRemote = rails.handleRemote(link);
|
445
|
+
// Response from rails.handleRemote() will either be false or a deferred object promise.
|
446
|
+
if (handleRemote === false) {
|
447
|
+
rails.enableElement(link);
|
448
|
+
} else {
|
449
|
+
handleRemote.fail( function() { rails.enableElement(link); } );
|
450
|
+
}
|
451
|
+
return false;
|
452
|
+
|
453
|
+
} else if (method) {
|
454
|
+
rails.handleMethod(link);
|
455
|
+
return false;
|
456
|
+
}
|
457
|
+
});
|
458
|
+
|
459
|
+
$document.delegate(rails.buttonClickSelector, 'click.rails', function(e) {
|
460
|
+
var button = $(this);
|
461
|
+
|
462
|
+
if (!rails.allowAction(button) || !rails.isRemote(button)) return rails.stopEverything(e);
|
463
|
+
|
464
|
+
if (button.is(rails.buttonDisableSelector)) rails.disableFormElement(button);
|
465
|
+
|
466
|
+
var handleRemote = rails.handleRemote(button);
|
467
|
+
// Response from rails.handleRemote() will either be false or a deferred object promise.
|
468
|
+
if (handleRemote === false) {
|
469
|
+
rails.enableFormElement(button);
|
470
|
+
} else {
|
471
|
+
handleRemote.fail( function() { rails.enableFormElement(button); } );
|
472
|
+
}
|
473
|
+
return false;
|
474
|
+
});
|
475
|
+
|
476
|
+
$document.delegate(rails.inputChangeSelector, 'change.rails', function(e) {
|
477
|
+
var link = $(this);
|
478
|
+
if (!rails.allowAction(link) || !rails.isRemote(link)) return rails.stopEverything(e);
|
479
|
+
|
480
|
+
rails.handleRemote(link);
|
481
|
+
return false;
|
482
|
+
});
|
483
|
+
|
484
|
+
$document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
|
485
|
+
var form = $(this),
|
486
|
+
remote = rails.isRemote(form),
|
487
|
+
blankRequiredInputs,
|
488
|
+
nonBlankFileInputs;
|
489
|
+
|
490
|
+
if (!rails.allowAction(form)) return rails.stopEverything(e);
|
491
|
+
|
492
|
+
// Skip other logic when required values are missing or file upload is present
|
493
|
+
if (form.attr('novalidate') === undefined) {
|
494
|
+
if (form.data('ujs:formnovalidate-button') === undefined) {
|
495
|
+
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector, false);
|
496
|
+
if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
|
497
|
+
return rails.stopEverything(e);
|
498
|
+
}
|
499
|
+
} else {
|
500
|
+
// Clear the formnovalidate in case the next button click is not on a formnovalidate button
|
501
|
+
// Not strictly necessary to do here, since it is also reset on each button click, but just to be certain
|
502
|
+
form.data('ujs:formnovalidate-button', undefined);
|
503
|
+
}
|
504
|
+
}
|
505
|
+
|
506
|
+
if (remote) {
|
507
|
+
rails.handleRemote(form);
|
508
|
+
return false;
|
509
|
+
|
510
|
+
} else {
|
511
|
+
// Slight timeout so that the submit button gets properly serialized
|
512
|
+
setTimeout(function(){ rails.disableFormElements(form); }, 13);
|
513
|
+
}
|
514
|
+
});
|
515
|
+
|
516
|
+
$document.delegate(rails.formInputClickSelector, 'click.rails', function(event) {
|
517
|
+
var button = $(this);
|
518
|
+
|
519
|
+
if (!rails.allowAction(button)) return rails.stopEverything(event);
|
520
|
+
|
521
|
+
// Register the pressed submit button
|
522
|
+
var name = button.attr('name'),
|
523
|
+
data = name ? {name:name, value:button.val()} : null;
|
524
|
+
|
525
|
+
var form = button.closest('form');
|
526
|
+
if (form.length === 0) {
|
527
|
+
form = $('#' + button.attr('form'));
|
528
|
+
}
|
529
|
+
form.data('ujs:submit-button', data);
|
530
|
+
|
531
|
+
// Save attributes from button
|
532
|
+
form.data('ujs:formnovalidate-button', button.attr('formnovalidate'));
|
533
|
+
form.data('ujs:submit-button-formaction', button.attr('formaction'));
|
534
|
+
form.data('ujs:submit-button-formmethod', button.attr('formmethod'));
|
535
|
+
});
|
536
|
+
|
537
|
+
$document.delegate(rails.formSubmitSelector, 'ajax:send.rails', function(event) {
|
538
|
+
if (this === event.target) rails.disableFormElements($(this));
|
539
|
+
});
|
540
|
+
|
541
|
+
$document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
|
542
|
+
if (this === event.target) rails.enableFormElements($(this));
|
543
|
+
});
|
544
|
+
|
545
|
+
$(function(){
|
546
|
+
rails.refreshCSRFTokens();
|
547
|
+
});
|
548
|
+
}
|
549
|
+
|
550
|
+
})( jQuery );
|
data/lib/better_frame/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_frame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yves Siegrist
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- Rakefile
|
86
86
|
- app/assets/javascripts/better_frame/application.js
|
87
87
|
- app/assets/javascripts/better_frame/better_frame.js
|
88
|
+
- app/assets/javascripts/better_frame/jquery-ujs.js
|
88
89
|
- app/assets/stylesheets/better_frame/application.css
|
89
90
|
- app/controllers/better_frame/api_controller.rb
|
90
91
|
- app/controllers/better_frame/application_controller.rb
|