Sha256: 190bcaed2ac4be848077e0f79804f7cc3c2d3db84812e0b49d2ade4075041739

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 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')) {

		          	url = url.split('?'); // split on GET params
					if(url[0].substr(-3) != '.js') url[0] += '.js'; // force rails to respond to respond to the request with :format = js
					url = url.join('?'); // join on GET params
					
	                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

3 entries across 3 versions & 2 rubygems

Version Path
remotipart-0.2.1 lib/generators/templates/jquery.remotipart.js
tfe-remotipart-0.2.1 lib/generators/templates/jquery.remotipart.js
remotipart-0.2.0 lib/generators/templates/jquery.remotipart.js