Skip to content

@dmitry /gist:127178
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
jQuery.fn.extend({
// upload file through iframe, without refreshing the page, must be wrapped by form
// jquery.timers dependent
// $("input[type='file']").iframeFileUpload({blank_pathname: '/my_blank_file.html', autoSubmit: true, onStart: function(el){}, onStop(el){}});
iframeFileUpload: function(options) {
return this.each(function(){
var blank_pathname = options.blank_pathname || '/blank.html';
var el = $(this);
var form = el.parents('form');
var iframe_id = 'iframe_' + form.attr('id');
if ($('#' + iframe_id).length == 0) {
var iframe = $("<iframe name='" + iframe_id + "'></iframe>"); // holly ie hack
iframe.attr('id', iframe_id);
iframe.css('display', 'none');
iframe.attr('src', blank_pathname);
$('body').prepend(iframe);
}
form.attr('target', iframe_id);
if (options.autoSubmit) {
el.change(function(e){
form.submit();
(options.onStart)(el);
jQuery.active++;
jQuery.event.trigger("ajaxStart");
jQuery.event.trigger("ajaxSend");
$(document).everyTime(100, iframe_id, function(i) {
if ($('#' + iframe_id).contents()[0].location.pathname != blank_pathname) {
$(document).stopTime(iframe_id);
--jQuery.active;
jQuery.event.trigger("ajaxComplete");
jQuery.event.trigger("ajaxStop");
iframe.attr('src', blank_pathname);
$(document).oneTime(10, function(i) {
(options.onStop)(el);
});
}
});
});
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.