diff --git a/js-compiled.js b/js-compiled.js index 5061d21..821b37c 100644 --- a/js-compiled.js +++ b/js-compiled.js @@ -102,7 +102,7 @@ function fa(a) { if (x(h) || null != h.f && " " != w(h)) { a.context.fillStyle = null != h.f ? "#DEF" : "#F5F5F5", b.fillRect(9 * g - a.offset.x, 17 * (k - 1) - a.offset.y, 9, 17); } - var t = E(a.state, new l(g, k)); + var t = ga(a.state, new l(g, k)); null == t || x(h) && !e || (a.context.fillStyle = "#000000", b.fillText(t, 9 * g - a.offset.x, 17 * k - a.offset.y - 3)); } } @@ -126,62 +126,62 @@ function fa(a) { function B(a, b) { return new l(Math.min(Math.max(1, Math.round(((new l((b.x - a.canvas.width / 2) / a.zoom + a.offset.x, (b.y - a.canvas.height / 2) / a.zoom + a.offset.y)).x - 4.5) / 9)), 1998), Math.min(Math.max(1, Math.round(((new l((b.x - a.canvas.width / 2) / a.zoom + a.offset.x, (b.y - a.canvas.height / 2) / a.zoom + a.offset.y)).y + 8.5) / 17)), 598)); } -;function F(a, b, c, d, e) { +;function E(a, b, c, d, e) { e = e || "+"; var g = Math.min(b.x, c.x), k = Math.min(b.y, c.y), h = Math.max(b.x, c.x), t = Math.max(b.y, c.y), u = d ? c.x : b.x; for (d = d ? b.y : c.y;g++ < h;) { var Q = new l(g, d), D = a.getContext(new l(g, d)); - " " == e && 2 == D.m + D.j || H(a, Q, e); + " " == e && 2 == D.m + D.j || F(a, Q, e); } for (;k++ < t;) { - Q = new l(u, k), D = a.getContext(new l(u, k)), " " == e && 2 == D.left + D.right || H(a, Q, e); + Q = new l(u, k), D = a.getContext(new l(u, k)), " " == e && 2 == D.left + D.right || F(a, Q, e); } - I(a, b, e); - I(a, c, e); - H(a, new l(u, d), e); + H(a, b, e); + H(a, c, e); + F(a, new l(u, d), e); } -function J(a) { +function I(a) { this.state = a; this.a = null; } -J.prototype.start = function(a) { +I.prototype.start = function(a) { this.a = a; }; -J.prototype.move = function(a) { +I.prototype.move = function(a) { this.g = a; + J(this.state); + E(this.state, this.a, a, !0); + E(this.state, this.a, a, !1); +}; +I.prototype.end = function() { K(this.state); - F(this.state, this.a, a, !0); - F(this.state, this.a, a, !1); }; -J.prototype.end = function() { - L(this.state); -}; -J.prototype.l = function() { +I.prototype.l = function() { return "crosshair"; }; -J.prototype.e = function() { +I.prototype.e = function() { }; -function M(a) { +function L(a) { this.state = a; this.a = null; } -M.prototype.start = function(a) { +L.prototype.start = function(a) { this.a = a; }; -M.prototype.move = function(a) { - K(this.state); +L.prototype.move = function(a) { + J(this.state); var b = this.state.getContext(this.a), c = this.state.getContext(a); - F(this.state, this.a, a, b.m && b.j || c.left && c.right); + E(this.state, this.a, a, b.m && b.j || c.left && c.right); }; -M.prototype.end = function() { - L(this.state); +L.prototype.end = function() { + K(this.state); }; -M.prototype.l = function() { +L.prototype.l = function() { return "crosshair"; }; -M.prototype.e = function() { +L.prototype.e = function() { }; -function N(a, b) { +function M(a, b) { this.state = a; this.value = b; f && ($("#freeform-tool-input").val(""), $("#freeform-tool-input").hide(0, function() { @@ -190,84 +190,84 @@ function N(a, b) { }); })); } -N.prototype.start = function(a) { - I(this.state, a, this.value); +M.prototype.start = function(a) { + H(this.state, a, this.value); }; -N.prototype.move = function(a) { - I(this.state, a, this.value); +M.prototype.move = function(a) { + H(this.state, a, this.value); }; -N.prototype.end = function() { - L(this.state); +M.prototype.end = function() { + K(this.state); }; -N.prototype.l = function() { +M.prototype.l = function() { return "crosshair"; }; -N.prototype.e = function(a) { +M.prototype.e = function(a) { f && (this.value = $("#freeform-tool-input").val().substr(0, 1), $("#freeform-tool-input").blur(), $("#freeform-tool-input").hide(0)); 1 == a.length && (this.value = a); }; -function O(a) { +function N(a) { this.state = a; this.a = null; } -O.prototype.start = function(a) { - L(this.state); +N.prototype.start = function(a) { + K(this.state); $("#text-tool-input").val(""); this.a = a; a = w(C(this.state, this.a)); - I(this.state, this.a, null == a ? "\u2009" : a); + H(this.state, this.a, null == a ? "\u2009" : a); }; -O.prototype.move = function() { +N.prototype.move = function() { }; -O.prototype.end = function() { +N.prototype.end = function() { null != this.a && (this.g = this.a, this.a = null, $("#text-tool-widget").hide(0, function() { $("#text-tool-widget").show(0, function() { $("#text-tool-input").focus(); }); })); }; -O.prototype.l = function() { +N.prototype.l = function() { return "pointer"; }; -O.prototype.e = function() { +N.prototype.e = function() { var a = $("#text-tool-input").val(); - K(this.state); + J(this.state); for (var b = 0, c = 0, d = 0;d < a.length;d++) { - "\n" == a[d] ? (c++, b = 0) : (I(this.state, this.g.add(new l(b, c)), a[d]), b++); + "\n" == a[d] ? (c++, b = 0) : (H(this.state, this.g.add(new l(b, c)), a[d]), b++); } }; -function P(a) { +function O(a) { this.state = a; this.g = this.a = null; } -P.prototype.start = function(a) { +O.prototype.start = function(a) { this.a = a; this.move(a); }; -P.prototype.move = function(a) { - K(this.state); +O.prototype.move = function(a) { + J(this.state); this.g = a; var b = Math.min(this.a.x, this.g.x); a = Math.min(this.a.y, this.g.y); for (var c = Math.max(this.a.x, this.g.x), d = Math.max(this.a.y, this.g.y);b <= c;b++) { for (var e = a;e <= d;e++) { - I(this.state, new l(b, e), "\u2009"); + H(this.state, new l(b, e), "\u2009"); } } }; -P.prototype.end = function() { - L(this.state); +O.prototype.end = function() { + K(this.state); }; -P.prototype.l = function() { +O.prototype.l = function() { return "crosshair"; }; -P.prototype.e = function() { +O.prototype.e = function() { }; -function R(a) { +function P(a) { this.state = a; this.h = this.a = null; } -R.prototype.start = function(a) { +P.prototype.start = function(a) { if (f && !x(C(this.state, a))) { var b = v.concat([p.add(r), p.add(s), q.add(r), q.add(s)]), c = null, d = 0, e; for (e in b) { @@ -282,13 +282,13 @@ R.prototype.start = function(a) { this.state.getContext(this.a); a = []; for (var h in v) { - var b = ga(this, this.a, v[h]), t; + var b = ha(this, this.a, v[h]), t; for (t in b) { if (c = b[t], d = 0 != v[h].x, 1 == y(this.state.getContext(c))) { a.push({position:c, v:d}); } else { for (var u in v) { - 0 != v[h].add(v[u]).length() && 2 != v[h].add(v[u]).length() && (e = ga(this, c, v[u]), 0 != e.length && a.push({position:e[e.length - 1], v:d})); + 0 != v[h].add(v[u]).length() && 2 != v[h].add(v[u]).length() && (e = ha(this, c, v[u]), 0 != e.length && a.push({position:e[e.length - 1], v:d})); } } } @@ -297,19 +297,19 @@ R.prototype.start = function(a) { this.move(this.a); } }; -R.prototype.move = function(a) { - K(this.state); +P.prototype.move = function(a) { + J(this.state); for (var b in this.h) { - F(this.state, this.a, this.h[b].position, this.h[b].v, " "); + E(this.state, this.a, this.h[b].position, this.h[b].v, " "); } for (b in this.h) { - F(this.state, a, this.h[b].position, this.h[b].v); + E(this.state, a, this.h[b].position, this.h[b].v); } }; -R.prototype.end = function() { - L(this.state); +P.prototype.end = function() { + K(this.state); }; -function ga(a, b, c) { +function ha(a, b, c) { for (var d = b.clone(), e = [];;) { var g = d.add(c); if (!x(C(a.state, g))) { @@ -319,12 +319,12 @@ function ga(a, b, c) { 3 == y(a.state.getContext(d)) && e.push(d); } } -R.prototype.l = function(a) { +P.prototype.l = function(a) { return x(C(this.state, a)) ? "pointer" : "default"; }; -R.prototype.e = function() { +P.prototype.e = function() { }; -function S() { +function R() { this.cells = Array(2E3); this.i = []; this.d = !0; @@ -337,33 +337,33 @@ function S() { } } } -S.prototype.clear = function() { +R.prototype.clear = function() { for (var a = 0;a < this.cells.length;a++) { for (var b = 0;b < this.cells[a].length;b++) { - null != w(this.cells[a][b]) && I(this, new l(a, b), "\u2009"); + null != w(this.cells[a][b]) && H(this, new l(a, b), "\u2009"); } } - L(this); + K(this); }; function C(a, b) { return a.cells[b.x][b.y]; } -function I(a, b, c) { +function H(a, b, c) { var d = C(a, b); a.i.push(new ea(b, d)); d.f = c; a.d = !0; } -function H(a, b, c) { - w(C(a, b)) != c && I(a, b, c); +function F(a, b, c) { + w(C(a, b)) != c && H(a, b, c); } -function K(a) { +function J(a) { for (var b in a.i) { a.i[b].F.f = null; } a.i.length = 0; } -function E(a, b) { +function ga(a, b) { var c = C(a, b), c = null != c.f ? c.f : c.value; if ("+" != c) { return c; @@ -371,12 +371,12 @@ function E(a, b) { c = a.getContext(b); return c.left && c.right && !c.m && !c.j ? "\u2013" : !c.left && !c.right && c.m && c.j ? "|" : c.left && c.right && c.m && c.j ? "\u2013" : "+"; } -S.prototype.getContext = function(a) { +R.prototype.getContext = function(a) { var b = x(C(this, a.add(p))), c = x(C(this, a.add(q))), d = x(C(this, a.add(r))); a = x(C(this, a.add(s))); return new ca(b, c, d, a); }; -function L(a, b) { +function K(a, b) { var c = [], d = a.i.map(function(a) { return a.position.x.toString() + a.position.y.toString(); }), e = a.i.filter(function(a, b) { @@ -397,27 +397,27 @@ function L(a, b) { 0 < c.length && (50 < e.length && e.shift(), e.push(c)); a.d = !0; } -function ha(a) { +function ia(a) { if (0 != a.D.length) { var b = a.D.pop(), c; for (c in b) { var d = b[c]; - I(a, d.position, d.value); + H(a, d.position, d.value); } - L(a, !0); + K(a, !0); } } -function ia(a) { +function ja(a) { if (0 != a.C.length) { var b = a.C.pop(), c; for (c in b) { var d = b[c]; - I(a, d.position, d.value); + H(a, d.position, d.value); } - L(a); + K(a); } } -function T(a) { +function S(a) { for (var b = new l(Number.MAX_VALUE, Number.MAX_VALUE), c = new l(-1, -1), d = 0;d < a.cells.length;d++) { for (var e = 0;e < a.cells[d].length;e++) { null != w(a.cells[d][e]) && (d < b.x && (b.x = d), e < b.y && (b.y = e), d > c.x && (c.x = d), e > c.y && (c.y = e)); @@ -428,13 +428,13 @@ function T(a) { } for (var g = "", e = b.y;e <= c.y;e++) { for (var k = "", d = b.x;d <= c.x;d++) { - var h = E(a, new l(d, e)), k = k + (null == h ? " " : h) + var h = ga(a, new l(d, e)), k = k + (null == h ? " " : h) } g += k.replace("\\s+$/g", "") + "\n"; } return g; } -function ja(a, b, c) { +function ka(a, b, c) { b = b.split("\n"); for (var d = new l(0, Math.round(b.length / 2)), e = 0;e < b.length;e++) { d.x = Math.max(d.x, Math.round(b[e].length / 2)); @@ -445,19 +445,19 @@ function ja(a, b, c) { if ("\u2013" == h || "|" == h) { h = "+"; } - I(a, n((new l(k, e)).add(c), d), h); + H(a, n((new l(k, e)).add(c), d), h); } } - L(a); + K(a); } -;function U(a, b) { +;function T(a, b) { this.view = a; this.state = b; - this.c = new J(b); + this.c = new I(b); this.mode = 0; this.n(); } -U.prototype.r = function(a) { +T.prototype.r = function(a) { var b = B(this.view, a); null == this.o && (this.o = b); m(b, this.o) || (this.view.canvas.style.cursor = this.c.l(b)); @@ -470,14 +470,14 @@ U.prototype.r = function(a) { } this.o = b; }; -function V(a) { +function U(a) { 2 == a.mode && a.c.end(); a.mode = 0; a.w = null; a.A = null; a.o = null; } -U.prototype.n = function() { +T.prototype.n = function() { var a = this; $(window).resize(function() { A(a.view); @@ -488,30 +488,30 @@ U.prototype.n = function() { $("#draw-tools > button.tool").removeClass("active"); $("#" + a).toggleClass("active"); $(".dialog").removeClass("visible"); - "box-button" == a && (this.c = new J(this.state)); - "line-button" == a && (this.c = new M(this.state)); - "freeform-button" == a && (this.c = new N(this.state, "+")); - "erase-button" == a && (this.c = new P(this.state)); - "move-button" == a && (this.c = new R(this.state)); - "text-button" == a && (this.c = new O(this.state)); - L(this.state); + "box-button" == a && (this.c = new I(this.state)); + "line-button" == a && (this.c = new L(this.state)); + "freeform-button" == a && (this.c = new M(this.state, "+")); + "erase-button" == a && (this.c = new O(this.state)); + "move-button" == a && (this.c = new P(this.state)); + "text-button" == a && (this.c = new N(this.state)); + K(this.state); this.view.canvas.focus(); }.bind(this)); $("#file-tools > button.tool").click(function(a) { a = a.target.id; $(".dialog").removeClass("visible"); $("#" + a + "-dialog").toggleClass("visible"); - "export-button" == a && ($("#export-area").val(T(this.state)), $("#export-area").focus(), $("#export-area").select()); + "export-button" == a && ($("#export-area").val(S(this.state)), $("#export-area").focus(), $("#export-area").select()); "clear-button" == a && this.state.clear(); - "undo-button" == a && ha(this.state); - "redo-button" == a && ia(this.state); + "undo-button" == a && ia(this.state); + "redo-button" == a && ja(this.state); }.bind(this)); $("button.close-dialog-button").click(function() { $(".dialog").removeClass("visible"); }.bind(this)); $("#import-submit-button").click(function() { this.state.clear(); - ja(this.state, $("#import-area").val(), B(this.view, new l(this.view.canvas.width / 2, this.view.canvas.height / 2))); + ka(this.state, $("#import-area").val(), B(this.view, new l(this.view.canvas.width / 2, this.view.canvas.height / 2))); $("#import-area").val(""); }.bind(this)); $("#use-lines-button").click(function() { @@ -532,7 +532,7 @@ U.prototype.n = function() { $(window).keydown(function(a) { var c = null; if (a.ctrlKey || a.metaKey) { - 67 == a.keyCode && (c = ""), 86 == a.keyCode && (c = ""), 90 == a.keyCode && ha(this.state), 89 == a.keyCode && ia(this.state), 88 == a.keyCode && (c = ""); + 67 == a.keyCode && (c = ""), 86 == a.keyCode && (c = ""), 90 == a.keyCode && ia(this.state), 89 == a.keyCode && ja(this.state), 88 == a.keyCode && (c = ""); } 8 == a.keyCode && (c = ""); 13 == a.keyCode && (c = ""); @@ -550,27 +550,27 @@ U.prototype.n = function() { }.bind(this)); $("#text-tool-close").click(function() { $("#text-tool-widget").hide(); - L(this.state); + K(this.state); }.bind(this)); }; -function ka(a, b) { +function la(a, b) { this.p = !1; this.state = a; this.view = b; this.file = null; - la(this); + ma(this); $("#drive-button").click(function() { - this.p ? ma(this) : (W(this, !1), na(this)); + this.p ? na(this) : (V(this, !1), oa(this)); }.bind(this)); $("#drive-filename").click(function() { var a = "" + $("#drive-filename").text(), a = prompt("Enter new filename:", a); this.file.title = a; this.save(); - oa(this); + pa(this); }.bind(this)); - pa(this); + qa(this); $(window).bind("hashchange", function() { - qa(this); + ra(this); }.bind(this)); $("#drive-new-file-button").click(function() { this.file = null; @@ -580,34 +580,34 @@ function ka(a, b) { $("#drive-dialog").removeClass("visible"); }.bind(this)); } -function W(a, b) { +function V(a, b) { window.gapi.auth.authorize({client_id:"125643747010-9s9n1ne2fnnuh5v967licfkt83r4vba5.apps.googleusercontent.com", scope:"https://www.googleapis.com/auth/drive", immediate:b}, function(a) { - !a || a.error || this.p || (this.p = !0, $("#drive-button").addClass("active"), qa(this)); + !a || a.error || this.p || (this.p = !0, $("#drive-button").addClass("active"), ra(this)); }.bind(a)); } -function la(a) { - window.gapi && window.gapi.auth && window.gapi.auth.authorize ? W(a, !0) : window.setTimeout(function() { - la(this); +function ma(a) { + window.gapi && window.gapi.auth && window.gapi.auth.authorize ? V(a, !0) : window.setTimeout(function() { + ma(this); }.bind(a), 500); } -function na(a) { +function oa(a) { window.setTimeout(function() { - this.p ? ma(this) : (W(this, !0), na(this)); + this.p ? na(this) : (V(this, !0), oa(this)); }.bind(a), 1E3); } -function ra(a, b) { +function sa(a, b) { a.file = b; $("#drive-filename").text(b.title); window.location.hash = b.id; } -function ma(a) { +function na(a) { $("#drive-dialog").addClass("visible"); - var b = T(a.state); + var b = S(a.state); 5 < b.length && b != a.u && a.save(); - oa(a); + pa(a); } -function oa(a) { - window.gapi.client.request({path:"/drive/v2/files", params:{q:"mimeType = 'text/plain' and trashed = false"}, method:"GET"}).execute(function(a) { +function pa(a) { + W(window.gapi.client.request({path:"/drive/v2/files", params:{q:"mimeType = 'text/plain' and trashed = false"}, method:"GET"}), function(a) { $("#drive-file-list").children().remove(); a = a.items; for (var c in a) { @@ -617,40 +617,48 @@ function oa(a) { } }.bind(a)); } -function pa(a) { - T(a.state) != a.u && a.file && a.file.editable && a.save(); +function W(a, b) { + try { + a.execute(function(a) { + a.error || b(a); + }); + } catch (c) { + } +} +function qa(a) { + S(a.state) != a.u && a.file && a.file.editable && a.save(); window.setTimeout(function() { - pa(this); + qa(this); }.bind(a), 5E3); } -ka.prototype.save = function() { - var a = T(this.state); +la.prototype.save = function() { + var a = S(this.state); $("#drive-save-state").text("Saving..."); - sa(this, a).execute(function(b) { - ra(this, b); + W(ta(this, a), function(b) { + sa(this, b); $("#drive-save-state").text("Saved"); this.u = a; }.bind(this)); }; -function qa(a) { - 1 < window.location.hash.length && ($("#drive-save-state").text("Loading..."), window.gapi.client.request({path:"/drive/v2/files/" + window.location.hash.substr(1, window.location.hash.length - 1), method:"GET"}).execute(function(a) { - ra(this, a); - ta(this); +function ra(a) { + 1 < window.location.hash.length && ($("#drive-save-state").text("Loading..."), W(window.gapi.client.request({path:"/drive/v2/files/" + window.location.hash.substr(1, window.location.hash.length - 1), method:"GET"}), function(a) { + sa(this, a); + ua(this); }.bind(a))); } -function ta(a) { - ua(a.file.downloadUrl, function(a) { +function ua(a) { + va(a.file.downloadUrl, function(a) { $("#drive-save-state").text("Loaded"); this.state.clear(); - ja(this.state, a, B(this.view, new l(this.view.canvas.width / 2, this.view.canvas.height / 2))); - this.u = T(this.state); + ka(this.state, a, B(this.view, new l(this.view.canvas.width / 2, this.view.canvas.height / 2))); + this.u = S(this.state); }.bind(a)); } -function sa(a, b) { +function ta(a, b) { var c = "\r\n---------314159265358979323846\r\nContent-Type: application/json\r\n\r\n" + JSON.stringify({title:null == a.file ? "Untitled ASCII Diagram" : a.file.title, mimeType:"text/plain"}) + "\r\n---------314159265358979323846\r\nContent-Type: text/plain\r\n\r\n" + b + "\r\n---------314159265358979323846--"; return window.gapi.client.request({path:"/upload/drive/v2/files" + (null == a.file ? "" : "/" + a.file.id), method:null == a.file ? "POST" : "PUT", params:{uploadType:"multipart"}, headers:{"Content-Type":'multipart/mixed; boundary="-------314159265358979323846"'}, body:c}); } -function ua(a, b) { +function va(a, b) { var c = window.gapi.auth.getToken().access_token, d = new XMLHttpRequest; d.open("GET", a); d.setRequestHeader("Authorization", "Bearer " + c); @@ -662,11 +670,11 @@ function ua(a, b) { }; d.send(); } -;function va(a) { +;function wa(a) { this.b = a; this.n(); } -va.prototype.n = function() { +wa.prototype.n = function() { var a = this.b.view.canvas; $(a).bind("mousewheel", function(a) { a = this.b.view.zoom * (0 < a.originalEvent.wheelDelta ? 1.1 : 0.9); @@ -687,10 +695,10 @@ va.prototype.n = function() { } }.bind(this)); $(a).mouseup(function() { - V(this.b); + U(this.b); }.bind(this)); $(a).mouseleave(function() { - V(this.b); + U(this.b); }.bind(this)); $(a).mousemove(function(a) { this.b.r(new l(a.clientX, a.clientY)); @@ -701,7 +709,7 @@ function X(a) { this.t = this.k = !1; this.n(); } -function wa(a, b) { +function xa(a, b) { a.B = b; a.I = $.now(); a.k = !1; @@ -732,12 +740,12 @@ X.prototype.n = function() { $(a).bind("touchstart", function(a) { a.preventDefault(); if (1 == a.originalEvent.touches.length) { - wa(this, new l(a.originalEvent.touches[0].pageX, a.originalEvent.touches[0].pageY)); + xa(this, new l(a.originalEvent.touches[0].pageX, a.originalEvent.touches[0].pageY)); } else { if (1 < a.originalEvent.touches.length) { var c = new l(a.originalEvent.touches[0].pageX, a.originalEvent.touches[0].pageY); a = new l(a.originalEvent.touches[1].pageX, a.originalEvent.touches[1].pageY); - V(this.b); + U(this.b); this.t = !0; this.k = !1; this.J = n(c, a).length(); @@ -760,12 +768,12 @@ X.prototype.n = function() { $(a).bind("touchend", function(a) { a.preventDefault(); this.reset(); - V(this.b); + U(this.b); }.bind(this)); }; -var Y = new S, Z = new z(Y), xa = new U(Z, Y); -new X(xa); -new va(xa); -new ka(Y, Z); +var Y = new R, Z = new z(Y), ya = new T(Z, Y); +new X(ya); +new wa(ya); +new la(Y, Z); Z.animate(); diff --git a/js-lib/drive-controller.js b/js-lib/drive-controller.js index 5ab27f1..6815c92 100644 --- a/js-lib/drive-controller.js +++ b/js-lib/drive-controller.js @@ -102,7 +102,7 @@ ascii.DriveController.prototype.waitForFullAuth = function() { ascii.DriveController.prototype.handleFile = function(file) { this.file = file; $('#drive-filename').text(file['title']); - window.location.hash = file.id; + window.location.hash = file['id']; }; @@ -121,7 +121,7 @@ ascii.DriveController.prototype.loadDialog = function() { }; ascii.DriveController.prototype.loadFileList = function() { - this.getListRequest().execute(function(result) { + this.safeExecute(this.getListRequest(), function(result) { $('#drive-file-list').children().remove(); var items = result['items']; for (var i in items) { @@ -131,6 +131,18 @@ ascii.DriveController.prototype.loadFileList = function() { } }.bind(this)); } + +ascii.DriveController.prototype.safeExecute = function(request, callback) { + // Could make the API call, don't blow up tho (mobiles n stuff). + try { + request['execute'](function(result) { + if (!result['error']) { + callback(result); + } + }); + } catch (e) {} +}; + /** * Repeatedly save the diagram if it is editable and loaded. */ @@ -150,7 +162,7 @@ ascii.DriveController.prototype.loopSave = function() { ascii.DriveController.prototype.save = function() { var text = this.state.outputText(); $('#drive-save-state').text('Saving...'); - this.getSaveRequest(text).execute(function(result) { + this.safeExecute(this.getSaveRequest(text), function(result) { this.handleFile(result); $('#drive-save-state').text('Saved'); this.cachedText = text; @@ -161,7 +173,7 @@ ascii.DriveController.prototype.loadFromHash = function() { if (window.location.hash.length > 1) { $('#drive-save-state').text('Loading...'); var fileId = window.location.hash.substr(1, window.location.hash.length - 1); - this.getLoadRequest(fileId).execute(function(result) { + this.safeExecute(this.getLoadRequest(fileId), function(result) { this.handleFile(result); this.reloadFileContent(); }.bind(this));