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 += "