Sha256: 2912c5933b94c4fa97dfd35096346e3639a171d003a77b70066f0ae7f8ef2ed5

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

jQuery(function ($) {
  $.fn.extend({
    /**
     * Handles execution of remote calls involving file uploads, firing overridable events along the way
     */
    callRemotipart: function () {
      var el      = this,
          url     = el.attr('action');

      if (url === undefined) {
        throw "No URL specified for remote call (action must be present).";
      } else {
        if (el.triggerAndReturn('ajax:before')) {

          // force rails to respond to respond to the request with :format = js
          // Add .js to the right part of the URL
          splitUrl = url.split("?");
          var path = splitUrl[0];
          var request_string = splitUrl[1];
          if (path.substr(-3) != '.js') path += '.js'; 
          url = path + "?" + request_string;

          el.ajaxSubmit({
            url: url,
            dataType: 'script',
            beforeSend: function (xhr) {
              el.trigger('ajax:loading', xhr);
            },
            success: function (data, status, xhr) {
              el.trigger('ajax:success', [data, status, xhr]);
            },
            complete: function (xhr) {
              el.trigger('ajax:complete', xhr);
            },
            error: function (xhr, status, error) {
              el.trigger('ajax:failure', [xhr, status, error]);
            }
          });
        }
        el.trigger('ajax:after');
      }
    },
    _callRemote: $.fn.callRemote, //store the original rails callRemote
    callRemote: function() { //override the rails callRemote and check for a file input
      if(this.find('input:file').length){
        this.callRemotipart();
      } else {
        this._callRemote();
      }
    }
  });
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i0n_rails3_generators-0.2.19 lib/generators/i0n/layout/templates/public/javascripts/vendor/jquery.remotipart.js
i0n_rails3_generators-0.2.18 lib/generators/i0n/layout/templates/public/javascripts/vendor/jquery.remotipart.js