remotipart 0.4.2 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ //= require jquery.iframe-transport.js
2
+ //= require_self
3
+
1
4
  (function($) {
2
5
 
3
6
  var remotipart;
@@ -6,47 +9,34 @@
6
9
 
7
10
  setup: function(form) {
8
11
  form
9
- // Append hidden input so we can tell from back-end when form has been submitted by remotipart
10
- .append($('<input />', {
11
- 'id': "remotipart_submitted",
12
- type: "hidden",
13
- name: "remotipart_submitted",
14
- value: true
15
- }))
16
-
17
- // Allow setup part of $.rails.handleRemot to setup remote settings before canceling default remote handler
18
- .bind('ajax:beforeSend.remotipart', function(e, xhr, origSettings){
19
- // Shallow copy
20
- var settings = $.extend({}, origSettings);
21
-
12
+ // Allow setup part of $.rails.handleRemote to setup remote settings before canceling default remote handler
13
+ // This is required in order to change the remote settings using the form details
14
+ .one('ajax:beforeSend.remotipart', function(e, xhr, settings){
22
15
  // Delete the beforeSend bindings, since we're about to re-submit via ajaxSubmit with the beforeSubmit
23
16
  // hook that was just setup and triggered via the default `$.rails.handleRemote`
17
+ // delete settings.beforeSend;
24
18
  delete settings.beforeSend;
25
- // form.js's `ajaxSubmit` will re-create this for us
26
- delete settings.data;
27
19
 
28
- // Manually set the default dataType if not defined, since the form.js's `ajaxSubmit` function
29
- // does not actually submit an xhr request (which has its default dataType set by rails.js)
30
- if (settings.dataType === undefined) settings.dataType = 'script';
20
+ settings.iframe = true;
21
+ settings.files = $($.rails.fileInputSelector, form);
22
+ settings.data = form.serializeArray();
23
+ settings.processData = false;
24
+
25
+ // Modify some settings to integrate JS request with rails helpers and middleware
26
+ if (settings.dataType === undefined) { settings.dataType = 'script *'; }
27
+ settings.data.push({name: 'remotipart_submitted', value: true});
31
28
 
32
29
  // Allow remotipartSubmit to be cancelled if needed
33
30
  if ($.rails.fire(form, 'ajax:remotipartSubmit', [xhr, settings])) {
31
+ // Second verse, same as the first
32
+ $.rails.ajax(settings);
33
+ }
34
34
 
35
- // Setup request URL for js dataType (needed for some versions of IE)
36
- if (settings.dataType == 'script') {
37
- settings.url = settings.url.split('?'); // split on GET params
38
- if (settings.url[0].substr(-3) != '.js') settings.url[0] += '.js'; // force rails to respond to respond to the request with :format = js
39
- settings.url = settings.url.join('?'); // join on GET params
40
- }
41
-
42
- // Update remotipartSubmitted data with dataType, in case needed in other scripts
43
- form.data('remotipartSubmitted', settings.dataType);
44
- // And finally, Use form.js's `ajaxSubmit` to do remote file uploading via iframe method
45
- form.ajaxSubmit(settings);
35
+ //Run cleanup
36
+ remotipart.teardown(form);
46
37
 
47
- // Cancel the default jquery-ujs remote call by returning false for `ajax:beforeSend`
48
- return false;
49
- }
38
+ // Cancel the jQuery UJS request
39
+ return false;
50
40
  })
51
41
 
52
42
  // Keep track that we just set this particular form with Remotipart bindings
@@ -57,27 +47,22 @@
57
47
  teardown: function(form) {
58
48
  form
59
49
  .unbind('ajax:beforeSend.remotipart')
60
- .children('#remotipart_submitted').remove();
61
- delete form.data.remotipartSubmitted;
50
+ .removeData('remotipartSubmitted')
62
51
  }
63
52
  };
64
53
 
65
54
  $('form').live('ajax:aborted:file', function(){
66
55
  var form = $(this);
67
56
 
68
- // Only need to setup form and make form bindings once.
69
- // If form has already been setup, just let bindings be executed.
70
- if (form.data('remotipartSubmitted') === undefined) remotipart.setup(form);
57
+ remotipart.setup(form);
71
58
 
72
59
  // If browser does not support submit bubbling, then this live-binding will be called before direct
73
60
  // bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
74
- if (!$.support.submitBubbles && 'callFormSubmitBindings' in $.rails && $.rails.callFormSubmitBindings(form) === false) return $.rails.stopEverything(e);
61
+ if (!$.support.submitBubbles && $.rails.callFormSubmitBindings(form) === false) return $.rails.stopEverything(e);
75
62
 
76
63
  // Manually call jquery-ujs remote call so that it can setup form and settings as usual,
77
64
  // and trigger the `ajax:beforeSend` callback to which remotipart binds functionality.
78
65
  $.rails.handleRemote(form);
79
-
80
- // Return false to prevent standard browser behavior (part of jquery-ujs api for `ajax:aborted:file`)
81
66
  return false;
82
67
  });
83
68
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotipart
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 4
9
- - 2
10
- version: 0.4.2
9
+ version: "1.0"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Greg Leppert
@@ -54,16 +53,18 @@ files:
54
53
  - VERSION_COMPATIBILITY.rdoc
55
54
  - lib/generators/remotipart/install/install_generator.rb
56
55
  - lib/remotipart.rb
56
+ - lib/remotipart/middleware.rb
57
57
  - lib/remotipart/rails.rb
58
58
  - lib/remotipart/rails/engine.rb
59
59
  - lib/remotipart/rails/railtie.rb
60
60
  - lib/remotipart/rails/version.rb
61
+ - lib/remotipart/render_overrides.rb
61
62
  - lib/remotipart/request_helper.rb
62
63
  - lib/remotipart/view_helper.rb
63
64
  - remotipart.gemspec
64
65
  - test/helper.rb
65
66
  - test/test_remotipart.rb
66
- - vendor/assets/javascripts/jquery.form.js
67
+ - vendor/assets/javascripts/jquery.iframe-transport.js
67
68
  - vendor/assets/javascripts/jquery.remotipart.js
68
69
  has_rdoc: true
69
70
  homepage: http://www.alfajango.com/blog/remotipart-rails-gem/