jquery-rails 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

@@ -1,3 +1,10 @@
1
+ ## 2.0.3 (16 August 2012)
2
+
3
+ - Updated to latest jquery-ujs
4
+ - created `rails:attachBindings` to allow for customization of $.rails object settings
5
+ - created `ajax:send` event to provide access to jqXHR object from ajax requests
6
+ - added support for `data-with-credentials`
7
+
1
8
  ## 2.0.2 (03 April 2012)
2
9
 
3
10
  - Updated to jQuery 1.7.2
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jquery-rails (2.0.0)
5
- railties (>= 3.2.0, < 5.0)
4
+ jquery-rails (2.0.3)
5
+ railties (>= 3.1.0, < 5.0)
6
6
  thor (~> 0.14)
7
7
 
8
8
  GEM
data/README.md CHANGED
@@ -4,46 +4,70 @@ jQuery! For Rails! So great.
4
4
 
5
5
  This gem provides:
6
6
 
7
- * jQuery 1.7.2
8
- * jQuery UI 1.8.18
9
- * the latest jQuery UJS adapter
10
- * and Sam Ruby's assert_select_jquery function, which is automatically included for use in tests.
7
+ * jQuery 1.7.2
8
+ * jQuery UI 1.8.18 (javascript only)
9
+ * the jQuery UJS adapter
10
+ * assert_select_jquery to test jQuery responses in Ruby tests
11
11
 
12
- ## Rails 3.1
12
+ ## Installation
13
13
 
14
- For Rails 3.1 and greater, the files will be added to the asset pipeline and available for you to use. These two lines will be added to the file `app/assets/javascripts/application.js` by default:
14
+ Apps generated with Rails 3.1 or later include jquery-rails in the Gemfile by default. So just make a new app:
15
15
 
16
- //= require jquery
17
- //= require jquery_ujs
16
+ ```sh
17
+ rails new myapp
18
+ ```
18
19
 
19
- If you wish to use jQuery UI as well, you can add this line to `application.js`:
20
+ If upgrading from an older version of rails, or for rails 3.0 apps,
21
+ add the jquery-rails gem to your Gemfile.
20
22
 
21
- //= require jquery-ui
23
+ ```ruby
24
+ gem "jquery-rails"
25
+ ```
22
26
 
23
- In order to use the themed parts of jQuery UI, you will also need to supply your own theme CSS. See [jqueryui.com](http://jqueryui.com) for more information.
27
+ And run `bundle install`. The rest of the installation depends on
28
+ whether the asset pipeline is being used.
24
29
 
25
- ### Installation
30
+ ### Rails 3.1 or greater (with asset pipeline *enabled*)
26
31
 
27
- New Rails 3.1 apps include jquery-rails in the Gemfile by default. So just make a new app:
32
+ The jquery and jquery-ujs files will be added to the asset pipeline and available for you to use. If they're not already in `app/assets/javascripts/application.js` by default, add these lines:
28
33
 
29
- rails new myapp
34
+ ```js
35
+ //= require jquery
36
+ //= require jquery_ujs
37
+ ```
30
38
 
31
- You're done!
32
-
33
- ## Rails 3.0
39
+ For jQuery UI, we recommend the [jquery-ui-rails](https://github.com/joliss/jquery-ui-rails) gem, as it includes the jquery-ui css and allows easier customization. This gem still packages the jQuery UI javascript for compatibility. To use it, add the following line to your `application.js`:
34
40
 
35
- This gem adds a single generator to Rails 3, jquery:install. Running the generator will remove any Prototype JS files you may happen to have, fetch jQuery and the jQuery-ujs driver for Rails, and (optionally) fetch jQuery UI.
41
+ ```js
42
+ //= require jquery-ui
43
+ ```
36
44
 
37
- The gem will also hook into the Rails configuration process, removing Prototype and adding jQuery to the javascript files included by the `javascript_include_tag(:defaults)` call. While the plugin downloads minified and un-minified versions of jQuery and jQuery UI, only the minified versions are included in :default.
45
+ In order to use the themed parts of jQuery UI, you will also need to supply [your own theme CSS](http://jqueryui.com) (or use the jquery-ui-rails gem mentioned above).
38
46
 
39
- ### Installation
47
+ ### Rails 3.0 (or greater with asset pipeline *disabled*)
40
48
 
41
- In your Gemfile, add this line:
49
+ This gem adds a single generator: `jquery:install`. Running the generator will remove any Prototype JS files you may happen to have, and copy jQuery and the jQuery-ujs driver for Rails (and optionally, jQuery UI) to the `public/javascripts` directory.
42
50
 
43
- gem "jquery-rails"
51
+ This gem will also hook into the Rails configuration process, removing Prototype and adding jQuery to the javascript files included by the `javascript_include_tag(:defaults)` call. While this gem contains the minified and un-minified versions of jQuery and jQuery UI, only the minified versions are included in `:defaults`.
44
52
 
45
- Then, run `bundle install`. To invoke the generator, run:
53
+ To invoke the generator, run:
46
54
 
47
- rails generate jquery:install #--ui to enable jQuery UI
55
+ ```sh
56
+ rails generate jquery:install #--ui to enable jQuery UI
57
+ ```
48
58
 
49
59
  You're done!
60
+
61
+ ## Contributing
62
+
63
+ Feel free to open an issue ticket if you find something that could be improved. A couple notes:
64
+
65
+ * If it's an issue pertaining to the jquery-ujs javascript, please report it to the [jquery-ujs project](https://github.com/rails/jquery-ujs).
66
+
67
+ * If the jquery or jquery-ui scripts are outdated (i.e. maybe a new version of jquery was released yesterday), feel free to open an issue and prod us to get that thing updated. However, for security reasons, we won't be accepting pull requests with updated jquery or jquery-ui scripts.
68
+
69
+ ## Acknowledgements
70
+
71
+ Many thanks are due to all of [the jquery-rails contributors](https://github.com/rails/jquery-rails/graphs/contributors). Special thanks to [JangoSteve](http://github.com/JangoSteve) for tirelessly answering questions and accepting patches, and the [Rails Core Team](https://github.com/organizations/rails/teams/617) for making jquery-rails an official part of Rails 3.1.
72
+
73
+ Copyright [André Arko](http://arko.net), released under the MIT License.
data/Rakefile CHANGED
@@ -1,10 +1,2 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
-
4
- # require "spec/rake/spectask"
5
- # desc "Run all examples"
6
- # Spec::Rake::SpecTask.new(:spec) do |t|
7
- # t.ruby_opts = ['-r test/unit']
8
- # t.spec_opts = %w[--color]
9
- # end
10
- task :default => :spec
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.rubyforge_project = "jquery-rails"
16
16
 
17
- s.add_dependency "railties", ">= 3.2.0", "< 5.0"
17
+ s.add_dependency "railties", ">= 3.1.0", "< 5.0"
18
18
  s.add_dependency "thor", "~> 0.14"
19
19
 
20
20
  s.files = `git ls-files`.split("\n")
@@ -1,8 +1,8 @@
1
1
  module Jquery
2
2
  module Rails
3
- VERSION = "2.0.2"
3
+ VERSION = "2.0.3"
4
4
  JQUERY_VERSION = "1.7.2"
5
5
  JQUERY_UI_VERSION = "1.8.18"
6
- JQUERY_UJS_VERSION = "caabad7f7ba6c35de1588ea263295ed5bc166a43"
6
+ JQUERY_UJS_VERSION = "8674fb14552d8c6e394da39dd352c68b25b78142"
7
7
  end
8
8
  end
@@ -45,6 +45,17 @@
45
45
  * });
46
46
  */
47
47
 
48
+ // Cut down on the number if issues from people inadvertently including jquery_ujs twice
49
+ // by detecting and raising an error when it happens.
50
+ var alreadyInitialized = function() {
51
+ var events = $(document).data('events');
52
+ return events && events.click && $.grep(events.click, function(e) { return e.namespace === 'rails'; }).length;
53
+ }
54
+
55
+ if ( alreadyInitialized() ) {
56
+ $.error('jquery-ujs has already been loaded!');
57
+ }
58
+
48
59
  // Shorthand to make it a little easier to call public rails functions from within rails.js
49
60
  var rails;
50
61
 
@@ -59,7 +70,7 @@
59
70
  formSubmitSelector: 'form',
60
71
 
61
72
  // 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])',
73
+ formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',
63
74
 
64
75
  // Form input elements disabled during form submission
65
76
  disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
@@ -106,10 +117,12 @@
106
117
 
107
118
  // Submits "remote" forms and links with ajax
108
119
  handleRemote: function(element) {
109
- var method, url, data, crossDomain, dataType, options;
120
+ var method, url, data, elCrossDomain, crossDomain, withCredentials, dataType, options;
110
121
 
111
122
  if (rails.fire(element, 'ajax:before')) {
112
- crossDomain = element.data('cross-domain') || null;
123
+ elCrossDomain = element.data('cross-domain');
124
+ crossDomain = elCrossDomain === undefined ? null : elCrossDomain;
125
+ withCredentials = element.data('with-credentials') || null;
113
126
  dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
114
127
 
115
128
  if (element.is('form')) {
@@ -134,7 +147,7 @@
134
147
  }
135
148
 
136
149
  options = {
137
- type: method || 'GET', data: data, dataType: dataType, crossDomain: crossDomain,
150
+ type: method || 'GET', data: data, dataType: dataType,
138
151
  // stopping the "ajax:beforeSend" event will cancel the ajax request
139
152
  beforeSend: function(xhr, settings) {
140
153
  if (settings.dataType === undefined) {
@@ -150,12 +163,18 @@
150
163
  },
151
164
  error: function(xhr, status, error) {
152
165
  element.trigger('ajax:error', [xhr, status, error]);
153
- }
166
+ },
167
+ xhrFields: {
168
+ withCredentials: withCredentials
169
+ },
170
+ crossDomain: crossDomain
154
171
  };
155
172
  // Only pass url to `ajax` options if not blank
156
173
  if (url) { options.url = url; }
157
174
 
158
- return rails.ajax(options);
175
+ var jqxhr = rails.ajax(options);
176
+ element.trigger('ajax:send', jqxhr);
177
+ return jqxhr;
159
178
  } else {
160
179
  return false;
161
180
  }
@@ -232,12 +251,13 @@
232
251
 
233
252
  // Helper function which checks for blank inputs in a form that match the specified CSS selector
234
253
  blankInputs: function(form, specifiedSelector, nonBlank) {
235
- var inputs = $(), input,
254
+ var inputs = $(), input, valueToCheck,
236
255
  selector = specifiedSelector || 'input,textarea';
237
256
  form.find(selector).each(function() {
238
257
  input = $(this);
239
- // Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
240
- if (nonBlank ? input.val() : !input.val()) {
258
+ valueToCheck = input.is(':checkbox,:radio') ? input.is(':checked') : input.val();
259
+ // If nonBlank and valueToCheck are both truthy, or nonBlank and valueToCheck are both falsey
260
+ if (valueToCheck == !!nonBlank) {
241
261
  inputs = inputs.add(input);
242
262
  }
243
263
  });
@@ -274,7 +294,7 @@
274
294
  element.data('ujs:enable-with', element.html()); // store enabled state
275
295
  element.html(element.data('disable-with')); // set to disabled state
276
296
  element.bind('click.railsDisable', function(e) { // prevent further clicking
277
- return rails.stopEverything(e)
297
+ return rails.stopEverything(e);
278
298
  });
279
299
  },
280
300
 
@@ -291,87 +311,98 @@
291
311
 
292
312
  };
293
313
 
294
- $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
314
+ if (rails.fire($(document), 'rails:attachBindings')) {
295
315
 
296
- $(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() {
297
- rails.enableElement($(this));
298
- });
316
+ $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
299
317
 
300
- $(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {
301
- var link = $(this), method = link.data('method'), data = link.data('params');
302
- if (!rails.allowAction(link)) return rails.stopEverything(e);
318
+ $(document).delegate(rails.linkDisableSelector, 'ajax:complete', function() {
319
+ rails.enableElement($(this));
320
+ });
303
321
 
304
- if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
322
+ $(document).delegate(rails.linkClickSelector, 'click.rails', function(e) {
323
+ var link = $(this), method = link.data('method'), data = link.data('params');
324
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
305
325
 
306
- if (link.data('remote') !== undefined) {
307
- if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
326
+ if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
308
327
 
309
- if (rails.handleRemote(link) === false) { rails.enableElement(link); }
310
- return false;
328
+ if (link.data('remote') !== undefined) {
329
+ if ( (e.metaKey || e.ctrlKey) && (!method || method === 'GET') && !data ) { return true; }
311
330
 
312
- } else if (link.data('method')) {
313
- rails.handleMethod(link);
314
- return false;
315
- }
316
- });
331
+ if (rails.handleRemote(link) === false) { rails.enableElement(link); }
332
+ return false;
317
333
 
318
- $(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) {
319
- var link = $(this);
320
- if (!rails.allowAction(link)) return rails.stopEverything(e);
334
+ } else if (link.data('method')) {
335
+ rails.handleMethod(link);
336
+ return false;
337
+ }
338
+ });
321
339
 
322
- rails.handleRemote(link);
323
- return false;
324
- });
340
+ $(document).delegate(rails.inputChangeSelector, 'change.rails', function(e) {
341
+ var link = $(this);
342
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
325
343
 
326
- $(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
327
- var form = $(this),
328
- remote = form.data('remote') !== undefined,
329
- blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
330
- nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
344
+ rails.handleRemote(link);
345
+ return false;
346
+ });
331
347
 
332
- if (!rails.allowAction(form)) return rails.stopEverything(e);
348
+ $(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
349
+ var form = $(this),
350
+ remote = form.data('remote') !== undefined,
351
+ blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
352
+ nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
333
353
 
334
- // skip other logic when required values are missing or file upload is present
335
- if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
336
- return rails.stopEverything(e);
337
- }
354
+ if (!rails.allowAction(form)) return rails.stopEverything(e);
338
355
 
339
- if (remote) {
340
- if (nonBlankFileInputs) {
341
- return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
356
+ // skip other logic when required values are missing or file upload is present
357
+ if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
358
+ return rails.stopEverything(e);
342
359
  }
343
360
 
344
- // If browser does not support submit bubbling, then this live-binding will be called before direct
345
- // bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
346
- if (!$.support.submitBubbles && $().jquery < '1.7' && rails.callFormSubmitBindings(form, e) === false) return rails.stopEverything(e);
361
+ if (remote) {
362
+ if (nonBlankFileInputs) {
363
+ setTimeout(function(){ rails.disableFormElements(form); }, 13);
364
+ return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
365
+ }
347
366
 
348
- rails.handleRemote(form);
349
- return false;
367
+ // If browser does not support submit bubbling, then this live-binding will be called before direct
368
+ // bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
369
+ if (!$.support.submitBubbles && $().jquery < '1.7' && rails.callFormSubmitBindings(form, e) === false) return rails.stopEverything(e);
350
370
 
351
- } else {
352
- // slight timeout so that the submit button gets properly serialized
353
- setTimeout(function(){ rails.disableFormElements(form); }, 13);
354
- }
355
- });
371
+ rails.handleRemote(form);
372
+ return false;
373
+
374
+ } else {
375
+ // slight timeout so that the submit button gets properly serialized
376
+ setTimeout(function(){ rails.disableFormElements(form); }, 13);
377
+ }
378
+ });
379
+
380
+ $(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
381
+ var button = $(this);
356
382
 
357
- $(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
358
- var button = $(this);
383
+ if (!rails.allowAction(button)) return rails.stopEverything(event);
359
384
 
360
- if (!rails.allowAction(button)) return rails.stopEverything(event);
385
+ // register the pressed submit button
386
+ var name = button.attr('name'),
387
+ data = name ? {name:name, value:button.val()} : null;
361
388
 
362
- // register the pressed submit button
363
- var name = button.attr('name'),
364
- data = name ? {name:name, value:button.val()} : null;
389
+ button.closest('form').data('ujs:submit-button', data);
390
+ });
365
391
 
366
- button.closest('form').data('ujs:submit-button', data);
367
- });
392
+ $(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
393
+ if (this == event.target) rails.disableFormElements($(this));
394
+ });
368
395
 
369
- $(document).delegate(rails.formSubmitSelector, 'ajax:beforeSend.rails', function(event) {
370
- if (this == event.target) rails.disableFormElements($(this));
371
- });
396
+ $(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
397
+ if (this == event.target) rails.enableFormElements($(this));
398
+ });
372
399
 
373
- $(document).delegate(rails.formSubmitSelector, 'ajax:complete.rails', function(event) {
374
- if (this == event.target) rails.enableFormElements($(this));
375
- });
400
+ $(function(){
401
+ // making sure that all forms have actual up-to-date token(cached forms contain old one)
402
+ csrf_token = $('meta[name=csrf-token]').attr('content');
403
+ csrf_param = $('meta[name=csrf-param]').attr('content');
404
+ $('form input[name="' + csrf_param + '"]').val(csrf_token);
405
+ });
406
+ }
376
407
 
377
408
  })( jQuery );
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: 2.0.2
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,25 +9,25 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-03 00:00:00.000000000Z
12
+ date: 2012-08-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70336830029280 !ruby/object:Gem::Requirement
16
+ requirement: &70150002916600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.0
21
+ version: 3.1.0
22
22
  - - <
23
23
  - !ruby/object:Gem::Version
24
24
  version: '5.0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70336830029280
27
+ version_requirements: *70150002916600
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: thor
30
- requirement: &70336830028560 !ruby/object:Gem::Requirement
30
+ requirement: &70150002927720 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
@@ -35,7 +35,7 @@ dependencies:
35
35
  version: '0.14'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70336830028560
38
+ version_requirements: *70150002927720
39
39
  description: This gem provides jQuery and the jQuery-ujs driver for your Rails 3 application.
40
40
  email:
41
41
  - andre@arko.net
@@ -57,8 +57,6 @@ files:
57
57
  - lib/jquery/rails.rb
58
58
  - lib/jquery/rails/engine.rb
59
59
  - lib/jquery/rails/version.rb
60
- - spec/lib/jquery-rails_spec.rb
61
- - spec/spec_helper.rb
62
60
  - vendor/assets/javascripts/jquery-ui.js
63
61
  - vendor/assets/javascripts/jquery-ui.min.js
64
62
  - vendor/assets/javascripts/jquery.js
@@ -76,6 +74,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
74
  - - ! '>='
77
75
  - !ruby/object:Gem::Version
78
76
  version: '0'
77
+ segments:
78
+ - 0
79
+ hash: 4351608392553699936
79
80
  required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  none: false
81
82
  requirements:
@@ -1,3 +0,0 @@
1
- require 'spec_helper'
2
-
3
- it "should probably test something, but I'm damned if I know what"
@@ -1,29 +0,0 @@
1
- # Set up RSpec
2
- require 'webmock/rspec'
3
-
4
- Spec::Runner.configure do |config|
5
- config.include WebMock::API
6
- end
7
-
8
- # Set up generator tests
9
- require 'rails/all'
10
- require 'rails/generators'
11
- require 'rails/generators/test_case'
12
-
13
- class TestApp < Rails::Application
14
- config.root = File.dirname(__FILE__)
15
- end
16
- Rails.application = TestApp
17
-
18
- module Rails
19
- def self.root
20
- @root ||= File.expand_path("../../tmp/rails", __FILE__)
21
- end
22
- end
23
- Rails.application.config.root = Rails.root
24
-
25
- # Call configure to load the settings from
26
- # Rails.application.config.generators to Rails::Generators
27
- Rails::Generators.configure!
28
-
29
-