jquery_on_rails 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2010 Joe Khoobyar
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2010 Joe Khoobyar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'rspec'
2
3
  require 'rake'
3
4
  gem 'rspec', '>= 2.0.0.beta.8'
4
5
  require 'rspec'
@@ -13,10 +14,10 @@ begin
13
14
  gem.email = "joe@ankhcraft.com"
14
15
  gem.homepage = "http://github.com/joekhoobyar/jquery_on_rails"
15
16
  gem.authors = ["Joe Khoobyar"]
16
- gem.files = Dir["{lib,public,spec}/**/*", "{bin}/*", "*"]
17
+ gem.files = Dir["{lib,public,spec}/**/*", "{bin}/*", "*"].reject{|f| f.end_with? '.log'}
17
18
  gem.rubyforge_project = "jquery_on_rails"
18
- gem.add_dependency "actionpack", ">= 3.0.0.beta1"
19
- gem.add_development_dependency "rspec", ">= 2.0.0.beta.8"
19
+ gem.add_dependency "actionpack", "~> 3.0.0"
20
+ gem.add_development_dependency "rspec", "~> 2.0"
20
21
  # gem.add_development_dependency "rspec-rails", ">= 2.0.0.beta.8"
21
22
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
23
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jquery_on_rails}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joe Khoobyar"]
@@ -66,15 +66,15 @@ Gem::Specification.new do |s|
66
66
  s.specification_version = 3
67
67
 
68
68
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
69
- s.add_runtime_dependency(%q<actionpack>, [">= 3.0.0.beta1"])
70
- s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.8"])
69
+ s.add_runtime_dependency(%q<actionpack>, ["~> 3.0.0"])
70
+ s.add_development_dependency(%q<rspec>, ["~> 2.0"])
71
71
  else
72
- s.add_dependency(%q<actionpack>, [">= 3.0.0.beta1"])
73
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.8"])
72
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
73
+ s.add_dependency(%q<rspec>, ["~> 2.0"])
74
74
  end
75
75
  else
76
- s.add_dependency(%q<actionpack>, [">= 3.0.0.beta1"])
77
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.8"])
76
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
77
+ s.add_dependency(%q<rspec>, ["~> 2.0"])
78
78
  end
79
79
  end
80
80
 
@@ -92,13 +92,13 @@ module JQueryOnRails
92
92
  # Mostly copied from Rails 3 PrototypeHelper
93
93
  module GeneratorMethods
94
94
  def to_s #:nodoc:
95
- returning javascript = @lines * $/ do
96
- if ActionView::Base.debug_rjs
97
- source = javascript.dup
98
- javascript.replace "try {\n#{source}\n} catch (e) "
99
- javascript << "{ alert('RJS error:\\n\\n' + e.toString()); alert('#{source.gsub('\\','\0\0').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }}'); throw e }"
100
- end
95
+ javascript = @lines * $/
96
+ if ActionView::Base.debug_rjs
97
+ source = javascript.dup
98
+ javascript.replace "try {\n#{source}\n} catch (e) "
99
+ javascript << "{ alert('RJS error:\\n\\n' + e.toString()); alert('#{source.gsub('\\','\0\0').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }}'); throw e }"
101
100
  end
101
+ javascript
102
102
  end
103
103
 
104
104
  def [](id)
@@ -195,9 +195,9 @@ module JQueryOnRails
195
195
  end
196
196
 
197
197
  def record(line)
198
- returning line = "#{line.to_s.chomp.gsub(/\;\z/, '')};" do
199
- self << line
200
- end
198
+ line = "#{line.to_s.chomp.gsub(/\;\z/, '')};"
199
+ self << line
200
+ line
201
201
  end
202
202
 
203
203
  def render(*options)
@@ -2,6 +2,8 @@ require 'jquery_on_rails'
2
2
  require 'rails'
3
3
 
4
4
  class JQueryOnRails::Railtie < Rails::Railtie
5
+
6
+ config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
5
7
 
6
8
  initializer "jquery_on_rails.action_view_helpers" do
7
9
  ActiveSupport.on_load(:action_view) do
@@ -16,14 +18,6 @@ class JQueryOnRails::Railtie < Rails::Railtie
16
18
  ActionView::Helpers::JavaScriptHelper.send :include, JQueryOnRails::Helpers::JQueryHelper
17
19
  ActionView::Helpers.send :include, JQueryOnRails::Helpers::JQueryHelper
18
20
  ActionView::Base.send :include, JQueryOnRails::Helpers::JQueryHelper
19
-
20
- # Redefine the default sources so that we don't try to include prototype JS files.
21
- require 'action_view/helpers/asset_tag_helper'
22
- ActionView::Helpers::AssetTagHelper.class_eval do
23
- remove_const :JAVASCRIPT_DEFAULT_SOURCES if const_defined? :JAVASCRIPT_DEFAULT_SOURCES
24
- const_set :JAVASCRIPT_DEFAULT_SOURCES, %w/jquery rails/
25
- reset_javascript_include_default
26
- end
27
21
  end
28
22
  end
29
23
  end
@@ -1,3 +1,24 @@
1
+ (function($) {
2
+
3
+ /*
4
+ * Since jQuery doesn't really have an easy to use
5
+ * reset function, this is to replicate $.clear();
6
+ **/
7
+ $.fn.clear = function() {
8
+ return this.each(function() {
9
+ var type = this.type, tag = this.tagName.toLowerCase();
10
+ if (tag == 'form')
11
+ $(':input',this).clear ();
12
+ else if (type == 'text' || type == 'password' || tag == 'textarea')
13
+ this.value = '';
14
+ else if (type == 'checkbox' || type == 'radio')
15
+ this.checked = false;
16
+ else if (tag == 'select')
17
+ this.selectedIndex = -1;
18
+ });
19
+ }
20
+ })(jQuery);
21
+
1
22
  jQuery(function ($) {
2
23
  var csrf_token = $('meta[name=csrf-token]').attr('content'),
3
24
  csrf_param = $('meta[name=csrf-param]').attr('content');
@@ -33,6 +54,7 @@ jQuery(function ($) {
33
54
  $.ajax({
34
55
  url: url,
35
56
  data: data,
57
+ dataType: 'script',
36
58
  type: method.toUpperCase(),
37
59
  beforeSend: function (xhr) {
38
60
  xhr.setRequestHeader("Accept", "text/javascript");
@@ -52,69 +74,116 @@ jQuery(function ($) {
52
74
 
53
75
  el.trigger('ajax:after');
54
76
  }
77
+ },
78
+
79
+ /**
80
+ * Creates and fills out a new form, using an anchor's href as the action URL.
81
+ */
82
+ applyToNewForm : function (options) {
83
+ var link = $(this), elements = [], form = null;
84
+ options = options || {};
85
+ options.url = options.url || link.attr('href') || window.location.href;
86
+ if (link && options.url) {
87
+ options.method = options.method || link.attr('data-method');
88
+ if (options.method)
89
+ elements.push ('<input name="_method" value="'+options.method+'" type="hidden" />');
90
+ if (csrf_param && csrf_token)
91
+ elements.push ('<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />');
92
+ return $('<form method="post"/>').hide().appendTo('body').applyToForm (elements, options);
93
+ }
94
+ },
95
+
96
+ /**
97
+ * Applies the given element list and options to this form.
98
+ */
99
+ applyToForm : function (elements, options) {
100
+ var form = $(this);
101
+ if (arguments.length < 3 && ! $.isArray (elements))
102
+ { options = elements; elements = null; }
103
+ elements = elements || [];
104
+ var url = options.url, params = options.parameters, method = options.method;
105
+ if (! url && (! params || $.isEmptyObject (params)))
106
+ return form;
107
+
108
+ // STRING parameter : HTTP GET parameters (query string fragment)
109
+ if (typeof(params)=='string')
110
+ url += (url.indexOf('?')<0 ? '?' : '&') + params;
111
+
112
+ // OBJECT parameter : HTTP POST variables (via hidden form elements)
113
+ // This feature converts values into hidden form inputs,
114
+ // flattening nested keys along the way.
115
+ else if ($.isPlainObject(params)) {
116
+ var key;
117
+
118
+ $.each (params, function (subkey,subval) {
119
+ if (key && typeof(subkey)=='string')
120
+ subkey = key+'['+subkey+']';
121
+
122
+ if (typeof(subval)!='string') {
123
+ key = subkey;
124
+ if ($.isPlainObject (subval) || $.isArray (subval))
125
+ $.each (subval, arguments.callee);
126
+ }
127
+ else if (form[0].elements[subkey]) {
128
+ $(form[0].elements[subkey]).val (subval);
129
+ }
130
+ else {
131
+ elements.push ($('<input type="hidden"/>').attr({'name': subkey, 'value' : subval}));
132
+ }
133
+ });
134
+ }
135
+
136
+ // Finally, we can fill in the form and return it.
137
+ for (var i = 0; i < elements.length; i++)
138
+ form.append(elements[i]);
139
+ if (url)
140
+ form.attr('action', url);
141
+ return form;
55
142
  }
56
143
  });
57
144
 
58
145
  /**
59
146
  * confirmation handler
60
147
  */
61
- $('a[data-confirm],input[data-confirm]').live('click', function () {
148
+ $('a[data-confirm],input[data-confirm]').live('click', function (e) {
62
149
  var el = $(this);
63
- if (el.triggerAndReturn('confirm')) {
64
- if (!confirm(el.attr('data-confirm'))) {
65
- return false;
66
- }
67
- }
150
+ if (el.triggerAndReturn('confirm') && !confirm(el.attr('data-confirm')))
151
+ return false;
68
152
  });
69
153
 
70
-
71
154
  /**
72
155
  * remote handlers
73
156
  */
74
- $('form[data-remote="true"]').live('submit', function (e) {
157
+ $('form[data-remote]').live('submit', function (e) {
75
158
  $(this).callRemote();
76
159
  e.preventDefault();
77
160
  });
78
161
 
79
- $('a[data-remote="true"],input[data-remote="true"]').live('click', function (e) {
162
+ $('a[data-remote],input[data-remote]').live('click', function(e) {
80
163
  $(this).callRemote();
81
164
  e.preventDefault();
82
165
  });
83
166
 
84
- $('a[data-method][data-remote!=true]').live('click',function(e){
85
- var link = $(this),
86
- href = link.attr('href'),
87
- method = link.attr('data-method'),
88
- form = $('<form method="post" action="'+href+'">'),
89
- input = $('<input name="_method" value="'+method+'" type="hidden" />'),
90
- csrf_input = $('<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />');
91
-
92
- form.hide()
93
- .append(input)
94
- .append(csrf_input)
95
- .appendTo('body'); // redundant?
96
-
167
+ $('a[data-method]:not([data-remote])').live('click', function(e) {
168
+ var form = $(this).applyToNewForm ();
97
169
  e.preventDefault();
98
170
  form.submit();
99
171
  });
100
172
 
101
173
  /**
102
- * disable_with handlers
174
+ * disable-with handlers
103
175
  */
104
- $('form[data-remote="true"]').live('ajax:before', function () {
105
- $(this).children('input[data-disable-with]').each(function () {
176
+ $('form[data-remote]:has(input[data-disable-with])').live('ajax:before', function () {
177
+ $('input[data-disable-with]', this).each(function () {
106
178
  var input = $(this);
107
- input.data('enable_with', input.val())
179
+ input.data('enable-with', input.val())
108
180
  .attr('value', input.attr('data-disable-with'))
109
181
  .attr('disabled', 'disabled');
110
182
  });
111
- });
112
-
113
- $('form[data-remote="true"]').live('ajax:after', function () {
114
- $(this).children('input[data-disable-with]').each(function () {
183
+ }).live('ajax:after', function () {
184
+ $('input[data-disable-with]', this).each(function () {
115
185
  var input = $(this);
116
- input.removeAttr('disabled')
117
- .val(input.data('enable_with'));
186
+ input.removeAttr('disabled').val(input.data('enable-with'));
118
187
  });
119
188
  });
120
189
  });
@@ -1,5 +1,5 @@
1
- class DummyController < ActionController::Base
2
-
3
- protect_from_forgery
4
-
5
- end
1
+ class DummyController < ActionController::Base
2
+
3
+ protect_from_forgery
4
+
5
+ end
@@ -1,2 +1,2 @@
1
- module DummyHelper
2
- end
1
+ module DummyHelper
2
+ end
@@ -1,3 +1,3 @@
1
- require 'rubygems'
2
-
3
- $:.unshift File.expand_path('../../../../lib', __FILE__)
1
+ require 'rubygems'
2
+
3
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,5 +1,5 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- Dummy::Application.initialize!
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -1,6 +1,8 @@
1
1
  Dummy::Application.configure do
2
2
  config.cache_classes = true
3
- config.consider_all_requests_local = true
3
+ config.consider_all_requests_local = true
4
4
  config.log_level = :debug
5
5
  config.threadsafe!
6
+
7
+ config.active_support.deprecation = :stderr
6
8
  end
@@ -1,3 +1,3 @@
1
- Dummy::Application.routes.draw do |map|
1
+ Dummy::Application.routes.draw do
2
2
  match ':controller(/:action(/:id(.:format)))'
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 2
9
- version: 0.2.2
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Khoobyar
@@ -22,14 +22,13 @@ dependencies:
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 3
29
29
  - 0
30
30
  - 0
31
- - beta1
32
- version: 3.0.0.beta1
31
+ version: 3.0.0
33
32
  type: :runtime
34
33
  version_requirements: *id001
35
34
  - !ruby/object:Gem::Dependency
@@ -37,15 +36,12 @@ dependencies:
37
36
  prerelease: false
38
37
  requirement: &id002 !ruby/object:Gem::Requirement
39
38
  requirements:
40
- - - ">="
39
+ - - ~>
41
40
  - !ruby/object:Gem::Version
42
41
  segments:
43
42
  - 2
44
43
  - 0
45
- - 0
46
- - beta
47
- - 8
48
- version: 2.0.0.beta.8
44
+ version: "2.0"
49
45
  type: :development
50
46
  version_requirements: *id002
51
47
  description: A complete replacement for Rails 3 javascript helpers and unobstrusive javacript (ujs) using JQuery instead of prototype/scriptaculous