aboutsummaryrefslogtreecommitdiffstats
path: root/caldav.js
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2013-01-07 05:16:42 -0800
committerJames Lal <james@lightsofapollo.com>2013-01-07 05:16:42 -0800
commit3f8833038d337d2840dc7ca06ddcb8c26a21bd14 (patch)
treebdb1dece706b0a2a4b5a0b8442a1bffc45fc794f /caldav.js
parent0b6e8afda0bc88fdfe0a64a15abfe537b5569bf7 (diff)
parent3170505852bbb6379a712ff816e1715f512516ad (diff)
downloadjsCalDAV-3f8833038d337d2840dc7ca06ddcb8c26a21bd14.tar.gz
Merge pull request #8 from mozilla-b2g/progress-events
Progress events
Diffstat (limited to 'caldav.js')
-rw-r--r--caldav.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/caldav.js b/caldav.js
index a37263e..32cfb34 100644
--- a/caldav.js
+++ b/caldav.js
@@ -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