jquery-rails 3.0.0 → 3.1.0

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.

Potentially problematic release.


This version of jquery-rails might be problematic. Click here for more details.

@@ -18,12 +18,13 @@
18
18
 
19
19
  // Shorthand to make it a little easier to call public rails functions from within rails.js
20
20
  var rails;
21
+ var $document = $(document);
21
22
 
22
23
  $.rails = rails = {
23
24
  // Link elements bound by jquery-ujs
24
25
  linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
25
26
 
26
- // Button elements boud jquery-ujs
27
+ // Button elements bound by jquery-ujs
27
28
  buttonClickSelector: 'button[data-remote]',
28
29
 
29
30
  // Select elements bound by jquery-ujs
@@ -56,6 +57,13 @@
56
57
  if (token) xhr.setRequestHeader('X-CSRF-Token', token);
57
58
  },
58
59
 
60
+ // making sure that all forms have actual up-to-date token(cached forms contain old one)
61
+ refreshCSRFTokens: function(){
62
+ var csrfToken = $('meta[name=csrf-token]').attr('content');
63
+ var csrfParam = $('meta[name=csrf-param]').attr('content');
64
+ $('form input[name="' + csrfParam + '"]').val(csrfToken);
65
+ },
66
+
59
67
  // Triggers an event on an element and returns false if the event result is false
60
68
  fire: function(obj, name, data) {
61
69
  var event = $.Event(name);
@@ -160,18 +168,18 @@
160
168
  var href = rails.href(link),
161
169
  method = link.data('method'),
162
170
  target = link.attr('target'),
163
- csrf_token = $('meta[name=csrf-token]').attr('content'),
164
- csrf_param = $('meta[name=csrf-param]').attr('content'),
171
+ csrfToken = $('meta[name=csrf-token]').attr('content'),
172
+ csrfParam = $('meta[name=csrf-param]').attr('content'),
165
173
  form = $('<form method="post" action="' + href + '"></form>'),
166
- metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
174
+ metadataInput = '<input name="_method" value="' + method + '" type="hidden" />';
167
175
 
168
- if (csrf_param !== undefined && csrf_token !== undefined) {
169
- metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
176
+ if (csrfParam !== undefined && csrfToken !== undefined) {
177
+ metadataInput += '<input name="' + csrfParam + '" value="' + csrfToken + '" type="hidden" />';
170
178
  }
171
179
 
172
180
  if (target) { form.attr('target', target); }
173
181
 
174
- form.hide().append(metadata_input).appendTo('body');
182
+ form.hide().append(metadataInput).appendTo('body');
175
183
  form.submit();
176
184
  },
177
185
 
@@ -279,22 +287,22 @@
279
287
 
280
288
  };
281
289
 
282
- if (rails.fire($(document), 'rails:attachBindings')) {
290
+ if (rails.fire($document, 'rails:attachBindings')) {
283
291
 
284
292
  $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
285
293
 
286
- $(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() {
294
+ $document.delegate(rails.linkDisableSelector, 'ajax:complete', function() {
287
295
  rails.enableElement($(this));
288
296
  });
289
297
 
290
- $(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {
291
- var link = $(this), method = link.data('method'), data = link.data('params');
298
+ $document.delegate(rails.linkClickSelector, 'click.rails', function(e) {
299
+ var link = $(this), method = link.data('method'), data = link.data('params'), metaClick = e.metaKey || e.ctrlKey;
292
300
  if (!rails.allowAction(link)) return rails.stopEverything(e);
293
301
 
294
- if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
302
+ if (!metaClick && link.is(rails.linkDisableSelector)) rails.disableElement(link);
295
303
 
296
304
  if (link.data('remote') !== undefined) {
297
- if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
305
+ if (metaClick && (!method || method === 'GET') && !data) { return true; }
298
306
 
299
307
  var handleRemote = rails.handleRemote(link);
300
308
  // response from rails.handleRemote() will either be false or a deferred object promise.
@@ -311,7 +319,7 @@
311
319
  }
312
320
  });
313
321
 
314
- $(document).delegate(rails.buttonClickSelector, 'click.rails', function(e) {
322
+ $document.delegate(rails.buttonClickSelector, 'click.rails', function(e) {
315
323
  var button = $(this);
316
324
  if (!rails.allowAction(button)) return rails.stopEverything(e);
317
325
 
@@ -319,7 +327,7 @@
319
327
  return false;
320
328
  });
321
329
 
322
- $(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) {
330
+ $document.delegate(rails.inputChangeSelector, 'change.rails', function(e) {
323
331
  var link = $(this);
324
332
  if (!rails.allowAction(link)) return rails.stopEverything(e);
325
333
 
@@ -327,7 +335,7 @@
327
335
  return false;
328
336
  });
329
337
 
330
- $(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
338
+ $document.delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
331
339
  var form = $(this),
332
340
  remote = form.data('remote') !== undefined,
333
341
  blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
@@ -362,7 +370,7 @@
362
370
  }
363
371
  });
364
372
 
365
- $(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
373
+ $document.delegate(rails.formInputClickSelector, 'click.rails', function(event) {
366
374
  var button = $(this);
367
375
 
368
376
  if (!rails.allowAction(button)) return rails.stopEverything(event);
@@ -374,19 +382,16 @@
374
382
  button.closest('form').data('ujs:submit-button', data);
375
383
  });
376
384
 
377
- $(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
385
+ $document.delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
378
386
  if (this == event.target) rails.disableFormElements($(this));
379
387
  });
380
388
 
381
- $(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
389
+ $document.delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
382
390
  if (this == event.target) rails.enableFormElements($(this));
383
391
  });
384
392
 
385
393
  $(function(){
386
- // making sure that all forms have actual up-to-date token(cached forms contain old one)
387
- var csrf_token = $('meta[name=csrf-token]').attr('content');
388
- var csrf_param = $('meta[name=csrf-param]').attr('content');
389
- $('form input[name="' + csrf_param + '"]').val(csrf_token);
394
+ rails.refreshCSRFTokens();
390
395
  });
391
396
  }
392
397
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-29 00:00:00.000000000Z
12
+ date: 2014-01-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70123675282520 !ruby/object:Gem::Requirement
16
+ requirement: &70241023851720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '5.0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70123675282520
27
+ version_requirements: *70241023851720
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: thor
30
- requirement: &70123675289200 !ruby/object:Gem::Requirement
30
+ requirement: &70241023850600 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,7 +38,7 @@ dependencies:
38
38
  version: '2.0'
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *70123675289200
41
+ version_requirements: *70241023850600
42
42
  description: This gem provides jQuery and the jQuery-ujs driver for your Rails 3 application.
43
43
  email:
44
44
  - andre@arko.net
@@ -53,6 +53,7 @@ files:
53
53
  - LICENSE
54
54
  - README.md
55
55
  - Rakefile
56
+ - VERSIONS.md
56
57
  - jquery-rails.gemspec
57
58
  - lib/generators/jquery/install/install_generator.rb
58
59
  - lib/jquery-rails.rb
@@ -78,9 +79,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
79
  - - ! '>='
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
- segments:
82
- - 0
83
- hash: 1047937440136072684
84
82
  required_rubygems_version: !ruby/object:Gem::Requirement
85
83
  none: false
86
84
  requirements: