Skip to content

Instantly share code, notes, and snippets.

@dsifry
Created July 18, 2010 07:50
Show Gist options
  • Save dsifry/480215 to your computer and use it in GitHub Desktop.
Save dsifry/480215 to your computer and use it in GitHub Desktop.
// if this is the iframe
// reload the parent
Event.observe(window, 'load',
function() {
try
{
if (self.parent.frames.length != 0)
self.parent.location=document.location;
}
catch (Exception) {}
}
);
Event.addBehavior({
"input.submit:click" : function () {
$('progress').show();
//add iframe and set form target to this iframe
$$("body").first().insert({bottom: "<iframe name='progressFrame' style='display:none; width:0; height:0; position: absolute; top:30000px;'></iframe>"});
$(this).up('form').writeAttribute("target", "progressFrame");
$(this).up('form').submit();
//update the progress bar
var uuid = $('X-Progress-ID').value;
new PeriodicalExecuter(
function(){
if(Ajax.activeRequestCount == 0){
new Ajax.Request("/progress",{
method: 'get',
parameters: 'X-Progress-ID=' + uuid,
onSuccess: function(xhr){
var upload = xhr.responseText.evalJSON();
if(upload.state == 'uploading'){
upload.percent = Math.floor((upload.received / upload.size) * 100);
$('bar').setStyle({width: upload.percent + "%"});
$('bar').update(upload.percent + "%");
}
}
})
}
},100);
return false;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment