var BufferedTimer = (function () { function BufferedTimer(id, context, event, timeout) { this.Timer = null; this.Event = event; this.TimeOut = timeout; this.Context = context; } BufferedTimer.prototype.Tick = function () { this.proxy(this.Event, this.Context)(); }; BufferedTimer.prototype.Update = function () { this.Stop(); this.Timer = setTimeout(this.proxy(this.Tick, this), this.TimeOut); }; BufferedTimer.prototype.Stop = function () { if (this.Timer != null) { window.clearTimeout(this.Timer); this.Timer = null; } }; BufferedTimer.prototype.proxy = function (func, obj) { if (typeof (func) != "function") return; if (!obj) obj = this; return function () { return func.apply(obj, arguments); }; }; return BufferedTimer; }()); var CodeEditor; (function (CodeEditor) { var EditorMonaco = (function () { function EditorMonaco() { this.valueToSet = ""; this.editorLoadedEvent = null; this.valueChangedEvent = null; this.saveEvent = null; } EditorMonaco.prototype.init = function (parent, readOnly) { var _this = this; var language = "cpp"; require.config({ "paths": { 'vs': '../Scripts/vseditor' } }); require(["vs/editor/editor.main"], function (a) { _this.edt = monaco.editor.create(parent, { "value": _this.valueToSet, "language": language, "folding": true, "suggestOnTriggerCharacters": true, "readOnly": readOnly, "mouseWheelZoom": true, "automaticLayout": true, "autoIndent": true, "formatOnType": true, "formatOnPaste": true, "dragAndDrop": true, "showFoldingControls": "always", "renderIndentGuides": true, "matchBrackets": true }); if (EditorMonaco.FirstLoad) { EditorMonaco.FirstLoad = false; } _this.edt.onDidChangeModelContent(function (e) { if (!e["isUndoing"] && !e["isRedoing"] && !e["isFlush"]) { if (e["changes"] != null && e["changes"]["length"] == 1) { } } if (_this.valueChangedEvent) { _this.valueChangedEvent(); } }); if (_this.editorLoadedEvent) { _this.editorLoadedEvent(); } }); }; EditorMonaco.prototype.setValue = function (value) { if (this.edt == null) { this.valueToSet = value; } else { this.edt.setValue(value); } }; EditorMonaco.prototype.getValue = function () { return this.edt.getValue(); }; EditorMonaco.prototype.saveViewState = function () { this.viewState = this.edt.saveViewState(); }; EditorMonaco.prototype.restoreViewState = function () { this.edt.restoreViewState(this.viewState); }; EditorMonaco.FirstLoad = true; return EditorMonaco; }()); CodeEditor.EditorMonaco = EditorMonaco; })(CodeEditor || (CodeEditor = {})); var HTML = (function () { function HTML() { } HTML.CreateButton = function (caption, parent, clicked) { var inp = document.createElement("input"); inp.type = "button"; inp.value = caption; inp.onclick = clicked; inp.style.margin = "5px 5px 5px 5px"; inp.style.padding = "5px 5px 5px 5px"; if (parent != null) { parent.appendChild(inp); } return inp; }; HTML.CreateDiv = function (parent, classes) { if (classes === void 0) { classes = null; } var div = document.createElement("div"); if (parent != null) { parent.appendChild(div); } if (classes != null) { for (var i = 0; i < classes.length; i++) { div.classList.add(classes[i]); } } return div; }; HTML.CreateInputBox = function (caption, parent, clicked) { var div = HTML.CreateDiv(parent); div.style.width = "100%"; div.style.margin = "5px 5px 5px 5px"; div.innerHTML = caption + "
"; var inp = document.createElement("input"); inp.type = "text"; inp.onclick = clicked; inp.style.padding = "5px 5px 5px 5px"; div.appendChild(inp); return inp; }; HTML.CreateDialog = function (titleS) { var modal = HTML.CreateDiv(document.body, ["modal"]); var dialog = HTML.CreateDiv(modal, ["modal-dialog"]); var content = HTML.CreateDiv(dialog, ["modal-content"]); var header = HTML.CreateDiv(content, ["modal-header"]); var title = document.createElement("h5"); title.innerHTML = titleS; title.classList.add("modal-title"); header.appendChild(title); var closeBtn = document.createElement("button"); closeBtn.classList.add("close"); header.appendChild(closeBtn); var closeIcon = document.createElement("span"); title.innerHTML = "×"; closeBtn.appendChild(closeIcon); var body = HTML.CreateDiv(content, ["modal-body"]); var footer = HTML.CreateDiv(content, ["modal-footer"]); var closeBtn2 = document.createElement("button"); closeBtn2.classList.add("btn"); closeBtn2.classList.add("btn-primary"); footer.appendChild(closeBtn2); $(modal).modal(); return { body: body }; }; HTML.CreateBtn = function (icon, caption, parent, top, left, clicked) { var btn = document.createElement("button"); btn.type = "button"; btn.classList.add("btn"); btn.classList.add("btn-warning"); btn.onclick = function () { if (clicked) { clicked(); } }; btn.style.zIndex = "10"; btn.style.position = "absolute"; btn.style.top = top + "px"; btn.style.left = left + "px"; btn.innerHTML = caption; parent.appendChild(btn); return btn; }; return HTML; }()); var cpp = (function () { function cpp() { } cpp.FullScreen = function () { var el = document.documentElement; var requestMethod = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen; requestMethod.call(el); document.body.style.overflow = "hidden"; }; cpp.GUID = function (prefix) { if (prefix === void 0) { prefix = "objid"; } return prefix.concat(Math.random().toString(36).substring(2, 15), Math.random().toString(36).substring(2, 15)); }; Object.defineProperty(cpp, "client", { get: function () { var client = localStorage.getItem("cl"); if (client != null) { return client; } client = cpp.GUID("cl"); localStorage.setItem("cl", client); return client; }, enumerable: true, configurable: true }); Object.defineProperty(cpp, "browser", { get: function () { var ret = []; for (var property in navigator) { var str = navigator[property]; if (str instanceof Function) { continue; } if (str instanceof Object) { continue; } ret.push(property + ":" + str); } return ret.join("|"); }, enumerable: true, configurable: true }); cpp.GetQueryString = function () { if (cpp.QueryString == null) { cpp.QueryString = {}; var hashFragment = window.location.search; if (hashFragment) { var paramStrs = hashFragment.slice(1).split("&"); for (var i = 0; i < paramStrs.length; i++) { var paramStr = paramStrs[i].split("="); cpp.QueryString[paramStr[0]] = decodeURIComponent(paramStr[1]); } } } return cpp.QueryString; }; cpp.RunApp = function () { document.body.style.textAlign = "center"; if (cpp.GetQueryString()["action"] == "view" || cpp.GetQueryString()["action"] == "viewsnap") { cpp.email = cpp.GetQueryString()["email"]; cpp.code = cpp.GetQueryString()["code"]; var client = cpp.GetQueryString()["client"]; cpp.firstname = cpp.GetQueryString()["firstname"]; cpp.lastname = cpp.GetQueryString()["lastname"]; cpp.HttpPost("data", { "action": cpp.GetQueryString()["action"], "email": cpp.email, "code": cpp.code, "client": client, "firstname": cpp.firstname, "lastname": cpp.lastname }, function (resp) { document.body.innerHTML = ""; var args = resp.split(cpp.DEL); if (args[0] != "OK") { alert(resp); return; } cpp.seat = parseInt(args[1]); var data = args[2]; cpp.ShowEditor(data, true); var user = HTML.CreateDiv(document.body); user.style.position = "absolute"; user.style.right = "30px"; user.style.top = "-17px"; user.style.fontSize = "48px"; user.style.fontWeight = "700"; user.style.zIndex = "100"; user.style.pointerEvents = "none"; user.style.color = "white"; user.innerHTML = cpp.firstname + " " + cpp.lastname + " [ " + cpp.code + " ]"; }); return; } var ifirstName = HTML.CreateInputBox("your first name", document.body, null); var ilastName = HTML.CreateInputBox("your last name", document.body, null); var iemail = HTML.CreateInputBox("your email address", document.body, null); var icode = HTML.CreateInputBox("provided exam code", document.body, null); var eemail = localStorage.getItem("email"); if (eemail != null) { iemail.value = eemail; } var ecode = localStorage.getItem("code"); if (ecode != null) { icode.value = ecode; } var efirstname = localStorage.getItem("firstname"); if (efirstname != null) { ifirstName.value = efirstname; } var elastname = localStorage.getItem("lastname"); if (elastname != null) { ilastName.value = elastname; } HTML.CreateButton("Start Your Session", document.body, function () { cpp.email = iemail.value; cpp.code = icode.value; cpp.firstname = ifirstName.value; cpp.lastname = ilastName.value; var msg = "Please confirm (double check) the information below: \n\nFirst Name: " + cpp.firstname + "\nLast Name: " + cpp.lastname + "\nYour Email: " + cpp.email + "\nExam Code: " + cpp.code + "\n\n Is this correct?"; if (!confirm(msg)) { return; } cpp.FullScreen(); localStorage.setItem("email", cpp.email); localStorage.setItem("code", cpp.code); localStorage.setItem("firstname", cpp.firstname); localStorage.setItem("lastname", cpp.lastname); document.body.innerHTML = "connecting... please wait..."; cpp.HttpPost("data", { "action": "init", "email": cpp.email, "code": cpp.code, "client": cpp.client, "browser": cpp.browser, "firstname": cpp.firstname, "lastname": cpp.lastname }, function (resp) { document.body.innerHTML = ""; var args = resp.split(cpp.DEL); if (args[0] != "OK") { alert(resp); return; } cpp.seat = parseInt(args[1]); var data = args[2]; cpp.ShowEditor(data); var seat = HTML.CreateDiv(document.body); seat.style.position = "absolute"; seat.style.right = "40px"; seat.style.top = "-105px"; seat.style.fontSize = "360px"; seat.style.fontWeight = "700"; seat.style.zIndex = "100"; seat.style.pointerEvents = "none"; seat.innerHTML = cpp.seat.toString(); var user = HTML.CreateDiv(document.body); user.style.position = "absolute"; user.style.right = "30px"; user.style.top = "-17px"; user.style.fontSize = "48px"; user.style.fontWeight = "700"; user.style.zIndex = "100"; user.style.pointerEvents = "none"; user.style.color = "white"; user.innerHTML = cpp.firstname + " " + cpp.lastname + " [ " + cpp.code + " ]"; }); }); }; cpp.HttpPost = function (url, params, asyncEvent, error, reqType, noProxy) { if (error === void 0) { error = null; } if (reqType === void 0) { reqType = "POST"; } if (noProxy === void 0) { noProxy = false; } url = "https://baruch-221323.appspot.com/" + url; var ret = $.ajax({ type: reqType, url: url, data: params, async: (asyncEvent != null), dataType: "text", error: function (jqXHR, textStatus, errorThrown) { var message = "

I had trouble communicating with the remote server. The details of the error can be found below.

"; message += ""; if (error != null) { error(message); } else { alert(message); } }, success: function (result) { if (asyncEvent != null) { asyncEvent(result); } } }).responseText; return ret; }; cpp.ShowEditor = function (code, viewOnly) { var _this = this; if (viewOnly === void 0) { viewOnly = false; } var body = document.body; body.style.backgroundColor = "#a50000"; var parent1 = document.createElement("div"); parent1.style.position = "absolute"; parent1.style.top = "50px"; parent1.style.left = "20px"; parent1.style.right = "20px"; parent1.style.bottom = "20px"; parent1.style.backgroundColor = "white"; parent1.style.borderRadius = "15px"; parent1.style.textAlign = "left"; body.appendChild(parent1); var parent = document.createElement("div"); parent.style.position = "absolute"; parent.style.top = "10px"; parent.style.left = "10px"; parent.style.right = "10px"; parent.style.bottom = "10px"; parent.style.backgroundColor = "white"; parent1.appendChild(parent); this.editor = new CodeEditor.EditorMonaco(); this.editor.init(parent, viewOnly); this.editor.editorLoadedEvent = function () { }; var log = document.createElement("div"); log.style.position = "absolute"; log.style.overflow = "hidden"; log.style.paddingTop = "10px"; log.style.paddingLeft = "10px"; log.style.bottom = "0px"; log.style.left = "0px"; log.style.right = "15px"; log.style.height = "50%"; log.style.backgroundColor = "#d2dbf3"; log.style.zIndex = "100"; log.innerHTML = "
Output Window
"; $(log).hide(); parent.appendChild(log); var logC = HTML.CreateDiv(log); logC.style.position = "absolute"; logC.style.overflow = "auto"; logC.style.left = "10px"; logC.style.right = "10px"; logC.style.top = "50px"; logC.style.bottom = "10px"; HTML.CreateBtn("fa-times", "Close", log, 5, 170, function () { $(log).hide(); }); HTML.CreateBtn("fa-play", "Test", document.body, 5, 200, function () { logC.innerHTML = ""; var code = _this.editor.getValue(); var input = "2\n3\n1\n5\n6\n1\n6\n4\n1\n7\n3\n1\n2\n8\n1\n5\n5\n1\n2\n4\n2\n3\n0"; var config = { stdio: { write: function (s) { s = s.replace("\n", "
"); logC.innerHTML += s; $(log).show(); } } }; try { var exitcode = JSCPP.run(code, input, config); logC.innerHTML += "
end of program (" + exitcode + ")" + "
"; $(log).show(); cpp.HttpPost("data", { "action": "test", "email": cpp.email, "code": cpp.code, "client": cpp.client, "browser": cpp.browser, "firstname": cpp.firstname, "lastname": cpp.lastname, "data": logC.innerHTML }, function (resp) { }); } catch (e) { logC.innerHTML += "
> " + e + "
"; $(log).show(); } }); if (!viewOnly) { HTML.CreateBtn("fa-desktop", "Full Screen", document.body, 5, 20, function () { cpp.FullScreen(); }); HTML.CreateBtn("fa-floppy-o", "Save", document.body, 5, 130, function () { save(); }); } var save = function () { if (viewOnly) { return; } var data = _this.editor.getValue(); cpp.HttpPost("data", { "action": "save", "email": cpp.email, "code": cpp.code, "client": cpp.client, "browser": cpp.browser, "firstname": cpp.firstname, "lastname": cpp.lastname, "data": data }, function (resp) { var args = resp.split(cpp.DEL); if (args[0] != "OK") { alert(resp); return; } }); }; this.editor.valueChangedEvent = function () { if (cpp.timer == null) { cpp.timer = new BufferedTimer("n1", _this, function () { save(); }, 2000); } cpp.timer.Update(); }; this.editor.saveEvent = function () { }; this.editor.setValue(code); }; cpp.editor = null; cpp.DEL = "._DEL_."; cpp.QueryString = null; cpp.timer = null; cpp.testtimer = null; return cpp; }()); window["RunApp"] = cpp.RunApp; //# sourceMappingURL=cpp.js.map