From a5742d1a2aa42db0993081269beea695049d2805 Mon Sep 17 00:00:00 2001 From: aj Date: Fri, 25 Aug 2017 23:47:31 +0000 Subject: [PATCH] add progress --- oauth3.core.js | 22 ++++++++++++++++++++-- oauth3.ng.js | 7 +++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/oauth3.core.js b/oauth3.core.js index 6765270..341ffe6 100644 --- a/oauth3.core.js +++ b/oauth3.core.js @@ -868,6 +868,9 @@ , request: function (preq, _sys) { return new OAUTH3.PromiseA(function (resolve, reject) { var xhr; + var headers = preq.headers || {}; + var multipart; + try { xhr = new XMLHttpRequest(_sys); } catch(e) { @@ -898,9 +901,24 @@ , status: xhr.status }); }; + + console.log('$$$$$$$$$$$$$$$$$$$$$$$$ preq.progress:'); + console.log(preq.progress); + if (preq.progress) { + xhr.upload.onprogress = function (ev) { + console.log('[progress]'); + console.log(ev); + preq.progress({ + loaded: ev.loaded + , total: ev.total + }); + if (OAUTH3._digest) { + // $rootScope.$digest(); + OAUTH3._digest(); + } + }; + } xhr.open(preq.method || 'GET', preq.url, true); - var headers = preq.headers || {}; - var multipart; if (preq.data) { headers['Content-Type'] = 'application/json'; // TODO XXX TODO utf8 diff --git a/oauth3.ng.js b/oauth3.ng.js index e8d089d..440975c 100644 --- a/oauth3.ng.js +++ b/oauth3.ng.js @@ -5,8 +5,8 @@ var modules = { azp: [ '$timeout' , '$q' - , function Oauth3($timeout, $q) { - + , '$rootScope' + , function Oauth3($timeout, $q, $rootScope) { var OAUTH3 = window.OAUTH3; // We need to make angular's $q appear to be a standard Promise/A+ @@ -29,6 +29,9 @@ var modules = { PromiseAngularQ.all = $q.all; OAUTH3.PromiseA = PromiseAngularQ; + OAUTH3._digest = function () { + $rootScope.$digest(); + }; window.ngOauth3 = OAUTH3;