Skip to content

Instantly share code, notes, and snippets.

@elhardoum
Created September 27, 2016 13:52
Show Gist options
  • Save elhardoum/22e4ae0f2bca905f88a89d9b2f056713 to your computer and use it in GitHub Desktop.
Save elhardoum/22e4ae0f2bca905f88a89d9b2f056713 to your computer and use it in GitHub Desktop.
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = (percentComplete.toFixed(2) * 100);
// add a progress bar container
if ( $('#upload-progress',container).length == 0 ) {
$(container).append('<div id="upload-progress" style="background: rgba(255, 186, 186, 0.32); width: 0; overflow: hidden; padding: 4px;"></div>');
}
$('#upload-progress',container).css({
width: percentComplete + '%'
});
}
}, false);
return xhr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment