From f31b976c83f80bac9519edc6d3bb12beeb58d851 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 8 Oct 2017 15:07:28 +1300 Subject: [PATCH] sdk: fix retrieving progress information --- static/sdk.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/static/sdk.js b/static/sdk.js index 69e0f63..abd1740 100644 --- a/static/sdk.js +++ b/static/sdk.js @@ -152,13 +152,20 @@ var contented = (function ($, currentScriptPath) { cache: false, contentType: false, processData: false, - beforeSend: function (xhr) { - xhr.on('progress', function (ev) { - if (ev.lengthComputable) { - setProgressCaption("Uploaded " + formatBytes(evt.loaded) + " of " + formatBytes(evt.total) + "..."); - setProgressPercentage(evt.loaded / evt.total); - } - }); + xhr: function() { + var xhr = $.ajaxSettings.xhr(); + xhr.upload.addEventListener( + 'progress', + function(ev) { + console.log([ev.lengthComputable, ev.loaded, ev.total]); + if (ev.lengthComputable) { + setProgressCaption("Uploading (" + formatBytes(ev.loaded) + " / " + formatBytes(ev.total) + ")..."); + setProgressPercentage(ev.total == 0 ? 0 : ev.loaded / ev.total); + } + }, + false + ); + return xhr; }, complete: function () { setProgressCaption("Upload complete.");