diff options
author | James Lal <james@lightsofapollo.com> | 2013-01-07 05:16:42 -0800 |
---|---|---|
committer | James Lal <james@lightsofapollo.com> | 2013-01-07 05:16:42 -0800 |
commit | 3f8833038d337d2840dc7ca06ddcb8c26a21bd14 (patch) | |
tree | bdb1dece706b0a2a4b5a0b8442a1bffc45fc794f /caldav.js | |
parent | 0b6e8afda0bc88fdfe0a64a15abfe537b5569bf7 (diff) | |
parent | 3170505852bbb6379a712ff816e1715f512516ad (diff) | |
download | jsCalDAV-3f8833038d337d2840dc7ca06ddcb8c26a21bd14.tar.gz |
Merge pull request #8 from mozilla-b2g/progress-events
Progress events
Diffstat (limited to 'caldav.js')
-rw-r--r-- | caldav.js | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -1425,6 +1425,10 @@ function write (chunk) { return this._parse.write(chunk); }, + close: function() { + this._parse.close(); + }, + get closed() { return this._parse.closed; }, @@ -2096,10 +2100,35 @@ function write (chunk) { } } + + var hasProgressEvents = false; + + // check for progress event support. + if ('onprogress' in xhr) { + hasProgressEvents = true; + var last = 0; + xhr.onprogress = function onProgress(event) { + var chunk = xhr.responseText.substr(last, event.loaded); + last = event.loaded; + if (this.ondata) { + this.ondata(chunk); + } + }.bind(this); + } + xhr.onreadystatechange = function onReadyStateChange() { var data; if (xhr.readyState === 4) { data = xhr.responseText; + + // emulate progress events for node... + // this really lame we should probably just + // use a real http request for node but this + // will let us do some testing via node for now. + if (!hasProgressEvents && this.ondata) { + this.ondata(data); + } + this.waiting = false; callback(null, xhr); } @@ -2666,12 +2695,16 @@ function write (chunk) { var req = this.xhr; req.data = this._createPayload(); + req.ondata = function xhrOnData(chunk) { + self.sax.write(chunk); + }; + // in the future we may stream data somehow req.send(function xhrResult() { var xhr = req.xhr; if (xhr.status > 199 && xhr.status < 300) { // success - self.sax.write(xhr.responseText).close(); + self.sax.close(); self._processResult(req, callback); } else { // fail |