From a772c692a0229a41943c27dd156cba8e81d301a1 Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 12 Apr 2014 13:05:47 +0100 Subject: [PATCH] Changed inputbox to make POST request without reloading the page --- lovebird.lua | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lovebird.lua b/lovebird.lua index e482ca5..2e3cc88 100644 --- a/lovebird.lua +++ b/lovebird.lua @@ -145,7 +145,7 @@ end
-
+
@@ -167,7 +167,7 @@ end return false; } - var getPage = function(url, onComplete, onFail) { + var geturl = function(url, onComplete, onFail) { var req = new XMLHttpRequest(); req.onreadystatechange = function() { if (req.readyState != 4) return; @@ -182,19 +182,22 @@ end req.send(); } - /* Scroll output to bottom */ - var scrolloutput = function() { - var div = document.getElementById("output"); - div.scrollTop = div.scrollHeight; + var onInputSubmit = function() { + var b = document.getElementById("inputbox"); + var req = new XMLHttpRequest(); + req.open("POST", "/", true); + req.send("input=" + encodeURIComponent(b.value)); + b.value = ""; + refreshOutput(); } - scrolloutput() /* Output buffer and status */ var refreshOutput = function() { - getPage("/buffer", function(text) { + geturl("/buffer", function(text) { updateDivContent("status", "connected ●"); if (updateDivContent("output", text)) { - scrolloutput(); + var div = document.getElementById("output"); + div.scrollTop = div.scrollHeight; } }, function(text) { @@ -206,7 +209,7 @@ end /* Environment variable view */ var envPath = ""; var refreshEnv = function() { - getPage("/env.json?p=" + envPath, function(text) { + geturl("/env.json?p=" + envPath, function(text) { var json = eval("(" + text + ")"); /* Header */