wagn 1.14.4 → 1.14.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/app/controllers/card_controller.rb +4 -3
  4. data/db/bootstrap/card_actions.yml +597 -583
  5. data/db/bootstrap/card_acts.yml +2 -2
  6. data/db/bootstrap/card_changes.yml +297 -248
  7. data/db/bootstrap/card_references.yml +3111 -1284
  8. data/db/bootstrap/cards.yml +1067 -1022
  9. data/db/migrate_core_cards/20141208132416_partial_reference_type.rb +7 -0
  10. data/db/migrate_core_cards/20141208162106_add_ace_script.rb +12 -0
  11. data/db/migrate_core_cards/20141230204340_uri_codename.rb +13 -0
  12. data/db/version_core_cards.txt +1 -1
  13. data/features/history.feature +2 -1
  14. data/features/layouts.feature +4 -0
  15. data/features/navbox.feature +1 -0
  16. data/features/step_definitions/wagn_steps.rb +6 -1
  17. data/features/support/env.rb +1 -1
  18. data/lib/card/env.rb +1 -1
  19. data/lib/card/format.rb +35 -48
  20. data/lib/card/loader.rb +9 -9
  21. data/lib/card/mailer.rb +0 -2
  22. data/lib/card/query.rb +8 -8
  23. data/lib/card/query/{card_spec.rb → card_clause.rb} +42 -42
  24. data/lib/card/query/{spec.rb → clause.rb} +3 -3
  25. data/lib/card/query/ref_clause.rb +47 -0
  26. data/lib/card/query/value_clause.rb +65 -0
  27. data/lib/card/reference.rb +11 -20
  28. data/lib/card/set.rb +6 -6
  29. data/lib/card/set_pattern.rb +5 -1
  30. data/lib/wagn/commands.rb +28 -14
  31. data/lib/wagn/config/environments/test.rb +3 -0
  32. data/lib/wagn/generators/wagn/templates/Gemfile +6 -0
  33. data/lib/wagn/generators/wagn/templates/Rakefile +1 -0
  34. data/lib/wagn/generators/wagn/templates/config/application.rb +1 -0
  35. data/lib/wagn/generators/wagn/templates/spec/javascripts/support/deck_jasmine.yml +56 -0
  36. data/lib/wagn/generators/wagn/templates/spec/javascripts/support/wagn_jasmine.yml +69 -0
  37. data/lib/wagn/generators/wagn/wagn_generator.rb +19 -2
  38. data/lib/wagn/migration.rb +10 -0
  39. data/lib/wagn/spec_helper.rb +2 -0
  40. data/lib/wagn/tasks/wagn.rake +9 -16
  41. data/mod/01_core/chunk/link.rb +2 -2
  42. data/mod/01_core/chunk/uri.rb +4 -4
  43. data/mod/01_core/format/html_format.rb +43 -280
  44. data/mod/01_core/set/all/active_card.rb +2 -0
  45. data/mod/01_core/set/all/collection.rb +19 -1
  46. data/mod/01_core/set/all/fetch.rb +5 -0
  47. data/mod/01_core/set/all/initialize.rb +1 -1
  48. data/mod/01_core/set/all/references.rb +25 -8
  49. data/mod/01_core/set/all/templating.rb +1 -1
  50. data/mod/01_core/set/all/tracked_attributes.rb +1 -1
  51. data/mod/01_core/set/all/type.rb +1 -1
  52. data/mod/01_core/set/all/utils.rb +1 -0
  53. data/mod/01_core/set_pattern/07_type_plus_right.rb +2 -1
  54. data/mod/01_core/spec/format/html_format_spec.rb +0 -2
  55. data/mod/01_core/spec/set/all/initialize_spec.rb +4 -4
  56. data/mod/01_core/spec/set/all/notify_spec.rb +9 -9
  57. data/mod/02_basic_types/set/type/pointer.rb +19 -8
  58. data/mod/03_machines/lib/javascript/ace.js +18204 -0
  59. data/mod/03_machines/lib/javascript/jquery-ui.js +13109 -11440
  60. data/mod/03_machines/lib/javascript/jquery.autosize.js +52 -33
  61. data/mod/03_machines/lib/javascript/jquery.fileupload.js +10 -8
  62. data/mod/03_machines/lib/javascript/jquery.iframe-transport.js +44 -16
  63. data/mod/03_machines/lib/javascript/jquery.js +4 -9473
  64. data/mod/03_machines/lib/javascript/jquery_ujs.js +156 -116
  65. data/mod/03_machines/lib/javascript/jquerymobile.js +14890 -8236
  66. data/mod/03_machines/lib/javascript/theme-textmate.js +130 -0
  67. data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +50 -10
  68. data/mod/03_machines/set/self/script_ace.rb +8 -0
  69. data/mod/03_machines/set/type/coffee_script.rb +1 -1
  70. data/mod/03_machines/set/type/css.rb +0 -2
  71. data/mod/03_machines/set/type/java_script.rb +1 -1
  72. data/mod/03_machines/spec/lib/{machine_spec.rb → shared_machine_examples.rb} +0 -0
  73. data/mod/03_machines/spec/lib/{machine_input_spec.rb → shared_machine_input_examples.rb} +0 -0
  74. data/mod/03_machines/spec/set/type/scss_spec.rb +2 -2
  75. data/mod/04_settings/set/right/comment.rb +2 -2
  76. data/mod/04_settings/set/type/setting.rb +2 -2
  77. data/mod/04_settings/spec/set/right/structure_spec.rb +2 -2
  78. data/mod/04_settings/spec/set/right/style_spec.rb +1 -1
  79. data/mod/05_email/set/type/email_template.rb +3 -2
  80. data/mod/05_standard/set/all/all_css.rb +1 -1
  81. data/mod/05_standard/set/all/all_js.rb +1 -1
  82. data/mod/05_standard/set/all/attach.rb +8 -7
  83. data/mod/05_standard/set/all/base.rb +6 -34
  84. data/mod/05_standard/set/all/editing.rb +145 -0
  85. data/mod/05_standard/set/all/error.rb +203 -0
  86. data/mod/05_standard/set/all/follow.rb +2 -2
  87. data/mod/05_standard/set/all/form.rb +211 -0
  88. data/mod/05_standard/set/all/header.rb +60 -0
  89. data/mod/05_standard/set/all/history.rb +3 -3
  90. data/mod/05_standard/set/all/links.rb +101 -0
  91. data/mod/05_standard/set/all/rich_html.rb +14 -392
  92. data/mod/05_standard/set/all/wrapper.rb +74 -0
  93. data/mod/05_standard/set/right/account.rb +1 -2
  94. data/mod/05_standard/set/rstar/rules.rb +5 -5
  95. data/mod/05_standard/set/self/account_links.rb +8 -4
  96. data/mod/05_standard/set/self/head.rb +3 -3
  97. data/mod/05_standard/set/self/signin.rb +5 -3
  98. data/mod/05_standard/set/type/search_type.rb +25 -25
  99. data/mod/05_standard/set/type/set.rb +2 -2
  100. data/mod/05_standard/set/type/signup.rb +0 -2
  101. data/mod/05_standard/set/type/uri.rb +11 -0
  102. data/mod/05_standard/spec/set/all/rich_html_spec.rb +6 -6
  103. data/mod/05_standard/spec/set/all/rss_spec.rb +1 -1
  104. data/mod/05_standard/spec/set/type/signup_spec.rb +0 -1
  105. data/mod/05_standard/spec/set/type/uri_spec.rb +41 -0
  106. data/public/assets/ace/mode-coffee.js +1 -0
  107. data/public/assets/ace/mode-css.js +1 -0
  108. data/public/assets/ace/mode-html.js +1 -0
  109. data/public/assets/ace/mode-javascript.js +1 -0
  110. data/public/assets/ace/mode-json.js +1 -0
  111. data/public/assets/ace/mode-scss.js +922 -0
  112. data/public/assets/ace/theme-github.js +98 -0
  113. data/public/assets/ace/theme-textmate.js +1 -0
  114. data/public/assets/ace/worker-coffee.js +1 -0
  115. data/public/assets/ace/worker-css.js +1 -0
  116. data/public/assets/ace/worker-html.js +1 -0
  117. data/public/assets/ace/worker-javascript.js +1 -0
  118. data/public/assets/ace/worker-json.js +1 -0
  119. data/spec/controllers/card_controller_spec.rb +0 -1
  120. data/spec/controllers/location_spec.rb +0 -2
  121. data/spec/javascripts/helpers/jasmine-jquery.js +812 -0
  122. data/spec/javascripts/support/jasmine.yml +8 -6
  123. data/spec/javascripts/support/jasmine_config.rb +1 -1
  124. data/spec/javascripts/support/jasmine_runner.rb +1 -1
  125. data/spec/javascripts/wagn_spec.coffee +2 -0
  126. data/spec/lib/card/content_spec.rb +28 -6
  127. data/spec/lib/card/format_spec.rb +62 -15
  128. data/spec/lib/card/reference_spec.rb +3 -3
  129. data/spec/spec_helper.rb +2 -2
  130. data/test/fixtures/card_actions.yml +1260 -1239
  131. data/test/fixtures/card_acts.yml +347 -341
  132. data/test/fixtures/card_changes.yml +2345 -2276
  133. data/test/fixtures/card_references.yml +4098 -1606
  134. data/test/fixtures/cards.yml +1950 -1887
  135. metadata +39 -13
  136. data/lib/card/query/ref_spec.rb +0 -37
  137. data/lib/card/query/value_spec.rb +0 -65
  138. data/lib/wagn/location.rb +0 -93
  139. data/spec/javascripts/helpers/jasmine-config.js +0 -2
  140. data/spec/javascripts/helpers/jasmine-jquery-1.3.1.js +0 -295
@@ -2,66 +2,30 @@
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
- *
29
- * Required fields in rails.js
30
- * ===========================
31
- *
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.
34
6
  *
35
- * The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
7
+ * Requires jQuery 1.8.0 or later.
36
8
  *
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.
9
+ * Released under the MIT license
39
10
  *
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
 
48
- // Cut down on the number if issues from people inadvertently including jquery_ujs twice
13
+ // Cut down on the number of issues from people inadvertently including jquery_ujs twice
49
14
  // by detecting and raising an error when it happens.
50
- var alreadyInitialized = function() {
51
- var events = $._data(document, 'events');
52
- return events && events.click && $.grep(events.click, function(e) { return e.namespace === 'rails'; }).length;
53
- }
54
-
55
- if ( alreadyInitialized() ) {
15
+ if ( $.rails !== undefined ) {
56
16
  $.error('jquery-ujs has already been loaded!');
57
17
  }
58
18
 
59
19
  // Shorthand to make it a little easier to call public rails functions from within rails.js
60
20
  var rails;
21
+ var $document = $(document);
61
22
 
62
23
  $.rails = rails = {
63
24
  // Link elements bound by jquery-ujs
64
- linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
25
+ linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with], a[data-disable]',
26
+
27
+ // Button elements bound by jquery-ujs
28
+ buttonClickSelector: 'button[data-remote]:not(form button), button[data-confirm]:not(form button)',
65
29
 
66
30
  // Select elements bound by jquery-ujs
67
31
  inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
@@ -70,22 +34,25 @@
70
34
  formSubmitSelector: 'form',
71
35
 
72
36
  // Form input elements bound by jquery-ujs
73
- formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',
37
+ 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])',
74
38
 
75
39
  // Form input elements disabled during form submission
76
- disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
40
+ 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',
77
41
 
78
42
  // Form input elements re-enabled after form submission
79
- enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
43
+ 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',
80
44
 
81
45
  // Form required input elements
82
46
  requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
83
47
 
84
48
  // Form file input elements
85
- fileInputSelector: 'input:file',
49
+ fileInputSelector: 'input[type=file]',
86
50
 
87
51
  // Link onClick disable selector with possible reenable after remote submission
88
- linkDisableSelector: 'a[data-disable-with]',
52
+ linkDisableSelector: 'a[data-disable-with], a[data-disable]',
53
+
54
+ // Button onClick disable selector with possible reenable after remote submission
55
+ buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]',
89
56
 
90
57
  // Make sure that every Ajax request sends the CSRF token
91
58
  CSRFProtection: function(xhr) {
@@ -93,6 +60,13 @@
93
60
  if (token) xhr.setRequestHeader('X-CSRF-Token', token);
94
61
  },
95
62
 
63
+ // making sure that all forms have actual up-to-date token(cached forms contain old one)
64
+ refreshCSRFTokens: function(){
65
+ var csrfToken = $('meta[name=csrf-token]').attr('content');
66
+ var csrfParam = $('meta[name=csrf-param]').attr('content');
67
+ $('form input[name="' + csrfParam + '"]').val(csrfToken);
68
+ },
69
+
96
70
  // Triggers an event on an element and returns false if the event result is false
97
71
  fire: function(obj, name, data) {
98
72
  var event = $.Event(name);
@@ -140,6 +114,11 @@
140
114
  url = element.data('url');
141
115
  data = element.serialize();
142
116
  if (element.data('params')) data = data + "&" + element.data('params');
117
+ } else if (element.is(rails.buttonClickSelector)) {
118
+ method = element.data('method') || 'get';
119
+ url = element.data('url');
120
+ data = element.serialize();
121
+ if (element.data('params')) data = data + "&" + element.data('params');
143
122
  } else {
144
123
  method = element.data('method');
145
124
  url = rails.href(element);
@@ -153,7 +132,11 @@
153
132
  if (settings.dataType === undefined) {
154
133
  xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
155
134
  }
156
- return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
135
+ if (rails.fire(element, 'ajax:beforeSend', [xhr, settings])) {
136
+ element.trigger('ajax:send', xhr);
137
+ } else {
138
+ return false;
139
+ }
157
140
  },
158
141
  success: function(data, status, xhr) {
159
142
  element.trigger('ajax:success', [data, status, xhr]);
@@ -164,17 +147,21 @@
164
147
  error: function(xhr, status, error) {
165
148
  element.trigger('ajax:error', [xhr, status, error]);
166
149
  },
167
- xhrFields: {
168
- withCredentials: withCredentials
169
- },
170
150
  crossDomain: crossDomain
171
151
  };
152
+
153
+ // There is no withCredentials for IE6-8 when
154
+ // "Enable native XMLHTTP support" is disabled
155
+ if (withCredentials) {
156
+ options.xhrFields = {
157
+ withCredentials: withCredentials
158
+ };
159
+ }
160
+
172
161
  // Only pass url to `ajax` options if not blank
173
162
  if (url) { options.url = url; }
174
163
 
175
- var jqxhr = rails.ajax(options);
176
- element.trigger('ajax:send', jqxhr);
177
- return jqxhr;
164
+ return rails.ajax(options);
178
165
  } else {
179
166
  return false;
180
167
  }
@@ -186,47 +173,69 @@
186
173
  var href = rails.href(link),
187
174
  method = link.data('method'),
188
175
  target = link.attr('target'),
189
- csrf_token = $('meta[name=csrf-token]').attr('content'),
190
- csrf_param = $('meta[name=csrf-param]').attr('content'),
176
+ csrfToken = $('meta[name=csrf-token]').attr('content'),
177
+ csrfParam = $('meta[name=csrf-param]').attr('content'),
191
178
  form = $('<form method="post" action="' + href + '"></form>'),
192
- metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
179
+ metadataInput = '<input name="_method" value="' + method + '" type="hidden" />';
193
180
 
194
- if (csrf_param !== undefined && csrf_token !== undefined) {
195
- metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
181
+ if (csrfParam !== undefined && csrfToken !== undefined) {
182
+ metadataInput += '<input name="' + csrfParam + '" value="' + csrfToken + '" type="hidden" />';
196
183
  }
197
184
 
198
185
  if (target) { form.attr('target', target); }
199
186
 
200
- form.hide().append(metadata_input).appendTo('body');
187
+ form.hide().append(metadataInput).appendTo('body');
201
188
  form.submit();
202
189
  },
203
190
 
191
+ // Helper function that returns form elements that match the specified CSS selector
192
+ // If form is actually a "form" element this will return associated elements outside the from that have
193
+ // the html form attribute set
194
+ formElements: function(form, selector) {
195
+ return form.is('form') ? $(form[0].elements).filter(selector) : form.find(selector);
196
+ },
197
+
204
198
  /* Disables form elements:
205
199
  - Caches element value in 'ujs:enable-with' data store
206
200
  - Replaces element text with value of 'data-disable-with' attribute
207
201
  - Sets disabled property to true
208
202
  */
209
203
  disableFormElements: function(form) {
210
- form.find(rails.disableSelector).each(function() {
211
- var element = $(this), method = element.is('button') ? 'html' : 'val';
212
- element.data('ujs:enable-with', element[method]());
213
- element[method](element.data('disable-with'));
214
- element.prop('disabled', true);
204
+ rails.formElements(form, rails.disableSelector).each(function() {
205
+ rails.disableFormElement($(this));
215
206
  });
216
207
  },
217
208
 
209
+ disableFormElement: function(element) {
210
+ var method, replacement;
211
+
212
+ method = element.is('button') ? 'html' : 'val';
213
+ replacement = element.data('disable-with');
214
+
215
+ element.data('ujs:enable-with', element[method]());
216
+ if (replacement !== undefined) {
217
+ element[method](replacement);
218
+ }
219
+
220
+ element.prop('disabled', true);
221
+ },
222
+
218
223
  /* Re-enables disabled form elements:
219
224
  - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
220
225
  - Sets disabled property to false
221
226
  */
222
227
  enableFormElements: function(form) {
223
- form.find(rails.enableSelector).each(function() {
224
- var element = $(this), method = element.is('button') ? 'html' : 'val';
225
- if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
226
- element.prop('disabled', false);
228
+ rails.formElements(form, rails.enableSelector).each(function() {
229
+ rails.enableFormElement($(this));
227
230
  });
228
231
  },
229
232
 
233
+ enableFormElement: function(element) {
234
+ var method = element.is('button') ? 'html' : 'val';
235
+ if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
236
+ element.prop('disabled', false);
237
+ },
238
+
230
239
  /* For 'data-confirm' attribute:
231
240
  - Fires `confirm` event
232
241
  - Shows the confirmation dialog
@@ -257,12 +266,12 @@
257
266
 
258
267
  allInputs.each(function() {
259
268
  input = $(this);
260
- valueToCheck = input.is(':checkbox,:radio') ? input.is(':checked') : input.val();
269
+ valueToCheck = input.is('input[type=checkbox],input[type=radio]') ? input.is(':checked') : input.val();
261
270
  // If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey
262
271
  if (!valueToCheck === !nonBlank) {
263
272
 
264
273
  // Don't count unchecked required radio if other radio with same name is checked
265
- if (input.is(':radio') && allInputs.filter('input:radio:checked[name="' + input.attr('name') + '"]').length) {
274
+ if (input.is('input[type=radio]') && allInputs.filter('input[type=radio]:checked[name="' + input.attr('name') + '"]').length) {
266
275
  return true; // Skip to next input
267
276
  }
268
277
 
@@ -284,23 +293,16 @@
284
293
  return false;
285
294
  },
286
295
 
287
- // find all the submit events directly bound to the form and
288
- // manually invoke them. If anyone returns false then stop the loop
289
- callFormSubmitBindings: function(form, event) {
290
- var events = form.data('events'), continuePropagation = true;
291
- if (events !== undefined && events['submit'] !== undefined) {
292
- $.each(events['submit'], function(i, obj){
293
- if (typeof obj.handler === 'function') return continuePropagation = obj.handler(event);
294
- });
295
- }
296
- return continuePropagation;
297
- },
298
-
299
296
  // replace element's html with the 'data-disable-with' after storing original html
300
297
  // and prevent clicking on it
301
298
  disableElement: function(element) {
299
+ var replacement = element.data('disable-with');
300
+
302
301
  element.data('ujs:enable-with', element.html()); // store enabled state
303
- element.html(element.data('disable-with')); // set to disabled state
302
+ if (replacement !== undefined) {
303
+ element.html(replacement);
304
+ }
305
+
304
306
  element.bind('click.railsDisable', function(e) { // prevent further clicking
305
307
  return rails.stopEverything(e);
306
308
  });
@@ -310,48 +312,89 @@
310
312
  enableElement: function(element) {
311
313
  if (element.data('ujs:enable-with') !== undefined) {
312
314
  element.html(element.data('ujs:enable-with')); // set to old enabled state
313
- // this should be element.removeData('ujs:enable-with')
314
- // but, there is currently a bug in jquery which makes hyphenated data attributes not get removed
315
- element.data('ujs:enable-with', false); // clean up cache
315
+ element.removeData('ujs:enable-with'); // clean up cache
316
316
  }
317
317
  element.unbind('click.railsDisable'); // enable element
318
318
  }
319
-
320
319
  };
321
320
 
322
- if (rails.fire($(document), 'rails:attachBindings')) {
321
+ if (rails.fire($document, 'rails:attachBindings')) {
323
322
 
324
323
  $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
325
324
 
326
- $(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() {
325
+ // This event works the same as the load event, except that it fires every
326
+ // time the page is loaded.
327
+ //
328
+ // See https://github.com/rails/jquery-ujs/issues/357
329
+ // See https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching
330
+ $(window).on("pageshow.rails", function () {
331
+ $($.rails.enableSelector).each(function () {
332
+ var element = $(this);
333
+
334
+ if (element.data("ujs:enable-with")) {
335
+ $.rails.enableFormElement(element);
336
+ }
337
+ });
338
+
339
+ $($.rails.linkDisableSelector).each(function () {
340
+ var element = $(this);
341
+
342
+ if (element.data("ujs:enable-with")) {
343
+ $.rails.enableElement(element);
344
+ }
345
+ });
346
+ });
347
+
348
+ $document.delegate(rails.linkDisableSelector, 'ajax:complete', function() {
327
349
  rails.enableElement($(this));
328
350
  });
329
351
 
330
- $(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {
331
- var link = $(this), method = link.data('method'), data = link.data('params');
352
+ $document.delegate(rails.buttonDisableSelector, 'ajax:complete', function() {
353
+ rails.enableFormElement($(this));
354
+ });
355
+
356
+ $document.delegate(rails.linkClickSelector, 'click.rails', function(e) {
357
+ var link = $(this), method = link.data('method'), data = link.data('params'), metaClick = e.metaKey || e.ctrlKey;
332
358
  if (!rails.allowAction(link)) return rails.stopEverything(e);
333
359
 
334
- if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
360
+ if (!metaClick && link.is(rails.linkDisableSelector)) rails.disableElement(link);
335
361
 
336
362
  if (link.data('remote') !== undefined) {
337
- if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
363
+ if (metaClick && (!method || method === 'GET') && !data) { return true; }
338
364
 
339
365
  var handleRemote = rails.handleRemote(link);
340
366
  // response from rails.handleRemote() will either be false or a deferred object promise.
341
367
  if (handleRemote === false) {
342
368
  rails.enableElement(link);
343
369
  } else {
344
- handleRemote.error( function() { rails.enableElement(link); } );
370
+ handleRemote.fail( function() { rails.enableElement(link); } );
345
371
  }
346
372
  return false;
347
373
 
348
- } else if (link.data('method')) {
374
+ } else if (method) {
349
375
  rails.handleMethod(link);
350
376
  return false;
351
377
  }
352
378
  });
353
379
 
354
- $(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) {
380
+ $document.delegate(rails.buttonClickSelector, 'click.rails', function(e) {
381
+ var button = $(this);
382
+
383
+ if (!rails.allowAction(button)) return rails.stopEverything(e);
384
+
385
+ if (button.is(rails.buttonDisableSelector)) rails.disableFormElement(button);
386
+
387
+ var handleRemote = rails.handleRemote(button);
388
+ // response from rails.handleRemote() will either be false or a deferred object promise.
389
+ if (handleRemote === false) {
390
+ rails.enableFormElement(button);
391
+ } else {
392
+ handleRemote.fail( function() { rails.enableFormElement(button); } );
393
+ }
394
+ return false;
395
+ });
396
+
397
+ $document.delegate(rails.inputChangeSelector, 'change.rails', function(e) {
355
398
  var link = $(this);
356
399
  if (!rails.allowAction(link)) return rails.stopEverything(e);
357
400
 
@@ -359,20 +402,24 @@
359
402
  return false;
360
403
  });
361
404
 
362
- $(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
405
+ $document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
363
406
  var form = $(this),
364
407
  remote = form.data('remote') !== undefined,
365
- blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
366
- nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
408
+ blankRequiredInputs,
409
+ nonBlankFileInputs;
367
410
 
368
411
  if (!rails.allowAction(form)) return rails.stopEverything(e);
369
412
 
370
413
  // skip other logic when required values are missing or file upload is present
371
- if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
372
- return rails.stopEverything(e);
414
+ if (form.attr('novalidate') == undefined) {
415
+ blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector);
416
+ if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
417
+ return rails.stopEverything(e);
418
+ }
373
419
  }
374
420
 
375
421
  if (remote) {
422
+ nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
376
423
  if (nonBlankFileInputs) {
377
424
  // slight timeout so that the submit button gets properly serialized
378
425
  // (make it easy for event handler to serialize form without disabled values)
@@ -385,10 +432,6 @@
385
432
  return aborted;
386
433
  }
387
434
 
388
- // If browser does not support submit bubbling, then this live-binding will be called before direct
389
- // bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
390
- if (!$.support.submitBubbles && $().jquery < '1.7' && rails.callFormSubmitBindings(form, e) === false) return rails.stopEverything(e);
391
-
392
435
  rails.handleRemote(form);
393
436
  return false;
394
437
 
@@ -398,7 +441,7 @@
398
441
  }
399
442
  });
400
443
 
401
- $(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
444
+ $document.delegate(rails.formInputClickSelector, 'click.rails', function(event) {
402
445
  var button = $(this);
403
446
 
404
447
  if (!rails.allowAction(button)) return rails.stopEverything(event);
@@ -410,19 +453,16 @@
410
453
  button.closest('form').data('ujs:submit-button', data);
411
454
  });
412
455
 
413
- $(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
456
+ $document.delegate(rails.formSubmitSelector, 'ajax:send.rails', function(event) {
414
457
  if (this == event.target) rails.disableFormElements($(this));
415
458
  });
416
459
 
417
- $(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
460
+ $document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
418
461
  if (this == event.target) rails.enableFormElements($(this));
419
462
  });
420
463
 
421
464
  $(function(){
422
- // making sure that all forms have actual up-to-date token(cached forms contain old one)
423
- csrf_token = $('meta[name=csrf-token]').attr('content');
424
- csrf_param = $('meta[name=csrf-param]').attr('content');
425
- $('form input[name="' + csrf_param + '"]').val(csrf_token);
465
+ rails.refreshCSRFTokens();
426
466
  });
427
467
  }
428
468