jquery-rails 1.0.13 → 1.0.14

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,11 @@
1
+ ## 1.0.14 (08 September 2011)
2
+
3
+ - Updated to latest jquery-ujs
4
+ - Added `disable-with` support for links
5
+ - minor bug fixes
6
+ - Added `data-remote` support for change events of all input types
7
+ - Added install generator for Rails 3.1 with instructional message
8
+
1
9
  ## 1.0.13 (11 August 2011)
2
10
 
3
11
  - Updated to latest jquery-ujs with `novalidate` support
@@ -1,39 +1,56 @@
1
1
  require 'rails'
2
2
 
3
- module Jquery
4
- module Generators
5
- class InstallGenerator < ::Rails::Generators::Base
3
+ if ::Rails.version < "3.1"
4
+ module Jquery
5
+ module Generators
6
+ class InstallGenerator < ::Rails::Generators::Base
6
7
 
7
- desc "This generator installs jQuery #{Jquery::Rails::JQUERY_VERSION}, jQuery-ujs, and (optionally) jQuery UI #{Jquery::Rails::JQUERY_UI_VERSION}"
8
- class_option :ui, :type => :boolean, :default => false, :desc => "Include jQueryUI"
9
- source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
8
+ desc "This generator installs jQuery #{Jquery::Rails::JQUERY_VERSION}, jQuery-ujs, and (optionally) jQuery UI #{Jquery::Rails::JQUERY_UI_VERSION}"
9
+ class_option :ui, :type => :boolean, :default => false, :desc => "Include jQueryUI"
10
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
10
11
 
11
- def remove_prototype
12
- Rails::PROTOTYPE_JS.each do |name|
13
- remove_file "public/javascripts/#{name}.js"
12
+ def remove_prototype
13
+ Rails::PROTOTYPE_JS.each do |name|
14
+ remove_file "public/javascripts/#{name}.js"
15
+ end
14
16
  end
15
- end
16
17
 
17
- def copy_jquery
18
- say_status("copying", "jQuery (#{Jquery::Rails::JQUERY_VERSION})", :green)
19
- copy_file "jquery.js", "public/javascripts/jquery.js"
20
- copy_file "jquery.min.js", "public/javascripts/jquery.min.js"
21
- end
18
+ def copy_jquery
19
+ say_status("copying", "jQuery (#{Jquery::Rails::JQUERY_VERSION})", :green)
20
+ copy_file "jquery.js", "public/javascripts/jquery.js"
21
+ copy_file "jquery.min.js", "public/javascripts/jquery.min.js"
22
+ end
22
23
 
23
- def copy_jquery_ui
24
- if options.ui?
25
- say_status("copying", "jQuery UI (#{Jquery::Rails::JQUERY_UI_VERSION})", :green)
26
- copy_file "jquery-ui.js", "public/javascripts/jquery-ui.js"
27
- copy_file "jquery-ui.min.js", "public/javascripts/jquery-ui.min.js"
24
+ def copy_jquery_ui
25
+ if options.ui?
26
+ say_status("copying", "jQuery UI (#{Jquery::Rails::JQUERY_UI_VERSION})", :green)
27
+ copy_file "jquery-ui.js", "public/javascripts/jquery-ui.js"
28
+ copy_file "jquery-ui.min.js", "public/javascripts/jquery-ui.min.js"
29
+ end
30
+ end
31
+
32
+ def copy_ujs_driver
33
+ say_status("copying", "jQuery UJS adapter (#{Jquery::Rails::JQUERY_UJS_VERSION[0..5]})", :green)
34
+ remove_file "public/javascripts/rails.js"
35
+ copy_file "jquery_ujs.js", "public/javascripts/jquery_ujs.js"
28
36
  end
29
- end
30
37
 
31
- def copy_ujs_driver
32
- say_status("copying", "jQuery UJS adapter (#{Jquery::Rails::JQUERY_UJS_VERSION[0..5]})", :green)
33
- remove_file "public/javascripts/rails.js"
34
- copy_file "jquery_ujs.js", "public/javascripts/jquery_ujs.js"
35
38
  end
39
+ end
40
+ end
41
+ else
42
+ module Jquery
43
+ module Generators
44
+ class InstallGenerator < ::Rails::Generators::Base
45
+ desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
36
46
 
47
+ def do_nothing
48
+ say_status("deprecated", "You are using Rails 3.1, so this generator is no longer needed. The necessary files are already in your asset pipeline.")
49
+ say_status("", "Just add `//= require jquery` and `//= require jquery_ujs` to your app/assets/javascripts/application.js")
50
+ say_status("", "If you upgraded your app from Rails 3.0 and still have jquery.js, rails.js, or jquery_ujs.js in your javascripts, be sure to remove them.")
51
+ # ok, nothing
52
+ end
53
+ end
37
54
  end
38
55
  end
39
- end if ::Rails.version < "3.1"
56
+ end
@@ -52,7 +52,7 @@ module ActionDispatch
52
52
 
53
53
  pattern = "\\.#{jquery_method || '\\w+'}\\("
54
54
  pattern = "#{pattern}['\"]#{jquery_opt}['\"],?\\s*" if jquery_opt
55
- pattern = "#{pattern}#{PATTERN_HTML}" if block
55
+ pattern = "#{pattern}#{PATTERN_HTML}"
56
56
  pattern = "(?:jQuery|\\$)\\(['\"]#{id}['\"]\\)#{pattern}" if id
57
57
 
58
58
  fragments = []
@@ -84,6 +84,7 @@ module ActionDispatch
84
84
  def unescape_js(js_string)
85
85
  # js encodes double quotes and line breaks.
86
86
  unescaped= js_string.gsub('\"', '"')
87
+ unescaped.gsub!('\\\'', "'")
87
88
  unescaped.gsub!(/\\\//, '/')
88
89
  unescaped.gsub!('\n', "\n")
89
90
  unescaped.gsub!('\076', '>')
@@ -95,4 +96,4 @@ module ActionDispatch
95
96
 
96
97
  end
97
98
  end
98
- end
99
+ end
@@ -1,8 +1,8 @@
1
1
  module Jquery
2
2
  module Rails
3
- VERSION = "1.0.13"
3
+ VERSION = "1.0.14"
4
4
  JQUERY_VERSION = "1.6.2"
5
5
  JQUERY_UI_VERSION = "1.8.14"
6
- JQUERY_UJS_VERSION = "cd619df9f0daad3303aacd4f992fff19158b1e5d"
6
+ JQUERY_UJS_VERSION = "c00a9726837756ea53404ca7e8b0f12df19a6496"
7
7
  end
8
8
  end
@@ -49,10 +49,10 @@
49
49
 
50
50
  $.rails = rails = {
51
51
  // Link elements bound by jquery-ujs
52
- linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]',
52
+ linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
53
53
 
54
54
  // Select elements bound by jquery-ujs
55
- selectChangeSelector: 'select[data-remote]',
55
+ inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
56
56
 
57
57
  // Form elements bound by jquery-ujs
58
58
  formSubmitSelector: 'form',
@@ -72,6 +72,9 @@
72
72
  // Form file input elements
73
73
  fileInputSelector: 'input:file',
74
74
 
75
+ // Link onClick disable selector with possible reenable after remote submission
76
+ linkDisableSelector: 'a[data-disable-with]',
77
+
75
78
  // Make sure that every Ajax request sends the CSRF token
76
79
  CSRFProtection: function(xhr) {
77
80
  var token = $('meta[name="csrf-token"]').attr('content');
@@ -99,7 +102,8 @@
99
102
  handleRemote: function(element) {
100
103
  var method, url, data,
101
104
  crossDomain = element.data('cross-domain') || null,
102
- dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
105
+ dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType),
106
+ options;
103
107
 
104
108
  if (rails.fire(element, 'ajax:before')) {
105
109
 
@@ -113,15 +117,15 @@
113
117
  data.push(button);
114
118
  element.data('ujs:submit-button', null);
115
119
  }
116
- } else if (element.is('select')) {
120
+ } else if (element.is(rails.inputChangeSelector)) {
117
121
  method = element.data('method');
118
122
  url = element.data('url');
119
123
  data = element.serialize();
120
- if (element.data('params')) data = data + "&" + element.data('params');
124
+ if (element.data('params')) data = data + "&" + element.data('params');
121
125
  } else {
122
- method = element.data('method');
123
- url = element.attr('href');
124
- data = element.data('params') || null;
126
+ method = element.data('method');
127
+ url = element.attr('href');
128
+ data = element.data('params') || null;
125
129
  }
126
130
 
127
131
  options = {
@@ -143,8 +147,8 @@
143
147
  element.trigger('ajax:error', [xhr, status, error]);
144
148
  }
145
149
  };
146
- // Do not pass url to `ajax` options if blank
147
- if (url) { $.extend(options, { url: url }); }
150
+ // Only pass url to `ajax` options if not blank
151
+ if (url) { options.url = url; }
148
152
 
149
153
  rails.ajax(options);
150
154
  }
@@ -252,15 +256,43 @@
252
256
  });
253
257
  }
254
258
  return continuePropagation;
259
+ },
260
+
261
+ // replace element's html with the 'data-disable-with' after storing original html
262
+ // and prevent clicking on it
263
+ disableElement: function(element) {
264
+ element.data('ujs:enable-with', element.html()); // store enabled state
265
+ element.html(element.data('disable-with')); // set to disabled state
266
+ element.bind('click.railsDisable', function(e) { // prevent further clicking
267
+ return rails.stopEverything(e)
268
+ });
269
+ },
270
+
271
+ // restore element to its original state which was disabled by 'disableElement' above
272
+ enableElement: function(element) {
273
+ if (element.data('ujs:enable-with') !== undefined) {
274
+ element.html(element.data('ujs:enable-with')); // set to old enabled state
275
+ // this should be element.removeData('ujs:enable-with')
276
+ // but, there is currently a bug in jquery which makes hyphenated data attributes not get removed
277
+ element.data('ujs:enable-with', false); // clean up cache
278
+ }
279
+ element.unbind('click.railsDisable'); // enable element
255
280
  }
281
+
256
282
  };
257
283
 
258
284
  $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { rails.CSRFProtection(xhr); }});
259
285
 
286
+ $(rails.linkDisableSelector).live('ajax:complete', function() {
287
+ rails.enableElement($(this));
288
+ });
289
+
260
290
  $(rails.linkClickSelector).live('click.rails', function(e) {
261
291
  var link = $(this);
262
292
  if (!rails.allowAction(link)) return rails.stopEverything(e);
263
293
 
294
+ if (link.is(rails.linkDisableSelector)) rails.disableElement(link);
295
+
264
296
  if (link.data('remote') !== undefined) {
265
297
  rails.handleRemote(link);
266
298
  return false;
@@ -270,13 +302,13 @@
270
302
  }
271
303
  });
272
304
 
273
- $(rails.selectChangeSelector).live('change.rails', function(e) {
305
+ $(rails.inputChangeSelector).live('change.rails', function(e) {
274
306
  var link = $(this);
275
307
  if (!rails.allowAction(link)) return rails.stopEverything(e);
276
308
 
277
309
  rails.handleRemote(link);
278
310
  return false;
279
- });
311
+ });
280
312
 
281
313
  $(rails.formSubmitSelector).live('submit.rails', function(e) {
282
314
  var form = $(this),
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jquery-rails
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.13
5
+ version: 1.0.14
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Andr\xC3\xA9 Arko"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-11 00:00:00 Z
13
+ date: 2011-09-08 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties