11
function historyDown()
13
if (this.cursor < this.items.length)
19
function historyCurr()
21
if (this.cursor < 0 || this.cursor >= this.items.length)
25
return this.items[this.cursor];
28
function historyAdd(text)
30
this.items[this.items.length] = text;
31
this.cursor = this.items.length
34
function historyShow()
37
if (this.cursor == -1)
41
for (var i = 0; i < this.items.length; i++)
47
res += this.items[i].toString();
54
if (this.cursor == this.items.length)
63
this.items = new Array();
66
this.down = historyDown;
67
this.curr = historyCurr;
68
this.add = historyAdd;
69
this.show = historyShow;
72
var hist = new History();
74
function make_query_string(pagename, args)
81
// vals can be an array, to make multiple args with the same name
82
// To handle this, make non-array objects into an array, then loop
83
if (!(vals instanceof Array))
85
for each (val in vals)
96
qs += encodeURI(key) + "=" + encodeURI(val);
102
function make_post_body(args)
109
// vals can be an array, to make multiple args with the same name
110
// To handle this, make non-array objects into an array, then loop
111
if (!(vals instanceof Array))
113
for each (val in vals)
123
qs += encodeURI(key) + "=" + encodeURI(val);
129
function enter_line()
131
var inp = document.getElementById('inputText');
132
var digest = hex_md5(inp.value + magic);
133
var xmlhttp = new XMLHttpRequest();
135
xmlhttp.open("POST", "chat", false);
136
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
137
xmlhttp.send(make_post_body({"digest":digest, "text":inp.value}))
138
var res = JSON.parse(xmlhttp.responseText);
139
var output = document.getElementById("output")
141
var pre = document.createElement("pre");
142
pre.setAttribute("class", "inputMsg");
143
pre.appendChild(document.createTextNode(inp.value + "\n"));
144
output.appendChild(pre);
149
// print out the output (res[0])
150
var pre = document.createElement("pre");
151
pre.setAttribute("class", "outputMsg");
152
pre.appendChild(document.createTextNode(res[0]));
153
output.appendChild(pre);
154
// print out the return value (res[1])
157
var pre = document.createElement("pre");
158
pre.setAttribute("class", "outputMsg");
159
pre.appendChild(document.createTextNode(res[1] + "\n"));
160
output.appendChild(pre);
162
// set the prompt to >>>
163
var prompt = document.getElementById("prompt");
164
prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
169
// print out the error message (res[2])
170
var pre = document.createElement("pre");
171
pre.setAttribute("class", "errorMsg");
172
pre.appendChild(document.createTextNode(res[2]));
173
output.appendChild(pre);
177
// Need more input, so set the prompt to ...
178
var prompt = document.getElementById("prompt");
179
prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
183
function catch_input(key)
185
var inp = document.getElementById('inputText');
190
inp.value = hist.curr();
195
inp.value = hist.curr();
200
inp.value = hist.curr();