rails-backbone-generator 0.0.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +15 -0
  2. data/README.md +18 -15
  3. data/lib/generators/backbone_generator.rb +1 -1
  4. data/lib/generators/{backbone → backbone_generator}/collection_generator.rb +9 -9
  5. data/lib/generators/{backbone → backbone_generator}/model_generator.rb +10 -10
  6. data/lib/generators/{backbone → backbone_generator}/namespace_generator.rb +18 -21
  7. data/lib/generators/{backbone → backbone_generator}/setup_generator.rb +25 -24
  8. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/Guardfile +4 -4
  9. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/app/assets/javascripts/application.js +7 -7
  10. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/app/assets/javascripts/shared/core_extentions/collections_extentions.coffee +8 -8
  11. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/app/assets/javascripts/shared/helpers/.gitkeep +0 -0
  12. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/app/assets/javascripts/shared/utils/.gitkeep +0 -0
  13. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/spec/javascripts/fixtures/.gitkeep +0 -0
  14. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/spec/javascripts/helpers/association_helpers.coffee +0 -0
  15. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/spec/javascripts/helpers/common_helpers.coffee +2 -2
  16. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/spec/javascripts/helpers/fake_host.coffee +3 -3
  17. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/spec/javascripts/helpers/headless_webkit_helper.coffee +0 -0
  18. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/spec/javascripts/support/jasmine.yml +0 -0
  19. data/lib/generators/backbone_generator/setup_generator/templates/vendor/assets/javascripts/backbone/backbone-1.1.0.js +1581 -0
  20. data/lib/generators/{backbone/setup_generator/templates/vendor/assets/javascripts/backbone/backbone-bind-to-1.0.0.coffee → backbone_generator/setup_generator/templates/vendor/assets/javascripts/backbone/backbone-bind-to-1.1.0.coffee} +23 -12
  21. data/lib/generators/backbone_generator/setup_generator/templates/vendor/assets/javascripts/backbone/backbone-handlebars-1.0.0.coffee +89 -0
  22. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/vendor/assets/javascripts/backbone/backbone-query-0.2.3.coffee +0 -0
  23. data/lib/generators/backbone_generator/setup_generator/templates/vendor/assets/javascripts/backbone/backbone-relational-0.8.6.js +1943 -0
  24. data/lib/generators/backbone_generator/setup_generator/templates/vendor/assets/javascripts/backbone/handlebars-1.1.2.js +2595 -0
  25. data/lib/generators/{backbone/setup_generator/templates/vendor/assets/javascripts/backbone/underscore-1.3.3.js → backbone_generator/setup_generator/templates/vendor/assets/javascripts/backbone/underscore-1.5.2.js} +529 -312
  26. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/vendor/assets/javascripts/browser_compatibility/json2.js +5 -6
  27. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/vendor/assets/javascripts/browser_compatibility/localstorage-polyfill.js +12 -12
  28. data/lib/generators/{backbone/setup_generator/templates/vendor/assets/javascripts/jquery/jquery-1.8.0.js → backbone_generator/setup_generator/templates/vendor/assets/javascripts/jquery/jquery-1.10.2.js} +4633 -4071
  29. data/lib/generators/backbone_generator/setup_generator/templates/vendor/assets/javascripts/jquery/jquery-ui-1.10.3.js +15003 -0
  30. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/vendor/assets/javascripts/jquery/jquery.easing-1.3.js +33 -33
  31. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/vendor/assets/javascripts/jquery/jquery_ujs.js +162 -136
  32. data/lib/generators/{backbone → backbone_generator}/setup_generator/templates/vendor/assets/javascripts/testing/backbone-factory.js +4 -4
  33. data/lib/generators/backbone_generator/setup_generator/templates/vendor/assets/javascripts/testing/jasmine-jquery-1.5.93.js +700 -0
  34. data/lib/generators/backbone_generator/setup_generator/templates/vendor/assets/javascripts/testing/jasmine-sinon-0.2.1.js +43 -0
  35. data/lib/generators/backbone_generator/setup_generator/templates/vendor/assets/javascripts/testing/mock-ajax-2.0.0.js +264 -0
  36. data/lib/generators/{backbone/setup_generator/templates/vendor/assets/javascripts/testing/sinon-1.4.2.js → backbone_generator/setup_generator/templates/vendor/assets/javascripts/testing/sinon-1.7.3.js} +686 -477
  37. data/lib/generators/{backbone → backbone_generator}/templates/app/assets/javascripts/%namespace%.coffee.tt +0 -1
  38. data/lib/generators/{backbone → backbone_generator}/templates/app/assets/javascripts/%namespace%/collections/%collection_name%.coffee.tt +0 -0
  39. data/lib/generators/{backbone → backbone_generator}/templates/app/assets/javascripts/%namespace%/collections/.gitkeep +0 -0
  40. data/lib/generators/{backbone → backbone_generator}/templates/app/assets/javascripts/%namespace%/models/%model_name%.coffee.tt +2 -2
  41. data/lib/generators/{backbone → backbone_generator}/templates/app/assets/javascripts/%namespace%/models/.gitkeep +0 -0
  42. data/lib/generators/{backbone → backbone_generator}/templates/app/assets/javascripts/%namespace%/routes/.gitkeep +0 -0
  43. data/lib/generators/{backbone → backbone_generator}/templates/app/assets/javascripts/%namespace%/templates/.gitkeep +0 -0
  44. data/lib/generators/{backbone → backbone_generator}/templates/app/assets/javascripts/%namespace%/views/.gitkeep +0 -0
  45. data/lib/generators/{backbone → backbone_generator}/templates/spec/javascripts/%namespace%/collections/%collection_name%_spec.coffee.tt +1 -1
  46. data/lib/generators/{backbone → backbone_generator}/templates/spec/javascripts/%namespace%/collections/.gitkeep +0 -0
  47. data/lib/generators/{backbone → backbone_generator}/templates/spec/javascripts/%namespace%/factories/%model_name%_factory.coffee.tt +1 -1
  48. data/lib/generators/{backbone → backbone_generator}/templates/spec/javascripts/%namespace%/factories/.gitkeep +0 -0
  49. data/lib/generators/{backbone → backbone_generator}/templates/spec/javascripts/%namespace%/models/%model_name%_spec.coffee.tt +3 -4
  50. data/lib/generators/{backbone → backbone_generator}/templates/spec/javascripts/%namespace%/models/.gitkeep +0 -0
  51. data/lib/generators/{backbone → backbone_generator}/templates/spec/javascripts/%namespace%/views/.gitkeep +0 -0
  52. data/lib/rails_backbone_generator/version.rb +1 -1
  53. metadata +53 -59
  54. data/lib/generators/backbone/setup_generator/templates/vendor/assets/javascripts/backbone/backbone-0.9.2.js +0 -1431
  55. data/lib/generators/backbone/setup_generator/templates/vendor/assets/javascripts/backbone/backbone-handlebars-1.0.0.js +0 -121
  56. data/lib/generators/backbone/setup_generator/templates/vendor/assets/javascripts/backbone/backbone-relational-0.6.0.js +0 -1687
  57. data/lib/generators/backbone/setup_generator/templates/vendor/assets/javascripts/backbone/handlebars-1.0.rc.1.js +0 -1920
  58. data/lib/generators/backbone/setup_generator/templates/vendor/assets/javascripts/jquery/jquery-ui.min.js +0 -17
  59. data/lib/generators/backbone/setup_generator/templates/vendor/assets/javascripts/testing/jasmine-jquery-1.3.1.js +0 -288
  60. data/lib/generators/backbone/setup_generator/templates/vendor/assets/javascripts/testing/jasmine-sinon.js +0 -43
  61. data/lib/generators/backbone/setup_generator/templates/vendor/assets/javascripts/testing/mock-ajax.js +0 -207
@@ -5,33 +5,33 @@
5
5
  * to offer multiple easing options
6
6
  *
7
7
  * TERMS OF USE - jQuery Easing
8
- *
9
- * Open source under the BSD License.
10
- *
8
+ *
9
+ * Open source under the BSD License.
10
+ *
11
11
  * Copyright © 2008 George McGinley Smith
12
12
  * All rights reserved.
13
- *
14
- * Redistribution and use in source and binary forms, with or without modification,
13
+ *
14
+ * Redistribution and use in source and binary forms, with or without modification,
15
15
  * are permitted provided that the following conditions are met:
16
- *
17
- * Redistributions of source code must retain the above copyright notice, this list of
16
+ *
17
+ * Redistributions of source code must retain the above copyright notice, this list of
18
18
  * conditions and the following disclaimer.
19
- * Redistributions in binary form must reproduce the above copyright notice, this list
20
- * of conditions and the following disclaimer in the documentation and/or other materials
19
+ * Redistributions in binary form must reproduce the above copyright notice, this list
20
+ * of conditions and the following disclaimer in the documentation and/or other materials
21
21
  * provided with the distribution.
22
- *
23
- * Neither the name of the author nor the names of contributors may be used to endorse
22
+ *
23
+ * Neither the name of the author nor the names of contributors may be used to endorse
24
24
  * or promote products derived from this software without specific prior written permission.
25
- *
26
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
25
+ *
26
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
27
27
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28
28
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29
29
  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
30
  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
31
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32
32
  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34
- * OF THE POSSIBILITY OF SUCH DAMAGE.
33
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
35
35
  *
36
36
  */
37
37
 
@@ -147,7 +147,7 @@ jQuery.extend( jQuery.easing,
147
147
  return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
148
148
  },
149
149
  easeInOutBack: function (x, t, b, c, d, s) {
150
- if (s == undefined) s = 1.70158;
150
+ if (s == undefined) s = 1.70158;
151
151
  if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
152
152
  return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
153
153
  },
@@ -174,32 +174,32 @@ jQuery.extend( jQuery.easing,
174
174
  /*
175
175
  *
176
176
  * TERMS OF USE - EASING EQUATIONS
177
- *
178
- * Open source under the BSD License.
179
- *
177
+ *
178
+ * Open source under the BSD License.
179
+ *
180
180
  * Copyright © 2001 Robert Penner
181
181
  * All rights reserved.
182
- *
183
- * Redistribution and use in source and binary forms, with or without modification,
182
+ *
183
+ * Redistribution and use in source and binary forms, with or without modification,
184
184
  * are permitted provided that the following conditions are met:
185
- *
186
- * Redistributions of source code must retain the above copyright notice, this list of
185
+ *
186
+ * Redistributions of source code must retain the above copyright notice, this list of
187
187
  * conditions and the following disclaimer.
188
- * Redistributions in binary form must reproduce the above copyright notice, this list
189
- * of conditions and the following disclaimer in the documentation and/or other materials
188
+ * Redistributions in binary form must reproduce the above copyright notice, this list
189
+ * of conditions and the following disclaimer in the documentation and/or other materials
190
190
  * provided with the distribution.
191
- *
192
- * Neither the name of the author nor the names of contributors may be used to endorse
191
+ *
192
+ * Neither the name of the author nor the names of contributors may be used to endorse
193
193
  * or promote products derived from this software without specific prior written permission.
194
- *
195
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
194
+ *
195
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
196
196
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
197
197
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
198
198
  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
199
199
  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
200
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
200
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
201
201
  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
202
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
203
- * OF THE POSSIBILITY OF SUCH DAMAGE.
202
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
203
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
204
204
  *
205
205
  */
@@ -2,64 +2,39 @@
2
2
 
3
3
  /**
4
4
  * Unobtrusive scripting adapter for jQuery
5
- *
6
- * Requires jQuery 1.6.0 or later.
7
5
  * https://github.com/rails/jquery-ujs
8
-
9
- * Uploading file using rails.js
10
- * =============================
11
- *
12
- * By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
13
- * in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
14
- *
15
- * The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
16
- *
17
- * Ex:
18
- * $('form').live('ajax:aborted:file', function(event, elements){
19
- * // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
20
- * // Returning false in this handler tells rails.js to disallow standard form submission
21
- * return false;
22
- * });
23
- *
24
- * The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
25
- *
26
- * Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
27
- * techniques like the iframe method to upload the file instead.
28
6
  *
29
- * Required fields in rails.js
30
- * ===========================
7
+ * Requires jQuery 1.7.0 or later.
31
8
  *
32
- * If any blank required inputs (required="required") are detected in the remote form, the whole form submission
33
- * is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
9
+ * Released under the MIT license
34
10
  *
35
- * The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
36
- *
37
- * !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
38
- * get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
39
- *
40
- * Ex:
41
- * $('form').live('ajax:aborted:required', function(event, elements){
42
- * // Returning false in this handler tells rails.js to submit the form anyway.
43
- * // The blank required inputs are passed to this function in `elements`.
44
- * return ! confirm("Would you like to submit the form with missing info?");
45
- * });
46
11
  */
47
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
+ if ( $.rails !== undefined ) {
16
+ $.error('jquery-ujs has already been loaded!');
17
+ }
18
+
48
19
  // Shorthand to make it a little easier to call public rails functions from within rails.js
49
20
  var rails;
21
+ var $document = $(document);
50
22
 
51
23
  $.rails = rails = {
52
24
  // Link elements bound by jquery-ujs
53
25
  linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
54
26
 
55
- // Select elements bound by jquery-ujs
56
- inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
27
+ // Button elements bound by jquery-ujs
28
+ buttonClickSelector: 'button[data-remote]',
29
+
30
+ // Select elements bound by jquery-ujs
31
+ inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
57
32
 
58
33
  // Form elements bound by jquery-ujs
59
34
  formSubmitSelector: 'form',
60
35
 
61
36
  // Form input elements bound by jquery-ujs
62
- formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not(button[type])',
37
+ formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',
63
38
 
64
39
  // Form input elements disabled during form submission
65
40
  disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
@@ -71,7 +46,7 @@
71
46
  requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
72
47
 
73
48
  // Form file input elements
74
- fileInputSelector: 'input:file',
49
+ fileInputSelector: 'input[type=file]',
75
50
 
76
51
  // Link onClick disable selector with possible reenable after remote submission
77
52
  linkDisableSelector: 'a[data-disable-with]',
@@ -99,14 +74,20 @@
99
74
  return $.ajax(options);
100
75
  },
101
76
 
77
+ // Default way to get an element's href. May be overridden at $.rails.href.
78
+ href: function(element) {
79
+ return element.attr('href');
80
+ },
81
+
102
82
  // Submits "remote" forms and links with ajax
103
83
  handleRemote: function(element) {
104
- var method, url, data,
105
- crossDomain = element.data('cross-domain') || null,
106
- dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType),
107
- options;
84
+ var method, url, data, elCrossDomain, crossDomain, withCredentials, dataType, options;
108
85
 
109
86
  if (rails.fire(element, 'ajax:before')) {
87
+ elCrossDomain = element.data('cross-domain');
88
+ crossDomain = elCrossDomain === undefined ? null : elCrossDomain;
89
+ withCredentials = element.data('with-credentials') || null;
90
+ dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
110
91
 
111
92
  if (element.is('form')) {
112
93
  method = element.attr('method');
@@ -123,14 +104,19 @@
123
104
  url = element.data('url');
124
105
  data = element.serialize();
125
106
  if (element.data('params')) data = data + "&" + element.data('params');
107
+ } else if (element.is(rails.buttonClickSelector)) {
108
+ method = element.data('method') || 'get';
109
+ url = element.data('url');
110
+ data = element.serialize();
111
+ if (element.data('params')) data = data + "&" + element.data('params');
126
112
  } else {
127
113
  method = element.data('method');
128
- url = element.attr('href');
114
+ url = rails.href(element);
129
115
  data = element.data('params') || null;
130
116
  }
131
117
 
132
118
  options = {
133
- type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain,
119
+ type: method || 'GET', data: data, dataType: dataType,
134
120
  // stopping the "ajax:beforeSend" event will cancel the ajax request
135
121
  beforeSend: function(xhr, settings) {
136
122
  if (settings.dataType === undefined) {
@@ -146,33 +132,47 @@
146
132
  },
147
133
  error: function(xhr, status, error) {
148
134
  element.trigger('ajax:error', [xhr, status, error]);
149
- }
135
+ },
136
+ crossDomain: crossDomain
150
137
  };
138
+
139
+ // There is no withCredentials for IE6-8 when
140
+ // "Enable native XMLHTTP support" is disabled
141
+ if (withCredentials) {
142
+ options.xhrFields = {
143
+ withCredentials: withCredentials
144
+ };
145
+ }
146
+
151
147
  // Only pass url to `ajax` options if not blank
152
148
  if (url) { options.url = url; }
153
149
 
154
- rails.ajax(options);
150
+ var jqxhr = rails.ajax(options);
151
+ element.trigger('ajax:send', jqxhr);
152
+ return jqxhr;
153
+ } else {
154
+ return false;
155
155
  }
156
156
  },
157
157
 
158
158
  // Handles "data-method" on links such as:
159
159
  // <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
160
160
  handleMethod: function(link) {
161
- var href = link.attr('href'),
161
+ var href = rails.href(link),
162
162
  method = link.data('method'),
163
163
  target = link.attr('target'),
164
- csrf_token = $('meta[name=csrf-token]').attr('content'),
165
- csrf_param = $('meta[name=csrf-param]').attr('content'),
164
+ csrfToken = $('meta[name=csrf-token]').attr('content'),
165
+ csrfParam = $('meta[name=csrf-param]').attr('content'),
166
166
  form = $('<form method="post" action="' + href + '"></form>'),
167
- metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
167
+ metadataInput = '<input name="_method" value="' + method + '" type="hidden" />';
168
168
 
169
- if (csrf_param !== undefined && csrf_token !== undefined) {
170
- metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
169
+ if (csrfParam !== undefined && csrfToken !== undefined) {
170
+ metadataInput += '<input name="' + csrfParam + '" value="' + csrfToken + '" type="hidden" />';
171
171
  }
172
172
 
173
173
  if (target) { form.attr('target', target); }
174
174
 
175
- form.hide().append(metadata_input).appendTo('body');
175
+ form.hide().append(metadataInput).appendTo('body');
176
176
  form.submit();
177
177
  },
178
178
 
@@ -226,12 +226,21 @@
226
226
 
227
227
  // Helper function which checks for blank inputs in a form that match the specified CSS selector
228
228
  blankInputs: function(form, specifiedSelector, nonBlank) {
229
- var inputs = $(), input,
230
- selector = specifiedSelector || 'input,textarea';
231
- form.find(selector).each(function() {
229
+ var inputs = $(), input, valueToCheck,
230
+ selector = specifiedSelector || 'input,textarea',
231
+ allInputs = form.find(selector);
232
+
233
+ allInputs.each(function() {
232
234
  input = $(this);
233
- // Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
234
- if (nonBlank ? input.val() : !input.val()) {
235
+ valueToCheck = input.is('input[type=checkbox],input[type=radio]') ? input.is(':checked') : input.val();
236
+ // If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey
237
+ if (!valueToCheck === !nonBlank) {
238
+
239
+ // Don't count unchecked required radio if other radio with same name is checked
240
+ if (input.is('input[type=radio]') && allInputs.filter('input[type=radio]:checked[name="' + input.attr('name') + '"]').length) {
241
+ return true; // Skip to next input
242
+ }
243
+
235
244
  inputs = inputs.add(input);
236
245
  }
237
246
  });
@@ -250,25 +259,13 @@
250
259
  return false;
251
260
  },
252
261
 
253
- // find all the submit events directly bound to the form and
254
- // manually invoke them. If anyone returns false then stop the loop
255
- callFormSubmitBindings: function(form) {
256
- var events = form.data('events'), continuePropagation = true;
257
- if (events !== undefined && events['submit'] !== undefined) {
258
- $.each(events['submit'], function(i, obj){
259
- if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data);
260
- });
261
- }
262
- return continuePropagation;
263
- },
264
-
265
262
  // replace element's html with the 'data-disable-with' after storing original html
266
263
  // and prevent clicking on it
267
264
  disableElement: function(element) {
268
265
  element.data('ujs:enable-with', element.html()); // store enabled state
269
266
  element.html(element.data('disable-with')); // set to disabled state
270
267
  element.bind('click.railsDisable', function(e) { // prevent further clicking
271
- return rails.stopEverything(e)
268
+ return rails.stopEverything(e);
272
269
  });
273
270
  },
274
271
 
@@ -276,93 +273,122 @@
276
273
  enableElement: function(element) {
277
274
  if (element.data('ujs:enable-with') !== undefined) {
278
275
  element.html(element.data('ujs:enable-with')); // set to old enabled state
279
- // this should be element.removeData('ujs:enable-with')
280
- // but, there is currently a bug in jquery which makes hyphenated data attributes not get removed
281
- element.data('ujs:enable-with', false); // clean up cache
276
+ element.removeData('ujs:enable-with'); // clean up cache
282
277
  }
283
278
  element.unbind('click.railsDisable'); // enable element
284
279
  }
285
280
 
286
281
  };
287
282
 
288
- $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
283
+ if (rails.fire($document, 'rails:attachBindings')) {
289
284
 
290
- $(rails.linkDisableSelector).live('ajax:complete', function() {
291
- rails.enableElement($(this));
292
- });
285
+ $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
293
286
 
294
- $(rails.linkClickSelector).live('click.rails', function(e) {
295
- var link = $(this), method = link.data('method'), data = link.data('params');
296
- if (!rails.allowAction(link)) return rails.stopEverything(e);
287
+ $document.delegate(rails.linkDisableSelector, 'ajax:complete', function() {
288
+ rails.enableElement($(this));
289
+ });
297
290
 
298
- if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
291
+ $document.delegate(rails.linkClickSelector, 'click.rails', function(e) {
292
+ var link = $(this), method = link.data('method'), data = link.data('params'), metaClick = e.metaKey || e.ctrlKey;
293
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
299
294
 
300
- if (link.data('remote') !== undefined) {
301
- if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
302
- rails.handleRemote(link);
295
+ if (!metaClick && link.is(rails.linkDisableSelector)) rails.disableElement(link);
296
+
297
+ if (link.data('remote') !== undefined) {
298
+ if (metaClick && (!method || method === 'GET') && !data) { return true; }
299
+
300
+ var handleRemote = rails.handleRemote(link);
301
+ // response from rails.handleRemote() will either be false or a deferred object promise.
302
+ if (handleRemote === false) {
303
+ rails.enableElement(link);
304
+ } else {
305
+ handleRemote.error( function() { rails.enableElement(link); } );
306
+ }
307
+ return false;
308
+
309
+ } else if (link.data('method')) {
310
+ rails.handleMethod(link);
311
+ return false;
312
+ }
313
+ });
314
+
315
+ $document.delegate(rails.buttonClickSelector, 'click.rails', function(e) {
316
+ var button = $(this);
317
+ if (!rails.allowAction(button)) return rails.stopEverything(e);
318
+
319
+ rails.handleRemote(button);
303
320
  return false;
304
- } else if (link.data('method')) {
305
- rails.handleMethod(link);
321
+ });
322
+
323
+ $document.delegate(rails.inputChangeSelector, 'change.rails', function(e) {
324
+ var link = $(this);
325
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
326
+
327
+ rails.handleRemote(link);
306
328
  return false;
307
- }
308
- });
329
+ });
309
330
 
310
- $(rails.inputChangeSelector).live('change.rails', function(e) {
311
- var link = $(this);
312
- if (!rails.allowAction(link)) return rails.stopEverything(e);
331
+ $document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
332
+ var form = $(this),
333
+ remote = form.data('remote') !== undefined,
334
+ blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
335
+ nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
313
336
 
314
- rails.handleRemote(link);
315
- return false;
316
- });
337
+ if (!rails.allowAction(form)) return rails.stopEverything(e);
317
338
 
318
- $(rails.formSubmitSelector).live('submit.rails', function(e) {
319
- var form = $(this),
320
- remote = form.data('remote') !== undefined,
321
- blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
322
- nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
339
+ // skip other logic when required values are missing or file upload is present
340
+ if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
341
+ return rails.stopEverything(e);
342
+ }
323
343
 
324
- if (!rails.allowAction(form)) return rails.stopEverything(e);
344
+ if (remote) {
345
+ if (nonBlankFileInputs) {
346
+ // slight timeout so that the submit button gets properly serialized
347
+ // (make it easy for event handler to serialize form without disabled values)
348
+ setTimeout(function(){ rails.disableFormElements(form); }, 13);
349
+ var aborted = rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
325
350
 
326
- // skip other logic when required values are missing or file upload is present
327
- if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
328
- return rails.stopEverything(e);
329
- }
351
+ // re-enable form elements if event bindings return false (canceling normal form submission)
352
+ if (!aborted) { setTimeout(function(){ rails.enableFormElements(form); }, 13); }
330
353
 
331
- if (remote) {
332
- if (nonBlankFileInputs) {
333
- return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
334
- }
354
+ return aborted;
355
+ }
335
356
 
336
- // If browser does not support submit bubbling, then this live-binding will be called before direct
337
- // bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
338
- if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e);
357
+ rails.handleRemote(form);
358
+ return false;
339
359
 
340
- rails.handleRemote(form);
341
- return false;
342
- } else {
343
- // slight timeout so that the submit button gets properly serialized
344
- setTimeout(function(){ rails.disableFormElements(form); }, 13);
345
- }
346
- });
360
+ } else {
361
+ // slight timeout so that the submit button gets properly serialized
362
+ setTimeout(function(){ rails.disableFormElements(form); }, 13);
363
+ }
364
+ });
365
+
366
+ $document.delegate(rails.formInputClickSelector, 'click.rails', function(event) {
367
+ var button = $(this);
347
368
 
348
- $(rails.formInputClickSelector).live('click.rails', function(event) {
349
- var button = $(this);
369
+ if (!rails.allowAction(button)) return rails.stopEverything(event);
350
370
 
351
- if (!rails.allowAction(button)) return rails.stopEverything(event);
371
+ // register the pressed submit button
372
+ var name = button.attr('name'),
373
+ data = name ? {name:name, value:button.val()} : null;
352
374
 
353
- // register the pressed submit button
354
- var name = button.attr('name'),
355
- data = name ? {name:name, value:button.val()} : null;
375
+ button.closest('form').data('ujs:submit-button', data);
376
+ });
356
377
 
357
- button.closest('form').data('ujs:submit-button', data);
358
- });
378
+ $document.delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
379
+ if (this == event.target) rails.disableFormElements($(this));
380
+ });
359
381
 
360
- $(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) {
361
- if (this == event.target) rails.disableFormElements($(this));
362
- });
382
+ $document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
383
+ if (this == event.target) rails.enableFormElements($(this));
384
+ });
363
385
 
364
- $(rails.formSubmitSelector).live('ajax:complete.rails', function(event) {
365
- if (this == event.target) rails.enableFormElements($(this));
366
- });
386
+ $(function(){
387
+ // making sure that all forms have actual up-to-date token(cached forms contain old one)
388
+ var csrfToken = $('meta[name=csrf-token]').attr('content');
389
+ var csrfParam = $('meta[name=csrf-param]').attr('content');
390
+ $('form input[name="' + csrfParam + '"]').val(csrfToken);
391
+ });
392
+ }
367
393
 
368
394
  })( jQuery );