remotipart 1.3.1 → 1.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec23f3df5458657f694d92ab33cd1222754fdce5
4
- data.tar.gz: 78bc0803e6c169d96490cd547e8dc7a1250bc5ae
3
+ metadata.gz: 8cd835a42fa4b39f9472499d433674c148afed2b
4
+ data.tar.gz: 487e0694c4122c8002f6da0f2b6466ec2b870a78
5
5
  SHA512:
6
- metadata.gz: 04e4a54250dcb7077680533f570cce060a86858cc15c7912ce522f3ce41a52eeee02a7a4f89cd6e50ad5970bd610f70cc9a7ef84fc75e259b5257072d5ee959a
7
- data.tar.gz: a07237bc926326c6033e6cb0ffd4f0ad634f21fd65eda3eb77cc578f00cc452fd4731df4f65ca2062f49364e793bde01208f69eca23eaba95302c7111615ee12
6
+ metadata.gz: 4173afdbc5e749e062b62d7370ff379d70302645fa0be40f0593d17f8a88d494f63c0606a396d79419ad3eb9b8776e53ea34f838deecc3748a9ee73d63688ba7
7
+ data.tar.gz: 457e29566c8271872d61703a68db861223dd5686421652cb35bdd7b7a75546bfe5afd900eefc848d7899c2a6bc2ebd056eeed000c13d8e8cd16a5514bfbcd8db
@@ -1,5 +1,14 @@
1
1
  = History
2
2
 
3
+ === 1.4.0 / 2018-04-09
4
+
5
+ * Added jQuery 3 compatibility.
6
+ * Changed to use ActiveSupport lazy load hooks on initialization.
7
+ * Changed jQuery iframe-transport to v1.0.1.
8
+ * Fixed to preserve original return value of render call for non-remotipart requests.
9
+ * Fixed remote javascript with " not being executed.
10
+ * Fixed method signature of render_with_remotipart, making RJS templates not usable.
11
+
3
12
  === 1.3.1 / 2016-10-06
4
13
 
5
14
  * Fixed remote form submit not working with Firefox 49.
@@ -24,8 +24,8 @@ module Remotipart
24
24
  end
25
25
 
26
26
  # Override the accepted format, because it isn't what we really want
27
- if params['X-Http-Accept']
28
- env['HTTP_ACCEPT'] = params['X-Http-Accept']
27
+ if params['X-HTTP-Accept']
28
+ env['HTTP_ACCEPT'] = params['X-HTTP-Accept']
29
29
  end
30
30
  end
31
31
 
@@ -23,13 +23,17 @@ module Remotipart
23
23
  end
24
24
 
25
25
  initializer "remotipart.view_helper" do
26
- ActionView::Base.send :include, RequestHelper
27
- ActionView::Base.send :include, ViewHelper
26
+ ActiveSupport.on_load(:action_view) do
27
+ include RequestHelper
28
+ include ViewHelper
29
+ end
28
30
  end
29
31
 
30
32
  initializer "remotipart.controller_helper" do
31
- ActionController::Base.send :include, RequestHelper
32
- ActionController::Base.send :include, RenderOverrides
33
+ ActiveSupport.on_load(:action_controller) do
34
+ include RequestHelper
35
+ include RenderOverrides
36
+ end
33
37
  end
34
38
 
35
39
  initializer "remotipart.include_middelware" do
@@ -1,6 +1,6 @@
1
1
  module Remotipart
2
2
  module Rails
3
- VERSION = "1.3.1"
3
+ VERSION = "1.4.0"
4
4
  IFRAMETRANSPORT_VERSION = "02.06.2013"
5
5
  end
6
6
  end
@@ -12,14 +12,16 @@ module Remotipart
12
12
  end
13
13
  end
14
14
 
15
- def render_with_remotipart *args
16
- render_without_remotipart *args
15
+ def render_with_remotipart(*args, &block)
16
+ render_return_value = render_without_remotipart(*args, &block)
17
17
  if remotipart_submitted?
18
18
  textarea_body = response.content_type == 'text/html' ? html_escape(response.body) : response.body
19
19
  response.body = %{<script type=\"text/javascript\">try{window.parent.document;}catch(err){document.domain=document.domain;}</script> <textarea data-type=\"#{response.content_type}\" data-status=\"#{response.response_code}\" data-statusText=\"#{response.message}\">#{textarea_body}</textarea>}
20
20
  response.content_type = ::Rails.version >= '5' ? Mime[:html] : Mime::HTML
21
+ response_body
22
+ else
23
+ render_return_value
21
24
  end
22
- response_body
23
25
  end
24
26
  end
25
27
  end
@@ -1,9 +1,20 @@
1
1
  module Remotipart
2
2
  module ViewHelper
3
+
4
+ def escape_javascript(javascript)
5
+ if remotipart_submitted?
6
+ super("#{javascript}")
7
+ else
8
+ super
9
+ end
10
+ end
11
+ alias_method :j, :escape_javascript
12
+
3
13
  #No longer used
4
14
  #Retrained to prevent issues while updating
5
15
  def remotipart_response(options = {}, &block)
6
16
  with_output_buffer(&block)
7
17
  end
18
+
8
19
  end
9
20
  end
@@ -2,18 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: remotipart 1.3.1 ruby lib
5
+ # stub: remotipart 1.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "remotipart"
9
- s.version = "1.3.1"
8
+ s.name = "remotipart".freeze
9
+ s.version = "1.4.0"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Greg Leppert", "Steve Schwartz"]
14
- s.date = "2016-10-06"
15
- s.description = "Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jquery-rails.\n This gem augments the native Rails 3 jQuery-UJS remote form function enabling asynchronous file uploads with little to no modification to your application.\n "
16
- s.email = ["greg@formasfunction.com", "steve@alfajango.com"]
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Greg Leppert".freeze, "Steve Schwartz".freeze]
14
+ s.date = "2018-04-09"
15
+ s.description = "Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jquery-rails.\n This gem augments the native Rails 3 jQuery-UJS remote form function enabling asynchronous file uploads with little to no modification to your application.\n ".freeze
16
+ s.email = ["greg@formasfunction.com".freeze, "steve@alfajango.com".freeze]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
19
  "README.rdoc"
@@ -41,23 +41,23 @@ Gem::Specification.new do |s|
41
41
  "vendor/assets/javascripts/jquery.iframe-transport.js",
42
42
  "vendor/assets/javascripts/jquery.remotipart.js"
43
43
  ]
44
- s.homepage = "http://opensource.alfajango.com/remotipart/"
45
- s.rubygems_version = "2.5.1"
46
- s.summary = "Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jquery-rails."
44
+ s.homepage = "http://opensource.alfajango.com/remotipart/".freeze
45
+ s.rubygems_version = "2.5.2".freeze
46
+ s.summary = "Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jquery-rails.".freeze
47
47
 
48
48
  if s.respond_to? :specification_version then
49
49
  s.specification_version = 4
50
50
 
51
51
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
- s.add_development_dependency(%q<rake>, [">= 0"])
53
- s.add_development_dependency(%q<jeweler>, [">= 0"])
52
+ s.add_development_dependency(%q<rake>.freeze, [">= 0"])
53
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
54
54
  else
55
- s.add_dependency(%q<rake>, [">= 0"])
56
- s.add_dependency(%q<jeweler>, [">= 0"])
55
+ s.add_dependency(%q<rake>.freeze, [">= 0"])
56
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
57
57
  end
58
58
  else
59
- s.add_dependency(%q<rake>, [">= 0"])
60
- s.add_dependency(%q<jeweler>, [">= 0"])
59
+ s.add_dependency(%q<rake>.freeze, [">= 0"])
60
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
61
61
  end
62
62
  end
63
63
 
@@ -1,12 +1,12 @@
1
- // This [jQuery](http://jquery.com/) plugin implements an `<iframe>`
2
- // [transport](http://api.jquery.com/extending-ajax/#Transports) so that
1
+ // This [jQuery](https://jquery.com/) plugin implements an `<iframe>`
2
+ // [transport](https://api.jquery.com/jQuery.ajax/#extending-ajax) so that
3
3
  // `$.ajax()` calls support the uploading of files using standard HTML file
4
4
  // input fields. This is done by switching the exchange from `XMLHttpRequest`
5
5
  // to a hidden `iframe` element containing a form that is submitted.
6
6
 
7
- // The [source for the plugin](http://github.com/cmlenz/jquery-iframe-transport)
8
- // is available on [Github](http://github.com/) and dual licensed under the MIT
9
- // or GPL Version 2 licenses.
7
+ // The [source for the plugin](https://github.com/cmlenz/jquery-iframe-transport)
8
+ // is available on [Github](https://github.com/) and licensed under the [MIT
9
+ // license](https://github.com/cmlenz/jquery-iframe-transport/blob/master/LICENSE).
10
10
 
11
11
  // ## Usage
12
12
 
@@ -70,9 +70,9 @@
70
70
  // impossible for the javascript code to determine the HTTP status code of the
71
71
  // servers response. Effectively, all of the calls you make will look like they
72
72
  // are getting successful responses, and thus invoke the `done()` or
73
- // `complete()` callbacks. You can only determine communicate problems using
74
- // the content of the response payload. For example, consider using a JSON
75
- // response such as the following to indicate a problem with an uploaded file:
73
+ // `complete()` callbacks. You can only communicate problems using the content
74
+ // of the response payload. For example, consider using a JSON response such as
75
+ // the following to indicate a problem with an uploaded file:
76
76
 
77
77
  // <textarea data-type="application/json">
78
78
  // {"ok": false, "message": "Please only upload reasonably sized files."}
@@ -96,6 +96,7 @@
96
96
  // switches to the "iframe" data type if it is `true`.
97
97
  $.ajaxPrefilter(function(options, origOptions, jqXHR) {
98
98
  if (options.iframe) {
99
+ options.originalURL = options.url;
99
100
  return "iframe";
100
101
  }
101
102
  });
@@ -109,18 +110,18 @@
109
110
  name = "iframe-" + $.now(),
110
111
  files = $(options.files).filter(":file:enabled"),
111
112
  markers = null,
112
- accepts;
113
+ accepts = null;
113
114
 
114
115
  // This function gets called after a successful submission or an abortion
115
116
  // and should revert all changes made to the page to enable the
116
117
  // submission via this transport.
117
118
  function cleanUp() {
118
- markers.each(function(i){
119
- $(this).replaceWith(files[i]);
120
- markers.splice(i, 1);
119
+ files.each(function(i, file) {
120
+ var $file = $(file);
121
+ $file.data("clone").replaceWith($file);
121
122
  });
122
123
  form.remove();
123
- iframe.bind("load", function() { iframe.remove(); });
124
+ iframe.one("load", function() { iframe.remove(); });
124
125
  iframe.attr("src", "about:blank");
125
126
  }
126
127
 
@@ -129,9 +130,14 @@
129
130
  // (unsupported) conversion from "iframe" to the actual type.
130
131
  options.dataTypes.shift();
131
132
 
133
+ // Use the data from the original AJAX options, as it doesn't seem to be
134
+ // copied over since jQuery 1.7.
135
+ // See https://github.com/cmlenz/jquery-iframe-transport/issues/6
136
+ options.data = origOptions.data;
137
+
132
138
  if (files.length) {
133
139
  form = $("<form enctype='multipart/form-data' method='post'></form>").
134
- hide().attr({action: options.url, target: name});
140
+ hide().attr({action: options.originalURL, target: name});
135
141
 
136
142
  // If there is any additional data specified via the `data` option,
137
143
  // we add it as hidden fields to the form. This (currently) requires
@@ -155,21 +161,27 @@
155
161
  $("<input type='hidden' value='IFrame' name='X-Requested-With' />").
156
162
  appendTo(form);
157
163
 
158
- // Borrowed straight from the JQuery source
159
- // Provides a way of specifying the accepted data type similar to HTTP_ACCEPTS
160
- accepts = options.dataTypes[ 0 ] && options.accepts[ options.dataTypes[0] ] ?
161
- options.accepts[ options.dataTypes[0] ] + ( options.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
162
- options.accepts[ "*" ]
163
-
164
- $("<input type='hidden' name='X-Http-Accept'>")
165
- .attr("value", accepts).appendTo(form);
164
+ // Borrowed straight from the JQuery source.
165
+ // Provides a way of specifying the accepted data type similar to the
166
+ // HTTP "Accept" header
167
+ if (options.dataTypes[0] && options.accepts[options.dataTypes[0]]) {
168
+ accepts = options.accepts[options.dataTypes[0]] +
169
+ (options.dataTypes[0] !== "*" ? ", */*; q=0.01" : "");
170
+ } else {
171
+ accepts = options.accepts["*"];
172
+ }
173
+ $("<input type='hidden' name='X-HTTP-Accept'>").
174
+ attr("value", accepts).appendTo(form);
166
175
 
167
176
  // Move the file fields into the hidden form, but first remember their
168
177
  // original locations in the document by replacing them with disabled
169
178
  // clones. This should also avoid introducing unwanted changes to the
170
179
  // page layout during submission.
171
180
  markers = files.after(function(idx) {
172
- return $(this).clone().prop("disabled", true);
181
+ var $this = $(this),
182
+ $clone = $this.clone().prop("disabled", true);
183
+ $this.data("clone", $clone);
184
+ return $clone;
173
185
  }).next();
174
186
  files.appendTo(form);
175
187
 
@@ -183,13 +195,13 @@
183
195
 
184
196
  // The first load event gets fired after the iframe has been injected
185
197
  // into the DOM, and is used to prepare the actual submission.
186
- iframe.bind("load", function() {
198
+ iframe.one("load", function() {
187
199
 
188
200
  // The second load event gets fired when the response to the form
189
201
  // submission is received. The implementation detects whether the
190
202
  // actual payload is embedded in a `<textarea>` element, and
191
203
  // prepares the required conversions to be made in that case.
192
- iframe.unbind("load").bind("load", function() {
204
+ iframe.one("load", function() {
193
205
  var doc = this.contentWindow ? this.contentWindow.document :
194
206
  (this.contentDocument ? this.contentDocument : this.document),
195
207
  root = doc.documentElement ? doc.documentElement : doc.body,
@@ -204,9 +216,6 @@
204
216
  root ? (root.textContent || root.innerText) : null
205
217
  };
206
218
  cleanUp();
207
- if (!jqXHR.responseText) {
208
- jqXHR.responseText = content.text;
209
- }
210
219
  completeCallback(status, statusText, content, type ?
211
220
  ("Content-Type: " + type) :
212
221
  null);
@@ -226,7 +235,7 @@
226
235
  // aborted.
227
236
  abort: function() {
228
237
  if (iframe !== null) {
229
- iframe.unbind("load").attr("src", "javascript:false;");
238
+ iframe.unbind("load").attr("src", "about:blank");
230
239
  cleanUp();
231
240
  }
232
241
  }
@@ -51,7 +51,7 @@
51
51
  // Allow remotipartSubmit to be cancelled if needed
52
52
  if ($.rails.fire(form, 'ajax:remotipartSubmit', [xhr, settings])) {
53
53
  // Second verse, same as the first
54
- $.rails.ajax(settings).complete(function(data){
54
+ $.rails.ajax(settings).always(function(data){
55
55
  $.rails.fire(form, 'ajax:remotipartComplete', [data]);
56
56
  });
57
57
  setTimeout(function(){ $.rails.disableFormElements(form); }, 20);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotipart
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Leppert
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-06 00:00:00.000000000 Z
12
+ date: 2018-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.5.1
95
+ rubygems_version: 2.5.2
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style