Remove use of jquery and fix some bugs.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3200 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2016-04-11 15:54:26 +00:00
parent 577606a0f9
commit d82fc5cc85
8 changed files with 61 additions and 36 deletions

View File

@ -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);

View File

@ -21,7 +21,6 @@
<button onclick="addLicense()"><img src="/terminal/agplv3-88x31.png" width="34" height="12"> Add License Header</button>
</div>
<textarea id="editor" class="main">$(SOURCE)</textarea>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="/terminal/editor.js"></script>
</div>
</body>

View File

@ -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() {

View File

@ -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);

View File

@ -25,7 +25,6 @@
<span id="prompt">&gt;</span>
<input type='text' id='input'></input>
</div>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="/terminal/client.js"></script>
</div>
</body>

View File

@ -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);

View File

@ -123,7 +123,6 @@ function editPage(event) {
</html>`, 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,

View File

@ -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");