2
ajaxterm.Terminal_ctor=function(id,width,height) {
4
if(window.ActiveXObject)
7
var query0="s="+sid+"&w="+width+"&h="+height;
8
var query1=query0+"&c=1&k=";
16
var div=document.getElementById(id);
17
var dstat=document.createElement('pre');
18
var sled=document.createElement('span');
19
var opt_get=document.createElement('a');
20
var opt_color=document.createElement('a');
21
var opt_paste=document.createElement('a');
22
var sdebug=document.createElement('span');
23
var dterm=document.createElement('div');
30
debug("Connection lost timeout ts:"+((new Date).getTime()));
32
function opt_add(opt,name) {
34
opt.innerHTML=' '+name+' ';
35
dstat.appendChild(opt);
36
dstat.appendChild(document.createTextNode(' '));
38
function do_get(event) {
39
opt_get.className=(opt_get.className=='off')?'on':'off';
40
debug('GET '+opt_get.className);
42
function do_color(event) {
43
var o=opt_color.className=(opt_color.className=='off')?'on':'off';
45
query1=query0+"&c=1&k=";
48
debug('Color '+opt_color.className);
50
function mozilla_clipboard() {
53
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
55
debug('Access denied, <a href="http://kb.mozillazine.org/Granting_JavaScript_access_to_the_clipboard" target="_blank">more info</a>');
58
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
59
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
60
if (!clip || !trans) {
63
trans.addDataFlavor("text/unicode");
64
clip.getData(trans,clip.kGlobalClipboard);
66
var strLength=new Object();
68
trans.getTransferData("text/unicode",str,strLength);
73
str=str.value.QueryInterface(Components.interfaces.nsISupportsString);
76
return str.data.substring(0,strLength.value / 2);
81
function do_paste(event) {
83
if (window.clipboardData) {
84
p=window.clipboardData.getData("Text");
85
} else if(window.netscape) {
86
p=mozilla_clipboard();
90
queue(encodeURIComponent(p));
95
// debug("ts: "+((new Date).getTime())+" rmax:"+rmax);
99
var r=new XMLHttpRequest();
101
while(keybuf.length>0) {
104
var query=query1+send;
105
if(opt_get.className=='on') {
106
r.open("GET","u?"+query,true);
108
r.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
111
r.open("POST","u",true);
113
r.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
114
r.onreadystatechange = function () {
115
// debug("xhr:"+((new Date).getTime())+" state:"+r.readyState+" status:"+r.status+" statusText:"+r.statusText);
116
if (r.readyState==4) {
118
window.clearTimeout(error_timeout);
119
de=r.responseXML.documentElement;
120
if(de.tagName=="pre") {
122
Sarissa.updateContentFromNode(de, dterm);
124
Sarissa.updateContentFromNode(de, dterm);
125
// old=div.firstChild;
126
// div.replaceChild(de,old);
135
sled.className='off';
136
timeout=window.setTimeout(update,rmax);
138
debug("Connection error status:"+r.status);
142
error_timeout=window.setTimeout(error,5000);
143
if(opt_get.className=='on') {
153
window.clearTimeout(timeout);
154
timeout=window.setTimeout(update,1);
157
function keypress(ev) {
158
if (!ev) var ev=window.event;
159
// s="kp keyCode="+ev.keyCode+" which="+ev.which+" shiftKey="+ev.shiftKey+" ctrlKey="+ev.ctrlKey+" altKey="+ev.altKey;
162
// else { if (!ev.ctrlKey || ev.keyCode==17) { return; }
170
if (kc>=65 && kc<=90)
172
if (kc>=97 && kc<=122) {
173
k=String.fromCharCode(27)+String.fromCharCode(kc);
175
} else if (ev.ctrlKey) {
176
if (kc>=65 && kc<=90) k=String.fromCharCode(kc-64); // Ctrl-A..Z
177
else if (kc>=97 && kc<=122) k=String.fromCharCode(kc-96); // Ctrl-A..Z
178
else if (kc==54) k=String.fromCharCode(30); // Ctrl-^
179
else if (kc==109) k=String.fromCharCode(31); // Ctrl-_
180
else if (kc==219) k=String.fromCharCode(27); // Ctrl-[
181
else if (kc==220) k=String.fromCharCode(28); // Ctrl-\
182
else if (kc==221) k=String.fromCharCode(29); // Ctrl-]
183
else if (kc==219) k=String.fromCharCode(29); // Ctrl-]
184
else if (kc==219) k=String.fromCharCode(0); // Ctrl-@
185
} else if (ev.which==0) {
186
if (kc==9) k=String.fromCharCode(9); // Tab
187
else if (kc==8) k=String.fromCharCode(127); // Backspace
188
else if (kc==27) k=String.fromCharCode(27); // Escape
190
if (kc==33) k="[5~"; // PgUp
191
else if (kc==34) k="[6~"; // PgDn
192
else if (kc==35) k="[4~"; // End
193
else if (kc==36) k="[1~"; // Home
194
else if (kc==37) k="[D"; // Left
195
else if (kc==38) k="[A"; // Up
196
else if (kc==39) k="[C"; // Right
197
else if (kc==40) k="[B"; // Down
198
else if (kc==45) k="[2~"; // Ins
199
else if (kc==46) k="[3~"; // Del
200
else if (kc==112) k="[[A"; // F1
201
else if (kc==113) k="[[B"; // F2
202
else if (kc==114) k="[[C"; // F3
203
else if (kc==115) k="[[D"; // F4
204
else if (kc==116) k="[[E"; // F5
205
else if (kc==117) k="[17~"; // F6
206
else if (kc==118) k="[18~"; // F7
207
else if (kc==119) k="[19~"; // F8
208
else if (kc==120) k="[20~"; // F9
209
else if (kc==121) k="[21~"; // F10
210
else if (kc==122) k="[23~"; // F11
211
else if (kc==123) k="[24~"; // F12
213
k=String.fromCharCode(27)+k;
218
k=String.fromCharCode(127); // Backspace
220
k=String.fromCharCode(kc);
223
// queue(encodeURIComponent(k));
230
ev.cancelBubble=true;
231
if (ev.stopPropagation) ev.stopPropagation();
232
if (ev.preventDefault) ev.preventDefault();
235
function keydown(ev) {
236
if (!ev) var ev=window.event;
238
// s="kd keyCode="+ev.keyCode+" which="+ev.which+" shiftKey="+ev.shiftKey+" ctrlKey="+ev.ctrlKey+" altKey="+ev.altKey;
240
o={9:1,8:1,27:1,33:1,34:1,35:1,36:1,37:1,38:1,39:1,40:1,45:1,46:1,112:1,
241
113:1,114:1,115:1,116:1,117:1,118:1,119:1,120:1,121:1,122:1,123:1};
242
if (o[ev.keyCode] || ev.ctrlKey || ev.altKey) {
249
sled.appendChild(document.createTextNode('\xb7'));
250
sled.className='off';
251
dstat.appendChild(sled);
252
dstat.appendChild(document.createTextNode(' '));
253
opt_add(opt_color,'Colors');
254
opt_color.className='on';
255
opt_add(opt_get,'GET');
256
opt_add(opt_paste,'Paste');
257
dstat.appendChild(sdebug);
258
dstat.className='stat';
259
div.appendChild(dstat);
260
div.appendChild(dterm);
261
if(opt_color.addEventListener) {
262
opt_get.addEventListener('click',do_get,true);
263
opt_color.addEventListener('click',do_color,true);
264
opt_paste.addEventListener('click',do_paste,true);
266
opt_get.attachEvent("onclick", do_get);
267
opt_color.attachEvent("onclick", do_color);
268
opt_paste.attachEvent("onclick", do_paste);
270
document.onkeypress=keypress;
271
document.onkeydown=keydown;
272
timeout=window.setTimeout(update,100);
276
ajaxterm.Terminal=function(id,width,height) {
277
return new this.Terminal_ctor(id,width,height);