// js/uix v0.44
// (c) mass:werk (n.landsteiner) 2003
// all rights reserved
// term gui
var conf_term_x=102;
var conf_term_y=34;
var conf_kbd_offset=34;
var termimgpath='jsuix_support/';
var termdiv='termdiv';
var termbgcolor='#181818';
var termframecolor='#555555';
var termpagecolor='#222222';
var conf_repeat_delay1=320;
var conf_repeat_delay2=170;
var termkbddiv='termkbddiv';
var termkbdbgcolor='#222222';
var keycapspath='jsuix_support/keycaps/';
var termsubdivs=false;
var termlayers=false;
var termdocns4=null;
var termstringstart='';
var termstringend='';
var termkbddocns4=null;
var termkbdon=false;
var keycapsshift=false;
var keycapscpslk=false;
var keycapsshiftref=new array();
var keycapscpslkref=new array();
var termspecials=new array();
termspecials[0]=' ';
termspecials[1]='$';
termspecials[2]=' ';
termspecials[3]='?';
termspecials[4]='#';
termspecials[32]=' ';
termspecials[34]='';
termspecials[38]='&';
termspecials[60]='termspecials[62]='>';
termspecials[127]='◊';
var termstyles=new array(1,2,4,8);
var termstyleopen=new array();
var termstyleclose=new array();
termstyleopen[1]='';
termstyleclose[1]='';
termstyleopen[2]='';
termstyleclose[2]='';
termstyleopen[4]='';
termstyleclose[4]='';
termstyleopen[8]='';
termstyleclose[8]='';
// buttons ui
var termimgnames=new array('left_lo', 'left_hi', 'right_lo', 'right_hi', 'delete_lo', 'delete_hi', 'esc_lo', 'esc_hi', 'kbd_show_lo', 'kbd_show_hi', 'kbd_hide_lo', 'kbd_hide_hi');
var termimages=new array();
function termimgpreload(path,imgnames) {
for (var i=0; i var n=imgnames[i];
termimages[n]=new image();
termimages[n].src=path+n+'.gif'
}
}
if (document.images) termimgpreload(termimgpath,termimgnames);
function termsetimg(n,v) {
if (document.images) {
var img=(termlayers)? termdocns4.images['term_'+n] : document.images['term_'+n];
var stat=(v)? '_hi' : '_lo';
img.src=termimages[n+stat].src
}
}
// ui keyboard
// key maps (200=left shift, 202=right shift, 204=cpslock)
var termkeymap= [
[96,49,50,51,52,53,54,55,56,57,48,45,61,8],
[27,113,119,101,114,116,121,117,105,111,112,91,93,13],
[204,97,115,100,102,103,104,106,107,108,59,39,35],
[200,92,122,120,99,118,98,110,109,44,46,47,30,202],
[32,28,31,29]
];
var termkeymapshift=[
[126,33,34,35,36,37,94,38,42,40,41,95,43,8],
[27,81,87,69,82,84,89,85,73,79,80,123,125,13],
[204,65,83,68,70,71,72,74,75,76,58,34,64],
[200,124,90,88,67,86,66,78,77,60,62,63,30,202],
[32,28,31,29]
];
var termkeymapcpslk=[
[96,49,50,51,52,53,54,55,56,57,48,45,61,8],
[27,81,87,69,82,84,89,85,73,79,80,91,93,13],
[204,65,83,68,70,71,72,74,75,76,59,39,35],
[200,92,90,88,67,86,66,78,77,44,46,47,30,202],
[32,28,31,29]
];
var termkeywdth=[
[35,35,35,35,35,35,35,35,35,35,35,35,35,69],
[55,35,35,35,35,35,35,35,35,35,35,35,35,0],
[65,35,35,35,35,35,35,35,35,35,35,35,35],
[49,35,35,35,35,35,35,35,35,35,35,35,35,54],
[252,35,35,35]
];
var keycapsimgnames=new array(200,201,202,203,204,205);
function termkeycaps(k) {
if ((k=32) && (repeattimer)) cleartimeout(repeattimer);
if (k==204) {
keycapscpslk=(!keycapscpslk);
var cnr=(keycapscpslk)? 205:204;
termkbdsetimg(204,cnr)
}
else if ((k==200) || (k==202)) {
keycapsshift=(!keycapsshift);
var m=(keycapsshift)? 1:0;
termkbdsetimg(200,200+m);
termkbdsetimg(202,202+m)
}
else {
var ch=0;
if (keycapsshift) {
ch=keycapsshiftref[k]
keycapsshift=false;
termkbdsetimg(200,200);
termkbdsetimg(202,202)
}
else if (keycapscpslk) ch=keycapscpslkref[k]
else ch=k;
keyhandler({which:ch,jsuix_remapped:true})
}
}
function termkbdsetimg(n,v) {
if (document.images) {
var img=(termlayers)? termkbddocns4.images['key'+n] : document.images['key'+n];
img.src=termimages[v].src
}
}
function termsetkbdbutton(v) {
if (document.images) {
var img=(termlayers)? termdocns4.images.term_kbd_show : document.images.term_kbd_show;
var n=(termkbdon)? 'kbd_hide' : 'kbd_show';
var stat=(v)? '_hi' : '_lo';
img.src=termimages[n+stat].src
}
}
function termkbdshow() {
if (termkbdon) {
setdivvisibility(termkbddiv,0);
termkbdon=false;
termsetkbdbutton(0)
}
else {
termimgpreload(keycapspath,keycapsimgnames);
keycapsshift=false;
keycapscpslk=false;
var s='\n';
s+='\n';
s+=' '+termmakekbd()+' \n';
s+'\n';
s+='
\n';
s+='';
writeelement(termkbddiv,s);
setdivxy(termkbddiv,conf_term_x,conf_term_y+conf_kbd_offset+conf_rows*conf_rowheigt);
if (termlayers) termkbddocns4=document.layers[termkbddiv].document;
termkbdon=true;
setdivvisibility(termkbddiv,1);
termsetkbdbutton(0)
}
}
function termmakekbd() {
var s='\n';
for (var i=0; i s+='';
for (var k=0; k var kc=termkeymap[i][k];
keycapsshiftref[kc]=termkeymapshift[i][k];
keycapscpslkref[kc]=termkeymapcpslk[i][k];
if (kc==13) {
s+='';
continue
};
if (kc==32) s+=''
else if (kc==28) {
s+='';
s+='';
continue
}
else if (kc==29) {
s+='';
continue
}
else if (kc==8) {
s+='';
continue
}
s+='';
if (kc==35) s+='';
};
s+='\n';
};
s+='';
return s
}
// term ui
function termhide() {
if (repeattimer) cleartimeout(repeattimer);
if (termkbdon) termkbdshow();
setdivvisibility(termdiv,0)
}
function maketerm() {
window.status='building terminal ...';
termlayers=(document.layers)? true:false;
termsubdivs=(navigator.useragent.indexof('gecko') var s='';
s+='\n';
s+='\n';
var rstr='';
for (var c=0; c for (var r=0; r var id=((termlayers) || (termsubdivs))? '' : ' id=term_'+r+'';
s+=''+rstr+'\n';
};
s+='\n';
s+='\n';
s+='
\n\n';
s+='\n';
s+=' \n';
s+='\n';
s+=' \n';
s+=' \n';
s+=' \n';
s+='\n';
s+='\n';
if (termlayers) {
for (var r=0; r s+='\n'
};
termdocns4=document.layers[termdiv].document;
termstringstart='';
termstringend='';
}
else if (termsubdivs) {
for (var r=0; r s+='\n'
};
termstringstart='';
termstringend='';
};
writeelement(termdiv,s);
setdivxy(termdiv,conf_term_x,conf_term_y);
setdivvisibility(termdiv,1);
window.status=''
}
function termdisplay(r) {
var s=termstringstart;
var curstyle=0;
for (var i=0; i var c=term[r][i];
var cs=termstyle[r][i];
if (cs!=curstyle) {
if (curstyle) {
for (var k=termstyles.length-1; k>=0; k--) {
var st=termstyles[k];
if (curstyle&st) s+=termstyleclose[st];
}
};
curstyle=cs;
for (var k=0; k var st=termstyles[k];
if (curstyle&st) s+=termstyleopen[st];
}
};
s+= (termspecials[c])? termspecials[c] : string.fromcharcode(c);
};
if (curstyle>0) {
for (var k=termstyles.length-1; k>=0; k--) {
var st=termstyles[k];
if (curstyle&st) s+=termstyleclose[st];
}
};
s+=termstringend;
writeelement('term_'+r,s,termdocns4)
}
function termguiready() {
ready=true;
if (termguielementready(termdiv, self.document)) {
for (var r=0; r if (termguielementready('term_'+r,termdocns4)==false) {
ready=false;
break
}
}
}
else ready=false;
return ready
}
function cursorkbdleft() {
keyhandler({which:28})
}
function cursorkbdright() {
keyhandler({which:29})
}
function termkbdbackspace() {
keyhandler({which:8})
}
function termkbdesc() {
keyhandler({which:27})
}
function termkbdclear() {
if ((!cnsllock) && (!cnslrawmode)) cnslreset();
}
// ui-button repeat
function repeatset(cmd,on) {
if (repeattimer) cleartimeout(repeattimer);
repeattimer=settimeout('repeatdo('+cmd+')',conf_repeat_delay1);
}
function repeatclear() {
if (repeattimer) cleartimeout(repeattimer);
}
function repeatdo(cmd) {
if (repeattimer) cleartimeout(repeattimer);
if (cmd=='left') cursorkbdleft()
else if (cmd=='right') cursorkbdright()
else if (cmd=='backspace') termkbdbackspace();
repeattimer=settimeout('repeatdo('+cmd+')',conf_repeat_delay2);
}
// basic dynamics
function writeelement(e,t,d) {
if (document.layers) {
var doc=(d)? d : self.document;
doc.layers[e].document.open();
doc.layers[e].document.write(t);
doc.layers[e].document.close()
}
else if (document.getelementbyid) {
var obj=document.getelementbyid(e);
obj.innerhtml=t
}
else if (document.all) {
document.all[e].innerhtml=t
}
}
function setdivxy(d,x,y) {
if (document.layers) {
document.layers[d].moveto(x,y)
}
else if (document.getelementbyid) {
var obj=document.getelementbyid(d);
obj.style.left=x+'px';
obj.style.top=y+'px'
}
else if (document.all) {
document.all[d].style.left=x+'px';
document.all[d].style.top=y+'px'
}
}
function setdivvisibility(d,v) {
if (document.layers) {
document.layers[d].visibility= (v)? 'show':'hide';
}
else if (document.getelementbyid) {
var obj=document.getelementbyid(d);
obj.style.visibility= (v)? 'visible':'hidden';
}
else if (document.all) {
document.all[d].style.visibility= (v)? 'visible':'hidden';
}
}
function termguielementready(e,d) {
if (document.layers) {
var doc=(d)? d : self.document;
return ((doc) && (doc.layers[e]))? true:false
}
else if (document.getelementbyid) {
return (document.getelementbyid(e))? true:false
}
else if (document.all) {
return (document.all[e])? true:false
}
else return false
}
//eof
