!function(e, t) { "object" == typeof module && "object" == typeof module.exports ? module.exports = e.document ? t(e, !0) : function(e) { if (!e.document) throw new Error("jQuery requires a window with a document"); return t(e); } : t(e); }("undefined" != typeof window ? window : this, function(e, t) { function n(e) { var t = "length" in e && e.length, n = Z.type(e); return "function" !== n && !Z.isWindow(e) && (!(1 !== e.nodeType || !t) || ("array" === n || 0 === t || "number" == typeof t && t > 0 && t - 1 in e)); } function r(e, t, n) { if (Z.isFunction(t)) return Z.grep(e, function(e, r) { return !!t.call(e, r, e) !== n; }); if (t.nodeType) return Z.grep(e, function(e) { return e === t !== n; }); if ("string" == typeof t) { if (ae.test(t)) return Z.filter(t, e, n); t = Z.filter(t, e); } return Z.grep(e, function(e) { return U.call(t, e) >= 0 !== n; }); } function i(e, t) { for (;(e = e[t]) && 1 !== e.nodeType; ) ; return e; } function o(e) { var t = he[e] = {}; return Z.each(e.match(de) || [], function(e, n) { t[n] = !0; }), t; } function s() { J.removeEventListener("DOMContentLoaded", s, !1), e.removeEventListener("load", s, !1), Z.ready(); } function a() { Object.defineProperty(this.cache = {}, 0, { get: function() { return {}; } }), this.expando = Z.expando + a.uid++; } function u(e, t, n) { var r; if (void 0 === n && 1 === e.nodeType) if (r = "data-" + t.replace(be, "-$1").toLowerCase(), n = e.getAttribute(r), "string" == typeof n) { try { n = "true" === n || "false" !== n && ("null" === n ? null : +n + "" === n ? +n : xe.test(n) ? Z.parseJSON(n) : n); } catch (i) {} ye.set(e, t, n); } else n = void 0; return n; } function l() { return !0; } function c() { return !1; } function f() { try { return J.activeElement; } catch (e) {} } function p(e, t) { return Z.nodeName(e, "table") && Z.nodeName(11 !== t.nodeType ? t : t.firstChild, "tr") ? e.getElementsByTagName("tbody")[0] || e.appendChild(e.ownerDocument.createElement("tbody")) : e; } function d(e) { return e.type = (null !== e.getAttribute("type")) + "/" + e.type, e; } function h(e) { var t = Pe.exec(e.type); return t ? e.type = t[1] : e.removeAttribute("type"), e; } function g(e, t) { for (var n = 0, r = e.length; r > n; n++) ve.set(e[n], "globalEval", !t || ve.get(t[n], "globalEval")); } function m(e, t) { var n, r, i, o, s, a, u, l; if (1 === t.nodeType) { if (ve.hasData(e) && (o = ve.access(e), s = ve.set(t, o), l = o.events)) { delete s.handle, s.events = {}; for (i in l) for (n = 0, r = l[i].length; r > n; n++) Z.event.add(t, i, l[i][n]); } ye.hasData(e) && (a = ye.access(e), u = Z.extend({}, a), ye.set(t, u)); } } function v(e, t) { var n = e.getElementsByTagName ? e.getElementsByTagName(t || "*") : e.querySelectorAll ? e.querySelectorAll(t || "*") : []; return void 0 === t || t && Z.nodeName(e, t) ? Z.merge([ e ], n) : n; } function y(e, t) { var n = t.nodeName.toLowerCase(); "input" === n && Ne.test(e.type) ? t.checked = e.checked : ("input" === n || "textarea" === n) && (t.defaultValue = e.defaultValue); } function x(t, n) { var r, i = Z(n.createElement(t)).appendTo(n.body), o = e.getDefaultComputedStyle && (r = e.getDefaultComputedStyle(i[0])) ? r.display : Z.css(i[0], "display"); return i.detach(), o; } function b(e) { var t = J, n = $e[e]; return n || (n = x(e, t), "none" !== n && n || (We = (We || Z("', r = 320, a = 195, i = embedUri, t = "external-embed"; else if (e.match(/http/) && e.replace(/[^<]/g, "").length < 3) if (youtubeMatcher = /youtube\.com\/.*v=([^&<]+)/, youtubeMatcher2 = /youtu\.be\/([^&<]+)/, soundcloudMatcher = /soundcloud\.com\/([^<]+)/, vimeoMatcher = /vimeo.com\/([^<]*)/, dailyMotionMatcher = /dailymotion.com\/video\/([^<]*)/, googleMapsMatcher = /google.com\/maps\?([^<]*)/, spacedeckMatcher = new RegExp(location.host + "/(spaces|folders)/([0-9a-f]{24})"), m = e.match(youtubeMatcher) || (m = e.match(youtubeMatcher2))) videoId = m[1], o = '', r = 320, a = 195, n = "youtube", c = "video"; else if (m = e.match(dailyMotionMatcher)) videoId = m[1], o = '', r = 268, a = 151, n = "dailymotion", c = "video"; else if (m = e.match(vimeoMatcher)) videoId = m[1], o = '', r = 268, a = 151, n = "vimeo", c = "video"; else if (m = e.match(soundcloudMatcher)) { var u, p = "https://" + m[0]; u = m[0].indexOf("soundcloud.com/player") >= 0 ? "https://w." + m[0] : "https://w.soundcloud.com/player/?url=" + encodeURI(p), o = '', r = 360, a = 184, i = p, n = "soundcloud", c = "audio"; } else (m = e.match(googleMapsMatcher)) ? (mapsParams = m[1], o = '', r = 320, a = 195, n = "google", c = "map") : (m = e.match(d)) && !isDataFileUrl(m[1]) ? (uri = m[1], grabUri = uri, endPoint = "/api/webgrabber/" + encodeURIComponent(btoa(grabUri)), o = e.replace(uri, ' '), r = 300, a = 300, i = uri) : l = !0; else l = !0; return l ? null : (result = { html: o, thumbnail_width: r, thumbnail_height: a, type: c, provider_name: n, url: i }, result); } function vec2_add(r, e) { return { dx: r.dx + e.dx, dy: r.dy + e.dy }; } function vec2_sub(r, e) { return { dx: r.dx - e.dx, dy: r.dy - e.dy }; } function vec2_mul(r, e) { return { dx: r.dx * e, dy: r.dy * e }; } function vec2_magn(r) { return Math.sqrt(r.dx * r.dx + r.dy * r.dy); } function vec2_unit(r) { var e = vec2_magn(r); return 0 == e ? { dx: 0, dy: 0 } : { dx: r.dx / e, dy: r.dy / e }; } function vec2_angle(r) { return 0 == r.dx ? Math.atan2(r.dx + .01, r.dy) : Math.atan2(r.dx, r.dy); } function render_vector_drawing(r, e) { var t = r.style.shape || "", n = [], o = r.control_points[0]; if (!o) return ""; if (n.push("M" + (o.dx + e) + "," + (o.dy + e) + " "), t.match("arrow")) { var c = r.control_points[0], a = r.control_points[1], d = r.control_points[2]; d || (d = a); var u = r._id, _ = c, v = a, s = vec2_sub(v, _), i = vec2_magn(s), l = vec2_mul(vec2_unit(s), i / 2), h = vec2_add(_, l), f = vec2_sub(d, h), p = vec2_add(vec2_mul(f, 2), h), g = "M" + (c.dx + e) + "," + (c.dy + e) + " Q" + (p.dx + e) + "," + (p.dy + e) + " " + (a.dx + e) + "," + (a.dy + e), y = "'; y += ''; var x = y + ""; return x; } for (var b, o, o, b = 0; b < r.control_points.length; b++) { var o = r.control_points[b], m = 0 == b ? "M" : "L"; n.push(m + (o.dx + e) + "," + (o.dy + e)); } return ""; } function render_vector_star(r, e, t, n) { r *= 2; for (var o = [], c = 360 / r, a = 0; a < r; a++) { var d = a * c - 90, u = e, _ = t; a % 2 && (20 == r ? (u /= 1.5, _ /= 1.5) : (u /= 2.8, _ /= 2.8)); var v = n + e + u * Math.cos(d * Math.PI / 180), s = n + t + _ * Math.sin(d * Math.PI / 180); o.push(v + "," + s); } return ""; } function transform_vector_template(r, e, t, n) { for (var o = "", c = 0; c < r.length; c += 2) { for (var a = r[c + 1], d = 0; d < a.length; d += 2) a[d] *= 2 * e / 100, a[d + 1] *= 2 * t / 100; o += r[c] + r[c + 1].join(",") + " "; } return o; } function render_vector_heart(r, e, t) { var n = [ "M", [ 50.141, 98.5 ], "c", [ 0, 0, -49, -38.334, -49, -67.982 ], "C", [ 1.141, 15.333, 14.356, 1, 30.659, 1 ], "c", [ 7.437, 0, 14.244, 2.791, 19.435, 7.33 ], "l", [ 0, 0 ], "C", [ 55.296, 3.742, 62.141, 1, 69.622, 1 ], "c", [ 16.303, 0, 29.519, 14.166, 29.519, 29.518 ], "C", [ 99.141, 60.334, 50.141, 98.5, 50.141, 98.5 ], "z", [] ]; return svg = "", svg; } function render_vector_cloud(r, e, t) { var n = [ "M", [ 17.544, 99.729 ], "c", [ 0, 0, -17.544, 6.929, -17.544, -36.699 ], "c", [ 0, -18.698, 19.298, -28.047, 19.298, -9.35 ], "c", [ 0, 0, -3.508, -54.46, 26.316, -53.672 ], "C", [ 71.93, .704, 68.421, 34.983, 68.421, 34.983 ], "S", [ 100, 25.634, 100, 72.379 ], "c", [ 0, 28.047, -21.053, 27.351, -21.053, 27.351 ], "z", [] ]; return svg = "", svg; } function render_vector_ellipse(r, e, t) { return svg = "", svg; } function render_vector_speechbubble(r, e, t) { var n = [ "M", [ 100, 50 ], "c", [ 0, 9.5, -2.7, 18, -7.4, 26 ], "C", [ 90, 80, 100, 100, 100, 100 ], "s", [ -23.194, -6.417, -28, -4.162 ], "c", [ -6.375, 3, -13.5, 4.7, -21, 4.7 ], "C", [ 23, 100, .5, 77, .5, 50 ], "C", [ .5, 23, 23, .5, 50, .5 ], "C", [ 77, .5, 100, 23, 100, 50 ], "z", [] ]; return svg = "", svg; } function render_vector_ngon(r, e, t, n) { for (var o = [], c = 360 / r, a = 0; a < r; a++) { var d = a * c - 90, u = n + e + e * Math.cos(d * Math.PI / 180), _ = n + t + t * Math.sin(d * Math.PI / 180); o.push(u + "," + _); } return ""; } function render_vector_rect(r, e, t) { return ""; } function render_vector_shape(r) { var e = parseInt(r.style.stroke) + 4, t = e / 2, n = (r.board.w - e) / 2, o = (r.board.h - e) / 2, c = { ellipse: function() { return render_vector_ellipse(n, o, t); }, pentagon: function() { return render_vector_ngon(5, n, o, t); }, hexagon: function() { return render_vector_ngon(6, n, o, t); }, octagon: function() { return render_vector_ngon(8, n, o, t); }, diamond: function() { return render_vector_ngon(4, n, o, t); }, square: function() { return ""; }, triangle: function() { return render_vector_ngon(3, n, o, t); }, star: function() { return render_vector_star(5, n, o, t); }, burst: function() { return render_vector_star(10, n, o, t); }, speechbubble: function() { return render_vector_speechbubble(n, o, t); }, heart: function() { return render_vector_heart(n, o, t); }, cloud: function() { return render_vector_cloud(n, o, t); } }, a = c[r.style.shape]; return a ? a() : ""; } function simplify_scribble_points(r) { for (var e = [], t = 2, n = 0; n < r.length; n++) { var o = r[n], c = r[n + 1]; if (n > 0) var a = r[n - 1]; c && a ? (dprev = vec2_sub(o, a), dnext = vec2_sub(c, o), aprev = vec2_angle(dprev), anext = vec2_angle(dnext), delta = Math.abs(Math.abs(aprev) - Math.abs(anext)), delta2 = vec2_magn(vec2_sub(o, a)), delta2 > t && delta > .1 && e.push(o)) : e.push(o); } return e; } "undefined" == typeof window && (exports.render_vector_shape = render_vector_shape, exports.render_vector_drawing = render_vector_drawing); !function(e, t, n) { function r(e, t, n) { return e.addEventListener ? void e.addEventListener(t, n, !1) : void e.attachEvent("on" + t, n); } function o(e) { if ("keypress" == e.type) { var t = String.fromCharCode(e.which); return e.shiftKey || (t = t.toLowerCase()), t; } return q[e.which] ? q[e.which] : P[e.which] ? P[e.which] : String.fromCharCode(e.which).toLowerCase(); } function i(e, t) { return e.sort().join(",") === t.sort().join(","); } function a(e) { e = e || {}; var t, n = !1; for (t in M) e[t] ? n = !0 : M[t] = 0; n || (x = !1); } function c(e, t, n, r, o, a) { var c, u, s = [], f = n.type; if (!N[e]) return []; for ("keyup" == f && d(e) && (t = [ e ]), c = 0; c < N[e].length; ++c) if (u = N[e][c], (r || !u.seq || M[u.seq] == u.level) && f == u.action && ("keypress" == f && !n.metaKey && !n.ctrlKey || i(t, u.modifiers))) { var l = !r && u.combo == o, p = r && u.seq == r && u.level == a; (l || p) && N[e].splice(c, 1), s.push(u); } return s; } function u(e) { var t = []; return e.shiftKey && t.push("shift"), e.altKey && t.push("alt"), e.ctrlKey && t.push("ctrl"), e.metaKey && t.push("meta"), t; } function s(e) { return e.preventDefault ? void e.preventDefault() : void (e.returnValue = !1); } function f(e) { return e.stopPropagation ? void e.stopPropagation() : void (e.cancelBubble = !0); } function l(e, t, n, r) { O.stopCallback(t, t.target || t.srcElement, n, r) || e(t, n) === !1 && (s(t), f(t)); } function p(e, t, n) { var r, o = c(e, t, n), i = {}, u = 0, s = !1; for (r = 0; r < o.length; ++r) o[r].seq && (u = Math.max(u, o[r].level)); for (r = 0; r < o.length; ++r) if (o[r].seq) { if (o[r].level != u) continue; s = !0, i[o[r].seq] = 1, l(o[r].callback, n, o[r].combo, o[r].seq); } else s || l(o[r].callback, n, o[r].combo); var f = "keypress" == n.type && j; n.type != x || d(e) || f || a(i), j = s && "keydown" == n.type; } function h(e) { "number" != typeof e.which && (e.which = e.keyCode); var t = o(e); if (t) return "keyup" == e.type && S === t ? void (S = !1) : void O.handleKey(t, u(e), e); } function d(e) { return "shift" == e || "ctrl" == e || "alt" == e || "meta" == e; } function y() { clearTimeout(K), K = setTimeout(a, 1e3); } function v() { if (!E) { E = {}; for (var e in q) e > 95 && e < 112 || q.hasOwnProperty(e) && (E[q[e]] = e); } return E; } function m(e, t, n) { return n || (n = v()[e] ? "keydown" : "keypress"), "keypress" == n && t.length && (n = "keydown"), n; } function k(e, t, n, r) { function i(t) { return function() { x = t, ++M[e], y(); }; } function c(t) { l(n, t, e), "keyup" !== r && (S = o(t)), setTimeout(a, 10); } M[e] = 0; for (var u = 0; u < t.length; ++u) { var s = u + 1 === t.length, f = s ? c : i(r || w(t[u + 1]).action); b(t[u], f, r, e, u); } } function g(e) { var t = e.split("+"); return "+" === e[e.length - 1] && (t.pop(), t.length && t.pop(), t.push("+")), t; } function w(e, t) { var n, r, o, i = []; for (n = g(e), o = 0; o < n.length; ++o) r = n[o], L[r] && (r = L[r]), t && "keypress" != t && T[r] && (r = T[r], i.push("shift")), d(r) && i.push(r); return t = m(r, i, t), { key: r, modifiers: i, action: t }; } function b(e, t, n, r, o) { A[e + ":" + n] = t, e = e.replace(/\s+/g, " "); var i, a = e.split(" "); return a.length > 1 ? void k(e, a, t, n) : (i = w(e, n), N[i.key] = N[i.key] || [], c(i.key, i.modifiers, { type: i.action }, r, e, o), void N[i.key][r ? "unshift" : "push"]({ callback: t, modifiers: i.modifiers, action: i.action, seq: r, level: o, combo: e })); } function C(e, t, n) { for (var r = 0; r < e.length; ++r) b(e[r], t, n); } for (var E, K, q = { 8: "backspace", 9: "tab", 13: "enter", 16: "shift", 17: "ctrl", 18: "alt", 20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home", 37: "left", 38: "up", 39: "right", 40: "down", 45: "ins", 46: "del", 91: "meta", 93: "meta", 224: "meta" }, P = { 106: "*", 107: "+", 109: "-", 110: ".", 111: "/", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", 221: "]", 222: "'" }, T = { "~": "`", "!": "1", "@": "2", "#": "3", $: "4", "%": "5", "^": "6", "&": "7", "*": "8", "(": "9", ")": "0", _: "-", "+": "=", ":": ";", '"': "'", "<": ",", ">": ".", "?": "/", "|": "\\" }, L = { option: "alt", command: "meta", "return": "enter", escape: "esc", mod: /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? "meta" : "ctrl" }, N = {}, A = {}, M = {}, S = !1, j = !1, x = !1, D = 1; D < 20; ++D) q[111 + D] = "f" + D; for (D = 0; D <= 9; ++D) q[D + 96] = D; r(t, "keypress", h), r(t, "keydown", h), r(t, "keyup", h); var O = { bind: function(e, t, n) { return e = e instanceof Array ? e : [ e ], C(e, t, n), this; }, unbind: function(e, t) { return O.bind(e, function() {}, t); }, trigger: function(e, t) { return A[e + ":" + t] && A[e + ":" + t]({}, e), this; }, reset: function() { return N = {}, A = {}, this; }, stopCallback: function(e, t) { return !((" " + t.className + " ").indexOf(" mousetrap ") > -1) && ("INPUT" == t.tagName || "SELECT" == t.tagName || "TEXTAREA" == t.tagName || t.isContentEditable); }, handleKey: p }; e.Mousetrap = O; }(window, document); !function(e, n) { var t = { smoketimeout: [], init: !1, zindex: 4e4, i: 0, bodyload: function(e) { var i = n.createElement("div"); i.setAttribute("id", "smoke-out-" + e), i.className = "smoke-base", i.style.zIndex = t.zindex, t.zindex++, n.body.appendChild(i); }, newdialog: function() { var n = new Date().getTime(); return n = Math.random(1, 99) + n, t.init ? t.bodyload(n) : t.listen(e, "load", function() { t.bodyload(n); }), n; }, forceload: function() {}, build: function(n, i) { t.i++, i.stack = t.i, n = n.replace(/\n/g, "
"), n = n.replace(/\r/g, "
"); var o, a = "", d = "OK", l = "Cancel", c = "", u = ""; "prompt" === i.type && (a = '
"), i.params.ok && (d = i.params.ok), i.params.cancel && (l = i.params.cancel), i.params.classname && (c = i.params.classname), "signal" !== i.type && (u = '
', "alert" === i.type ? u += '" : "quiz" === i.type ? (i.params.button_1 && (u += '"), i.params.button_2 && (u += '"), i.params.button_3 && (u += '"), i.params.button_cancel && (u += '")) : "prompt" !== i.type && "confirm" !== i.type || (u += i.params.reverseButtons ? '" : '"), u += "
"), o = '
' + n + a + u + "
", t.init ? t.finishbuild(n, i, o) : t.listen(e, "load", function() { t.finishbuild(n, i, o); }); }, finishbuild: function(e, i, o) { var a = n.getElementById("smoke-out-" + i.newid); for (a.className = "smoke-base smoke-visible smoke-" + i.type, a.innerHTML = o; "" === a.innerHTML; ) a.innerHTML = o; switch (t.smoketimeout[i.newid] && clearTimeout(t.smoketimeout[i.newid]), i.type) { case "alert": t.finishbuildAlert(e, i, o); break; case "confirm": t.finishbuildConfirm(e, i, o); break; case "quiz": t.finishbuildQuiz(e, i, o); break; case "prompt": t.finishbuildPrompt(e, i, o); break; case "signal": t.finishbuildSignal(e, i, o); break; default: throw "Unknown type: " + i.type; } }, finishbuildAlert: function(i, o, a) { t.listen(n.getElementById("alert-ok-" + o.newid), "click", function() { t.destroy(o.type, o.newid), "undefined" != typeof o.callback && o.callback(); }), n.onkeyup = function(n) { n || (n = e.event), 13 !== n.keyCode && 32 !== n.keyCode && 27 !== n.keyCode || (t.destroy(o.type, o.newid), "undefined" != typeof o.callback && o.callback()); }; }, finishbuildConfirm: function(i, o, a) { t.listen(n.getElementById("confirm-cancel-" + o.newid), "click", function() { t.destroy(o.type, o.newid), o.callback(!1); }), t.listen(n.getElementById("confirm-ok-" + o.newid), "click", function() { t.destroy(o.type, o.newid), o.callback(!0); }), n.onkeyup = function(n) { n || (n = e.event), 13 === n.keyCode || 32 === n.keyCode ? (t.destroy(o.type, o.newid), o.callback(!0)) : 27 === n.keyCode && (t.destroy(o.type, o.newid), o.callback(!1)); }; }, finishbuildQuiz: function(i, o, a) { var d, l, c; t.listen(n.getElementById("quiz-cancel-" + o.newid), "click", function() { t.destroy(o.type, o.newid), o.callback(!1); }), (d = n.getElementById("quiz-ok1-" + o.newid)) && t.listen(d, "click", function() { t.destroy(o.type, o.newid), o.callback(d.innerHTML); }), (l = n.getElementById("quiz-ok2-" + o.newid)) && t.listen(l, "click", function() { t.destroy(o.type, o.newid), o.callback(l.innerHTML); }), (c = n.getElementById("quiz-ok3-" + o.newid)) && t.listen(c, "click", function() { t.destroy(o.type, o.newid), o.callback(c.innerHTML); }), n.onkeyup = function(n) { n || (n = e.event), 27 === n.keyCode && (t.destroy(o.type, o.newid), o.callback(!1)); }; }, finishbuildPrompt: function(i, o, a) { var d = n.getElementById("smoke-dialog-input-" + o.newid); setTimeout(function() { d.focus(), d.select(); }, 100), t.listen(n.getElementById("prompt-cancel-" + o.newid), "click", function() { t.destroy(o.type, o.newid), o.callback(!1); }), t.listen(n.getElementById("prompt-ok-" + o.newid), "click", function() { t.destroy(o.type, o.newid), o.callback(d.value); }), n.onkeyup = function(n) { n || (n = e.event), 13 === n.keyCode ? (t.destroy(o.type, o.newid), o.callback(d.value)) : 27 === n.keyCode && (t.destroy(o.type, o.newid), o.callback(!1)); }; }, finishbuildSignal: function(i, o, a) { n.onkeyup = function(n) { n || (n = e.event), 27 === n.keyCode && (t.destroy(o.type, o.newid), "undefined" != typeof o.callback && o.callback()); }, t.smoketimeout[o.newid] = setTimeout(function() { t.destroy(o.type, o.newid), "undefined" != typeof o.callback && o.callback(); }, o.timeout); }, destroy: function(e, i) { var o = n.getElementById("smoke-out-" + i); if ("quiz" !== e) var a = n.getElementById(e + "-ok-" + i); var d = n.getElementById(e + "-cancel-" + i); if (o.className = "smoke-base", a && (t.stoplistening(a, "click", function() {}), n.onkeyup = null), "quiz" === e) for (var l = n.getElementsByClassName("quiz-button"), c = 0; c < l.length; c++) t.stoplistening(l[c], "click", function() {}), n.onkeyup = null; d && t.stoplistening(d, "click", function() {}), t.i = 0, o.innerHTML = ""; }, alert: function(e, n, i) { "object" != typeof i && (i = !1); var o = t.newdialog(); t.build(e, { type: "alert", callback: n, params: i, newid: o }); }, signal: function(e, n, i) { "object" != typeof i && (i = !1); var o = 5e3; "undefined" !== i.duration && (o = i.duration); var a = t.newdialog(); t.build(e, { type: "signal", callback: n, timeout: o, params: i, newid: a }); }, confirm: function(e, n, i) { "object" != typeof i && (i = !1); var o = t.newdialog(); t.build(e, { type: "confirm", callback: n, params: i, newid: o }); }, quiz: function(e, n, i) { "object" != typeof i && (i = !1); var o = t.newdialog(); t.build(e, { type: "quiz", callback: n, params: i, newid: o }); }, prompt: function(e, n, i) { "object" != typeof i && (i = !1); var o = t.newdialog(); return t.build(e, { type: "prompt", callback: n, params: i, newid: o }); }, listen: function(e, n, t) { return e.addEventListener ? e.addEventListener(n, t, !1) : !!e.attachEvent && e.attachEvent("on" + n, t); }, stoplistening: function(e, n, t) { return e.removeEventListener ? e.removeEventListener(n, t, !1) : !!e.detachEvent && e.detachEvent("on" + n, t); } }; t.init = !0, "undefined" != typeof module && module.exports ? module.exports = t : "function" == typeof define && define.amd ? define("smoke", [], function() { return t; }) : this.smoke = t; }(window, document); function validateEmail(e) { var t = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return t.test(e); } function zero_pad(e) { return zero = 2 - e.toString().length + 1, Array(+(zero > 0 && zero)).join("0") + e; } function format_time(e) { return isNaN(e) && (e = 0), zero_pad(parseInt(e / 60)) + ":" + zero_pad(parseInt(e % 60)); } function urls_to_links(e) { return e.replace(url_to_links_rx, "$1$2"); } function get_query_param(e) { e = e.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var t = new RegExp("[\\?&]" + e + "=([^&#]*)"), r = t.exec(location.search); return null == r ? "" : decodeURIComponent(r[1].replace(/\+/g, " ")); } function random_string(e) { for (var t = "", r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!-_", a = 0; a < e; a++) t += r.charAt(Math.floor(Math.random() * r.length)); return t; } function fixup_touches(e) { var t = e; return e.originalEvent && (t = e.originalEvent), e = { pageX: e.pageX, pageY: e.pageY, offsetX: e.offsetX, offsetY: e.offsetY, clientX: e.clientX, clientY: e.clientY, layerX: e.layerX, layerY: e.layerY, target: e.target, currentTarget: e.currentTarget }, t.changedTouches && t.changedTouches.length ? (e.pageX = t.changedTouches[0].pageX, e.pageY = t.changedTouches[0].pageY) : t.touches && t.touches.length && (e.pageX = t.touches[0].pageX, e.pageY = t.touches[0].pageY), e; } function rgb_to_hex(e, t, r) { return ((1 << 24) + (parseInt(e) << 16) + (parseInt(t) << 8) + parseInt(r)).toString(16).slice(1); } function hex_to_rgba(e) { if (!e || "transparent" == e) return { r: 0, g: 0, b: 0, a: 0 }; if (e.match("rgb\\(")) return e = e.replace("rgb(", "").replace(")", "").split(","), { r: e[0], g: e[1], b: e[2], a: 255 }; if (e.match("rgba\\(")) return e = e.replace("rgba(", "").replace(")", "").split(","), { r: e[0], g: e[1], b: e[2], a: 255 * e[3] }; var t = parseInt(e.substr(1, 2), 16), r = parseInt(e.substr(3, 2), 16), a = parseInt(e.substr(5, 2), 16), n = 255; return e.length > 7 && (n = parseInt(e.substr(7, 2), 16)), { r: t, g: r, b: a, a: n }; } function rgb_to_hsv() { var e, t, r, a, n, o = arguments[0] / 255, c = arguments[1] / 255, i = arguments[2] / 255, s = Math.max(o, c, i), l = s - Math.min(o, c, i), g = function(e) { return (s - e) / 6 / l + .5; }; return 0 == l ? a = n = 0 : (n = l / s, e = g(o), t = g(c), r = g(i), o === s ? a = r - t : c === s ? a = 1 / 3 + e - r : i === s && (a = 2 / 3 + t - e), a < 0 ? a += 1 : a > 1 && (a -= 1)), { h: a || 0, s: n || 0, v: s || 0 }; } function hsv_to_rgb(e, t, r) { var a, n, o, c, i, s, l, g; switch (e && void 0 === t && void 0 === r && (t = e.s, r = e.v, e = e.h), c = Math.floor(6 * e), i = 6 * e - c, s = r * (1 - t), l = r * (1 - i * t), g = r * (1 - (1 - i) * t), c % 6) { case 0: a = r, n = g, o = s; break; case 1: a = l, n = r, o = s; break; case 2: a = s, n = r, o = g; break; case 3: a = s, n = l, o = r; break; case 4: a = g, n = s, o = r; break; case 5: a = r, n = s, o = l; } return { r: Math.round(255 * a), g: Math.round(255 * n), b: Math.round(255 * o) }; } function render_grid(e, t, r) { temp_grid_canvas.width = e, temp_grid_canvas.height = t; var a = e / r, n = temp_grid_canvas.getContext("2d"); n.strokeStyle = "#f0f0f0", n.lineWidth = 1; for (var o = "rgba(60,60,60,0.125)", c = "rgba(60,60,60,0.075)", i = 0; i < t; i += a) 0 == i ? n.fillStyle = o : n.fillStyle = c, n.fillRect(0, i, e, 1); for (var s = 0; s < t; s += a) 0 == s ? n.fillStyle = o : n.fillStyle = c, n.fillRect(s, 0, 1, t); var l = temp_grid_canvas.toDataURL(); return l; } function focus_contenteditable(e, t) { if (range = document.createRange(), range && e) { var r = $(e).find("p"); r.length && (r = r[r.length - 1], range.selectNodeContents(r), selection = window.getSelection(), selection.removeAllRanges(), "Text" != range.toString() && range.collapse(!1), selection.addRange(range), e.focus()); } } function setup_exclusive_audio_video_playback() { document.addEventListener("play", function(e) { for (var t = [ "audio", "video" ], r = 0; r < t.length; r++) for (var a = t[r], n = document.getElementsByTagName(a), r = 0, o = n.length; r < o; r++) n[r] != e.target && n[r].pause(); }, !0); } var url_to_links_rx = /(^|[\s\n]|>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi; temp_grid_canvas = document.createElement("canvas"); GrowingPacker = function() {}, GrowingPacker.prototype = { fit: function(o) { var t, i, h, r = o.length, n = r > 0 ? o[0].w : 0, s = r > 0 ? o[0].h : 0; for (this.root = { x: 0, y: 0, w: n, h: s }, t = 0; t < r; t++) h = o[t], (i = this.findNode(this.root, h.w, h.h)) ? h.fit = this.splitNode(i, h.w, h.h) : h.fit = this.growNode(h.w, h.h); }, findNode: function(o, t, i) { return o.used ? this.findNode(o.right, t, i) || this.findNode(o.down, t, i) : t <= o.w && i <= o.h ? o : null; }, splitNode: function(o, t, i) { return o.used = !0, o.down = { x: o.x, y: o.y + i, w: o.w, h: o.h - i }, o.right = { x: o.x + t, y: o.y, w: o.w - t, h: i }, o; }, growNode: function(o, t) { var i = o <= this.root.w, h = t <= this.root.h, r = h && this.root.h >= this.root.w + o, n = i && this.root.w >= this.root.h + t; return r ? this.growRight(o, t) : n ? this.growDown(o, t) : h ? this.growRight(o, t) : i ? this.growDown(o, t) : null; }, growRight: function(o, t) { return this.root = { used: !0, x: 0, y: 0, w: this.root.w + o, h: this.root.h, down: this.root, right: { x: this.root.w, y: 0, w: o, h: this.root.h } }, (node = this.findNode(this.root, o, t)) ? this.splitNode(node, o, t) : null; }, growDown: function(o, t) { return this.root = { used: !0, x: 0, y: 0, w: this.root.w, h: this.root.h + t, down: { x: 0, y: this.root.h, w: this.root.w, h: t }, right: this.root }, (node = this.findNode(this.root, o, t)) ? this.splitNode(node, o, t) : null; } }; var SpacedeckRoutes = { internal_route: function(t, i) { this.router || (this.router = new RouteRecognizer(), this.router.add([ { path: "/spaces/:id", handler: function(t, i) { this.load_space(t.id, i); }.bind(this) } ]), this.router.add([ { path: "/confirm/:token", handler: function(t) { this.logged_in ? this.confirm_account(t.token) : this.redirect_to("/login"); }.bind(this) } ]), this.router.add([ { path: "/password-confirm/:token", handler: function(t) { console.log(t.token), this.logged_in ? this.redirect_to("/spaces") : (this.reset_token = t.token, this.active_view = "password-confirm"); }.bind(this) } ]), this.router.add([ { path: "/password-reset", handler: function(t, i) { this.logged_in || (this.active_view = "password-reset"); }.bind(this) } ]), this.router.add([ { path: "/accept/:membership_id", handler: function(t, i) { if (this.logged_in) { var e = get_query_param("code"); accept_invitation(t.membership_id, e, function(t) { window._spacedeck_location_change = !0, location.href = "/spaces/" + t.space._id; }.bind(this), function(t) { smoke.alert("Error (" + t.status + ")", function() { this.redirect_to("/spaces"); }.bind(this)); }.bind(this)); } else this.redirect_to("/login"); }.bind(this) } ]), this.router.add([ { path: "/signup", handler: function(t) { var i = get_query_param("code"); i && (this.invitation_token = i), this.logged_in ? this.redirect_to("/spaces") : this.active_view = "signup"; }.bind(this) } ]), this.router.add([ { path: "/login", handler: function(t) { this.logged_in ? this.invitation_token ? accept_invitation(this.accept_invitation, function(t) { window._spacedeck_location_change = !0, location.href = "spaces/" + t.space_id; }.bind(this), function(t) { console.error(t); }) : this.redirect_to("/spaces") : (this.active_view = "login", token = get_query_param("code"), token && this.login_with_token(token)); }.bind(this) } ]), this.router.add([ { path: "/logout", handler: function(t) { this.logged_in ? this.logout(function(t) { this.redirect_to("/login"); }.bind(this), function(t) { console.error(t); }) : this.redirect_to("/login"); }.bind(this) } ]), this.router.add([ { path: "/spaces", handler: function(t) { this.logged_in ? this.logged_in && this.user.home_folder_id ? this.load_space(this.user.home_folder_id) : location.href = "/" : (window._spacedeck_location_change = !0, location.href = "/login"); }.bind(this) } ]), this.router.add([ { path: "/account", handler: function(t) { this.logged_in ? (this.active_view = "account", this.load_subscription()) : (window._spacedeck_location_change = !0, location.href = "/"); }.bind(this) } ]), this.router.add([ { path: "/team", handler: function(t) { this.logged_in ? (this.active_view = "team", this.load_team()) : (window._spacedeck_location_change = !0, location.href = "/"); }.bind(this) } ]), this.router.add([ { path: "/folders/:id", handler: function(t) { this.load_space(t.id, null, function(t) { console.log("couldn't load folder: " + t.status), this.redirect_to("/spaces", function() {}); }.bind(this)); }.bind(this) } ]), this.router.add([ { path: "/", handler: function(t) { location.href = "/"; }.bind(this) } ]), this.router.add([ { path: "/terms", handler: function(t) { location.href = "/terms"; }.bind(this) } ]), this.router.add([ { path: "/privacy", handler: function(t) { location.href = "/privacy"; }.bind(this) } ])); var e = this.router.recognize(t); e ? e[0].handler(e[0].params, i) : location.href = "/not_found"; }, route: function() { if (window.onpopstate = function(t) { t.preventDefault(), this.internal_route(location.pathname); }.bind(this), $("body").on("click", "a", function(t) { t.currentTarget.hash && t.currentTarget.hash.length > 1 || (console.log("clicked", t.currentTarget.pathname), t.currentTarget.host == location.host && (t.metaKey || t.ctrlKey || t.shiftKey || t.currentTarget.pathname.match(/^\/t\//) || (this.internal_route(t.currentTarget.pathname), history.pushState(null, null, t.currentTarget.pathname), t.preventDefault()))); }.bind(this)), location.host != ENV.webHost) { if (!subdomainTeam) return void (location.href = ENV.webEndpoint); if (!subdomainTeam.subdomain) return void (location.href = ENV.webEndpoint); var t = subdomainTeam.subdomain + "." + ENV.webHost; if (location.host != t) return void (location.href = t); } if (this.logged_in && this.user.team && this.user.team.subdomain && this.user.team.subdomain.length > 0) { var t = this.user.team.subdomain + "." + ENV.webHost; if (location.host != t) return void (location.href = location.protocol + "//" + t + location.pathname); } this.internal_route(location.pathname); }, open_url: function(t) { window.open(t, "_blank"); }, redirect_to: function(t, i) { i ? (this.internal_route(t, i), history.pushState(null, null, t)) : (window._spacedeck_location_change = !0, location.href = t); }, link_to_parent_folder: function(t) { return "/folders/" + t; }, link_to_space: function(t) { return "/" + t.space_type + "s/" + t._id; } }; var SpacedeckFormatting = { apply_formatting: function(e, o, t, a) { console.log("apply_formatting: ", e, o); var n = _scribe_handle_for_object[e._id], c = n.getCommand(o); "createLink" == o && (t = prompt("Link URL?")), n.el.focus(), c.execute(t, a); } }; var SpacedeckSections = { data: { MAX_COLUMNS: 20, redo_stack: [], undo_stack: [], opened_dialog: "none", color_options_picker: !1, advanced_properties: !1, embed_code_html: "", active_tool: "pointer", lightbox_artifact: {}, snap_ruler_y: -1e3, snap_ruler_x: -1e3, minimap_width: 100, minimap_height: 200, minimap_scale: 10, scroll_left: 0, scroll_top: 0, window_width: 800, window_height: 600, bounds_margin_horiz: 0, bounds_margin_vert: 0, editing_artifact_id: null, selected_artifacts_dict: {}, first_selected_artifact: null, selection_metrics: { contains_text: !1, contains_images: !1, contains_audio: !1, contains_vectors: !1, contains_shapes: !1, borders_stylable: !0, count: 0, x: 0, y: 0, w: 0, h: 0, x1: 0, y1: 0, x2: 0, y2: 0, style: "display:none", vector_points: [ {}, {} ], vector_selection: !1 }, selected_artifacts_json: "", zones: [], user_cursors: [], default_style: {}, active_style: { border_radius: 0, stroke: 0, font_family: "Avenir W01", font_size: 18, line_height: 1.5, letter_spacing: 0, stroke_color: "#000000", fill_color: "#00000000", text_color: "#000000", background_color: "#ffffff", padding: 0, padding_horz: 0, padding_vert: 0, padding_top: 0, padding_left: 0, padding_right: 0, padding_bottom: 0, margin: 0, margin_horz: 0, margin_vert: 0, margin_top: 0, margin_left: 0, margin_right: 0, margin_bottom: 0, brightness: 100, contrast: 100, opacity: 100, saturation: 100, blur: 0, hue: 0, columns: 1, column_width: 900, row_height: 0, gutter: 0 }, color_picker_target: "fill_color", color_picker_saturation: 255, color_picker_value: 255, color_picker_hue: 127, color_picker_opacity: 255, swatches: [ { id: 0, hex: "#4a2f7e" }, { id: 1, hex: "#9b59b6" }, { id: 2, hex: "#3498db" }, { id: 3, hex: "#2ecc71" }, { id: 4, hex: "#f1c40f" }, { id: 5, hex: "#e67e22" }, { id: 6, hex: "#d55c4b" }, { id: 7, hex: "#6f4021" }, { id: 8, hex: "#ffffff" }, { id: 9, hex: "#95a5a6" }, { id: 10, hex: "#252525" }, { id: 11, hex: "rgba(0,0,0,0)" } ], swatches_text: [ { id: 1, hex: "#9b59b6" }, { id: 2, hex: "#3498db" }, { id: 3, hex: "#2ecc71" }, { id: 4, hex: "#f1c40f" }, { id: 5, hex: "#e67e22" }, { id: 6, hex: "#d55c4b" }, { id: 8, hex: "#ffffff" }, { id: 10, hex: "#252525" } ], fonts: [ "Arial", "Courier", "Georgia", "Verdana", "Comic Sans MS", "Montserrat", "Lato", "Roboto", "Crimson Text", "EB Garamond", "Vollkorn", "Avenir W01" ], detected_text_formats: {}, active_text_format_name: "Paragraph", image_search_results: [], video_search_results: [], audio_search_results: [], generic_search_query: "", media_search_target: "google", search_loading: !1, viewport_zoom: 1, viewport_zoom_percent: 100, bounds_zoom: 1, current_zone_idx: -1, margin_mode: "global", padding_mode: "global", delete_artifact: "unconfirmed", color_mode: "palette", background_mode: "image", layout_mode: "layout", follow_mode: !0, space_background_uploading: !1, toolbar_props_x: 0, toolbar_props_y: 0, toolbar_props_in: !1, toolbar_artifacts_x: "-1000px", toolbar_artifacts_y: "-1000px", toolbar_artifacts_in: !1 }, methods: { setup_section_module: function() { this.default_style = _.clone(this.active_style), Mousetrap.bind("del", function(t) { this.if_editable(function() { this.delete_selected_artifacts(t); }); }.bind(this)), Mousetrap.bind("backspace", function(t) { this.if_editable(function() { this.delete_selected_artifacts(t); }); }.bind(this)), Mousetrap.bind([ "command+d", "ctrl+d" ], function(t) { t.preventDefault(), t.stopPropagation(), this.if_editable(function() { this.duplicate_selected_artifacts(); }); }.bind(this)), Mousetrap.bind([ "command+z", "ctrl+z" ], function(t) { this.if_editable(function() { this.undo(); }); }.bind(this)), Mousetrap.bind([ "command+shift+z", "ctrl+shift+z" ], function(t) { this.if_editable(function() { this.redo(); }); }.bind(this)), Mousetrap.bind([ "command+a", "ctrl+a" ], function(t) { this.if_editable(function() { this.select_all_artifacts(); }); }.bind(this)), Mousetrap.bind([ "command+e", "ctrl+e" ], function(t) { this.if_editable(function() { this.toggle_full_width(); }); }.bind(this)), Mousetrap.bind([ "command+=", "ctrl+=" ], function(t) { t.preventDefault(), t.stopPropagation(), this.zoom_in(); }.bind(this)), Mousetrap.bind([ "command+-", "ctrl+-" ], function(t) { t.preventDefault(), t.stopPropagation(), this.zoom_out(); }.bind(this)), Mousetrap.bind("+", function(t) { t.preventDefault(), t.stopPropagation(), this.zoom_in(); }.bind(this)), Mousetrap.bind("-", function(t) { t.preventDefault(), t.stopPropagation(), this.zoom_out(); }.bind(this)), Mousetrap.bind("up", function(t) { this.nudge_selected_artifacts(0, -1, t); }.bind(this)), Mousetrap.bind("down", function(t) { this.nudge_selected_artifacts(0, 1, t); }.bind(this)), Mousetrap.bind("left", function(t) { this.nudge_selected_artifacts(-1, 0, t); }.bind(this)), Mousetrap.bind("right", function(t) { this.nudge_selected_artifacts(1, 0, t); }.bind(this)), Mousetrap.bind("shift+up", function(t) { this.if_editable(function() { this.nudge_selected_artifacts(0, -10, t); }); }.bind(this)), Mousetrap.bind("shift+down", function(t) { this.if_editable(function() { this.nudge_selected_artifacts(0, 10, t); }); }.bind(this)), Mousetrap.bind("shift+left", function(t) { this.if_editable(function() { this.nudge_selected_artifacts(-10, 0, t); }); }.bind(this)), Mousetrap.bind("shift+right", function(t) { this.if_editable(function() { this.nudge_selected_artifacts(10, 0, t); }); }.bind(this)), Mousetrap.bind("space", function(t) { this.activate_pan_tool(t); }.bind(this)), $(document).bind("beforecopy", this.handle_onbeforecopy.bind(this)), $(window).bind("beforeunload", this.handle_onunload.bind(this)), $(window).bind("resize", this.handle_window_resize.bind(this)); }, setup_watches: function() { this.$watch("active_style.stroke", function(t, i) { this.set_artifact_style_prop("stroke", parseInt(this.active_style.stroke)); }.bind(this)), this.$watch("active_style.border_radius", function(t, i) { this.set_artifact_style_prop("border_radius", parseInt(this.active_style.border_radius)); }.bind(this)), this.$watch("active_style.padding", function(t, i) { this.active_style.padding_horz = this.active_style.padding, this.active_style.padding_vert = this.active_style.padding; }.bind(this)), this.$watch("active_style.padding_horz", function(t, i) { this.active_style.padding_left = this.active_style.padding_horz, this.active_style.padding_right = this.active_style.padding_horz; }.bind(this)), this.$watch("active_style.padding_vert", function(t, i) { this.active_style.padding_top = this.active_style.padding_vert, this.active_style.padding_bottom = this.active_style.padding_vert; }.bind(this)), this.$watch("active_style.padding_top", function(t, i) { this.set_artifact_style_prop("padding_top", parseInt(this.active_style.padding_top)); }.bind(this)), this.$watch("active_style.padding_bottom", function(t, i) { this.set_artifact_style_prop("padding_bottom", parseInt(this.active_style.padding_bottom)); }.bind(this)), this.$watch("active_style.padding_left", function(t, i) { this.set_artifact_style_prop("padding_left", parseInt(this.active_style.padding_left)); }.bind(this)), this.$watch("active_style.padding_right", function(t, i) { this.set_artifact_style_prop("padding_right", parseInt(this.active_style.padding_right)); }.bind(this)), this.$watch("active_style.margin", function(t, i) { this.active_style.margin_horz = this.active_style.margin, this.active_style.margin_vert = this.active_style.margin; }.bind(this)), this.$watch("active_style.margin_horz", function(t, i) { this.active_style.margin_left = this.active_style.margin_horz, this.active_style.margin_right = this.active_style.margin_horz; }.bind(this)), this.$watch("active_style.margin_vert", function(t, i) { this.active_style.margin_top = this.active_style.margin_vert, this.active_style.margin_bottom = this.active_style.margin_vert; }.bind(this)), this.$watch("active_style.margin_top", function(t, i) { this.set_artifact_style_prop("margin_top", parseInt(this.active_style.margin_top)); }.bind(this)), this.$watch("active_style.margin_bottom", function(t, i) { this.set_artifact_style_prop("margin_bottom", parseInt(this.active_style.margin_bottom)); }.bind(this)), this.$watch("active_style.margin_left", function(t, i) { this.set_artifact_style_prop("margin_left", parseInt(this.active_style.margin_left)); }.bind(this)), this.$watch("active_style.margin_right", function(t, i) { this.set_artifact_style_prop("margin_right", parseInt(this.active_style.margin_right)); }.bind(this)), this.$watch("active_style.stroke_color", function(t, i) { this.set_artifact_style_prop("stroke_color", this.active_style.stroke_color); var e = hex_to_rgba(this.active_style.stroke_color), a = rgb_to_hsv(e.r, e.g, e.b); this.active_style.stroke_color_hsv = a; }.bind(this)), this.$watch("active_style.fill_color", function(t, i) { this.set_artifact_style_prop("fill_color", this.active_style.fill_color); var e = hex_to_rgba(this.active_style.fill_color), a = rgb_to_hsv(e.r, e.g, e.b); this.active_style.fill_color_hsv = a; }.bind(this)), this.$watch("active_style.text_color", function(t, i) { this.set_artifact_style_prop("text_color", this.active_style.text_color), this.apply_formatting(null, "forecolor", this.active_style.text_color); var e = hex_to_rgba(this.active_style.text_color), a = rgb_to_hsv(e.r, e.g, e.b); this.active_style.text_color_hsv = a; }.bind(this)), this.$watch("active_style.font_size", function(t, i) { this.apply_formatting(null, "preciseFontSize", this.active_style.font_size + "px"); }.bind(this)), this.$watch("active_style.line_height", function(t, i) { this.apply_formatting(null, "lineHeight", this.active_style.line_height + "em"); }.bind(this)), this.$watch("active_style.letter_spacing", function(t, i) { this.apply_formatting(null, "letterSpacing", this.active_style.letter_spacing + "px"); }.bind(this)), this.$watch("color_picker_hue", function(t, i) { this.apply_color_picker(); }.bind(this)), this.$watch("color_picker_value", function(t, i) { this.apply_color_picker(); }.bind(this)), this.$watch("color_picker_saturation", function(t, i) { this.apply_color_picker(); }.bind(this)), this.$watch("color_picker_opacity", function(t, i) { this.apply_color_picker(); }.bind(this)), this.$watch("active_style.brightness", function(t, i) { this.set_artifact_style_prop("brightness", parseInt(this.active_style.brightness)); }.bind(this)), this.$watch("active_style.blur", function(t, i) { this.set_artifact_style_prop("blur", parseInt(this.active_style.blur)); }.bind(this)), this.$watch("active_style.contrast", function(t, i) { this.set_artifact_style_prop("contrast", parseInt(this.active_style.contrast)); }.bind(this)), this.$watch("active_style.saturation", function(t, i) { this.set_artifact_style_prop("saturation", parseInt(this.active_style.saturation)); }.bind(this)), this.$watch("active_style.hue", function(t, i) { this.set_artifact_style_prop("hue", parseInt(this.active_style.hue)); }.bind(this)), this.$watch("active_style.opacity", function(t, i) { this.set_artifact_style_prop("opacity", parseInt(this.active_style.opacity)); }.bind(this)), this.throttled_save_active_space = _.throttle(function() { save_space(this.active_space); }.bind(this), 2e3), this.$watch("active_style.background_color", function(t, i) { this.active_style.background_color != this.active_space.advanced.background_color && (this.$set("active_space.advanced.background_color", this.active_style.background_color), this.throttled_save_active_space()); var e = hex_to_rgba(this.active_style.background_color), a = rgb_to_hsv(e.r, e.g, e.b); this.active_style.background_color_hsv = a; }.bind(this)); }, if_editable: function(t) { "viewer" != this.active_space_role && t.bind(this)(); }, background_image_style: function(t) { if (!t) return null; isNaN(t.length) && (t = [ t ]); for (var i = 0; i < t.length; i++) if (t[i] && t[i].length > 0) return "background-image: url(" + t[i] + ")"; }, space_thumbnail_style: function(t) { return t.avatar_thumb_uri && t.avatar_thumb_uri.length > 0 ? "background-image:url('" + t.avatar_thumb_uri + "')" : "folder" == t.space_type ? "" : "background-image:url('/api/spaces/" + t._id + "/png')"; }, reset_artifact_filters: function() { this.active_style.brightness = this.default_style.brightness, this.active_style.contrast = this.default_style.contrast, this.active_style.opacity = this.default_style.opacity, this.active_style.saturation = this.default_style.saturation, this.active_style.blur = this.default_style.blur, this.active_style.hue = this.default_style.hue; }, increase_columns: function() { this.active_style.columns < this.MAX_COLUMNS && this.active_style.columns++; }, decrease_columns: function() { this.active_style.columns > 1 && this.active_style.columns--; }, extract_properties_from_selection: function() { this.skip_formatting = !0; var t = this.selected_artifacts(); if (window.setTimeout(function() { this.skip_formatting = !1; }.bind(this), 10), t.length) { if (1 == t.length) { for (var i = t[0], e = [ "stroke", "border_radius", "letter_spacing", "stroke_color", "fill_color", "text_color" ], a = 0; a < e.length; a++) { var s = e[a]; this.active_style[s] = i.style[s]; } this.active_style.font_size = this.default_style.font_size, this.active_style.line_height = this.default_style.line_height, this.active_style.letter_spacing = this.default_style.letter_spacing, this.active_style.padding_top = i.style.padding_top || 0, this.active_style.padding_bottom = i.style.padding_bottom || 0, this.active_style.padding_left = i.style.padding_left || 0, this.active_style.padding_right = i.style.padding_right || 0, this.active_style.padding_top == this.active_style.padding_bottom && (this.active_style.padding_vert = this.active_style.padding_top), this.active_style.padding_left == this.active_style.padding_right && (this.active_style.padding_horz = this.active_style.padding_left), this.active_style.padding_top == this.active_style.padding_bottom && this.active_style.padding_left == this.active_style.padding_right && this.active_style.padding_left == this.active_style.padding_top && (this.active_style.padding = this.active_style.padding_top), this.active_style.margin_top = i.style.margin_top || 0, this.active_style.margin_bottom = i.style.margin_bottom || 0, this.active_style.margin_left = i.style.margin_left || 0, this.active_style.margin_right = i.style.margin_right || 0, this.active_style.margin_top == this.active_style.margin_bottom && (this.active_style.margin_vert = this.active_style.margin_top), this.active_style.margin_left == this.active_style.margin_right && (this.active_style.margin_horz = this.active_style.margin_left), this.active_style.margin_top == this.active_style.margin_bottom && this.active_style.margin_left == this.active_style.margin_right && this.active_style.margin_left == this.active_style.margin_top && (this.active_style.margin = this.active_style.margin_top); } this.update_selection_metrics(), this.selection_metrics.contains_text = !1, this.selection_metrics.contains_images = !1, this.selection_metrics.contains_audio = !1, this.selection_metrics.contains_embeds = !1, this.selection_metrics.contains_vectors = !1, this.selection_metrics.contains_shapes = !1, this.selection_metrics.borders_stylable = !1; var o = _.filter(t, function(t) { return "text/html" == t.mime || "x-spacedeck/shape" == t.mime; }); if (o.length >= 1 && (this.selection_metrics.contains_text = !0, 1 == o.length)) { var i = o[0], n = $("
" + i.description + "
")[0], r = n.firstChild; do r && r.style && (r.style.fontSize && (this.active_style.font_size = parseInt(r.style.fontSize)), r.style.fontFamily && (this.active_style.font_family = r.style.fontFamily), r.style.letterSpacing && (this.active_style.letter_spacing = parseInt(r.style.letterSpacing)), r.style.lineHeight && (this.active_style.line_height = parseFloat(r.style.lineHeight)), r.style.color && (this.active_style.text_color = r.style.color)); while (r && (r = n.nextSibling)); } 1 == t.length && this.extract_color_picker_from_selection(); var c = _.filter(t, function(t) { return t.mime.match("image"); }); c.length >= 1 && (this.selection_metrics.contains_images = !0); var l = _.filter(t, function(t) { return t.mime.match("audio"); }); l.length >= 1 && (this.selection_metrics.contains_audio = !0); var h = _.filter(t, function(t) { return t.mime.match("embed"); }); h.length >= 1 && (this.selection_metrics.contains_embeds = !0); var h = _.filter(t, function(t) { return "x-spacedeck/vector" == t.mime; }); h.length >= 1 && (this.selection_metrics.contains_vectors = !0); var h = _.filter(t, function(t) { return "x-spacedeck/shape" == t.mime; }); h.length >= 1 && (this.selection_metrics.contains_shapes = !0); var d = this.selection_metrics; this.selection_metrics.borders_stylable = !(d.contains_vectors || d.contains_shapes); } }, increase_letter_spacing: function(t) { this.active_style.letter_spacing++; }, decrease_letter_spacing: function(t) { this.active_style.letter_spacing--; }, apply_font: function(t, i) { this.apply_formatting(t, "fontName", i), this.active_style.font_family = i; }, toggle_advanced_properties: function() { this.advanced_properties = !this.advanced_properties; }, open_dialog: function(t, i) { return i && (i.stopPropagation(), i.preventDefault()), this.active_tool = "pointer", this.opened_dialog == t ? void (this.opened_dialog = "none") : (_.contains([ "mobile", "shapes", "zones" ], t) && this.deselect(), this.opened_dialog = t, (t.match("color") || t.match("background")) && (this.color_picker_target = t.replace("color-", "") + "_color", this.color_mode = "palette", this.extract_color_picker_from_selection()), _.contains([ "audio", "video", "image", "search" ], t) && $("#" + t + " input")[0] && $("#" + t + " input")[0].focus(), "background" == this.opened_dialog && (this.color_picker_target = "background_color", this.background_mode = "color"), void ("info" == this.opened_dialog && (this.access_settings_space = this.active_space, this.access_settings_memberships = this.active_space_memberships, this.editors_section = "list", this.active_space_is_readonly || this.embedded ? this.space_info_section = "info" : "admin" == this.active_space_role && (this.space_info_section = "access")))); }, toggle_color_options: function() { this.color_options_picker = !this.color_options_picker; }, close_lightbox: function() { this.lightbox_artifact = {}, this.close_modal(); }, prepare_clipboard: function() { "ontouchstart" in window || (this.selected_artifacts_json = JSON.stringify(this.selected_artifacts()), this.prepare_clipboard_step2()); }, prepare_clipboard_step2: function() { "ontouchstart" in window || setTimeout(function() { $("#space-clipboard > textarea").length && ($("#space-clipboard > textarea")[0].focus(), $("#space-clipboard > textarea")[0].select()); }, 100); }, handle_section_keydown: function(t) { return 67 == t.keyCode && (t.ctrlKey || t.metaKey) && (this.prepare_clipboard(), this.prepare_clipboard_step2()), !0; }, handle_onbeforecopy: function(t) { if (!this.editing_artifact_id) { var i = t.target.nodeName.toLowerCase(); "body" == i && (this.prepare_clipboard_step2(), window.setTimeout(function() { $("#space-clipboard > textarea").length && $("#space-clipboard > textarea")[0].blur(); }, 10)); } }, handle_onunload: function(t) { if (window.artifact_save_queue) { var i = Object.keys(window.artifact_save_queue).length; if (i > 0) { var e = "There are " + i + " changes that are still being saved. Discard them?"; return t.returnValue = e, e; } window._spacedeck_location_change = !0; } }, handle_window_resize: function(t) { this.adjust_bounds_zoom(); }, handle_scroll: function(t) { "space" == this.active_view && $("#space").length && (el = $("#space")[0], this.scroll_left = el.scrollLeft / this.viewport_zoom, this.scroll_top = el.scrollTop / this.viewport_zoom, this.window_width = window.innerWidth / this.viewport_zoom, this.window_height = window.innerHeight / this.viewport_zoom, this.resize_minimap(), this.logged_in && this.present_mode && "viewer" != this.active_space_role && this.presenter_send_viewport()); }, presenter_send_viewport: function() { name = this.user.nickname || this.user.email; var t = { action: "viewport", x: this.scroll_left, y: this.scroll_top, w: this.window_width, h: this.window_height, zoom: this.viewport_zoom, name: name, id: this.user._id }, i = JSON.stringify(t); i != this._old_viewport_msg && (this._old_viewport_msg = i, this.present_mode && "viewer" != this.active_space_role && this.websocket_send(t)); }, presenter_send_media_action: function(t, i, e, a) { name = this.user.nickname || this.user.email; var s = { action: "media", artifact_id: t, type: i, command: e, time: a, name: name, id: this.user._id }; this.present_mode && "viewer" != this.active_space_role && this.websocket_send(s); }, resize_minimap: function() { this.active_space && this.active_space.advanced && (this.minimap_scale = this.active_space.advanced.width / 100); }, handle_minimap_mouseup: function(t) { this.minimap_mouse_state = "idle"; }, handle_minimap_mousemove: function(t) { "pressed" == this.minimap_mouse_state && this.handle_minimap_mousedown(t); }, handle_minimap_mousedown: function(t) { if ($("#space").length) { this.minimap_mouse_state = "pressed", el = $("#space")[0], t = fixup_touches(t); var i = $(t.target).offset(), e = t.pageX - i.left, a = t.pageY - i.top; el.scrollLeft = (e - this.window_width / (2 * this.minimap_scale)) * this.minimap_scale * this.viewport_zoom, el.scrollTop = (a - this.window_height / (2 * this.minimap_scale)) * this.minimap_scale * this.viewport_zoom, this.handle_scroll(); } }, handle_user_cursor_update: function(t) { var i = new Date().getTime(); t.t = i; for (var e = !1, a = 0; a < this.user_cursors.length; a++) { var s = this.user_cursors[a]; s.id == t.id ? (s.x = t.x, s.y = t.y, s.t = i, s.name = t.name, e = !0) : i - s.t > 5e3 && (s.x = -1e4); } e || this.user_cursors.push(_.clone(t)); }, handle_presenter_viewport_update: function(t) { this.zoom_to_rect({ x1: t.x, y1: t.y, x2: t.x + t.w, y2: t.y + t.h }); }, handle_presenter_media_update: function(t) { if (this.follow_mode) { if ("audio" == t.type) { var i = "#artifact-" + t.artifact_id + " .audio"; try { $(i)[0].dispatchEvent(new Event("remote_" + t.command)), console.log("event dispatched"); } catch (e) {} } if ("video" == t.type) { var i = "#artifact-" + t.artifact_id + " .video"; try { $(i)[0].dispatchEvent(new Event("remote_" + t.command)), console.log("event dispatched"); } catch (e) {} } } else console.log("ignore media update, muted"); }, may_select: function(t) { return !!t && (!!this.active_space && (!("viewer" == this.active_space_role || t.locked && "admin" != this.active_space_role) && !(this.active_space.editors_locking && !this.logged_in && this.guest_nickname != t.editor_name))); }, select: function(t, i) { this.may_select(i) && (t && !t.shiftKey && this.is_selected(i) || (t && t.shiftKey || this.deselect(), t && t.shiftKey && this.selected_artifacts_dict[i._id] ? delete this.selected_artifacts_dict[i._id] : this.selected_artifacts_dict[i._id] = !0, this.update_board_artifact_viewmodel(i), this.extract_properties_from_selection(), this.update_selection_metrics(), this.prepare_clipboard(), this.show_toolbar_props())); }, select_all_artifacts: function(t) { this.deselect(); for (var i = 0; i < this.active_space_artifacts.length; i++) { var e = this.active_space_artifacts[i]; this.may_select(e) && (this.selected_artifacts_dict[e._id] = !0, this.update_board_artifact_viewmodel(e)); } this.update_selection_metrics(), this.extract_properties_from_selection(), this.prepare_clipboard(), this.show_toolbar_props(); }, multi_select: function(t) { for (var i = 0; i < t.length; i++) { var e = t[i]; this.may_select(e) && (this.selected_artifacts_dict[e._id] = !0, this.update_board_artifact_viewmodel(e)); } this.extract_properties_from_selection(), this.update_selection_metrics(), this.prepare_clipboard(), this.show_toolbar_props(); }, discover_zones: function() { this.zones = _.sortBy(_.filter(this.active_space_artifacts, function(t) { return "x-spacedeck/zone" == t.mime; }), function(t) { return t.style.order; }); }, artifact_plaintext: function(t) { if (!t) return ""; var i = $("
" + t.description + "
").text(); return i || ""; }, deselect: function(t) { if (window._sd_fader_moving) return void (window._sd_fader_moving = !1); this.hide_toolbar_props(), document.getSelection().removeAllRanges(), blur(), this.prepare_clipboard_step2(), this.discover_zones(); var i = this.selected_artifacts(); this.selected_artifacts_dict = {}; for (var e = 0; e < i.length; e++) { var a = i[e], s = !0; if (a && "text/html" == a.mime) { var o = this.artifact_plaintext(a); 0 == o.length && (s = !0); } s || (this.selected_artifacts_dict[a._id] = a); } this.delete_selected_artifacts(null, !0), this.selected_artifacts_dict = {}, this.editing_artifact_id = null, this.opened_dialog = "none"; for (var e = 0; e < i.length; e++) this.update_board_artifact_viewmodel(i[e]); this.selection_metrics.contains_text = !1, this.selection_metrics.count = 0, t && (this.active_tool = "pointer", this.mouse_state = "idle"), this.update_selection_metrics(); }, is_selected: function(t) { if (t) return !!this.selected_artifacts_dict[t._id]; }, unselected_artifacts: function() { return this.active_space_artifacts.filter(function(t) { return !this.is_selected(t); }.bind(this)); }, selection_rect_style: function() { var t = this.selection_rect(); return null == t ? "display:none" : "left:" + t.x1 + "px;top:" + t.y1 + "px;width:" + (t.x2 - t.x1) + "px;height:" + (t.y2 - t.y1) + "px;"; }, selection_rect: function() { return this.enclosing_rect(this.selected_artifacts()); }, enclosing_rect: function(t) { return 0 == t.length ? null : (t = _.filter(t), { x1: parseInt(_.min(t.map(function(t) { return t.board && t.board.x ? t.board.x : 0; }))), y1: parseInt(_.min(t.map(function(t) { return t.board && t.board.y ? t.board.y : 0; }))), x2: parseInt(_.max(t.map(function(t) { return t.board ? t.board.x + t.board.w : 0; }))), y2: parseInt(_.max(t.map(function(t) { return t.board ? t.board.y + t.board.h : 0; }))) }); }, update_selection_metrics: function(t) { if ("scribble" == this.active_tool) return void (this.selection_metrics.count = 1); var i = this.selection_rect() || { x: 0, y: 0, w: 0, h: 0, style: "display:none" }; if (i.x1 || i.x2) { i.w = i.x2 - i.x1, i.h = i.y2 - i.y1, i.style = this.selection_rect_style(); var e = this.space_point_to_window(i.x1 + i.w / 2, i.y2), a = this.space_point_to_window(i.x1 + i.w / 2, i.y1); e.x -= 260, e.y -= 10, e.y >= window.innerHeight - 300 && (e.y = a.y - 100), e.x < 0 && (e.x = 0), e.y < 0 && (e.y = 0), this.toolbar_props_x = e.x + "px", this.toolbar_props_y = e.y + "px", this.hide_toolbar_artifacts(); } this.selection_metrics.x1 = i.x1, this.selection_metrics.x2 = i.x2, this.selection_metrics.y1 = i.y1, this.selection_metrics.y2 = i.y2, this.selection_metrics.x = i.x, this.selection_metrics.y = i.y, this.selection_metrics.w = i.w, this.selection_metrics.h = i.h, this.selection_metrics.style = i.style, t || (t = this.selected_artifacts()), this.first_selected_artifact = t[0], this.selection_metrics.count = t.length, this.selection_metrics.scribble_selection = !1, 1 == t.length && "x-spacedeck/vector" == t[0].mime ? ("scribble" == t[0].style.shape && (this.selection_metrics.scribble_selection = !0), this.selection_metrics.vector_points = t[0].control_points, this.selection_metrics.vector_selection = !0) : (this.selection_metrics.vector_points = [ {}, {} ], this.selection_metrics.vector_selection = !1), this.selection_metrics.has_link = !1, this.insert_link_url = "", 1 == t.length && t[0].meta && t[0].meta.link_uri && t[0].meta.link_uri.length > 0 && (this.selection_metrics.has_link = !0, this.insert_link_url = t[0].meta.link_uri); }, begin_transaction: function() { this.transaction_running = !0, this.undo_stack.length && "empty" == this.undo_stack[this.undo_stack.length - 1].action || this.undo_stack.push({ action: "empty" }), this.redo_stack = [], this.artifacts_before_transaction = this.active_space_artifacts.map(function(t) { return _.cloneDeep(t); }); }, fixup_space_size: function() { this.active_space && (this.active_space.advanced.width = Math.max(this.active_space.advanced.width, window.innerWidth), this.active_space.advanced.height = Math.max(this.active_space.advanced.height, window.innerHeight)); }, end_transaction: function() { if (this.transaction_running = !1, this.throttled_process_artifact_save_queue(), this.active_space) { var t = this.enclosing_rect(this.active_space_artifacts); t && (this.active_space.advanced.width = Math.max(t.x2 + 100, window.innerWidth), this.active_space.advanced.height = Math.max(t.y2 + 100, window.innerHeight), this._last_bounds_width == this.active_space.advanced.width && this._last_bounds_height == this.active_space.advanced.height || (this._last_bounds_width = this.active_space.advanced.width, this._last_bounds_height = this.active_space.advanced.height, save_space(this.active_space)), this.resize_minimap(), this.discover_zones()); } }, find_artifact_before_transaction: function(t) { return this.find_artifact_in_array(this.artifacts_before_transaction, t); }, find_artifact_in_array: function(t, i) { var e = _.find(t, function(t) { return i._id && t._id == i._id; }); return e; }, unsaved_transactions: function() { return window.artifact_save_queue ? Object.keys(window.artifact_save_queue).length : 0; }, process_artifact_save_queue: function() { if (window.artifact_save_queue) { if (this.transaction_running) return void console.log("not saving, transaction still in progress."); for (var t = Object.keys(window.artifact_save_queue), i = 0; i < t.length; i++) { var e = t[i], a = window.artifact_save_queue[e]; this.guest_nickname && (a.editor_name = this.guest_nickname), save_artifact(a, function() { delete window.artifact_save_queue[e]; }.bind(this), function(t) { t && 404 == t.status ? delete window.artifact_save_queue[e] : console.log("could not save artifact, will try again:", a, t); }); } this.active_space && (this.active_space.updated_at = new Date().getTime()); } }, throttled_process_artifact_save_queue: function() { this._throttled_process_artifact_save_queue || (this._throttled_process_artifact_save_queue = _.throttle(this.process_artifact_save_queue, 500)), this._throttled_process_artifact_save_queue(); }, queue_artifact_for_save: function(t) { window.artifact_save_queue || (window.artifact_save_queue = {}), t._id || console.log("warning: illegal artifact queued for save"), t.view && t.view.vector_svg && (t.style.shape_svg = t.view.vector_svg), window.artifact_save_queue[t._id] = t; }, update_properties: function(t, i) { for (var e = 0; e < t.length; e++) { var a = t[e], s = this.find_artifact_by_id(a); if (s) { var o = !1; for (k in i[e]) s[k] = i[e][k], o = !0; this.update_board_artifact_viewmodel(s), o && this.queue_artifact_for_save(s); } } }, update_artifacts: function(t, i) { for (var e = [], a = [], s = 0; s < t.length; s++) { var o = t[s], n = i(o); n && (e.push(o._id), a.push(n)); } a.length && this.push_to_undo({ action: "update", artifact_ids: e, changes: a, snapshot: this.artifacts_before_transaction }), a.length && this.update_properties(e, a); }, push_to_undo: function(t) { this.undo_stack[this.undo_stack.length - 1] = t; }, undo: function() { if (!this.undo_stack.length || "empty" == this.undo_stack[this.undo_stack.length - 1].action) return void console.log("nothing to undo!"); var t = this.undo_stack.pop(); console.log("undo popped: ", t), this.redo_stack.push(t); for (var i = 0; i < t.artifact_ids.length; i++) { var e = t.artifact_ids[i], a = this.find_artifact_in_array(t.snapshot, { _id: e }); "update" == t.action ? a && this.update_properties([ e ], [ a ]) : (delete a._id, save_artifact(a, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t); }.bind(this))); } this.update_selection_metrics(); }, redo: function() { if (!this.redo_stack.length) return void console.log("nothing to redo!"); var t = this.redo_stack.pop(); console.log("redo popped: ", t), this.undo_stack.push(t), this.update_properties(t.artifact_ids, t.changes), this.update_selection_metrics(); }, set_artifact_prop: function(t, i) { this.begin_transaction(), this.update_selected_artifacts(function(e) { var a = {}; return a[t] != i ? (a[t] = i, a) : null; }); }, set_artifact_style_prop: function(t, i) { this.begin_transaction(), this.update_selected_artifacts(function(e) { var a = { style: e.style || {} }; return a.style[t] != i ? (a.style[t] = i, a) : null; }); }, activate_color_mode: function(t) { this.color_mode = t, "picker" == t && 0 == this.color_picker_hue && 0 == this.color_picker_saturation && 0 == this.color_picker_value && 0 == this.color_picker_opacity && (this.color_picker_opacity = 255, this.color_picker_value = 255); }, reset_stroke: function() { this.active_style.stroke = 0, this.active_style.border_radius = 0, this.active_style.stroke_style = "solid"; }, apply_font_size: function(t) { this.apply_formatting(null, "preciseFontSize", t + "px"); }, apply_swatch_color: function(t) { var i = hex_to_rgba(t.hex), e = rgb_to_hsv(i.r, i.g, i.b); this.color_picker_hue = parseFloat(255 * e.h), this.color_picker_saturation = parseFloat(255 * e.s), this.color_picker_value = parseFloat(255 * e.v), this.color_picker_opacity = 255 * i.a, this.color_picker_rgb = rgb_to_hex(i.r, i.g, i.b), this.active_style[this.color_picker_target] = t.hex, "stroke_color" == this.color_picker_target && (this.active_style.stroke || (this.active_style.stroke = 2)); }, apply_color_picker: function() { var t = hsv_to_rgb(this.color_picker_hue / 255, this.color_picker_saturation / 255, this.color_picker_value / 255), i = this.color_picker_opacity / 255; this.active_style[this.color_picker_target] = "rgba(" + [ t.r, t.g, t.b, i ].join(",") + ")"; }, extract_color_picker_from_selection: function() { if (1 == this.selected_artifacts().length || "background" == this.opened_dialog) { "background" == this.opened_dialog ? this.active_style[this.color_picker_target] = this.active_space.advanced.background_color : this.active_style[this.color_picker_target] || (this.active_style[this.color_picker_target] = this.default_style[this.color_picker_target]); var t = hex_to_rgba(this.active_style[this.color_picker_target]), i = rgb_to_hsv(t.r, t.g, t.b); this.color_picker_hue = parseFloat(255 * i.h), this.color_picker_saturation = parseFloat(255 * i.s), this.color_picker_value = parseFloat(255 * i.v), this.color_picker_opacity = parseInt(t.a), this.color_picker_rgb = rgb_to_hex(t.r, t.g, t.b); } }, update_selected_artifacts: function(t, i) { var e = this.selected_artifacts(!i); e.length && (this.update_artifacts(e, t), this.update_selection_metrics()); }, nudge_selected_artifacts: function(t, i, e) { if (this.present_mode) { if (t > 0 || i > 0) return void this.go_to_next_zone(); if (t < 0 || i < 0) return void this.go_to_previous_zone(); } if (!this.selected_artifacts().length) { if (!$("#space").length) return; var a = $("#space")[0]; return a.scrollLeft += 100 * t, void (a.scrollTop += 100 * i); } this.active_space_is_readonly || (e && (e.preventDefault(), e.stopPropagation()), this.begin_transaction(), this.update_selected_artifacts(function(e) { return { board: _.extend(e.board, { x: e.board.x + t, y: e.board.y + i }) }; })); }, highest_z: function() { var t = _.max(this.active_space_artifacts.map(function(t) { return t.board.z || 0; })); return t < 0 && (t = 0), t > 999 && (t = 999), t; }, find_place_for_item: function(t, i) { var e = this.active_space_artifacts, a = window.innerWidth, s = window.innerHeight, o = $("#space")[0]; if (!o) return { x: 0, y: 0, z: 1 }; var n = $(".wrapper"), _ = parseInt(n.css("margin-left")), r = parseInt(n.css("margin-top")), c = parseInt((o.scrollLeft + a / 2) / this.viewport_zoom - t / 2 - _ / this.viewport_zoom), l = parseInt((o.scrollTop + s / 2) / this.viewport_zoom - i / 2 - r / this.viewport_zoom), h = this.highest_z() + 1; return 0 == e.length ? { x: c, y: l } : (c += parseInt(20 * Math.random()) - 10, l += parseInt(20 * Math.random()) - 10, { x: c, y: l, z: h }); }, save_audio_edit: function(t) { this.opened_dialog = "none", this.update_board_artifact_viewmodel(t), save_artifact(t); }, save_artifact: function(t, i) { this.guest_nickname && (t.editor_name = this.guest_nickname), this.update_board_artifact_viewmodel(t), save_artifact(t, i); }, add_artifact: function(t, i, e, a) { if (this.active_tool = "pointer", this.mouse_state = "idle", this.hide_toolbar_artifacts(), e || "image" != i && "video" != i && "embed" != i || (e = prompt("URL?"), e && e.length)) { var s = 300, o = 200, n = this.highest_z() + 1; mimes = { text: "text/html", note: "text/html", image: "image/jpg", video: "video/mp4" }; var _ = { mime: mimes[i], description: "", payload_uri: e, payload_thumbnail_medium_uri: e || null, payload_thumbnail_web_uri: e || null, space_id: t._id, style: { order: this.active_space_artifacts.length + 1, valign: "middle", align: "center" } }; if ("text/html" == mimes[i] && (_.style.padding_left = 10, _.style.padding_top = 10, _.style.padding_right = 10, _.style.padding_bottom = 10, _.style.fill_color = "rgba(255,255,255,1)", _.description = "

Text

"), a) { var r = this.cursor_point_to_space(a); r.x -= 100, r.y -= 100; } else { var r = this.find_place_for_item(s, o); n = r.z; } _.board = { x: parseInt(r.x), y: parseInt(r.y), w: s, h: o, z: n }, this.guest_nickname && (_.editor_name = this.guest_nickname), save_artifact(_, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t), e || this.select(null, t), i.match("text") && (this.editing_artifact_id = t._id, window.setTimeout(function() { var i = $("#artifact-" + t._id + " .text-editing"); focus_contenteditable(i[0], !1); }, 400)); }.bind(this)); } }, go_to_first_zone: function() { this.discover_zones(), this.zones.length && this.zoom_to_zone(this.zones[0]); }, go_to_previous_zone: function() { if (this.discover_zones(), this.zones.length) { var t = this.current_zone_idx - 1; t < 0 && (t = this.zones.length - 1), this.current_zone_idx = t, this.zoom_to_zone(this.zones[this.current_zone_idx]); } }, go_to_next_zone: function() { if (this.discover_zones(), this.zones.length) { var t = (this.current_zone_idx + 1) % this.zones.length; this.current_zone_idx = t, this.zoom_to_zone(this.zones[this.current_zone_idx]); } }, sort_zone_up: function(t) { var i = this.zones.indexOf(t); if (!(i < 1)) { for (var e = _.flatten([ this.zones.slice(0, i - 1), [ t ], this.zones[i - 1], this.zones.slice(i + 1, this.zones.length) ]), a = 0; a < e.length; a++) e[a] && (e[a].style || (e[a].style = {}), e[a].style.order = a, save_artifact(e[a])); this.discover_zones(); } }, sort_zone_down: function(t) { var i = this.zones.indexOf(t); if (!(i >= this.zones.length)) { for (var e = _.flatten([ this.zones.slice(0, i), this.zones[i + 1], [ t ], this.zones.slice(i + 2, this.zones.length) ]), a = 0; a < e.length; a++) e[a] && (e[a].style || (e[a].style = {}), e[a].style.order = a, save_artifact(e[a])); this.discover_zones(); } }, add_zone: function() { var t = 600, i = 600, e = this.find_place_for_item(t, i), a = { space_id: this.active_space._id, mime: "x-spacedeck/zone", description: "Zone " + (this.zones.length + 1), board: { x: e.x, y: e.y, w: t, h: i, z: 0 }, style: { valign: "middle", align: "center" } }; this.guest_nickname && (a.editor_name = this.guest_nickname), save_artifact(a, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t), this.select(null, t); }.bind(this)); }, add_shape: function(t, i) { var e = 200, a = 200; "cloud" == t && (e = 400); var s = this.cursor_point_to_space(i), o = { space_id: this.active_space._id, mime: "x-spacedeck/shape", description: "Text", board: { x: s.x, y: s.y, z: s.z, w: e, h: a }, style: { stroke_color: "#ffffff", text_color: "#ffffff", stroke: 0, fill_color: "#000000", shape: t, valign: "middle", align: "center" } }; this.guest_nickname && (o.editor_name = this.guest_nickname), save_artifact(o, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t), this.select(null, t); }.bind(this)); }, cursor_point_to_space: function(t) { if (!t) return { x: 0, y: 0 }; if (!$("#space").length) return { x: 0, y: 0 }; var i = $("#space")[0], e = parseInt($("#space").css("padding-top")), a = t.pageX, s = t.pageY; !("pageX" in t) && "originalEvent" in t && (a = t.originalEvent.pageX, s = t.originalEvent.pageY); var o = (a + i.scrollLeft - this.bounds_margin_horiz) / this.viewport_zoom, n = (s + i.scrollTop - e - this.bounds_margin_vert) / this.viewport_zoom; return { x: o, y: n }; }, space_point_to_window: function(t, i) { var e = 0, a = 0, s = $("#space")[0]; return e = t * this.viewport_zoom - s.scrollLeft + this.bounds_margin_horiz, a = i * this.viewport_zoom - s.scrollTop + this.bounds_margin_vert, { x: e, y: a }; }, create_artifact_via_upload: function(t, i, e) { if ("viewer" == this.active_space_role) return !1; this.hide_toolbar_artifacts(); var a = 300, s = 150, o = "transparent"; i.type.match("audio") && (a = 600, s = 150, o = "#ffffff"); var n = this.cursor_point_to_space(t); n.x -= a / 2, n.y -= s / 2, e && (n = this.find_place_for_item(a, s)); var _ = { space_id: this.active_space._id, mime: i.type, description: "Uploading…", state: "uploading", payload_thumbnail_medium_uri: null, payload_thumbnail_web_uri: null, board: { x: n.x, y: n.y, w: a, h: s, z: n.z }, style: { order: this.active_space_artifacts.length + 1, fill_color: o } }; this.update_board_artifact_viewmodel(_), this.guest_nickname && (_.editor_name = this.guest_nickname), save_artifact(_, function(t) { _ = t, this.update_board_artifact_viewmodel(_), this.active_space_artifacts.push(_), save_artifact_file(_, i, i.name, function(t) { console.log("file saved. result: ", t), _.payload_uri = t.payload_uri, _.payload_thumbnail_web_uri = t.payload_thumbnail_web_uri, _.payload_thumbnail_medium_uri = t.payload_thumbnail_medium_uri, _.payload_thumbnail_big_uri = t.payload_thumbnail_big_uri, _.payload_alternatives = t.payload_alternatives, _.mime = t.mime, _.board = t.board, _.state = t.state, this.update_board_artifact_viewmodel(_); }.bind(this), null, function(t) { var i = t.loaded / t.total; (i = 1) ? _.description = "Converting Media…" : _.description = "Upload " + parseInt(100 * i) + "%", this.update_board_artifact_viewmodel(_), _.view.progress = parseInt(100 * i); }.bind(this)); }.bind(this), this.display_saving_error); }, delete_selected_artifacts: function(t, i) { if (this.active_space) { t && (t.preventDefault(), t.stopPropagation()), this.begin_transaction(); var e = this.selected_artifacts().map(function(t) { return t._id; }), a = [], s = []; if (!(e.length > 1) || i || confirm("Delete " + e.length + " items?")) { for (var o = 0; o < e.length; o++) if (this.selected_artifacts_dict[e[o]]) { var n = e[o], _ = this.find_artifact_by_id(n); _ && (a.push(_), s.push(n), delete_artifact(_)); var r = this.active_space_artifacts.indexOf(_); this.active_space_artifacts.splice(r, 1); } this.push_to_undo({ action: "delete", artifact_ids: s, snapshot: a }), i || this.deselect(); } } }, find_artifact_by_id: function(t) { for (var i = this.active_space_artifacts, e = 0; e < i.length; e++) { var a = i[e]; if (a._id == t) return a; } return null; }, selected_artifacts: function(t) { return this.active_space && this.active_space_artifacts ? this.active_space_artifacts.filter(function(i) { var e = this.artifact_is_selected(i); return e && i.locked ? !t : e; }.bind(this)) : []; }, delayed_edit_artifact: function(t) { t.stopPropagation(), t.preventDefault(); var i = this.selected_artifacts()[0], e = $("#ios-focuser-" + i._id); e.focus(), e.select(), this.toggle_selected_artifact_editing(!0, !0); }, toggle_selected_artifact_editing: function(t, i) { var e = this.selected_artifacts()[0]; if (!e) return void (this.editing_artifact_id = null); if (this.editing_artifact_id == e._id && !t) return void (this.editing_artifact_id = null); if (!e.locked && _.include([ "text/html", "x-spacedeck/shape", "x-spacedeck/zone" ], e.mime) && this.editing_artifact_id != e._id) { this.editing_artifact_id = e._id; var a = 100; i && (a = 500), window.setTimeout(function() { var t = $("#artifact-" + e._id + " .text-editing"); t[0] ? focus_contenteditable(t[0], !0) : window.setTimeout(function() { var t = $("#artifact-" + e._id + " .text-editing"); focus_contenteditable(t[0], !0); }, a); }, a); } }, clear_formatting_walk: function(t, i, e, a) { if (t && t.style && ("preciseFontSize" == i ? t.style.fontSize = null : "letterSpacing" == i ? t.style.letterSpacing = null : "lineHeight" == i ? t.style.lineHeight = null : "fontName" == i ? t.style.fontFamily = null : "fontWeight" == i ? (t.style.fontWeight = null, t.style.fontStyle = null) : "bold" == i ? t.style.fontWeight = null : "italic" == i ? t.style.fontStyle = null : "underline" == i ? t.style.textDecoration = null : "strikeThrough" == i ? t.style.textDecoration = null : "forecolor" == i && (t.style.color = null)), t && t.childNodes) for (var s = 0; s < t.childNodes.length; s++) this.clear_formatting_walk(t.childNodes[s], i, e, a); }, apply_formatting: function(t, i, e, a) { if (t && (t.preventDefault(), t.stopPropagation()), !this.skip_formatting && ("createlink" != i || (e = prompt("Link URL?")))) { var s = this.selected_artifacts(), o = !1; if (window.selection && "Caret" != window.selection.type && "None" != window.selection.type || (o = !0), this.editing_artifact_id && "preciseFontSize" != i && "forecolor" != i) { if (this.editing_artifact_id) { var n = this.find_artifact_by_id(this.editing_artifact_id), _ = this.medium_for_object[n._id]; _ && n && (_.focus(), _.element.focus(), _.invokeElement(i), n.description = _.value(), this.queue_artifact_for_save(n)); } } else for (var r = 0; r < s.length; r++) { var n = s[r], c = $("
" + n.description + "
")[0], l = c.firstChild; do { if (l && l.childNodes) for (var h = 0; h < l.childNodes.length; h++) this.clear_formatting_walk(l.childNodes[h], i, e, a); l && l.style && ("preciseFontSize" == i ? e == this.default_style.font_size + "px" ? l.style.fontSize = null : l.style.fontSize = e : "letterSpacing" == i ? e == this.default_style.letter_spacing + "px" ? l.style.letterSpacing = null : l.style.letterSpacing = e : "lineHeight" == i ? e == this.default_style.line_height + "em" ? l.style.lineHeight = null : l.style.lineHeight = e : "fontName" == i ? l.style.fontFamily = e : "fontWeight" == i ? (l.style.fontWeight = e, l.style.fontStyle = a) : "bold" == i ? l.style.fontWeight = "bold" != l.style.fontWeight ? "bold" : "normal" : "italic" == i ? l.style.fontStyle = "italic" != l.style.fontStyle ? "italic" : "normal" : "underline" == i ? l.style.textDecoration = "underline" != l.style.textDecoration ? "underline" : "none" : "strikeThrough" == i ? l.style.textDecoration = "line-through" != l.style.textDecoration ? "line-through" : "none" : "forecolor" == i && (l.style.color = e)); } while (l && (l = l.nextSibling)); if (n.description != c.innerHTML && (n.description = c.innerHTML, this.update_board_artifact_viewmodel(n), this.queue_artifact_for_save(n), this.editing_artifact_id)) { var n = this.find_artifact_by_id(this.editing_artifact_id), _ = this.medium_for_object[n._id]; _ && n && _.value(n.description); } } this.extract_text_format_from_selection(); } }, remove_link_from_selected_artifacts: function() { this.update_selected_artifacts(function(t) { var i = t.meta || {}; return delete i.link_uri, { meta: i }; }); }, create_link_on_selected_artifacts: function() { var t = "", i = this.selected_artifacts(); i.length >= 1 && i[0].meta && i[0].meta.link_uri && (t = i[0].meta.link_uri); var e = prompt("URL:", t); this.update_selected_artifacts(function(t) { var i = t.meta || {}; i.link_uri = e; var a = { meta: i }; if (t.payload_uri && t.payload_uri.match("webgrabber")) { var s = encodeURIComponent(btoa(e)), o = ENV.apiEndpoint + "/api/webgrabber/" + s; a.payload_uri = o, a.payload_thumbnail_web_uri = o, a.payload_thumbnail_medium_uri = o, a.payload_thumbnail_big_uri = o; } return a; }), this.opened_dialog = "none"; }, clone_artifact: function(t, i, e, a) { var s = _.cloneDeep(t); return delete s.$index, delete s._id, i && (s.board.x += i), e && (s.board.y += e), s.style || (s.style = {}), s.style.order = this.active_space_artifacts.length + 1, this.guest_nickname && (s.editor_name = this.guest_nickname), s.space_id = this.active_space._id, save_artifact(s, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t), a ? a(t) : this.select(null, t); }.bind(this)), s; }, toggle_lock_of_selected_artifacts: function() { this.update_selected_artifacts(function(t) { return { locked: !t.locked }; }, !0); }, duplicate_selected_artifacts: function() { for (var t = this.selected_artifacts(), i = 0; i < t.length; i++) { var e = t[i]; this.clone_artifact(e, 50, 50); } }, copy_selected_artifacts_to_clipboard: function() { "ontouchstart" in window || ($("#space-clipboard").focus(), $("#space-clipboard").select()); }, handle_section_click: function(t) { t.target == t.currentTarget && this.deselect(); }, handle_space_doubleclick: function(t) { this.selected_artifacts().length || this.guest_nickname || this.active_space && "public" == this.active_space.access_mode; }, handle_body_click: function(t) { "space" == this.active_view && this.handle_section_click(t), this.close_dropdown(t); }, extract_text_format_from_selection: function() { if (window.selection) { var t = $(window.selection.baseNode).parents().toArray(); this.detected_text_formats = {}; for (var i = { p: "Paragraph", h1: "Headline 1", h2: "Headline 2", h3: "Headline 3", h4: "Headline 4", h5: "Headline 5", h6: "Headline 6", ul: "Bullet List", ol: "Numbered List", blockquote: "Blockquote" }, e = 0; e < t.length; e++) { var a = t[e]; if ("true" == a.contentEditable) break; var s = a.nodeName.toLowerCase(); i[s] && (this.detected_text_formats[s] = !0, this.active_text_format_name = i[s]); } } }, save_edited_artifact_text: function(t) { if (this.editing_artifact_id) { var i = this.find_artifact_by_id(this.editing_artifact_id); i && this.queue_artifact_for_save(i), this.extract_text_format_from_selection(); } }, handle_section_paste: function(t) { if (!this.editing_artifact_id) { var i = null; try { i = t.clipboardData.getData("text/plain"); } catch (e) {} i && (i.match(/<[a-zA-Z]+>/g) || (i = i.replace(/\n/g, "
")), this.insert_embedded_artifact(i)); } }, insert_embedded_artifact: function(t) { var i = this.active_space; if (i) { if ("[" == t[0] || "{" == t[0]) try { parsed = JSON.parse(t), "{" == t[0] && (parsed = [ parsed ]), this.deselect(); for (var e = 0; e < parsed.length; e++) if (parsed[e].mime) { var a = this.highest_z() + 1; if (1 == parsed.length) { var s = parsed[e].board.w, o = parsed[e].board.h, n = this.find_place_for_item(s, o); parsed[e].board.x = n.x, parsed[e].board.y = n.y, parsed[e].board.z = n.z; } else parsed[e].board.x = parsed[e].board.x + 50, parsed[e].board.y = parsed[e].board.y + 50, parsed[e].board.y = parsed[e].board.z + a; this.clone_artifact(parsed[e], 0, 0, function(t) { this.multi_select([ t ]); }.bind(this)); } return; } catch (_) {} if (t.match(/^http[s]*\:\/\//)) return void this.create_artifact_via_embed_url(t); var r = { mime: "text/html", description: t.replace("\n", "
"), title: "", space_id: i._id }, s = 400, o = 300, n = this.find_place_for_item(s, o); r.board = { x: n.x, y: n.y, w: s, h: o, z: n.z }, this.guest_nickname && (r.editor_name = this.guest_nickname), save_artifact(r, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t); }.bind(this)); } }, create_artifact_via_embed_url: function(t) { this.close_modal(); var i = this.find_place_for_item(200, 200), e = this.highest_z() + 1, a = { space_id: this.active_space._id, mime: "image/png", description: t, state: "uploading", board: { x: i.x, y: i.y, w: 200, h: 200, z: e }, style: { order: this.active_space_artifacts.length } }, s = parse_link(t); if (s) { if ("unknown" == s.type) { var o = encodeURIComponent(btoa(t)); return a.meta = { link_uri: t }, this.guest_nickname && (a.editor_name = this.guest_nickname), void save_artifact(a, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t); var i = ENV.apiEndpoint + "/api/webgrabber/" + o; t.state = "idle", t.payload_uri = i, t.payload_thumbnail_web_uri = i, t.payload_thumbnail_medium_uri = i, t.payload_thumbnail_big_uri = i, save_artifact(t, function(i) { this.update_board_artifact_viewmodel(t); }.bind(this)); }.bind(this)); } var n = s.thumbnail_width || 200, r = s.thumbnail_height || 200; n < 200 && (n = 200), r < 200 && (r = 200), "soundcloud" == s.provider_name && (n = 500, r = 150), a = _.extend(a, { mime: "oembed/" + s.type + "-" + s.provider_name, description: s.url || t, payload_thumbnail_medium_uri: s.thumbnail_url, payload_thumbnail_web_uri: s.thumbnail_url, state: "idle", meta: { title: s.title, link_uri: s.url || t }, board: { x: i.x - n / 2, y: i.y - r / 2, w: n, h: r } }), this.guest_nickname && (a.editor_name = this.guest_nickname), save_artifact(a, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t); }.bind(this)); } }, create_artifact_via_payload_url: function(t, i) { this.add_artifact(this.active_space, t, i, null); }, handle_touch_select_background_image: function() { $("#background-uploader").click(); }, handle_insert_image_url: function(t) { return t && t.length ? (this.create_artifact_via_payload_url("image", t), void (this.insert_image_url = "")) : void $("#image_file_upload").click(); }, handle_insert_video_url: function(t) { if (!t.length) return void $("#video_file_upload").click(); var i = parse_link(t); i ? this.create_artifact_via_embed_url(t) : this.create_artifact_via_payload_url("video", t), this.insert_video_url = ""; }, handle_insert_audio_url: function(t) { if (!t.length) return void $("#audio_file_upload").click(); var i = parse_link(t); i ? this.create_artifact_via_embed_url(t) : this.create_artifact_via_payload_url("audio", t), this.insert_audio_url = ""; }, handle_generic_file_upload: function(t) { var i = t.target.files; if (this.opened_dialog = "none", i && i.length) { console.log("file: ", i[0]); for (var e = 0; e < i.length; e++) { var a = i[e]; if ("application/pdf" === a.type) { var s = { x: 100, y: 100 }; this.dropped_point = s, this.pending_pdf_file = a, this.activate_modal("pdfoptions"); } else this.create_artifact_via_upload(null, a, !0); } } }, handle_image_file_upload: function(t) { this.handle_generic_file_upload(t); }, handle_video_file_upload: function(t) { this.handle_generic_file_upload(t); }, handle_audio_file_upload: function(t) { this.handle_generic_file_upload(t); }, handle_section_background_upload: function(t) { var i = t.target.files[0]; this.space_background_uploading = !0, save_space_background_file(this.active_space, i, function(t) { this.active_space = t, this.space_background_uploading = !1; }.bind(this)); }, remove_section_background: function() { this.active_space.advanced.background_uri = null, save_space(this.active_space); }, show_toolbar_props: function() { if (0 != this.selection_metrics.count) { arts = this.selected_artifacts(); for (var t = 0; t < arts.length; t++) if ("x-spacedeck/zone" == arts[t].mime) return; this.toolbar_props_in = !0; } }, hide_toolbar_props: function() { this.toolbar_props_in = !1; }, show_toolbar_artifacts: function(t, i) { this.toolbar_artifacts_x = t - 175 + "px", this.toolbar_artifacts_y = i + "px", this.toolbar_artifacts_in = !0; }, hide_toolbar_artifacts: function() { this.toolbar_artifacts_in = !1; }, start_adding_artifact: function(t) { return t = fixup_touches(t), this.toolbar_artifacts_in ? void this.hide_toolbar_artifacts() : void this.show_toolbar_artifacts(t.pageX, t.pageY); }, start_drawing_scribble: function(t) { this.hide_toolbar_artifacts(), this.active_tool = "scribble", this.opened_dialog = "none"; }, start_drawing_arrow: function(t) { this.hide_toolbar_artifacts(), this.active_tool = "arrow", this.opened_dialog = "none"; }, start_drawing_line: function(t) { this.hide_toolbar_artifacts(), this.active_tool = "line", this.opened_dialog = "none"; }, adjust_bounds_zoom: function() { if (this.active_space) { this.bounds_zoom = this.viewport_zoom; var t = this.active_space.advanced.width * this.viewport_zoom, i = this.active_space.advanced.height * this.viewport_zoom; window.innerWidth > t ? this.bounds_margin_horiz = (window.innerWidth - t) / 2 : this.bounds_margin_horiz = 0, window.innerHeight - 80 > i ? this.bounds_margin_vert = (window.innerHeight - i) / 2 - 80 : this.bounds_margin_vert = 0; } }, zoom_to_original: function() { var t = this.viewport_zoom; this.viewport_zoom = 1, this.viewport_zoom_percent = parseInt(100 * this.viewport_zoom), this.adjust_bounds_zoom(), this.zoom_adjust_scroll(this.viewport_zoom / t); }, zoom_to_fit: function() { var t = this.enclosing_rect(this.active_space_artifacts); if (t) { var i = 200; t.x1 -= i, t.y1 -= i - 100, t.x2 += i, t.y2 += i + 100, this.zoom_to_rect(t, 1); } }, zoom_to_zone: function(t) { if ($("#space").length) { var i = this.enclosing_rect([ t ]), e = $("#space")[0], a = { x1: e.scrollLeft / this.viewport_zoom, y1: e.scrollTop / this.viewport_zoom, x2: (e.scrollLeft + window.innerWidth) / this.viewport_zoom, y2: (e.scrollTop + window.innerHeight) / this.viewport_zoom }, s = 10; i.x1 -= s, i.y1 -= s, i.x2 += s, i.y2 += s, this.animation_running || (this.animation_running = !0, this.animate_zoom_to_rect(i, 200, a), this.current_zone_idx = this.zones.indexOf(t)); } }, zoom_to_rect: function(t, i) { if ($("#space").length) { var e = $("#space")[0], a = t.x2 - t.x1, s = t.y2 - t.y1; if (a > s ? (this.viewport_zoom = window.innerWidth / a, window.innerHeight < s * this.viewport_zoom && (this.viewport_zoom = window.innerHeight / s)) : (this.viewport_zoom = window.innerHeight / s, window.innerWidth < a * this.viewport_zoom && (this.viewport_zoom = window.innerWidth / a)), i && this.viewport_zoom > i && (this.viewport_zoom = i), this.viewport_zoom < .05 && (this.viewport_zoom = .05), this.viewport_zoom_percent = parseInt(100 * this.viewport_zoom), this.adjust_bounds_zoom(), e) { var o = function() { e.scrollTop = (t.y1 + s / 2) * this.viewport_zoom - window.innerHeight / 2, e.scrollLeft = (t.x1 + a / 2) * this.viewport_zoom - window.innerWidth / 2, this.handle_scroll(); }.bind(this); "requestAnimationFrame" in window ? window.requestAnimationFrame(o) : o(); } } }, animate_zoom_to_rect: function(t, i, e, a) { if ($("#space").length) { var s = ($("#space")[0], 20); if (a || (a = 0), i > a) { window.setTimeout(function() { this.animate_zoom_to_rect(t, i, e, a + s); }.bind(this), s); var o = (t.x1 - e.x1) / i * a, n = (t.x2 - e.x2) / i * a, _ = (t.y1 - e.y1) / i * a, r = (t.y2 - e.y2) / i * a, c = { x1: e.x1 + o, x2: e.x2 + n, y1: e.y1 + _, y2: e.y2 + r }; this.zoom_to_rect(c); } else this.zoom_to_rect(t), this.animation_running = !1; } }, zoom_to_point: function(t, i) { var e = $("#space")[0], a = e.scrollLeft / this.viewport_zoom, s = e.scrollTop / this.viewport_zoom, o = window.innerWidth / this.viewport_zoom, n = window.innerHeight / this.viewport_zoom, _ = (t.x - (a + o / 2)) * i, r = (t.y - (s + n / 2)) * i, c = -_, l = -r, h = { x1: t.x - o / 2 * i + c, y1: t.y - n / 2 * i + l, x2: t.x + o / 2 * i + c, y2: t.y + n / 2 * i + l }; this.zoom_to_rect(h, 2); }, throttled_zoom_to_point: _.throttle(function(t, i) { this.zoom_to_point(t, i); }, 50), zoom_to_cursor: function(t, i) { var e = this.cursor_point_to_space(t); this.throttled_zoom_to_point.bind(this)(e, i); }, zoom_adjust_scroll: function(t) { var i = function() { if ($("#space").length && this.active_space && this.active_space_loaded) { var i = $("#space")[0], e = this.active_space.advanced.width * this.viewport_zoom, a = this.active_space.advanced.height * this.viewport_zoom, s = i.scrollLeft, o = i.scrollTop, n = window.innerWidth / 2, _ = window.innerHeight / 2, r = t * (s + n) - n, c = t * (o + _) - _; e < window.innerWidth && (r = 0), a < window.innerHeight && (c = 0), i.scrollLeft = r, i.scrollTop = c, this.handle_scroll(); } }; "requestAnimationFrame" in window ? window.requestAnimationFrame(i.bind(this)) : i(); }, zoom_in: function() { this.viewport_zoom || (this.viewport_zoom = 1); var t = this.viewport_zoom; this.viewport_zoom *= 1.5, this.viewport_zoom >= 2 && (this.viewport_zoom = 2), this.viewport_zoom_percent = parseInt(100 * this.viewport_zoom), this.adjust_bounds_zoom(), this.zoom_adjust_scroll(this.viewport_zoom / t); }, zoom_out: function() { this.viewport_zoom || (this.viewport_zoom = 1); var t = this.viewport_zoom; this.viewport_zoom /= 1.5, this.viewport_zoom < .05 && (this.viewport_zoom = .05), this.viewport_zoom_percent = parseInt(100 * this.viewport_zoom), this.adjust_bounds_zoom(), this.zoom_adjust_scroll(this.viewport_zoom / t); }, activate_pan_tool: function(t) { t && (t.stopPropagation(), t.preventDefault()), this.active_tool = "pan", this.stop_pan_timeout && window.clearTimeout(this.stop_pan_timeout), this.stop_pan_timeout = window.setTimeout(function() { "pan" == this.active_tool && (this.active_tool = "pointer"); }.bind(this), 500); }, approve_pdf_upload: function(t, i, e) { this.close_modal(), "classic" == e && this.create_artifact_via_upload(t, this.pending_pdf_file, !1), "grid" == e && (this.global_spinner = !0, save_pdf_file(this.active_space, this.dropped_point, this.pending_pdf_file, i, function(t) { this.global_spinner = !1, _.each(t, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t); }.bind(this)); }.bind(this), function(t) { this.global_spinner = !1, alert("Error PDF (" + t.status + ")"); }.bind(this))); }, handle_data_drop: function(t) { if ("viewer" == this.active_space_role) return !1; var i = t.dataTransfer.getData("application/json"), e = (this.active_space, t.dataTransfer.files); if (e && e.length) for (var a = 0; a < e.length; a++) { var s = e[a]; if ("application/pdf" === s.type) { var o = this.cursor_point_to_space(t); this.dropped_point = o, this.pending_pdf_file = s, this.activate_modal("pdfoptions"); } else this.create_artifact_via_upload(t, s, e.length > 1); } else { var i = t.dataTransfer.getData("application/json"); if (i) { var n = JSON.parse(i); delete n._id, n.space_id = this.active_space._id; var _ = 300, r = 200; n.board && n.board.w && n.board.h && (_ = n.board.w, r = n.board.h); var o = this.cursor_point_to_space(t); return o.x -= _ / 2, o.y -= r / 2, n.board = { x: o.x, y: o.y, w: _, h: r, z: 20 }, this.guest_nickname && (n.editor_name = this.guest_nickname), void save_artifact(n, function(t) { this.update_board_artifact_viewmodel(t), this.active_space_artifacts.push(t); }.bind(this)); } var c = t.dataTransfer.getData("text/html"); if (c) { var l = /src="([^"]+)"/g, h = l.exec(c); h && this.add_artifact(this.active_space, "image", h[1], t); } } }, clear_search_results: function() { this.image_search_results = [], this.audio_search_results = [], this.video_search_results = []; }, download_selected_artifacts: function() { var t = this.selected_artifacts(); if (1 == t.length && t[0].payload_uri) try { window.open(t[0].payload_uri); } catch (i) {} } } }; var SpacedeckSpaces = { data: { active_space: { advanced: {} }, active_space_loaded: !1, active_space_role: "viewer", active_space_version_dirty: !0, active_space_messages: [], active_space_memberships: [], active_folder_history_items: [], active_space_users: [], active_space_artifacts: [], active_space_path: [], access_settings_space: null, access_settings_memberships: [], duplicate_folders: [], duplicate_folder_id: "", pending_pdf_files: [], meta_visible: !1, meta_unseen: 0, present_mode: !1, space_editing_title: !1, create_space_title: "", folder_reverse: 1, embedded: !1, remix_cta: "Create Reply", publish_cta: "Publish", remix_copying: !0, remix_style: "", guest_signup_enabled: !1, space_embed_html: "", share_base: location.origin, share_base_url: location.origin + "/spaces/", share_base_url_enc: encodeURIComponent(location.origin + "/spaces/"), social_bar: !0, can_add_comment: !1, space_info_section: "access", editors_section: "list", selected_member: null, invite_member_role: "viewer", invite_email_error: null, invite_email: "", invite_message: "", active_join_link: "", join_link_role: "viewer", mouse_state: "idle", active_folder: null, folder_sorting: "updated_at", folder_spaces_filter: null, active_path_length: 0, space_comment: "", folder_spaces_search: "", medium_for_object: {} }, methods: { search_spaces: function() { var e = this.folder_spaces_search; console.log("search query: ", e), load_spaces_search(e, function(e) { console.log("results: ", e), this.active_profile_spaces = e; }.bind(this)); }, guest_logout: function() { "localStorage" in window && localStorage && delete localStorage.guest_nickname, this.guest_nickname = "", location.reload(); }, ask_guestname: function(e, i) { console.log("ask_guestname"); var t = "Spacedeck"; subdomainTeam && (t = subdomainTeam.name), smoke.prompt(__("what_is_your_name", t), function(t) { if (t && 0 !== t.length) { if (this.guest_nickname = t, "localStorage" in window && localStorage) try { localStorage.guest_nickname = this.guest_nickname; } catch (s) { console.error(s); } i && i(); } else this.ask_guestname(e, i); }.bind(this), { value: e || "Guest " + parseInt(1e4 * Math.random()), ok: __("ok"), cancel: __("cancel") }); }, load_space: function(e, i, t) { console.log("load space: ", e), this.folder_spaces_filter = "", this.folder_spaces_search = "", space_auth = get_query_param("spaceAuth"); var s = function() { if (get_query_param("embedded") && (this.embedded = !0, this.guest_signup_enabled = !0, get_query_param("publish_cta") && (this.publish_cta = get_query_param("publish_cta")), get_query_param("nosocial") && (this.social_bar = !1)), get_query_param("confirm") && this.logged_in) { var s = get_query_param("confirm"); return void confirm_user(this.user, s, function() { this.redirect_to("/spaces/" + e + "?show_access=1"); }.bind(this), function() { alert("An error occured confirming your email with the given token."); }); } this.close_dropdown(), this.active_space_loaded = !1, this.viewport_zoom = 1, this.viewport_zoom_percent = 100, this.loading_space_id = e, this.present_mode = !1, this.active_space_is_readonly = !0, this.opened_dialog = "none", this.open_space_dialog = "none", this.selected_artifacts_dict = {}, this.update_selection_metrics(), this.can_add_comment = !1; var a = !1; this.user && (a = e == this.user.home_folder_id), document.title = "Loading… | Spacedeck", load_space(e, function(t, s) { if (document.title = t.name, this.active_space_role = s || "viewer", this.space_embed_html = '', a || load_members(t, function(e) { this.active_space_memberships = e; }.bind(this)), console.log("[websocket] auth start"), "folder" == t.space_type) { if (this.active_space = { advanced: {} }, document.title = "Spacedeck", load_spaces(e, a, function(e) { t.children = e, this.loading_space_id = null, this.active_profile_spaces = t.children, this.active_folder = t, this.access_settings_space = t, this.auth_websocket(this.active_folder), this.load_space_path(this.active_folder), a && (this.root_folder = t), load_history(t, function(e) { if (console.log("loaded digest", e), this.active_folder_history_items = e, this.meta_unseen = 0, "localStorage" in window && localStorage) var i = parseInt(localStorage[this.meta_last_seen_key()], 10); else var i = 0; for (var t = 0; t < e.length; t++) { var s = e[t], a = new Date(s.last_action).getTime(), n = !1; 1 == s.users.length && "you" == s.users[0] && (n = !0), a > i && !n && this.meta_unseen++; } }.bind(this)), this.active_view = "folders"; }.bind(this)), "localStorage" in window) { var n = "folder_sorting_" + e, o = "folder_reverse_" + e; localStorage[n] && localStorage[o] && (this.folder_sorting = localStorage[n], this.folder_reverse = parseInt(localStorage[o]), console.log("loaded folder sorting: ", this.folder_sorting, this.folder_reverse)); } "opened_at" == this.folder_sorting && (this.folder_sorting = "name"); } else "space" == t.space_type && (this.artifacts = [], this.loading_space_id = null, document.title = t.name, (space_auth || this.logged_in) && (this.can_add_comment = !0), this.setup_watches(), load_artifacts(t._id, function(e) { e || (e = []); for (var s = 0; s < e.length; s++) this.update_board_artifact_viewmodel(e[s]); this.active_space_artifacts = e, this.$set("active_space", t), this.active_space = t, this.auth_websocket(this.active_space), this.active_view = "space", this.fixup_space_size(), t._id != this.active_space._id ? (this.present_mode = !0, this.active_space_is_readonly = !0) : this.active_space_is_readonly = !1, this.discover_zones(), window.setTimeout(function() { this.zoom_to_fit(); }.bind(this), 10), i && i(), this.active_space_loaded = !0, this.extract_properties_from_selection(), load_comments(t._id, function(e) { e || (e = []), this.active_space_messages = e, this.refresh_space_comments(); }.bind(this), function(e) { console.error(e); }); }.bind(this)), "editor" != this.active_space_role && "admin" != this.active_space_role || (this.present_mode = !1, this.active_space_is_readonly = !1), this.active_join_link = "", this.join_link_role = "viewer", "admin" == this.active_space_role ? this.space_info_section = "access" : "editor" == this.active_space_role || (this.space_info_section = "info")); }.bind(this), function(i) { return t ? t(i) : void (403 == i.status ? this.logged_in ? this.redirect_to("/") : this.redirect_to("/login?space_id=" + e) : (this.redirect_to("/not_found"), console.error(i))); }.bind(this)); }.bind(this), a = ""; "localStorage" in window && localStorage && localStorage.guest_nickname && (this.guest_nickname = localStorage.guest_nickname, a = this.guest_nickname, s()), space_auth ? this.guest_nickname ? s() : this.ask_guestname(a, function() { s(); }) : (this.guest_nickname = "", s()); }, refresh_space_comments: function() { this.meta_unseen = 0; var e = this.active_space_messages, i = 0; "localStorage" in window && localStorage && (i = parseInt(localStorage[this.meta_last_seen_key()], 10)); for (var t = 0; t < e.length; t++) { var s = e[t], a = new Date(s.updated_at).getTime(), n = !1; this.user && this.user._id != s.user_id && !s.editor_name && (n = !0), a > i && !n && this.meta_unseen++; } }, go_to_next_space: function() { var e = this.active_folder.children.map(function(e) { return e._id; }), i = e.indexOf(this.active_space._id); console.log("index: ", i); for (var t = i, s = !1; !s; ) { var a = this.active_folder.children[(i + 1) % e.length]; "folder" == a.space_type ? (s = !1, i++) : s = !0, t == i && (s = !0); } this.load_space(a._id); }, go_to_previous_space: function() { var e = this.active_folder.children.map(function(e) { return e._id; }), i = e.indexOf(this.active_space._id); console.log("index: ", i); for (var t = i, s = !1; !s; ) { var i = (i < 1 ? e.length : i) - 1, a = this.active_folder.children[i]; "folder" == a.space_type ? (s = !1, i--) : s = !0, t == i && (s = !0); } this.load_space(a._id); }, filtered_folder_children: function(e) { var e = e || "space"; return _.filter(this.active_folder.children, function(i) { return i.space_type == e; }); }, load_space_path: function(e) { return e ? void load_space_path(e._id, function(e) { this.active_space_path = e; }.bind(this), function() { console.log("could not load folder path"); }) : []; }, is_active_space_role: function(e) { return !!this.active_space && this.active_space_role == e; }, create_space: function(e) { if (this.active_folder) { this.close_modal(), this.folder_spaces_filter = "", this.active_folder.children || (this.active_folder.children = []), e || (e = "space"); var i = { name: "space" == e ? __("untitled_space") : __("untitled_folder"), artifacts: [], space_type: e, parent_space_id: this.active_folder._id }; this.create_space_title.length && (i.name = this.create_space_title), save_space(i, function(i) { this.active_folder.children.push(i), "folder" != e ? this.redirect_to("/" + i.space_type + "s/" + i._id, function(e) {}) : this.rename_folder(i); }.bind(this), function(e) { alert("Error: Could not create Space (" + e.status + ")."); }.bind(this)); } }, save_space: function(e) { save_space(e); }, create_space_version: function() { if (!this.is_pro(this.user)) return void smoke.confirm(__("spacedeck_pro_ad_versions"), function(e) { e && this.show_upgrade_modal(); }.bind(this)); this.version_saving = !0, this.present_mode = !1; var e = this.active_space.draft_space; console.log("create_space_version:", e), duplicate_space(e, null, function(e) { load_spaces(this.active_space._id, !1, function(e) { this.version_saving = !1, this.activate_space_version(e, e.draft_space), alert("Version saved."); }.bind(this)); }.bind(this), function(e) { console.error(e); }.bind(this)); }, finalize_folder_profile_edit: function() { save_space(this.active_folder, function(e) { this.close_modal(); }.bind(this)); }, finalize_space_profile_edit: function() { save_space(this.active_space, function(e) { this.close_modal(); }.bind(this)); }, delete_space: function(e) { smoke.confirm("Really delete " + e.name + "?", function(i) { if (i) { var t = this.active_folder.children.indexOf(e); delete_space(e, function() { e.parent_space_id ? this.redirect_to("/folders/" + e.parent_space_id, function(e) {}) : this.redirect_to("/spaces", function(e) {}), this.close_modal(), this.active_folder.children.splice(t, 1); }.bind(this)); } }.bind(this)); }, duplicate_space: function(e) { duplicate_space(e, null, function(e) { this.active_folder.children.push(e); }.bind(this), function(e) { console.error(e); }.bind(this)); }, remove_avatar: function(e) { remove_avatar_file("space", e, function(e) { this.active_space = e; }.bind(this)); }, rename_space: function(e) { return this.close_dropdown(), "folder" == e.space_type ? this.rename_folder(e) : void smoke.prompt(__("new_space_title"), function(i) { i && i.length && (e.name = i, save_space(e)); }.bind(this), { value: e.name }); }, rename_folder: function(e) { this.close_dropdown(), smoke.prompt(__("new_folder_title"), function(i) { i && i.length && (e.name = i, save_space(e)); }.bind(this), { value: e.name }); }, edit_space_title: function() { this.close_dropdown(), "editor" != this.active_space_role && "admin" != this.active_space_role || (this.space_editing_title = !0, $("#space-title").focus()); }, save_space_title: function(e) { this.active_space.name = e, save_space(this.active_space, function() { this.space_editing_title = !1; }.bind(this)); }, save_space_keydown: function(e) { if (e) { if (13 != e.keyCode) return void (this.space_editing_title = !0); e.preventDefault(), e.stopPropagation(), e.target.blur(); } save_space(this.active_space, function(e) { this.active_space.edit_slug = e.edit_slug, this.space_editing_title = !1; }.bind(this)); }, save_space_description: function(e) { e.preventDefault(), e.stopPropagation(); var i = e.target.innerText; e.target.blur(), this.active_space.description = i, save_space(this.active_space); }, save_space_domain: function(e) { e.preventDefault(), e.stopPropagation(); var i = e.target.innerText; e.target.blur(), this.active_space.domain = i, save_space(this.active_space); }, download_space: function() { smoke.quiz(__("download_space"), function(e, i) { "PDF" == e ? this.download_space_as_pdf(this.active_space) : "ZIP" == e ? this.download_space_as_zip(this.active_space) : "TXT" == e && this.download_space_as_list(this.active_space); }.bind(this), { button_1: "PDF", button_2: "ZIP", button_3: "TXT", button_cancel: __("cancel") }); }, download_space_as_png: function(e) { window.open(ENV.apiEndpoint + "/api/spaces/" + e._id + "/png"); }, download_space_as_pdf: function(e) { this.global_spinner = !0, get_resource("/spaces/" + e._id + "/pdf", function(e) { this.global_spinner = !1, location.href = e.url; }.bind(this), function(e) { this.global_spinner = !1, alert("PDF export problem (" + e.status + ")."); }.bind(this)); }, download_space_as_zip: function(e) { this.global_spinner = !0, get_resource("/spaces/" + e._id + "/zip", function(e) { this.global_spinner = !1, location.href = e.url; }.bind(this), function(e) { this.global_spinner = !1, alert("ZIP export problem (" + e.status + ")."); }.bind(this)); }, download_space_as_list: function(e) { this.global_spinner = !0, location.href = "/api/spaces/" + e._id + "/list"; }, duplicate_space_into_folder: function() { load_writable_folders(function(e) { this.duplicate_folders = _.sortBy(e, function(e) { return e.name; }); }.bind(this), function(e) { console.error(e); }); }, duplicate_folder_confirm: function() { var e = this.duplicate_folder_id, i = _.findIndex(this.duplicate_folders, function(i) { return i._id == e; }); i < 0 && (i = 0); var t = this.duplicate_folders[i]; console.log("df f", t), t && duplicate_space(this.active_space, t._id, function(e) { this.duplicate_folders = [], this.duplicate_folder = null, smoke.quiz(__("duplicate_success", this.active_space.name, t.name), function(i, s) { i == __("goto_space", e.name) ? this.redirect_to("/spaces/" + e._id) : i == __("goto_folder", t.name) && this.redirect_to("/folders/" + t._id); }.bind(this), { button_1: __("goto_space", e.name), button_2: __("goto_folder", t.name), button_cancel: __("stay_here") }); }.bind(this), function(e) { console.error(e), smoke.prompt("error: " + e.statusText); }.bind(this)); }, toggle_follow_mode: function() { this.deselect(), this.follow_mode = !this.follow_mode; }, toggle_present_mode: function() { this.deselect(), this.present_mode = !this.present_mode, this.present_mode; }, meta_last_seen_key: function() { var e = "meta-seen-"; if ("space" == this.active_view) { if (!this.active_space) return "invalid"; e += this.active_space._id; } else if ("folders" == this.active_view) { if (!this.active_folder) return "invalid"; e += this.active_folder._id; } return e; }, toggle_meta: function() { if (this.meta_visible = !this.meta_visible, this.meta_visible) { var e = this.meta_last_seen_key(); "localStorage" in window && localStorage && (localStorage[e] = new Date().getTime(), console.log("seen_key: ", e, localStorage[e]), this.meta_last_seen = localStorage[e]), this.meta_unseen = 0; } }, toggle_space_access_mode: function() { this.access_settings_space.access_mode = "public" == this.access_settings_space.access_mode ? "private" : "public", save_space(this.access_settings_space); }, save_space_access_mode: function(e) { this.access_settings_space.access_mode = e.currentTarget.value, save_space(this.access_settings_space); }, save_space_editors_locking: function(e) { this.access_settings_space.editors_locking = e.currentTarget.checked, save_space(this.access_settings_space); }, create_join_link: function() { create_join_link(this.active_space._id, this.join_link_role, function(e) { this.active_join_link = "https://" + location.host + "/invitations/" + e.code + "/accept"; }.bind(this)); }, delete_join_link: function() { get_join_link(this.active_space._id, function(e) { e && e.length && delete_join_link(e[e.length - 1]._id, function() { this.active_join_link = ""; }.bind(this)); }.bind(this)); }, invite_member: function(e, i, t, s) { this.invite_email_error = null; var a = i.split(","), n = !1; _.each(a, function(i) { if (i = i.trim(), !validateEmail(i)) return void (this.invite_email_error = "Please enter a valid address."); var a = { email_invited: i, personal_message: t, role: s }; create_membership(e, a, function(e) { this.access_settings_memberships.push(e), console.log("membership created:", e), this.editors_section = "list", n || (n = !0, smoke.alert("Invitation(s) sent."), this.invite_email = "", this.invite_message = ""); }.bind(this), function(e) { text = JSON.stringify(e.responseText), smoke.alert("Error: " + text); }.bind(this)); }.bind(this)); }, update_member: function(e, i, t) { i.role = t, save_membership(e, i, function() { console.log("saved"); }.bind(this), function(e) { console.error(e); }.bind(this)); }, remove_member: function(e, i) { delete_membership(e, i, function() { this.access_settings_memberships.splice(this.access_settings_memberships.indexOf(i), 1); }.bind(this), function(e) { console.error(e); }.bind(this)); }, history_back: function() { window.history.back(); }, create_space_comment: function(e) { if (e.length) { var i = { space: this.active_space._id, message: e, editor_name: this.guest_nickname, user: this.user }; save_comment(this.active_space._id, i, function(e) { console.log("comment saved: ", e.created_at), this.active_space_messages.push(e), this.space_comment = ""; }.bind(this), function(e) { console.error(e); }.bind(this)); } }, remove_space_comment: function(e) { delete_comment(this.active_space._id, e._id, function() { console.log("comment id:", e._id), this.active_space_messages = _.filter(this.active_space_messages, function(i) { return i._id != e._id; }); }.bind(this), function(e) { console.error(e); }.bind(this)); }, emojified_comment: function(e) { return twemoji.parse(e); }, set_folder_sorting: function(e, i) { this.folder_sorting = e, this.folder_reverse = i ? -1 : 1, console.log(e, i), "localStorage" in window && (localStorage["folder_sorting_" + this.active_folder._id] = this.folder_sorting, localStorage["folder_reverse_" + this.active_folder._id] = this.folder_reverse); }, activate_space_info_section: function(e) { this.space_info_section = e, this.editors_section = "list", "versions" == e && load_spaces(this.active_space._id, null, function(e) { this.active_space.children = e.children, console.log("loaded: ", e); }.bind(this)); }, handle_folder_drop: function(e, i) { try { var t = JSON.parse(e.dataTransfer.getData("application/json")); } catch (s) { return; } if (t && t._id && t.parent_space_id && i._id && t._id != i._id) { if ("folder" != i.space_type) return void alert("Spaces can only be moved into folders."); t.parent_space_id = i._id, save_space(t, function() { var e = _.findIndex(this.active_folder.children, function(e) { return e._id == t._id; }); e >= 0 && (this.active_folder.children.splice(e, 1), console.log("spliced: ", e)); }.bind(this)); } }, activate_access: function() { if (this.activate_modal("access"), this.active_space._id) this.access_settings_space = this.active_space; else { if (!this.active_folder || !this.active_folder._id) return; this.access_settings_space = this.active_folder; } this.access_settings_memberships = this.active_space_memberships; }, close_access: function() { this.close_modal(); }, show_offline_help: function() { smoke.confirm(__("was_offline"), function(e) { e && location.reload(); }); } } }; var SpacedeckTeams = { data: { team_members: [], team_loading: !1, team_logo: "", team_emails: "", team_email_invited: !1, team_plan_calculation: "" }, methods: { is_admin: function(e) { return _.filter(e.team.admins, function(t) { return t == e._id; }).length > 0; }, calculate_team: function() { this.team_plan_calculation = ""; }, load_team: function() { this.user.team && load_resource("GET", "/teams/" + this.user.team._id + "/memberships", null, function(e) { this.team_members = e, this.calculate_team(); }.bind(this), function(e, t, i) { console.log(e, t, i); }); }, team_save: function() { load_resource("PUT", "/teams/" + this.user.team._id, this.user.team, function(e, t) { alert("Team updated."); }.bind(this), function(e) { console.error(e), alert("Could not update Team."); }); }, team_update_member: function(e) { load_resource("PUT", "/teams/" + this.user.team._id + "/memberships/" + e._id, e, function(e, t) { console.log("members updated"); }.bind(this), function(e) { console.error(e); }); }, team_invite_members: function(e) { var t = e.split(","); for (_i = 0, _len = t.length; _i < _len; _i++) if (email = t[_i], email = email.replace(new RegExp(" ", "g"), "").toLowerCase(), validateEmail(email)) { var i = { email: email }; load_resource("POST", "/teams/" + this.user.team._id + "/memberships", i, function(e, t) { this.team_email_invited = !0, this.team_members.push(e); window.setTimeout(function() { this.team_email_invited = !1; }.bind(this), 1e3); this.team_emails = ""; }.bind(this), function(e, t, i) { console.log(e, t, i), this.team_invite_error = JSON.parse(e.responseText).error; }.bind(this)); } }, team_promote_member: function(e) { load_resource("GET", "/teams/" + this.user.team._id + "/memberships/" + e._id + "/promote", null, function(e, t) { this.load_user(function() { this.load_team(); }.bind(this)); }.bind(this), function(e) { console.error(e); }); }, team_demote_member: function(e) { load_resource("GET", "/teams/" + this.user.team._id + "/memberships/" + e._id + "/demote", null, function(e, t) { this.load_user(function() { this.load_team(); }.bind(this)); }.bind(this), function(e) { console.error(e); }); }, team_remove_member: function(e) { confirm("Really delete this member?") && (e.user_id && "active" === e.state ? load_resource("DELETE", "/users/" + e._id, null, function(t, i) { var s = this.team_members.indexOf(e); this.team_members.splice(s, 1); }.bind(this), function(e) { console.error(e); }) : load_resource("DELETE", "/teams/" + this.user.team._id + "/memberships/" + e._id, null, function(t, i) { var s = this.team_members.indexOf(e); this.team_members.splice(s, 1); }.bind(this), function(e) { console.error(e); })); } } }; var SpacedeckBoardArtifacts = { update_board_artifact_viewmodel: function(t) { var e = this.artifact_major_type(t); if (t.view = { _id: t._id, classes: this.artifact_classes(t), style: this.artifact_style(t), grid_style: this.artifact_style(t, !0), inner_style: this.artifact_inner_style(t), text_cell_style: this.artifact_text_cell_style(t), vector_svg: this.artifact_vector_svg(t), payload_uri: t.payload_uri, thumbnail_uri: this.artifact_thumbnail_uri(t), major_type: e, text_blank: this.artifact_is_text_blank(t), payload_alternatives: t.payload_alternatives, filename: this.artifact_filename(t), oembed_html: this.artifact_oembed_html(t), link: this.artifact_link(t), link_caption: this.artifact_link_caption(t), interactive: 0 }, "audio" != e && "video" != e || t.player_view || (t.player_view = { state: "stop", current_time_string: "", total_time_string: "", current_time_float: 0, inpoint_float: 0, outpoint_float: 0 }), "medium_for_object" in this) { var a = this.medium_for_object[t._id]; a && t._id != this.editing_artifact_id && a.value(t.description); } }, is_artifact_audio: function(t) { return !!t && t.mime.match("audio"); }, artifact_filename: function(t) { return t.payload_uri ? t.payload_uri.replace(/.*\//g, "") : ""; }, artifact_link: function(t) { return t.meta && t.meta.link_uri ? t.meta.link_uri : ""; }, artifact_link_caption: function(t) { if (t.meta && t.meta.link_uri) { var e = t.meta.link_uri.split("/"); return e.length > 2 ? e[2] : "Link"; } return ""; }, artifact_is_selected: function(t) { return !!t && !!this.selected_artifacts_dict[t._id]; }, artifact_is_text_blank: function(t) { if (t.description) { var e = t.description.replace(/<[^>]+>/g, "").replace(/\s/g, ""); return e.length < 1; } return !1; }, artifact_classes: function(t) { return clzs = [ "artifact", "artifact-" + this.artifact_major_type(t), t.mime.replace("/", "-") ], this.artifact_is_selected(t) && this.editing_artifact_id != t._id && clzs.push("selected"), t._id || clzs.push("creating"), t.style && (clzs.push("align-" + t.style.align), clzs.push("align-" + t.style.valign)), clzs.push("state-" + t.state), this.artifact_is_text_blank(t) && clzs.push("text-blank"), t.locked && clzs.push("locked"), clzs.join(" "); }, artifact_inner_style: function(t) { var e = []; if (t.style) { var a = (t.mime.match("vector") || t.mime.match("shape")) && "square" != t.style.shape; a || (t.style.stroke && (e.push("border-width:" + t.style.stroke + "px"), e.push("border-style:" + (t.style.stroke_style || "solid"))), t.style.stroke_color && e.push("border-color:" + t.style.stroke_color), t.style.border_radius && e.push("border-radius:" + t.style.border_radius + "px")), t.style.fill_color && !a && e.push("background-color:" + t.style.fill_color), t.style.text_color && e.push("color:" + t.style.text_color); var r = []; isNaN(t.style.brightness) || 100 == t.style.brightness || r.push("brightness(" + t.style.brightness + "%)"), isNaN(t.style.contrast) || 100 == t.style.contrast || r.push("contrast(" + t.style.contrast + "%)"), isNaN(t.style.opacity) || 100 == t.style.opacity || r.push("opacity(" + t.style.opacity + "%)"), !isNaN(t.style.hue) && t.style.hue && r.push("hue-rotate(" + t.style.hue + "deg)"), isNaN(t.style.saturation) || 100 == t.style.saturation || r.push("saturate(" + t.style.saturation + "%)"), !isNaN(t.style.blur) && t.style.blur && r.push("blur(" + t.style.blur + "px)"), r.length && (e.push("-webkit-filter:" + r.join(" ")), e.push("filter:" + r.join(" "))); } return e.join(";"); }, artifact_text_cell_style: function(t, e) { var a = []; return t.style && (t.style.padding_left && a.push("padding-left:" + t.style.padding_left + "px"), t.style.padding_right && a.push("padding-right:" + t.style.padding_right + "px"), t.style.padding_top && a.push("padding-top:" + t.style.padding_top + "px"), t.style.padding_bottom && a.push("padding-bottom:" + t.style.padding_bottom + "px")), a.join(";"); }, artifact_style: function(t, e) { var a = [], r = 0; return t.board && (r = t.board.z, r < 0 && (r = 0), a = [ "left:" + t.board.x + "px", "top:" + t.board.y + "px", "width:" + t.board.w + "px", "height:" + t.board.h + "px", "z-index:" + r ]), t.style && (t.style.margin_left && a.push("margin-left:" + t.style.margin_left + "px"), t.style.margin_right && a.push("margin-right:" + t.style.margin_right + "px"), t.style.margin_top && a.push("margin-top:" + t.style.margin_top + "px"), t.style.margin_bottom && a.push("margin-bottom:" + t.style.margin_bottom + "px")), t.mime.match("vector") && a.push("overflow:visible"), a.join(";"); }, artifact_major_type: function(t) { return t.mime.match("oembed") ? "oembed" : t.mime.match("zone") ? "zone" : t.mime.match("svg") ? "svg" : t.mime.match("image") ? "image" : t.mime.match("pdf") ? "image" : t.mime.match("video") ? "video" : t.mime.match("audio") ? "audio" : t.mime.match("website") ? "website" : t.mime.match("vector") ? "vector" : t.mime.match("shape") ? "shape" : t.mime.match("placeholder") ? "placeholder" : t.mime.match("text") || t.mime.match("note") ? "text" : "file"; }, artifact_thumbnail_uri: function(t) { return t.payload_thumbnail_big_uri && t.board && t.board.w > 800 ? t.payload_thumbnail_big_uri : t.payload_thumbnail_medium_uri || t.payload_thumbnail_big_uri || t.payload_thumbnail_web_uri || ""; }, artifact_oembed_html: function(t) { if ("oembed" != this.artifact_major_type(t)) return ""; var e = t.mime.split("/")[1].split("-"), a = e[0], r = e[1]; if (!t.meta || !t.meta.link_uri) return console.log("missing meta / link_uri: ", t), console.log("type/provider: ", a, r), "missing metadata: " + t._id; if ("youtube" == r) { var i = t.meta.link_uri.match(/(v=|\/)([a-zA-Z0-9\-_]{11})/); if (i && i.length > 2) { var n = "https://youtube.com/embed/" + i[2]; return ''; } return "Can't resolve: " + t.payload_uri; } if ("dailymotion" == r) { var o = t.meta.link_uri.match(/dailymotion.com\/video\/([^<]*)/); if (o && o.length > 1) { var n = "https://www.dailymotion.com/embed/video/" + o[1]; return ''; } return "Can't resolve: " + t.payload_uri; } if ("vimeo" == r) { var o = t.meta.link_uri.match(/https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/); if (o) { var n = "https://player.vimeo.com/video/" + o[2]; return ''; } return "Can't resolve: " + t.payload_uri; } return "soundcloud" == r ? '' : "spacedeck" == r ? "" : "Don't know how to embed " + t.mime + "."; }, artifact_vector_svg: function(t) { var e = this.artifact_major_type(t); if ("vector" != e && "shape" != e) return ""; var a, r = (t.style.shape || "", 32 + 2 * t.style.stroke), i = ""; "vector" == e ? (a = render_vector_drawing(t, r), i = "fill:none") : (a = render_vector_shape(t, r), i = "fill:" + t.style.fill_color + ";", r = 0); var n = r, o = "", o += a, o += ""; }, artifact_enclosing_rect: function(t) { return 0 == t.length ? null : (r = { x1: parseInt(_.min(t.map(function(t) { return t.board.x; }))), y1: parseInt(_.min(t.map(function(t) { return t.board.y; }))), x2: parseInt(_.max(t.map(function(t) { return t.board.x + t.board.w; }))), y2: parseInt(_.max(t.map(function(t) { return t.board.y + t.board.h; }))) }, r.x = r.x1, r.y = r.y1, r.w = r.x2 - r.x1, r.h = r.y2 - r.y1, r); }, artifact_selection_rect: function() { return this.artifact_enclosing_rect(this.selected_artifacts()); }, rects_intersecting: function(t, e) { return !(t.x + t.w < e.x || t.x > e.x + e.w || t.y + t.h < e.y || t.y > e.y + e.h); }, artifacts_in_rect: function(t) { return _.filter(this.active_space_artifacts, function(e) { return this.rects_intersecting(e.board, t); }.bind(this)); }, layout_stack_top: function() { this.begin_transaction(); var t = this.artifact_selection_rect(), e = _.filter(this.artifacts_in_rect(t), function(t) { return !this.is_selected(t); }.bind(this)), a = _.max(e, function(t) { return t.board.z; }); a = a.board ? a.board.z + 1 : 1, this.update_selected_artifacts(function(t) { return { board: _.extend(t.board, { z: a }) }; }); }, layout_stack_bottom: function() { this.begin_transaction(); var t = this.artifact_selection_rect(), e = _.filter(this.artifacts_in_rect(t), function(t) { return !this.is_selected(t); }.bind(this)), a = _.min(e, function(t) { return t.board ? t.board.z : 0; }); a = a.board ? a.board.z - 1 : 0; var r = _.max(this.selected_artifacts(), function(t) { t.board ? t.board.z : 0; }); return r = r.board ? r.board.z - 1 : 0, a < 0 ? void this.update_artifacts(e, function(t) { return { board: _.extend(t.board, { z: r + (t.board ? t.board.z : 0) + 1 }) }; }) : void this.update_selected_artifacts(function(t) { return { board: _.extend(t.board, { z: a }) }; }); }, layout_align_left: function() { this.begin_transaction(); var t = this.artifact_selection_rect(); this.update_selected_artifacts(function(e) { return { board: _.extend(e.board, { x: t.x1 }) }; }); }, layout_align_top: function() { this.begin_transaction(); var t = this.artifact_selection_rect(); this.update_selected_artifacts(function(e) { return { board: _.extend(e.board, { y: t.y1 }) }; }); }, layout_align_right: function() { this.begin_transaction(); var t = this.artifact_selection_rect(); this.update_selected_artifacts(function(e) { return { board: _.extend(e.board, { x: t.x2 - e.board.w }) }; }); }, layout_align_bottom: function() { this.begin_transaction(); var t = this.artifact_selection_rect(); this.update_selected_artifacts(function(e) { return { board: _.extend(e.board, { y: t.y2 - e.board.h }) }; }); }, layout_align_center: function() { this.begin_transaction(); var t = this.artifact_selection_rect(), e = t.x1 + (t.x2 - t.x1) / 2; this.update_selected_artifacts(function(t) { return { board: _.extend(t.board, { x: e - t.board.w / 2 }) }; }); }, layout_align_middle: function() { this.begin_transaction(); var t = this.artifact_selection_rect(), e = t.y1 + (t.y2 - t.y1) / 2; this.update_selected_artifacts(function(t) { return { board: _.extend(t.board, { y: e - t.board.h / 2 }) }; }); }, layout_match_size_horiz: function() { this.begin_transaction(); var t = this.selected_artifacts(); if (!(t.length < 2)) { var e = _.reduce(t, function(t, e) { return t + e.board.w; }, 0), a = e / t.length; this.update_selected_artifacts(function(t) { return { board: _.extend(t.board, { w: a }) }; }); } }, layout_match_size_vert: function() { this.begin_transaction(); var t = this.selected_artifacts(); if (!(t.length < 2)) { var e = _.reduce(t, function(t, e) { return t + e.board.h; }, 0), a = e / t.length; this.update_selected_artifacts(function(t) { return { board: _.extend(t.board, { h: a }) }; }); } }, layout_match_size_both: function() { this.layout_match_size_horiz(), this.layout_match_size_vert(); }, layout_distribute_horizontal: function() { this.begin_transaction(); var t = this.selected_artifacts(); if (!(t.length < 3)) for (var e = _.sortBy(t, function(t) { return t.board.x; }), a = e[0].board.x + e[0].board.w / 2, r = _.last(e).board.x + _.last(e).board.w / 2, i = (r - a) / (e.length - 1), n = 1; n < e.length - 1; n++) { var o = e[n], s = a + i * n - o.board.w / 2; this.update_artifacts([ o ], function(t) { return { board: _.extend(t.board, { x: s }) }; }); } }, layout_distribute_vertical: function() { this.begin_transaction(); var t = this.selected_artifacts(); if (!(t.length < 3)) for (var e = _.sortBy(t, function(t) { return t.board.y; }), a = e[0].board.y + e[0].board.h / 2, r = _.last(e).board.y + _.last(e).board.h / 2, i = (r - a) / (e.length - 1), n = 1; n < e.length - 1; n++) { var o = e[n], s = a + i * n - o.board.h / 2; this.update_artifacts([ o ], function(t) { return { board: _.extend(t.board, { y: s }) }; }); } }, layout_distribute_horizontal_spacing: function() { this.begin_transaction(); var t = this.selected_artifacts(); if (!(t.length < 3)) for (var e = _.sortBy(t, function(t) { return t.board.x; }), a = e[0].board.x, r = _.last(e).board.x + _.last(e).board.w, i = r - a, n = _.reduce(e, function(t, e) { return t + e.board.w; }, 0), o = (i - n) / (e.length - 1), s = a + e[0].board.w, c = 1; c < e.length - 1; c++) { var l = e[c], d = s + o; this.update_artifacts([ l ], function(t) { return { board: _.extend(t.board, { x: d }) }; }), s = d + l.board.w; } }, layout_distribute_vertical_spacing: function() { this.begin_transaction(); var t = this.selected_artifacts(); if (!(t.length < 3)) for (var e = _.sortBy(t, function(t) { return t.board.y; }), a = e[0].board.y, r = _.last(e).board.y + _.last(e).board.h, i = r - a, n = _.reduce(e, function(t, e) { return t + e.board.h; }, 0), o = (i - n) / (e.length - 1), s = a + e[0].board.h, c = 1; c < e.length - 1; c++) { var l = e[c], d = s + o; this.update_artifacts([ l ], function(t) { return { board: _.extend(t.board, { y: d }) }; }), s = d + l.board.h; } }, layout_auto: function() { this.begin_transaction(); var t = this.selected_artifacts(); if (!(t.length < 2)) { for (var e = _.sortBy(t, function(t) { return t.board.x + t.board.y * this.active_space.advanced.width; }.bind(this)), a = e[0].board.x, r = e[0].board.y, e = _.sortBy(t, function(t) { return -Math.max(t.board.w, t.board.h); }.bind(this)), i = [], n = 0; n < e.length; n++) { var o = e[n]; i.push({ w: o.board.w, h: o.board.h, a: o }); } var s = new GrowingPacker(); s.fit(i); for (var n = 0; n < i.length; n++) { var c = i[n]; if (c.fit) { var o = c.a; this.update_artifacts([ o ], function(t) { return { board: _.extend(t.board, { x: a + c.fit.x, y: r + c.fit.y }) }; }); } } } }, show_artifact_comments: function(t) { t.preventDefault(), t.stopPropagation(); var e = this.selected_artifacts()[0]; this.selected_artifact = e, this.activate_modal("artifact"); }, create_artifact_comment: function(t, e) { var a = { artifact_id: t._id, space_id: this.active_space._id, message: e, user: this.user }; save_comment(this.active_space._id, a, function(t) { this.active_space_messages.push(t), this.artifact_comment = ""; }.bind(this), function(t) { console.error(t); }.bind(this)); }, remove_artifact_comment: function(t) { delete_comment(this.active_space._id, t._id, function(t) { this.active_space_messages.pop(t); }.bind(this), function(t) { console.error(t); }.bind(this)); } }; "undefined" == typeof window && (exports.SpacedeckBoardArtifacts = SpacedeckBoardArtifacts); SpacedeckUsers = { data: { user_forms_email: "", user_forms_name: "", invitation_token: null, login_email: "", login_password: "", signup_password: "", signup_password_confirmation: "", account_remove_error: null, loading_user: !1, password_reset_confirm_error: "", password_reset_error: "" }, methods: { load_user: function(t, e) { this.loading_user = !0, load_current_user(function(e) { this.user = e, this.loading_user = !1, this.logged_in = !0, t && t(e); }.bind(this), function() { this.loading_user = !1, this.logout(), e && e(); }.bind(this)); }, login_google: function(t) { this.loading_user = !0, create_oauthtoken(function(t) { this.loading_user = !1, location.href = t.url; }, function(t) { this.loading_user = !1, alert("could not get oauth token"); }); }, finalize_login: function(t, e) { window.socket_auth && "" != window.socket_auth && "null" != window.socket_auth || (window.socket_auth = t), this.load_user(function(t) { this.invitation_token ? accept_invitation(this.invitation_token, function(t) { this.redirect_to("/spaces/" + t.space_id); }.bind(this), function(t) { console.error(t), alert("Could not accept invitation. Maybe it was already accepted?"), this.redirect_to("/spaces"); }.bind(this)) : e ? e(this.user) : get_query_param("space_id") && 24 == get_query_param("space_id").length ? this.redirect_to("/spaces/" + get_query_param("space_id")) : this.redirect_to("/spaces", function() {}); }.bind(this)); }, login_with_token: function(t) { create_session_for_oauthtoken(t, function(t) { this.session = t, this.finalize_login(t.token); }.bind(this), function(t) {}.bind(this)); }, login_submit: function(t, e, s, i) { this.loading_user = !0, this.login_error = null, s && (s.preventDefault(), s.stopPropagation()), create_session(t, e, function(t) { console.log("session: ", t), this.loading_user = !1, this.session = t, this.finalize_login(t.token, i); }.bind(this), function(t) { this.loading_user = !1; var e = ""; if (t.status >= 403) var e = "error_unknown_email"; else try { var e = "error_" + JSON.parse(t.responseText).error; } catch (s) { var e = (t.responseText || "Unknown Error.").replace(/,/g, " "); } this.login_error = __(e); }.bind(this)); }, login_submit_modal: function(t, e) { this.login_submit(t, e, null, function() { location.reload(); }); }, signup_guest: function(t) {}, signup_submit: function(t, e, s, i, r, o) { this.creating_user = !0, this.signup_error = null, "localStorage" in window && localStorage && (localStorage.sd_api_token = null), api_token = null, t && (t.preventDefault(), t.stopPropagation()), create_user(e, s, i, r, function(t) { this.creating_user = !1, this.login_submit(s, i, null, o); }.bind(this), function(t) { this.creating_user = !1; try { var e = "error_" + JSON.parse(t.responseText).error; } catch (s) { var e = (t.responseText || "Unknown Error.").replace(/,/g, " "); } var e = __(e); this.signup_error = e; }.bind(this)); }, signup_submit_modal: function(t, e, s, i, r) { this.signup_submit(t, e, s, i, r, function() { alert("Success."), location.reload(); }); }, password_reset_submit: function(t, e) { return t && (t.preventDefault(), t.stopPropagation()), this.password_reset_error = null, this.password_reset_send = !1, void 0 === e || e.length < 3 ? void (this.password_reset_error = "This is not a valid email address") : void create_password_reset(e, function(t, e) { 201 == e.status && (this.password_reset_send = !0); }.bind(this), function(t) { if (console.log(t.status), 404 == t.status) var e = "error_unknown_email"; else try { var e = "error_" + JSON.parse(t.responseText).error; } catch (s) { var e = (t.responseText || "Unknown Error.").replace(/,/g, " "); } this.password_reset_error = __(e); }.bind(this)); }, password_reset_confirm: function(t, e, s) { return t && (t.preventDefault(), t.stopPropagation()), this.password_reset_confirm_error = null, this.password_reset_send = !1, e != s ? void (this.password_reset_confirm_error = "Passwords do not match.") : e.length < 5 ? void (this.password_reset_confirm_error = "Password too short (must have at least 5 characters).") : void confirm_password_reset(e, this.reset_token, function(t, e) { 201 == e.status && (this.active_view = "login"); }.bind(this), function(t) { if (404 == t.status) var e = "user not found"; else var e = "error: " + t.statusText; this.password_reset_confirm_error = e; }.bind(this)); }, logout: function() { this.active_view = "login", this.logged_in = !1, delete_session(function() { this.active_space = { advanced: {} }, this.active_space_loaded = !1, this.active_sidebar_item = "none", this.sidebar_state = "closed", this.loading_user = !1, api_token = null, this.user = {}, this.active_content_type = "login", this.redirect_to("/"); }.bind(this)); }, send_feedback: function(t) { t.length > 0 && create_feedback(this.user, t, function(t) { alert(__("feedback_sent")), this.close_modal(); }.bind(this), function(t) { console.error(t); }); }, remove_account: function(t, e) { return this.account_remove_error = null, e && e.length && e.length > 1 && create_feedback(this.user, e, function(t) { console.log("feedback sent"); }, function(t) {}), t ? void delete_user(this.user, t, function(t) { alert("Sorry to see you go. Goodbye!"), this.logout(); }.bind(this), function(t) { this.account_remove_error = "Password not correct (" + t.status + ")"; }.bind(this)) : void (this.account_remove_error = "Password not correct"); }, user_avatar_image: function(t) { return t.avatar_thumb_uri; }, user_initials: function(t) { var e = (t ? t.nickname || t.email : "anonymous").replace(/[^a-zA-Z]/g, " ").replace(/ +/g, " ").split(" "); return e.length > 1 ? e[0][0] + e[1][0] : e[0].substring(0, 2); }, has_avatar_image: function(t) { return !!(t && t.avatar_thumb_uri && t.avatar_thumb_uri.length > 0); }, is_pro: function(t) { return !0; } } }; SpacedeckAccount = { data: { account_confirmed_sent: !1, account_tab: "invoices", password_change_error: null, feedback_text: "" }, methods: { show_account: function(s) { this.activate_dropdown("account"), this.load_subscription(), this.load_billing(); }, account_save_user_digest: function(s) { this.user.preferences.daily_digest = s, this.save_user(function() {}); }, account_save_user_notifications: function(s) { this.user.preferences.email_notifications = s, this.save_user(function() {}); }, save_user_email: function() { this.save_user(function() {}.bind(this)); }, save_user_language: function(s) { localStorage.lang = s, this.user.preferences && (this.user.preferences.language = s, this.save_user(function() { window._spacedeck_location_change = !0, location.href = "/spaces"; }.bind(this))); }, save_user: function(s) { this.user.email_changed && (this.user.confirmed_at = null), window._spacedeck_location_change = !0, save_user(this.user, function(e) { s ? s() : location.href = "/spaces"; }.bind(this), function(s) { console.error(s); }); }, save_user_password: function(s, e, n) { return this.password_change_error = null, s ? e && n ? e != n ? void (this.password_change_error = "New Passwords do not match") : e.length < 6 ? void (this.password_change_error = "New Password to short") : void save_user_password(this.user, s, e, function() { alert("OK. Password Changed."), this.password_change_current = "", this.password_change_new = "", this.password_change_new_confirmation = ""; }.bind(this), function(s) { 403 == s.status ? this.password_change_error = "Old Password not correct" : this.password_change_error = "Something went wrong. Please try again later."; }.bind(this)) : void (this.password_change_error = "New password/password confirmation required") : void (this.password_change_error = "Current password required"); }, confirm_again: function() { resent_confirm_mail(this.user, function(s) { this.account_confirmed_sent = !0, alert(__("confirm_again")); }.bind(this), function(s) { console.error(s), alert("Something went wrong, please try again."); }); }, confirm_account: function(s) { confirm_user(this.user, s, function(s) { smoke.alert(__("confirmed"), function() { this.redirect_to("/spaces"); }.bind(this)); }.bind(this), function(s) { console.error(s), alert(s.responseText), this.redirect_to("/spaces"); }.bind(this)); } } }; var SpacedeckModals = { data: { active_modal: null, active_account_section: "user", active_space_profile_section: null, account_sections: [ { id: "user", title: "Profile", icon: "icon-user" }, { id: "language", title: "Language", icon: "icon-globe" }, { id: "email-notifications", title: "Notifications", icon: "icon-bell" }, { id: "reset-password", title: "Password", icon: "icon-lock-closed" }, { id: "remove-account", title: "Terminate", icon: "icon-logout" } ], folder_profile_sections: [ { id: "editors", title: "Editors", icon: "icon-user-group", count: 1 }, { id: "visibility", title: "Visibility", icon: "icon-eye-open", count: 1 } ], space_profile_sections: [ { id: "comments", title: "Comments", icon: "icon-messages", count: 1 }, { id: "history", title: "History", icon: "icon-history", count: 1 }, { id: "editors", title: "Editors", icon: "icon-user-group", count: 1 }, { id: "visibility", title: "Visibility", icon: "icon-eye-open", count: 1 } ] }, methods: { activate_modal: function(i) { this.active_modal = i, "folder-settings" == i && (this.access_settings_space = this.active_folder, this.access_settings_memberships = this.active_space_memberships, this.editors_section = "list"); }, close_modal: function() { this.active_modal = null; }, activate_account_section: function(i) { this.active_account_section = i; }, activate_space_profile_section: function(i) { this.active_space_profile_section = i; } } }; var SpacedeckAvatars = { data: { uploading_avatar: !1, uploading_folder_avatar: !1, uploading_cover: !1 }, methods: { save_avatar_image: function(a, i, e) { if (a.files.length > 0) { var t = a.files[0], r = function() { this.uploading_avatar = !1, this.uploading_cover = !1, this.uploading_folder_avatar = !1; }.bind(this); if (!_.include([ "image/jpeg", "image/jpg", "image/png", "image/gif" ], t.type)) return alert("Unsupported file type. Please upload JPEG, PNG or GIF."), void r(); if (t.size > 3145728) return alert("File must be smaller than 3 megabytes."), void r(); save_avatar_file(i, e, t, function(a) { r(), this.uploading_avatar = !1, this.uploading_cover = !1; var i = a.avatar_thumb_uri; e.avatar_thumb_uri = i + "?cachebuster=" + Math.random(); }.bind(this), function(a) { alert("Upload failed: " + a), r(); }); } }, save_space_avatar_image: function(a) { this.uploading_avatar = !0; var i = this.save_avatar_image.bind(this); i(a.$event.target, "space", this.active_space); }, save_folder_avatar_image: function(a) { this.uploading_folder_avatar = !0; var i = this.save_avatar_image.bind(this); i(a.$event.target, "space", this.active_folder); }, save_user_avatar_image: function(a) { this.uploading_avatar = !0; var i = this.save_avatar_image.bind(this); i(a.$event.target, "user", a.$root.user); }, delete_user_avatar_image: function() { this.user.avatar_original_uri = "", this.user.avatar_thumb_uri = "", save_user(this.user, function(a) {}.bind(this)); }, save_user_background_image: function(a) { var i = a.$event.target; this.uploading_cover = !0; var e = i.files[0]; save_user_background_file(this.user, e, function(a) { this.user.background_original_uri = a.background_original_uri, this.uploading_cover = !1; }.bind(this)); } } }; SpacedeckWebsockets = { data: { users_online: {} }, methods: { handle_live_updates: function(e) { if ("Space" == e.model && e.object && "space" == e.object.space_type && this.active_space && this.active_space._id == e.object._id && (this.active_space = _.merge(this.active_space, e.object)), "Message" == e.model && "create" == e.action && e.object) { var t = e.object; this.active_space && this.active_space._id == t.space._id ? (this.active_space_messages.push(t), this.refresh_space_comments()) : console.log("message created in another space."); } if ("Artifact" == e.model) if ("create" == e.action && e.object) { var i = e.object; if (this.active_space && this.active_space._id == i.space_id) { var s = i; s._id && !this.find_artifact_by_id(s._id) ? (this.update_board_artifact_viewmodel(i), this.active_space_artifacts.push(i)) : (console.log("warning: got create on existing artifact."), e.action = "update"); } else console.log("artifact created in another space."); } else if ("update" == e.action && e.object) { if (this.active_space) { var s = e.object; if (s && s._id) { var c = this.find_artifact_by_id(s._id); if (c) for (key in s) c[key] = s[key], this.update_board_artifact_viewmodel(c); else c = s; } } } else if ("delete" == e.action && e.object && this.active_space) { var s = e.object; if (s._id) { var c = this.find_artifact_by_id(s._id); if (c) { var o = this.active_space_artifacts.indexOf(c); this.active_space_artifacts.splice(o, 1); } else console.log("existing artifact to delete not found"); } else console.error("object without _id"); } }, subscribe: function(e) { this.websocket && 1 == this.websocket.readyState ? this.websocket.send(JSON.stringify({ action: "subscribe", space_id: e._id })) : console.error("socket not ready yet. (subscribe)"); }, is_member_online: function(e, t) { if (!t.user) return !1; if (!this.users_online[e._id]) return !1; var i = _.find(this.users_online[e._id], function(e) { return e._id == t.user._id; }); return i; }, auth_websocket: function(e) { if (this.websocket || this.init_websocket(), this.websocket && 1 == this.websocket.readyState) { var t = { action: "auth", editor_auth: space_auth, editor_name: this.guest_nickname, auth_token: window.socket_auth, space_id: e._id }; console.log("[websocket] auth space"), this.websocket.send(JSON.stringify(t)); } }, websocket_send: function(e) { if (this.websocket && 1 == this.websocket.readyState) try { this.websocket.send(JSON.stringify(e)); } catch (t) {} }, init_websocket: function() { this.websocket && (this.websocket = null), this.current_timeout && (clearTimeout(this.current_timeout), this.current_timeout = null); try { this.websocket = new WebSocket(ENV.websocketsEndpoint + "/socket"); } catch (e) { console.log("[websocket] cannot establish websocket connection: ", e), this.current_timeout = setTimeout(function() { console.log("[websocket] reconnecting", e), this.init_websocket(); }.bind(this), 5e3); } return this.websocket ? (this.websocket.onopen = function(e) { this.current_timeout && (clearTimeout(this.current_timeout), this.current_timeout = null), this.active_space_loaded && this.auth_websocket(this.active_space), this.online = !0; }.bind(this), this.websocket.onclose = function(e) { window._spacedeck_location_change || (this.online = !1), this.current_timeout || (this.current_timeout = setTimeout(function() { console.log("[websocket] onclose: reconnecting", e), this.init_websocket(); }.bind(this), 5e3)); }.bind(this), this.websocket.onmessage = function(e) { this.online = !0; try { var t = JSON.parse(e.data); } catch (i) { return void console.log("[websocket] malformed message: ", e.data); } if (t.channel_id != channel_id && ("cursor" == t.action ? this.handle_user_cursor_update(t) : "viewport" == t.action ? this.handle_presenter_viewport_update(t) : "media" == t.action && this.handle_presenter_media_update(t), "update" != t.action && "create" != t.action && "delete" != t.action || this.handle_live_updates(t), "init" == t.action && (channel_id = t.channel_id), "auth_valid" == t.action && this.active_space && (this.subscribe(this.active_space), this.unsaved_transactions() && (console.log("[websockets-saver] found unsaved transactions, triggering save."), this.process_artifact_save_queue())), "subscription_valid" == t.action && console.log("subscription_valid"), "status_update" == t.action)) { var s = t.space_id, c = t.users; this.user && this.user._id && (c = _.filter(c, function(e) { return e && e._id != this.user._id; }.bind(this))), c = _.filter(c, function(e) { return e && (e._id || e.nickname); }), this.users_online[s] = c, this.active_space && this.active_space._id == s && (this.active_space_users = c); } }.bind(this), void (this.websocket.onerror = function(e) { console.log("websocket.onerror:", e), window._spacedeck_location_change || (this.online = !1, this.was_offline = !0), this.current_timeout || (this.current_timeout = setTimeout(function() { console.log("websocket.onerror: reconnecting", e), this.init_websocket(); }.bind(this), 5e3)); }.bind(this))) : void console.log("[websocket] no websocket support?"); } } }; function setup_whiteboard_directives() { if ("ontouchstart" in window) var t = "touchstart", e = "touchmove", s = "touchend"; else var t = "mousedown", e = "mousemove", s = "mouseup"; Vue.directive("sd-whiteboard", { bind: function() { var o = this.el; $(o).on(t, ".artifact", this.handle_mouse_down_artifact.bind(this)), $(o).on("dblclick", ".artifact", this.handle_double_click_artifact.bind(this)), $(o).on("keyup", ".artifact", this.handle_key_up_artifact.bind(this)), $(o).on("keydown", ".artifact", this.handle_key_down_artifact.bind(this)), $(o).bind(t, this.handle_mouse_down_space.bind(this)), $(o).bind(e, this.handle_mouse_move.bind(this)), $(o).bind(s, this.handle_mouse_up_space.bind(this)), $(o).bind("wheel", this.handle_wheel_space.bind(this)), $(document.body).bind("mouseleave", this.handle_mouse_leave.bind(this)), $(o).find(".handle.resize-nw").bind(t, function(t) { this.handle_transform_mouse_down(t, 1, 1); }.bind(this)), $(o).find(".handle.resize-n").bind(t, function(t) { this.handle_transform_mouse_down(t, .5, 1); }.bind(this)), $(o).find(".handle.resize-ne").bind(t, function(t) { this.handle_transform_mouse_down(t, 0, 1); }.bind(this)), $(o).find(".handle.resize-e").bind(t, function(t) { this.handle_transform_mouse_down(t, 0, .5); }.bind(this)), $(o).find(".handle.resize-se").bind(t, function(t) { this.handle_transform_mouse_down(t, 0, 0); }.bind(this)), $(o).find(".handle.resize-s").bind(t, function(t) { this.handle_transform_mouse_down(t, .5, 0); }.bind(this)), $(o).find(".handle.resize-sw").bind(t, function(t) { this.handle_transform_mouse_down(t, 1, 0); }.bind(this)), $(o).find(".handle.resize-w").bind(t, function(t) { this.handle_transform_mouse_down(t, 1, .5); }.bind(this)), $(o).find(".edge-handle.resize-n").bind(t, function(t) { this.handle_transform_mouse_down(t, .5, 1); }.bind(this)), $(o).find(".edge-handle.resize-s").bind(t, function(t) { this.handle_transform_mouse_down(t, .5, 0); }.bind(this)), $(o).find(".edge-handle.resize-e").bind(t, function(t) { this.handle_transform_mouse_down(t, 0, .5); }.bind(this)), $(o).find(".edge-handle.resize-w").bind(t, function(t) { this.handle_transform_mouse_down(t, 1, .5); }.bind(this)), $(o).on(t, ".vector-handle", function(t) { this.handle_vector_transform_mouse_down(t); }.bind(this)); var i = this.vm.$root; this.space_zoom = 1, this.artifacts_before_transaction = [], i.active_tool = "pointer"; }, update: function() {}, unbind: function() { var o = this.el; $(o).off(t + " " + e + " " + s + " keyup keydown mouseleave"), $(document.body).unbind("mouseleave"); }, handle_key_down_artifact: function(t) { this.vm.$root; }, handle_key_up_artifact: function(t) { this.vm.$root; }, handle_mouse_down_artifact: function(t) { var e = this.vm.$root; e.editing_artifact_id || (t.preventDefault(), t.stopPropagation()); var s = e.find_artifact_by_id(t.currentTarget.id.replace("artifact-", "")); if ("zoom" != e.active_tool) { if ("eyedrop" == e.active_tool) { var o = e.selected_artifacts(); if (!e.is_selected(s) && o.length > 0) return e.begin_transaction(), e.update_selected_artifacts(function(t) { t.style = _.clone(s.style); }), void (e.active_tool = "pointer"); } if ("pan" == e.active_tool) return void this.start_pan(t); "pointer" == e.active_tool && (e.is_selected(s) && !t.shiftKey || this.select(t, s), t.altKey && (s = e.clone_artifact(s), this.select(t, s))), e.begin_transaction(); var i = this.cursor_point_to_space(t); e.mouse_ox = i.x, e.mouse_oy = i.y, e.mouse_moved = !1, this.mouse_state = "move", t.stopPropagation(); } }, handle_double_click_artifact: function(t) { var e = this.vm.$root, s = e.find_artifact_by_id(t.currentTarget.id.replace("artifact-", "")); s && (s.payload_uri && e.download_selected_artifacts(), e.toggle_selected_artifact_editing(!0)); }, handle_transform_mouse_down: function(t, e, s) { t.stopPropagation(), t.preventDefault(); var o = this.vm.$root; o.begin_transaction(); var i = this.cursor_point_to_space(t); this.mouse_state = "transform", o.mouse_ox = i.x, o.mouse_oy = i.y, o.transform_ox = e, o.transform_oy = s; }, handle_vector_transform_mouse_down: function(t) { t.stopPropagation(), t.preventDefault(); var e = this.vm.$root, s = parseInt($(t.currentTarget).attr("data-idx")); e.selected_control_point_idx = s, e.begin_transaction(); var o = this.cursor_point_to_space(t); this.mouse_state = "vector_transform", e.mouse_ox = o.x, e.mouse_oy = o.y; }, handle_wheel_space: function(t) { var e = this.vm.$root; if (t.ctrlKey || t.shiftKey) { t.preventDefault(), t.stopPropagation(); var s = 1, o = t.originalEvent.deltaY; if (o > 0) { if (s = 1.2, e.viewport_zoom <= .05) return !1; } else { if (!(o < 0)) return !1; if (s = .9, e.viewport_zoom >= 2) return !1; } e.zoom_to_cursor(t, s); } }, handle_mouse_down_space: function(t) { if (t.target == t.currentTarget || _.include([ "wrapper" ], t.target.className)) { var e = this.vm.$root; e.opened_dialog = "none"; var s = this.cursor_point_to_space(t); if (e.mouse_ox = s.x, e.mouse_oy = s.y, 2 != t.which && 4 != t.buttons || (e.active_tool = "pan"), "note" == e.active_tool) return this.deselect(), this.mouse_state = "transform", e.mouse_state = this.mouse_state, void this.start_adding_note(t); if ("arrow" == e.active_tool) return this.deselect(), this.mouse_state = "vector_transform", e.mouse_state = this.mouse_state, void this.start_drawing_arrow(t); if ("line" == e.active_tool) return this.deselect(), this.mouse_state = "vector_transform", e.mouse_state = this.mouse_state, void this.start_drawing_line(t); if ("scribble" == e.active_tool) return this.deselect(), this.mouse_state = "scribble", e.mouse_state = this.mouse_state, void this.start_drawing_scribble(t); if ("zoom" == e.active_tool) return void (t.altKey ? e.zoom_out() : e.zoom_in()); if ("pointer" == e.active_tool) this.mouse_state = "lasso", this.start_lasso(t); else { if ("zone" == e.active_tool) return this.deselect(), this.mouse_state = "transform", void e.start_adding_zone(t); if ("image" == e.active_tool) return this.deselect(), this.mouse_state = "transform", void e.start_adding_placeholder(t); if ("pan" == e.active_tool) return void this.start_pan(t); } e.selection_metrics.count > 0 && (this._no_artifact_toolbar_this_round = !0), this.deselect(); } }, start_pan: function(t) { var e = this.vm.$root; el = $("#space")[0], el && (this.mouse_state = "pan", this.old_panx = el.scrollLeft, this.old_pany = el.scrollTop); var s = this.cursor_point_to_space(t); e.mouse_ox = s.x, e.mouse_oy = s.y, e.mouse_moved = !1; }, deselect: function() { var t = this.vm.$root; t.deselect(); }, select: function(t, e) { var s = this.vm.$root; s.select(t, e); }, multi_select: function(t) { var e = this.vm.$root; e.multi_select(t); }, start_lasso: function(t) { var e = this.cursor_point_to_space(t); this.lasso = { x: e.x, y: e.y, w: 0, h: 0 }; }, rects_intersecting: function(t, e) { return !(!t || !e) && !(t.x + t.w < e.x || t.x > e.x + e.w || t.y + t.h < e.y || t.y > e.y + e.h); }, artifacts_in_rect: function(t) { if (!t) return []; var e = this.vm.$root; return _.filter(e.active_space_artifacts, function(e) { return this.rects_intersecting(e.board, t); }.bind(this)); }, abs_rect: function(t) { var e = { x: t.x, y: t.y, w: Math.abs(t.w), h: Math.abs(t.h) }; return t.w < 0 && (e.x += t.w), t.h < 0 && (e.y += t.h), e; }, lasso_style: function() { var t = this.vm.$root; if (!this.lasso) return ""; var e = { x: this.lasso.x, y: this.lasso.y, w: this.lasso.w * t.viewport_zoom, h: this.lasso.h * t.viewport_zoom }; e = this.abs_rect(e), e.x += t.bounds_margin_horiz, e.y += t.bounds_margin_vert; var s = "left:" + e.x + "px;"; return s += "top:" + e.y + "px;", s += "width:" + e.w + "px;", s += "height:" + e.h + "px;", s += "opacity: 1;"; }, render_lasso: function() { return this.lasso ? ($("#lasso").attr("style", this.lasso_style()), void $("#lasso").show()) : void $("#lasso").hide(); }, cursor_point_to_space: function(t) { var e = this.vm.$root, s = { left: 0, top: 0 }; return t = fixup_touches(t), { x: (parseInt(t.pageX) - parseInt(s.left) - e.bounds_margin_horiz) / this.space_zoom, y: (parseInt(t.pageY) - parseInt(s.top) - e.bounds_margin_vert) / this.space_zoom }; }, rect_to_points: function(t) { return [ { x: t.x, y: t.y }, { x: t.x + t.w, y: t.y }, { x: t.x, y: t.y + t.h }, { x: t.x + t.w, y: t.y + t.h } ]; }, old_selection_rect: function() { var t = this.vm.$root, e = t.selected_artifacts().map(function(e) { return t.find_artifact_before_transaction(e); }.bind(this)); return t.enclosing_rect(e); }, snap_point: function(t, e, s) { var o = this.vm.$root, i = 8, a = []; if (s && a.push([ [ t - window.innerWidth / 2, Math.abs(e - window.innerHeight / 2) ], [ t - window.innerWidth / 2, Math.abs(e - window.innerHeight / 2) ] ]), o.grid_active) { var n = o.grid.spacing / o.grid.subdivisions, r = o.grid.spacing / o.grid.subdivisions, d = parseInt(t / n) * n, c = parseInt(e / r) * r, h = (parseInt(t / n) + 1) * n, l = (parseInt(e / r) + 1) * r; a = [ [ [ Math.abs(d - t), d ], [ Math.abs(c - e), c ] ], [ [ Math.abs(h - t), h ], [ Math.abs(l - e), l ] ] ]; } else a = o.unselected_artifacts().map(function(o) { var i = this.rect_to_points(o.board), a = Math.abs(i[0].x - t), n = Math.abs(i[1].x - t), r = Math.abs(i[0].x + o.board.w / 2 - t), _ = Math.abs(i[0].y - e), d = Math.abs(i[2].y - e), c = Math.abs(i[0].y + o.board.h / 2 - e); if (!s) { if (n < a) var h = n, l = i[1].x; else var h = a, l = i[0].x; if (d < _) var u = d, f = i[2].y; else var u = _, f = i[0].y; } if (s) var h = r, l = i[0].x + o.board.w / 2, u = c, f = i[0].y + o.board.h / 2; return [ [ h, l ], [ u, f ] ]; }.bind(this)); a.push([ [ Math.abs(t), 0 ], [ Math.abs(e), 0 ] ]); var u = _.unzip(a), f = _.sortBy(u[0], function(t) { return t[0]; }), p = _.sortBy(u[1], function(t) { return t[0]; }), m = { snapx: f[0], snapy: p[0] }; return (!f[0] || f[0][0] > i) && (m.snapx = [ 0, t ]), (!p[0] || p[0][0] > i) && (m.snapy = [ 0, e ]), m; }, offset_point_in_wrapper: function(t) { var e = this.vm.$root, s = $(this.el)[0], o = e.viewport_zoom, i = parseInt($("#space").css("padding-top")); return t.y = (t.y + s.scrollTop - i) / o, t.x = (t.x + s.scrollLeft) / o, t; }, start_drawing_scribble: function(t) { t.preventDefault(), t.stopPropagation(); var e = this.vm.$root, s = this.offset_point_in_wrapper(this.cursor_point_to_space(t)), o = e.highest_z() + 1; e.deselect(); var i = { space_id: e.active_space._id, mime: "x-spacedeck/vector", description: "", control_points: [ { dx: 0, dy: 0 } ], board: { x: s.x, y: s.y, z: o, w: 64, h: 64 }, style: { stroke_color: "#000000", stroke: 2, shape: "scribble" } }; e.save_artifact(i, function(s) { e.update_board_artifact_viewmodel(s), e.active_space_artifacts.push(s), this.select(t, s), e.transform_ox = 0, e.transform_oy = 0, e.begin_transaction(); }.bind(this)); }, start_drawing_arrow: function(t) { t.preventDefault(), t.stopPropagation(); var e = this.vm.$root, s = this.cursor_point_to_space(t); this.offset_point_in_wrapper(s); var o = e.highest_z() + 1, i = { space_id: e.active_space._id, mime: "x-spacedeck/vector", description: "", control_points: [ { dx: 0, dy: 0 }, { dx: 0, dy: 0 }, { dx: 0, dy: 0 } ], board: { x: s.x, y: s.y, z: o, w: 64, h: 64 }, style: { stroke_color: "#000000", stroke: 2, shape: "arrow" } }; e.save_artifact(i, function(s) { e.update_board_artifact_viewmodel(s), e.active_space_artifacts.push(s), e.select(t, i), e.selected_control_point_idx = 1, e.transform_ox = 0, e.transform_oy = 0, e.begin_transaction(); }.bind(this)); }, start_drawing_line: function(t) { t.preventDefault(), t.stopPropagation(); var e = this.vm.$root, s = this.cursor_point_to_space(t); this.offset_point_in_wrapper(s); var o = e.highest_z() + 1, i = { space_id: e.active_space._id, mime: "x-spacedeck/vector", description: "", control_points: [ { dx: 0, dy: 0 }, { dx: 0, dy: 0 } ], board: { x: s.x, y: s.y, z: o, w: 64, h: 64 }, style: { stroke_color: "#000000", stroke: 2, shape: "line" } }; e.save_artifact(i, function(s) { e.update_board_artifact_viewmodel(s), e.active_space_artifacts.push(s), e.select(t, i), e.selected_control_point_idx = 1, e.transform_ox = 0, e.transform_oy = 0, e.begin_transaction(); }.bind(this)); }, snap_point_simple: function(t) { var e = this.snap_point(t.x, t.y); return { x: e.snapx[1], y: e.snapy[1] }; }, handle_mouse_up_space: function(t) { var e = this.vm.$root; if (t.preventDefault(), "lasso" == this.mouse_state) { var s = this.abs_rect(this.offset_point_in_wrapper(this.lasso)); if (s.w > 0 && s.h > 0) { var o = this.artifacts_in_rect(s); this.multi_select(o); } else this._no_artifact_toolbar_this_round ? this._no_artifact_toolbar_this_round = !1 : e.start_adding_artifact(t); this.lasso = null, this.render_lasso(); } else if (_.include([ "transform", "move", "vector_transform", "scribble" ], this.mouse_state)) for (var i = e.selected_artifacts(), a = 0; a < i.length; a++) _.include([ "text", "placeholder" ], e.artifact_major_type(i[a])) && (i[a].board.w < 10 && (i[a].board.w = 10), i[a].board.h < 10 && (i[a].board.h = 10)); if ("text_editor" != this.mouse_state) { if (_.include([ "zoom" ], e.active_tool)) return this.mouse_state = "idle", e.mouse_state = this.mouse_state, e.end_transaction(), void e.deselect(); this.mouse_state = "idle", e.mouse_state = this.mouse_state, this.lasso = null, e.active_tool = "pointer", e.end_transaction(), e.show_toolbar_props(); } }, handle_mouse_leave: function(t) { var e = this.vm.$root; this.mouse_state = "idle", this.lasso = null, e.active_tool = "pointer", e.end_transaction(), this.render_lasso(); }, handle_mouse_move: function(t) { var e = this.vm.$root; if (e.active_space) { e.editing_artifact_id || (t.preventDefault(), t.stopPropagation()), e.handle_scroll(); var s = this.cursor_point_to_space(t), o = s.x - e.mouse_ox, i = s.y - e.mouse_oy, a = new Date().getTime() - this.last_mouse_move_time; this.last_mouse_move_time = new Date().getTime(); var n = e.viewport_zoom || 1; if (n && (o /= n, i /= n), o > 10 || i > 10 || a > 100) { var r = "anonymous"; r = e.logged_in ? e.user.nickname || e.user.email : e.guest_nickname || "anonymous"; var d = { action: "cursor", x: s.x / n, y: s.y / n, name: r, id: e.user._id || r }; e.websocket_send(d); } if (e.snap_ruler_x = -1e3, e.snap_ruler_y = -1e3, e.mouse_moved = !0, e.transform_lock = t.shiftKey, e.transform_lock && ("transform" == this.mouse_state || (Math.abs(i) > Math.abs(o) ? o = 0 : i = 0)), "move" == this.mouse_state) { e.hide_toolbar_props(); var c = 0, h = 0, l = e.selected_artifacts(), u = this.old_selection_rect(); if (l.length && l[0]._id == e.editing_artifact_id) return; if (u) { var f = u.x1 + (u.x2 - u.x1) / 2, p = u.y1 + (u.y2 - u.y1) / 2, m = this.snap_point(u.x1 + o, u.y1 + i, !1), v = this.snap_point(u.x2 + o, u.y2 + i, !1), b = this.snap_point(f + o, p + i, !0); c = b.snapx[0] > 0 ? f + o - b.snapx[1] : v.snapx[0] > 0 ? u.x2 + o - v.snapx[1] : u.x1 + o - m.snapx[1], h = b.snapy[0] > 0 ? p + i - b.snapy[1] : v.snapy[0] > 0 ? u.y2 + i - v.snapy[1] : u.y1 + i - m.snapy[1]; } e.update_selected_artifacts(function(t) { var s = e.find_artifact_before_transaction(t); return s ? { board: _.extend(t.board, { x: s.board.x + o - c, y: s.board.y + i - h }) } : {}; }.bind(this)); } else if ("transform" == this.mouse_state) { var l = e.selected_artifacts(), y = this.old_selection_rect(); if (!y) return void (this.mouse_state = "idle"); e.hide_toolbar_props(); var x = y.x2 - y.x1, w = y.y2 - y.y1, g = y.x1 + x * e.transform_ox, z = y.y1 + w * e.transform_oy, k = y.x1 + x * (1 - e.transform_ox) - g, M = y.y1 + w * (1 - e.transform_oy) - z, D = this.snap_point(g + k + o, z + M + i), I = D.snapx[1] - g, P = D.snapy[1] - z, T = k ? I / k : 1, K = M ? P / M : 1; e.transform_lock && (K = T), e.update_selected_artifacts(function(t) { var s = e.find_artifact_before_transaction(t), o = g + (s.board.x - g) * T, i = z + (s.board.y - z) * K, a = g + (s.board.x + s.board.w - g) * T, n = z + (s.board.y + s.board.h - z) * K; if (o > a) { var r = o; o = a, a = r; } if (i > n) { var r = i; i = n, n = r; } return { board: _.extend(t.board, { x: o, y: i, w: a - o, h: n - i }) }; }.bind(this)); } else if ("lasso" == this.mouse_state) this.lasso.w = o, this.lasso.h = i, this.render_lasso(); else if ("vector_transform" == this.mouse_state) { e.hide_toolbar_props(); var L = this; e.update_selected_artifacts(function(t) { var s = e.find_artifact_before_transaction(t), a = _.cloneDeep(s.control_points), n = _.clone(s.board), r = a[e.selected_control_point_idx], d = L.snap_point(n.x + r.dx + o, n.y + r.dy + i); return o = d.snapx[1] - (n.x + r.dx), i = d.snapy[1] - (n.y + r.dy), r.dx += o, r.dy += i, "arrow" == t.style.shape && 2 != e.selected_control_point_idx && (a[2].dx = (a[0].dx + a[1].dx) / 2, a[2].dy = (a[0].dy + a[1].dy) / 2), L.normalize_control_points(a, n); }); } else if ("scribble" == this.mouse_state) { e.update_selected_artifacts(function(t) { var e = t, o = _.cloneDeep(e.control_points), i = _.clone(e.board), a = this.offset_point_in_wrapper({ x: s.x, y: s.y }); return o.push({ dx: a.x - i.x, dy: a.y - i.y }), this.normalize_control_points(simplify_scribble_points(o), i); }.bind(this)); var B = e.selected_artifacts(); B.length && e.update_board_artifact_viewmodel(B[0]); } else if ("pan" == this.mouse_state) { if (!$("#space").length) return; el = $("#space")[0], el.scrollLeft = this.old_panx - o * e.viewport_zoom, el.scrollTop = this.old_pany - i * e.viewport_zoom, e.handle_scroll(); } } }, normalize_control_points: function(t, e) { var s = _.min(t, "dx").dx, o = _.min(t, "dy").dy, i = _.max(t, "dx").dx, a = _.max(t, "dy").dy, n = -s, r = -o, d = t.map(function(t) { return { dx: t.dx + n, dy: t.dy + r }; }), c = Math.abs(i - s), h = Math.abs(a - o), l = 0, u = 0; e.w < 0 && (l = -e.w), e.h < 0 && (u = -e.h); var f = { x: e.x + l - n, y: e.y + u - r, w: c, h: h, z: e.z }; return { board: f, control_points: d }; } }); } function setup_directives() { if (Vue.directive("clipboard", { bind: function() { this.clipboard = new Clipboard(".clipboard-btn"); }, update: function(e) {}, unbind: function() { this.clipboard.destroy(); } }), Vue.directive("t", { update: function(e, t) { this.el.innerHTML = t; } }), "ontouchstart" in window) var e = "touchstart", t = "touchmove", a = "touchend"; else var e = "mousedown", t = "mousemove", a = "mouseup"; Vue.directive("videoplayer", { update: function(t) { var a = this.el, i = (this.vm.$root, a.querySelectorAll("video")[0]), r = a.querySelectorAll(".play")[0], n = a.querySelectorAll(".pause")[0], o = a.querySelectorAll(".stop")[0], d = "stop", s = function() { try { t.player_view || (t.player_view = {}), t.player_view.state = d; } catch (e) {} }, c = function() { i.play(), d = "playing", s(); }, u = function() { try { i.pause(), d = "paused", s(); } catch (e) {} }, l = function() { try { d = "stop", i.pause(), i.currentTime = 0, s(); } catch (e) {} }; a.addEventListener("remote_play", c), a.addEventListener("remote_pause", u), a.addEventListener("remote_stop", l), r.addEventListener(e, function(e) { try { c(), spacedeck.presenter_send_media_action(t._id, "video", "play", i.currentTime); } catch (a) {} }, !1), n.addEventListener(e, function(e) { u(), spacedeck.presenter_send_media_action(t._id, "video", "pause", i.currentTime); }, !1), o.addEventListener(e, function(e) { l(), spacedeck.presenter_send_media_action(t._id, "video", "stop", 0); }, !1); } }), Vue.directive("audioplayer", { update: function(t) { var a = this.el, i = this.vm.$root, r = a.querySelectorAll(".play")[0], n = a.querySelectorAll(".pause")[0], o = a.querySelectorAll(".stop")[0], d = a.querySelectorAll(".timeline")[0], s = a.querySelectorAll(".set-inpoint")[0], c = a.querySelectorAll(".set-outpoint")[0], u = a.querySelectorAll(".reset-points")[0], l = "stop", p = 0, f = 0, m = a.querySelectorAll("audio")[0], v = function() { try { t.meta ? (t.meta.play_to || (t.meta.play_to = m.duration), p = parseFloat(t.meta.play_from) || 0, f = parseFloat(t.meta.play_to) || 0) : (p = 0, f = parseFloat(m.duration) || 0, t.meta = {}); } catch (e) {} }, _ = function() { try { t.player_view || (t.player_view = {}), t.player_view.state = l, t.player_view.total_time_string = format_time(m.duration), t.player_view.current_time_string = format_time(m.currentTime), t.player_view.current_time_float = m.currentTime / m.duration, t.player_view.inpoint_float = p / m.duration, t.player_view.outpoint_float = f / m.duration, t.player_view.duration = m.duration; } catch (e) {} }, h = function() { try { m.pause(), l = "paused"; } catch (e) {} _(); }, y = function() { try { m.currentTime = p, m.pause(), l = "stop"; } catch (e) {} _(); }; _(), m.addEventListener("loadedmetadata", function(e) { v(), _(); }, !1), m.addEventListener("timeupdate", function(e) { try { v(), m.currentTime >= f && "playing" == l && y(), _(); } catch (t) {} }, !1); var g = function() { "stop" == l && (m.currentTime = p), l = "playing", v(), m.play(), _(); }, b = function() { h(), _(); }, w = function() { y(), _(); }; a.addEventListener("remote_play", g), a.addEventListener("remote_pause", b), a.addEventListener("remote_stop", w), r.addEventListener(e, function(e) { try { g(), spacedeck.presenter_send_media_action(t._id, "audio", "play", m.currentTime); } catch (a) {} }, !1), n.addEventListener(e, function(e) { b(), spacedeck.presenter_send_media_action(t._id, "audio", "pause", m.currentTime); }, !1), o.addEventListener(e, function(e) { w(), spacedeck.presenter_send_media_action(t._id, "audio", "stop", 0); }, !1), d.addEventListener(e, function(e) { var t = parseFloat(e.offsetX) / e.currentTarget.offsetWidth * m.duration; isNaN(t) && (t = 0); try { m.currentTime = t; } catch (a) {} }, !1), s.addEventListener(e, function(e) { t.meta || (t.meta = {}), t.meta.play_from = m.currentTime, t.meta.play_to < t.meta.play_from && (t.meta.play_to = m.duration), v(), y(), _(), i.save_artifact(t); }, !1), c.addEventListener(e, function(e) { t.meta || (t.meta = {}), t.meta.play_to = m.currentTime, t.meta.play_to < t.meta.play_from && (t.meta.play_from = 0), v(), y(), _(), i.save_artifact(t); }, !1), u.addEventListener(e, function(e) { t.meta || (t.meta = {}), t.meta.play_from = 0, t.meta.play_to = m.duration, v(), y(), _(), i.save_artifact(t); }, !1); } }), Vue.directive("sd-richtext", { twoWay: !0, update: function(e) { this.mode = "rich", $(this.el).addClass("text-editing"), this.medium = new Medium({ element: this.el, mode: Medium.richMode, attributes: { remove: [ "class", "href", "onclick", "onmousedown", "onmouseup" ] } }), this.medium.value(e.description), this.medium.element.addEventListener("keyup", function() { e.description = this.medium.value(), spacedeck.queue_artifact_for_save(e); }.bind(this)), spacedeck.medium_for_object[e._id] = this.medium; } }), Vue.directive("focus", { bind: function() { var e = this.el; window.setTimeout(function() { if (e.contentEditable && "inherit" != e.contentEditable) { var t = document.createRange(); t.selectNodeContents(e); } else e.focus(), e.select(); }, 500); } }), Vue.directive("sd-draggable", { update: function(e) { var t = this.el; t.addEventListener("dragstart", function(a) { return $(t).find(".text-editing").length ? (a.stopPropagation(), void a.preventDefault()) : (a.dataTransfer.setData("application/json", JSON.stringify(e)), void $(t).addClass("dragging")); }, !1); } }), Vue.directive("sd-droppable", { isFn: !0, bind: function() { var e = this.el, t = this.expression, a = t.split(";"), i = a[0], r = a[1]; e.addEventListener("dragover", function(t) { return t.dataTransfer.dropEffect = "copy", t.preventDefault && t.preventDefault(), e.classList.add("over"), !1; }.bind(this), !1), e.addEventListener("dragenter", function(t) { return e.classList.add("over"), !1; }.bind(this), !1), e.addEventListener("dragleave", function(t) { return e.classList.remove("over"), !1; }, !1), e.addEventListener("drop", function(e) { e.stopPropagation(), e.preventDefault(), $(e.currentTarget).find(".over").removeClass("over"), $(e.currentTarget).find(".dragging").removeClass("dragging"); var t = this.vm.$root[i].bind(this.vm.$root); if (this._scope) var a = this._scope[r]; else var a = this.vm[r]; return t(e, a), !1; }.bind(this), !1); } }), Vue.directive("sd-fader", { bind: function(i) { function r(e, t, a) { return Math.max(t, Math.min(a, e)); } var n = this.vm.$root; this.fader_state = "idle", this.fader_mx = 0, this.fader_my = 0; var o = $(this.el), d = o.find(".fader-selector"), s = o.find(".fader-indicator"), c = o.find(".fader-constraint"); c.length || (c = o); var u = o.attr("sd-fader-var-x"), l = o.attr("sd-fader-var-y"), p = 0, f = 0, m = 0, v = 0, _ = 0, h = 0; g && (h = n.$get(u)); var y = 0; b && (y = n.$get(l)); var g = !!u, b = !!l, w = !d[0], L = parseFloat(o.attr("sd-fader-step")) || 1, E = parseFloat(o.attr("sd-fader-sens")) || 1, x = function() { f = parseInt(o.attr("sd-fader-min-x")) || 0, m = parseInt(o.attr("sd-fader-min-y")) || 0, v = parseInt(o.attr("sd-fader-max-x")) || c.width() - 1, _ = parseInt(o.attr("sd-fader-max-y")) || c.height() - 1; }, T = function() { x(), h && !isNaN(h) || (h = 0), y && !isNaN(y) || (y = 0), d[0] && (g && (d[0].style.left = h + "px"), b && (d[0].style.top = _ - y + "px")), s[0] && (s[0].style.height = y + "px"); }.bind(this), q = function(e, t) { x(), g && (h = r(e, f, v), n.$set(u, h)), b && (y = r(t, m, _), L < 1 && (y = y.toFixed(1)), n.$set(l, y)); }.bind(this), S = function(e) { e = fixup_touches(e); var t = parseInt((e.pageX - this.fader_mx) * E), a = parseInt((e.pageY - this.fader_my) * E); t *= L, a *= L, q(this.fader_oldx + t, this.fader_oldy - a); }.bind(this), A = function(e) { this.fader_state = "idle", $("body").off(t, S), $("body").off("mouseleave " + a + " blur", A), window._sd_fader_moving = !1; }.bind(this); o.on(e, function(e) { e.preventDefault(), e.stopPropagation(), e = fixup_touches(e); var i = $(e.target).offset(); this.fader_state = "drag", w || q(e.pageX - i.left, _ - (e.pageY - i.top) + p / 2), b && (y = n.$get(l)), $("body").on(t, S), $("body").on("mouseleave " + a + " blur", A), this.fader_mx = e.pageX, this.fader_my = e.pageY, this.fader_oldx = h || 0, this.fader_oldy = y || 0, window._sd_fader_moving = !0; }.bind(this)), T(), g && n.$watch(u, function(e) { h = parseInt(n.$get(u)), T(); }), b && n.$watch(l, function(e) { y = parseInt(n.$get(l)), T(); }); }, unbind: function() { var e = (this.vm.$root, $(this.el)); e.attr("sd-fader-var-x"), e.attr("sd-fader-var-y"); } }); } function boot_spacedeck() { console.log("booting..."), setup_directives(), setup_whiteboard_directives(), setup_exclusive_audio_video_playback(); var data = { active_view: null, online: !0, was_offline: !1, account: "profile", logged_in: !1, guest_nickname: null, user: {}, active_profile: null, active_profile_spaces: [], active_dropdown: "none", creating_user: !1, signup_error: null, login_error: null, password_reset_send: !1, password_reset_error: null, password_reset_email: null, password_reset_confirm_error: null, reset_token: null, global_spinner: !1 }, methods = { activate_dropdown: function(e, t) { return this.active_dropdown == e ? void (this.active_dropdown = "none") : void (this.active_dropdown = e); }, close_dropdown: function(e) { e && $(e.target).parents(".dropdown").length || (this.active_dropdown = "none"); }, translate: function() { return i18n.t(arguments); } }; methods = _.extend(methods, SpacedeckUsers.methods), methods = _.extend(methods, SpacedeckWebsockets.methods), methods = _.extend(methods, SpacedeckSpaces.methods), methods = _.extend(methods, SpacedeckTeams.methods), methods = _.extend(methods, SpacedeckBoardArtifacts), methods = _.extend(methods, SpacedeckFormatting), methods = _.extend(methods, SpacedeckSections.methods), methods = _.extend(methods, SpacedeckAvatars.methods), methods = _.extend(methods, SpacedeckModals.methods), methods = _.extend(methods, SpacedeckAccount.methods), methods = _.extend(methods, SpacedeckRoutes), data = _.extend(data, SpacedeckUsers.data), data = _.extend(data, SpacedeckAccount.data), data = _.extend(data, SpacedeckWebsockets.data), data = _.extend(data, SpacedeckSpaces.data), data = _.extend(data, SpacedeckTeams.data), data = _.extend(data, SpacedeckSections.data), data = _.extend(data, SpacedeckAvatars.data), data = _.extend(data, SpacedeckModals.data), Vue.filter("select", function(array, key, operant, value) { var res = _.filter(array, function(e) { var test = eval(e[key] + " " + operant + " " + value); return test; }); return res; }), Vue.filter("date", function(e, t) { var a = moment(e); return a.format(t).replace("'", "").replace("'", ""); }), Vue.filter("exceptFilter", function(e, t) { var a = _.filter(e, function(e) { return void 0 == e[t]; }); return a; }), Vue.filter("size", function(e) { return e.length; }), Vue.filter("empty?", function(e) { return 0 == e.length; }), Vue.filter("urls_to_links", function(e) { return urls_to_links(e); }), window.spacedeck = new Vue({ el: "body", data: data, methods: methods }); var lang = "en"; window.refreshLocale = function() { spacedeck && spacedeck.user && spacedeck.user.preferences ? lang = spacedeck.user.preferences.language || "en" : window.browser_lang && (lang = window.browser_lang); }, window.refreshLocale(), i18n.init({ lng: lang, resStore: window.locales }, function(e, t) { console.log("i18n initialized: " + lang); }), window.__ = function() { var e = Array.prototype.slice.call(arguments); return e.shift(), window.refreshLocale(), i18n.t(arguments[0], { postProcess: "sprintf", sprintf: e }); }, spacedeck.setup_section_module(), spacedeck.load_user(function() { spacedeck.route(); }, function() { spacedeck.route(); }), window.addEventListener("paste", function(e) { "INPUT" == e.target.nodeName || "TEXTAREA" == e.target.nodeName && "clipboard-ta" != e.target.id || e.target.contenteditable || spacedeck.active_space && spacedeck.handle_section_paste(e); }); } $(document).ready(function() { window.smoke = smoke, window.alert = smoke.alert, FastClick.attach(document.body), boot_spacedeck(); });