summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/MochiKit/Async.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/MochiKit/Async.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/js/MochiKit/Async.js118
1 files changed, 92 insertions, 26 deletions
diff --git a/frontend/gamma/js/MochiKit/Async.js b/frontend/gamma/js/MochiKit/Async.js
index c7408e7..cc43835 100644
--- a/frontend/gamma/js/MochiKit/Async.js
+++ b/frontend/gamma/js/MochiKit/Async.js
@@ -10,3 +10,3 @@ See <http://mochikit.com/> for documentation, downloads, license, etc.
10 10
11MochiKit.Base._module('Async', '1.5', ['Base']); 11MochiKit.Base.module(MochiKit, 'Async', '1.5', ['Base']);
12 12
@@ -22,2 +22,3 @@ MochiKit.Async.Deferred = function (/* optional */ canceller) {
22 this.chained = false; 22 this.chained = false;
23 this.finalized = false;
23}; 24};
@@ -27,11 +28,3 @@ MochiKit.Async.Deferred.prototype = {
27 repr: function () { 28 repr: function () {
28 var state; 29 return 'Deferred(' + this.id + ', ' + this.state() + ')';
29 if (this.fired == -1) {
30 state = 'unfired';
31 } else if (this.fired === 0) {
32 state = 'success';
33 } else {
34 state = 'error';
35 }
36 return 'Deferred(' + this.id + ', ' + state + ')';
37 }, 30 },
@@ -42,4 +35,15 @@ MochiKit.Async.Deferred.prototype = {
42 35
36 /** @id MochiKit.Async.Deferred.prototype.state */
37 state: function () {
38 if (this.fired == -1) {
39 return 'unfired';
40 } else if (this.fired === 0) {
41 return 'success';
42 } else {
43 return 'error';
44 }
45 },
46
43 /** @id MochiKit.Async.Deferred.prototype.cancel */ 47 /** @id MochiKit.Async.Deferred.prototype.cancel */
44 cancel: function () { 48 cancel: function (e) {
45 var self = MochiKit.Async; 49 var self = MochiKit.Async;
@@ -52,6 +56,11 @@ MochiKit.Async.Deferred.prototype = {
52 if (this.fired == -1) { 56 if (this.fired == -1) {
53 this.errback(new self.CancelledError(this)); 57 if (typeof(e) === 'string') {
58 e = new self.GenericError(e);
59 } else if (!(e instanceof Error)) {
60 e = new self.CancelledError(this);
61 }
62 this.errback(e);
54 } 63 }
55 } else if ((this.fired === 0) && (this.results[0] instanceof self.Deferred)) { 64 } else if ((this.fired === 0) && (this.results[0] instanceof self.Deferred)) {
56 this.results[0].cancel(); 65 this.results[0].cancel(e);
57 } 66 }
@@ -67,3 +76,5 @@ MochiKit.Async.Deferred.prototype = {
67 this.results[this.fired] = res; 76 this.results[this.fired] = res;
77 if (this.paused === 0) {
68 this._fire(); 78 this._fire();
79 }
69 }, 80 },
@@ -131,2 +142,5 @@ MochiKit.Async.Deferred.prototype = {
131 } 142 }
143 if (this.finalized) {
144 throw new Error("Finalized Deferreds can not be re-used");
145 }
132 this.chain.push([cb, eb]); 146 this.chain.push([cb, eb]);
@@ -138,2 +152,20 @@ MochiKit.Async.Deferred.prototype = {
138 152
153 /** @id MochiKit.Async.Deferred.prototype.setFinalizer */
154 setFinalizer: function (fn) {
155 if (this.chained) {
156 throw new Error("Chained Deferreds can not be re-used");
157 }
158 if (this.finalized) {
159 throw new Error("Finalized Deferreds can not be re-used");
160 }
161 if (arguments.length > 1) {
162 fn = MochiKit.Base.partial.apply(null, arguments);
163 }
164 this._finalizer = fn;
165 if (this.fired >= 0) {
166 this._fire();
167 }
168 return this;
169 },
170
139 _fire: function () { 171 _fire: function () {
@@ -162,7 +194,4 @@ MochiKit.Async.Deferred.prototype = {
162 cb = function (res) { 194 cb = function (res) {
163 self._resback(res);
164 self.paused--; 195 self.paused--;
165 if ((self.paused === 0) && (self.fired >= 0)) { 196 self._resback(res);
166 self._fire();
167 }
168 }; 197 };
@@ -180,2 +209,6 @@ MochiKit.Async.Deferred.prototype = {
180 this.results[fired] = res; 209 this.results[fired] = res;
210 if (this.chain.length == 0 && this.paused === 0 && this._finalizer) {
211 this.finalized = true;
212 this._finalizer(res);
213 }
181 if (cb && this.paused) { 214 if (cb && this.paused) {
@@ -251,3 +284,3 @@ MochiKit.Base.update(MochiKit.Async, {
251 status = this.status; 284 status = this.status;
252 if (!status && m.isNotEmpty(this.responseText)) { 285 if (!status && (this.response || m.isNotEmpty(this.responseText))) {
253 // 0 or undefined seems to mean cached or local 286 // 0 or undefined seems to mean cached or local
@@ -339,3 +372,4 @@ MochiKit.Base.update(MochiKit.Async, {
339 headers: undefined, 372 headers: undefined,
340 mimeType: undefined 373 mimeType: undefined,
374 responseType: undefined
341 */ 375 */
@@ -373,2 +407,5 @@ MochiKit.Base.update(MochiKit.Async, {
373 } 407 }
408 if ("responseType" in opts && "responseType" in req) {
409 req.responseType = opts.responseType;
410 }
374 return self.sendXMLHttpRequest(req, opts.sendContent); 411 return self.sendXMLHttpRequest(req, opts.sendContent);
@@ -406,2 +443,35 @@ MochiKit.Base.update(MochiKit.Async, {
406 443
444 /** @id MochiKit.Async.loadScript */
445 loadScript: function (url) {
446 var d = new MochiKit.Async.Deferred();
447 var script = document.createElement("script");
448 script.type = "text/javascript";
449 script.src = url;
450 script.onload = function () {
451 script.onload = null;
452 script.onerror = null;
453 script.onreadystatechange = null;
454 script = null;
455 d.callback();
456 };
457 script.onerror = function (msg) {
458 script.onload = null;
459 script.onerror = null;
460 script.onreadystatechange = null;
461 script = null;
462 msg = "Failed to load script at " + url + ": " + msg;
463 d.errback(new URIError(msg, url));
464 }
465 script.onreadystatechange = function () {
466 if (script.readyState == "loaded" || script.readyState == "complete") {
467 script.onload();
468 } else {
469 // IE doesn't bother to report errors...
470 MochiKit.Async.callLater(10, script.onerror, "Script loading timed out")
471 }
472 };
473 document.getElementsByTagName("head")[0].appendChild(script);
474 return d;
475 },
476
407 /** @id MochiKit.Async.wait */ 477 /** @id MochiKit.Async.wait */
@@ -409,9 +479,4 @@ MochiKit.Base.update(MochiKit.Async, {
409 var d = new MochiKit.Async.Deferred(); 479 var d = new MochiKit.Async.Deferred();
410 var m = MochiKit.Base; 480 var cb = MochiKit.Base.bind("callback", d, value);
411 if (typeof(value) != 'undefined') { 481 var timeout = setTimeout(cb, Math.floor(seconds * 1000));
412 d.addCallback(function () { return value; });
413 }
414 var timeout = setTimeout(
415 m.bind("callback", d),
416 Math.floor(seconds * 1000));
417 d.canceller = function () { 482 d.canceller = function () {
@@ -512,2 +577,3 @@ MochiKit.Async.DeferredList = function (list, /* optional */fireOnOneCallback, f
512MochiKit.Async.DeferredList.prototype = new MochiKit.Async.Deferred(); 577MochiKit.Async.DeferredList.prototype = new MochiKit.Async.Deferred();
578MochiKit.Async.DeferredList.prototype.constructor = MochiKit.Async.DeferredList;
513 579