diff --git a/core/client.js b/core/client.js index 1c6b6e9e..1e05ba48 100644 --- a/core/client.js +++ b/core/client.js @@ -34,13 +34,14 @@ function enter(event) { && !event.altKey && !event.ctrlKey && !event.shiftKey) { - var value = $("#input").val(); + var input = document.getElementById("input"); + var value = input.value; if (value && value[value.length - 1] == '\\') { - $("#input").val(value.substring(0, value.length - 1) + ";"); + input.value = value.substring(0, value.length - 1) + ";"; event.preventDefault(); } else { storeTarget(value); - $("#input").val(""); + input.value = ""; event.preventDefault(); } } @@ -66,7 +67,7 @@ function hash() { } function storeTarget(target) { - $("#target").text(target || ""); + document.getElementById("target").innerText = target || ""; } function split(container, children) { @@ -238,7 +239,7 @@ function printStructured(container, data) { function commandClick() { send(this.dataset.command); - $("#input").focus(); + document.getElementById("input").focus(); } function autoScroll(terminal) { @@ -257,10 +258,10 @@ function setErrorMessage(message) { function send(command) { var value = command; if (!command) { - var target = $("#target").text(); + var target = document.getElementById("target").innerText; var prefix = target ? target + " " : ""; - value = prefix + $("#input").val(); - $("#input").val(""); + value = prefix + document.getElementById("input").value; + document.getElementById("input").value = ""; } try { gSocket.send(JSON.stringify({action: "command", command: value})); @@ -305,15 +306,16 @@ var gOriginalInput; function dragHover(event) { event.stopPropagation(); event.preventDefault(); + var input = document.getElementById("input"); if (event.type == "dragover") { - if (!$("#input").hasClass("drop")) { - $("#input").addClass("drop"); - gOriginalInput = $("#input").val(); - $("#input").val("drop file to upload"); + if (!input.classList.contains("drop")) { + input.classList.add("drop"); + gOriginalInput = input.value; + input.value = "drop file to upload"; } } else { - $("#input").removeClass("drop"); - $("#input").val(gOriginalInput); + input.classList.remove("drop"); + input.value = gOriginalInput; } } @@ -411,12 +413,13 @@ function onMessage(event) { var gSocket; -$(document).ready(function() { +window.addEventListener("load", function() { if (Notification) { Notification.requestPermission(); } - $("#input").keydown(enter); - $("#input").focus(); + var input = document.getElementById("input"); + input.addEventListener("keydown", enter); + input.focus(); window.addEventListener("hashchange", hashChange); window.addEventListener("focus", focus); window.addEventListener("blur", blur); diff --git a/core/edit.html b/core/edit.html index 8b4879e5..1b77cd8c 100644 --- a/core/edit.html +++ b/core/edit.html @@ -21,7 +21,6 @@ - diff --git a/core/editor.js b/core/editor.js index 8bd0dfa5..2ed622a8 100644 --- a/core/editor.js +++ b/core/editor.js @@ -1,7 +1,7 @@ var gBackup; var gEditor; -$(document).ready(function() { +window.addEventListener("load", function() { gEditor = CodeMirror.fromTextArea(document.getElementById("editor"), { 'theme': 'base16-dark', 'lineNumbers': true, @@ -40,22 +40,39 @@ function save(newName) { var contents = gEditor.getValue(); var run = document.getElementById("run").checked; - return $.ajax({ - type: "POST", - url: newName ? "../" + newName + "/save" : "save", - data: contents, - dataType: "text", - }).done(function(uri) { - gBackup = contents; - if (run) { - back(uri); - } - }).fail(function(xhr, status, error) { - alert("Unable to save: " + xhr.responseText); - }).always(function() { + var request = new XMLHttpRequest(); + + var always = function() { document.getElementById("save").disabled = false; document.getElementById("saveAs").disabled = false; + }; + + request.addEventListener("error", function() { + alert("Error saving: " + request.responseText); + always(); }); + request.addEventListener("loadend", function() { + if (request.status == 200) { + gBackup = contents; + if (run) { + back(request.responseText); + } + } else { + alert("Unable to save: " + request.responseText); + } + always(); + }); + request.addEventListener("timeout", function() { + alert("Timed out saving: " + request.responseText); + always(); + }); + request.addEventListener("abort", function() { + alert("Save aborted: " + request.responseText); + always(); + }); + request.open("POST", newName ? "../" + newName + "/save" : "save", true); + request.setRequestHeader("Content-Type", "text/plain"); + request.send(contents); } function saveAs() { diff --git a/core/httpd.js b/core/httpd.js index b9c9c825..9d13c3f4 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -361,7 +361,9 @@ function handleConnection(client) { lineByLine = false; body = ""; return true; - } else if (headers["connection"].toLowerCase().split(",").map(x => x.trim()).indexOf("upgrade") != -1 + } else if (headers["connection"] + && headers["connection"].toLowerCase().split(",").map(x => x.trim()).indexOf("upgrade") != -1 + && headers["upgrade"] && headers["upgrade"].toLowerCase() == "websocket") { var requestObject = new Request(request[0], request[1], request[2], headers, body, client); var response = new Response(requestObject, client); diff --git a/core/index.html b/core/index.html index 63ce3b6f..7b1982d2 100644 --- a/core/index.html +++ b/core/index.html @@ -25,7 +25,6 @@ > - diff --git a/packages/cory/documentation/documentation.js b/packages/cory/documentation/documentation.js index 2e4df34d..a8b891f1 100644 --- a/packages/cory/documentation/documentation.js +++ b/packages/cory/documentation/documentation.js @@ -7,6 +7,8 @@ let kDocumentation = { "core.getUser": ["", "Gets information about the current user."], "core.getUsers": ["packageOwner, packageName", "Get a list of all online users, restricted to a package if specified."], "core.register": ["eventName, handlerFunction", "Register a callback function for the given event."], + "core.unregister": ["eventName, handlerFunction", "Unregister a callback function for the given event."], + "core.user.postMessage": ["message", "Send a message to the process for the given user session."], "database.get": ["key", "Retrieve the database value associated with the given key."], "database.set": ["key, value", "Sets the database value for the given key, overwriting any existing value."], "database.getAll": ["", "Retrieve a list of all key names."], @@ -25,6 +27,10 @@ let kDocumentation = { "terminal.setHash": ["hash", "Sets the URL #hash, typically so that the user can copy / bookmark it and return to a similar state."], "terminal.postMessageToIframe": ["name, message", "Sends the message to the iframe that was created with the given name using window.postMessage."], "terminal.notify": ["body, {title, icon}", ["Produces an ", {href: "https://developer.mozilla.org/en-US/docs/Web/API/notification", value: "HTML5 Notification"}, ". Arguments are the same as the Notification constructor."]], + "terminal.cork": ["", "Stop sending updates to the terminal until uncork() is called. Can be used to prevent flickering when clearing and redrawing."], + "terminal.uncork": ["", "Resume sending updates to the terminal."], + "terminal.split": ["terminalList", "Reconfigures the terminal layout (often into multiple split panes)."], + "terminal.select": ["name", "Directs subsequent output to the named terminal."], }; terminal.print("V8 Version ", version); diff --git a/packages/cory/wiki/wiki.js b/packages/cory/wiki/wiki.js index 24ff26fb..5b1e9c44 100644 --- a/packages/cory/wiki/wiki.js +++ b/packages/cory/wiki/wiki.js @@ -123,7 +123,6 @@ function editPage(event) { `, name: "iframe", style: "flex: 1 1 auto; border: 0; width: 100%"}); } -// XXX: Why do I need .js? require("ui").fileList({ title: "Live Markdeep Editor", edit: editPage, diff --git a/packages/cory/xmpp/xmpp.js b/packages/cory/xmpp/xmpp.js index a4e990f7..e862347d 100644 --- a/packages/cory/xmpp/xmpp.js +++ b/packages/cory/xmpp/xmpp.js @@ -783,7 +783,7 @@ function schedulePing(socket) { terminal.split([ {type: "horizontal", children: [ {name: "terminal", grow: 1}, - {name: "users", grow: 0}, + {name: "users", basis: "2in", grow: 0, shrink: 0}, ]}, ]); terminal.select("terminal");