svn%xmlterm.org 877783f732 xmlterm changes only (not part of the default build).
Minor tweaks to handle input of control characters. Switched to double clicks, instead of single clicks, to activate XMLterm features (to protect the user).


git-svn-id: svn://10.0.0.236/trunk@62305 18797224-902f-48f8-a5cc-f745e15eee43
2000-03-07 15:45:16 +00:00

461 lines
15 KiB
HTML

<!-- xmlterm.html: XMLterm page -->
<HTML>
<HEAD>
<TITLE>XMLterm Page</TITLE>
<LINK TITLE="DefaultStyle" REL="stylesheet" TYPE="text/css"
HREF="chrome://xmlterm/skin/xmltpage.css">
<SCRIPT language="JavaScript">
// CONVENTION: All pre-defined XMLTerm Javascript functions
// begin with an upper letter. This allows
// an easy distinction with user defined functions,
// which should begin with a lower case letter.
// Show all output
function ShowAll() {
return DisplayAllOutput(true);
}
// Hide all output
function HideAll() {
return DisplayAllOutput(false);
}
// Set history buffer size
function SetHistory(value) {
dump("SetHistory("+value+")\n");
window.xmlterm.SetHistory(value, document.cookie);
return (false);
}
// Set prompt
function SetPrompt(value) {
dump("SetPrompt("+value+")\n");
window.xmlterm.SetPrompt(value, document.cookie);
return (false);
}
// Create new XMLTerm window
function NewXMLTerm(firstcommand) {
newwin = window.openDialog( "chrome://xmlterm/content/xmlterm.xul",
"xmlterm", "chrome,dialog=no,resizable",
firstcommand);
//newwin = window.xmlterm.NewXMLTermWindow(firstcommand);
dump("NewXMLTerm: "+newwin+"\n")
return (false);
}
// Handle resize events
function Resize(event) {
dump("Resize()\n");
window.xmlterm.Resize();
return (false);
}
// Scroll Home
function ScrollHome(isShift, isControl) {
dump("ScrollHome("+isShift+","+isControl+")\n");
if (isShift && window.xmltbrowser) {
window.xmltbrowser.scroll(0,0);
} else {
window.scroll(0,0);
}
return false;
}
// Scroll End
function ScrollEnd(isShift, isControl) {
dump("ScrollEnd("+isShift+","+isControl+")\n");
if (isShift && window.xmltbrowser) {
window.xmltbrowser.scroll(0,9999);
} else {
window.scroll(0,9999);
}
return false;
}
// Scroll PageUp
function ScrollPageUp(isShift, isControl) {
dump("ScrollPageUp("+isShift+","+isControl+")\n");
if (isShift && window.xmltbrowser) {
window.xmltbrowser.scrollBy(0,-300);
} else {
window.scrollBy(0,-300);
}
return false;
}
// Scroll PageDown
function ScrollPageDown(isShift, isControl) {
dump("ScrollPageDown("+isShift+","+isControl+")\n");
if (isShift && window.xmltbrowser) {
window.xmltbrowser.scrollBy(0,300);
} else {
window.scrollBy(0,300);
}
return false;
}
// Form Focus (workaround for form input being transmitted to xmlterm)
function FormFocus() {
dump("FormFocus()\n");
window.xmlterm.IgnoreKeyPress(true, document.cookie);
return false;
}
// Form Blur (workaround for form input being transmitted to xmlterm)
function FormBlur() {
dump("FormBlur()\n");
window.xmlterm.IgnoreKeyPress(false, document.cookie);
return false;
}
// Handle default meta command
function MetaDefault(arg1) {
return Load("http://"+arg1);
}
// Load URL in XMLTermBrowser window
function Load(url) {
var succeeded = false;
if (window.xmltbrowser) {
dump("Load:xmltbrowser.location.href="+window.xmltbrowser.location.href+"\n");
if (window.xmltbrowser.location.href.length) {
window.xmltbrowser.location = url;
succeeded = true;
}
}
if (!succeeded) {
window.xmltbrowser = window.open(url, "xmltbrowser");
}
return (false);
}
// Control display of all output elements
function DisplayAllOutput(flag) {
var outputElements = document.getElementsByName("output");
for (i=0; i<outputElements.length; i++) {
var outputElement = outputElements[i];
outputElement.style.display = (flag) ? "block" : "none";
}
var promptElements = document.getElementsByName("prompt");
for (i=0; i<promptElements.length; i++) {
promptElement = promptElements[i];
promptElement.style.setProperty("text-decoration",
(flag) ? "none" : "underline", "")
}
return (false);
}
// Centralized event handler
// eventType values:
// click
//
// targetType:
// textlink - hyperlink
// prompt - command prompt
// command - command line
// exec - execute command with sendln/createln
// (depending upon window.commandMode)
// send - transmit arg to LineTerm
// sendln - transmit arg+newline to LineTerm
// createln - transmit arg+newline as first command to new XMLTerm
//
// entryNumber: >=0 means process only if current entry
// <0 means process anytime
//
// arg1: command/pathname string (without newline)
// arg2: alternate command line (for use in current entry only;
// uses relative pathnames assuming current working directory)
//
function HandleEvent(eventObj, eventType, targetType, entryNumber,
arg1, arg2) {
dump("HandleEvent("+eventObj+","+eventType+","+targetType+","+
entryNumber+","+arg1+","+arg2+")\n");
// Entry independent targets
if (action === "textlink") {
dump("textlink = "+arg1+"\n");
Load(arg1);
} else if (eventType === "click") {
if (targetType === "prompt") {
var outputElement = document.getElementById("output"+entryNumber);
var promptElement = document.getElementById("prompt"+entryNumber);
//dump(promptElement.style.getPropertyValue("text-decoration"));
if (outputElement.style.display == "none") {
outputElement.style.display = "block";
promptElement.style.setProperty("text-decoration","none","");
} else {
outputElement.style.display = "none";
promptElement.style.setProperty("text-decoration","underline","");
}
} else if (targetType === "command") {
var commandElement = document.getElementById(targetType+entryNumber);
var command = commandElement.firstChild.data;
dump("command = "+command+"\n\n");
window.xmlterm.SendText("\025"+command+"\n", document.cookie);
} else {
// Targets which may be qualified only for current entry
if ((entryNumber >= 0) &&
(window.xmlterm.currentEntryNumber != entryNumber)) {
dump("NOT CURRENT COMMAND\n");
return (false);
}
var action = targetType;
if (action === "exec") {
if (window.commandMode === "window") {
action = "createln";
} else {
action = "sendln";
}
}
if (action === "send") {
dump("send = "+arg1+"\n");
window.xmlterm.SendText(arg1, document.cookie);
} else if (action === "sendln") {
if ((Math.abs(entryNumber)+1 == window.xmlterm.currentEntryNumber) &&
(arg2 != null)) {
// Current command
dump("sendln = "+arg2+"\n\n");
window.xmlterm.SendText("\025"+arg2+"\n", document.cookie);
} else {
// Not current command
dump("sendln = "+arg1+"\n\n");
window.xmlterm.SendText("\025"+arg1+"\n", document.cookie);
}
} else if (action === "createln") {
dump("createln = "+arg1+"\n\n");
newwin = NewXMLTerm(arg1+"\n");
}
}
}
return (false);
}
// Set history buffer count using form entry
function SetHistoryValue() {
var field = document.getElementById('InputValue');
return SetHistory(field.value);
}
// Set prompt using form entry
function SetPromptValue() {
var field = document.getElementById('InputValue');
return SetPrompt(field.value);
}
// Usage tips
var tips = new Array();
tips[0] = 'Click the SetPrompt button to use a cool Mozilla prompt from dmoz.org!';
tips[1] = '"js:SetPrompt(HTMLstring);" sets prompt to HTML string.';
tips[2] = 'Type "js:func(arg);" to execute inline Javascript function func.';
tips[3] = 'Inline Javascript ("js:...") can be used to produce HTML output.';
tips[4] = 'XMLterm supports full screen commands like "vi", "emacs -nw", and "less".';
tips[5] = 'Use "xls -i" for iconic display of directory contents.';
tips[6] = 'Use "xcat file" to display file.';
// Display random usage tip
// (should cease to operate after a few cycles;
// need to use Prefs to keep track of that)
function UsageTip() {
var tipCount = tips.length;
var ranval = Math.random();
var tipIndex = Math.floor(ranval * tipCount);
if (tipIndex >= tipCount) tipIndex = 0;
dump("xmlterm: UsageTip "+tipIndex+","+ranval+"\n");
var tiphead = document.getElementById('tiphead');
var tipdata = document.getElementById('tipdata');
tiphead.firstChild.data = "Tip:";
tipdata.firstChild.data = tips[tipIndex];
return false;
}
// Display more tips
function MoreTips() {
dump("xmlterm: MoreTips\n");
var moreTipsElement = document.getElementById('moretips');
var moreTipsFrame = document.getElementById('moretipsframe');
if (moreTipsFrame) {
// Remove more tips iframe
document.body.removeChild(moreTipsFrame);
moreTipsElement.firstChild.data = "More tips/news";
} else {
// Create more tips iframe
moreTipsFrame = document.createElement("iframe");
moreTipsFrame.setAttribute('ID', 'moretipsframe');
moreTipsFrame.setAttribute('CLASS', 'moretipsframe');
moreTipsFrame.setAttribute('WIDTH', '100%');
moreTipsFrame.setAttribute('SRC', 'http://xmlterm.org/newstips.html');
dump(moreTipsFrame);
// Insert more tips iframe in body
var sessionElement = document.getElementById('session');
document.body.insertBefore(moreTipsFrame, sessionElement);
moreTipsElement.firstChild.data = "Hide tips/news";
}
return false;
}
// onLoad event handler
function LoadHandler() {
dump("xmlterm: LoadHandler ... "+window.xmlterm+"\n");
UsageTip();
if (window.xmlterm) {
// XMLTerm already initialized
return (false);
}
dump("LoadHandler: WINDOW.ARGUMENTS="+window.arguments+"\n");
dump("Trying to make an XMLTerm Shell through the component manager...\n");
var xmltshell = Components.classes["component://mozilla/xmlterm/xmltermshell"].createInstance();
dump("Interface xmltshell1 = " + xmltshell + "\n");
xmltshell = xmltshell.QueryInterface(Components.interfaces.mozIXMLTermShell);
dump("Interface xmltshell2 = " + xmltshell + "\n");
if (!xmltshell) {
dump("Failed to create XMLTerm shell\n");
window.close();
return;
}
// Store the XMLTerm shell in the window
window.xmlterm = xmltshell;
// Content window same as current window
var contentWindow = window;
// Initialize XMLTerm shell in content window with argvals
window.xmlterm.Init(contentWindow, "", "");
//dump("LoadHandler:"+document.cookie+"\n");
dump("contentWindow="+contentWindow+"\n");
dump("document="+document+"\n");
dump("documentElement="+document.documentElement+"\n");
// Handle resize events
//contentWindow.addEventListener("onresize", Resize);
contentWindow.onresize = Resize;
// Set focus to appropriate frame
contentWindow.focus();
//contentWindow.xmlterm = xmlterm;
//dump(contentWindow.xmlterm);
// The following code is for testing IFRAMEs only
dump("[Main] "+window+"\n");
dump(window.screenX+", "+window.screenY+"\n");
dump(window.scrollX+", "+window.scrollY+"\n");
dump(window.pageXOffset+", "+window.pageYOffset+"\n");
dump("IFRAME checks\n");
var iframe = document.getElementById('iframe1');
dump("iframe="+iframe+"\n");
frames=document.frames;
dump("frames="+frames+"\n");
dump("frames.length="+frames.length+"\n");
framewin = frames[0];
dump("framewin="+framewin+"\n");
dump("framewin.document="+framewin.document+"\n");
dump(framewin.screenX+", "+framewin.screenY+"\n");
dump(framewin.scrollX+", "+framewin.scrollY+"\n");
dump(framewin.pageXOffset+", "+framewin.pageYOffset+"\n");
var body = framewin.document.getElementsByTagName("BODY")[0];
dump("body="+body+"\n");
var height= body.scrollHeight;
dump("height="+height+"\n");
// iframe.height = 800;
// iframe.width = 700;
// framewin.sizeToContent();
framewin.xmltshell = xmltshell;
dump(framewin.xmltshell+"\n");
dump("xmlterm: LoadHandler completed\n");
return (false);
}
</SCRIPT>
</HEAD>
<BODY onLoad="return LoadHandler();">
<TABLE FRAME=none BORDER=0>
<TBODY>
<TR><TD ALIGN=center>
<FORM NAME="XMLTERM form">
<INPUT TYPE="button" VALUE="Hide all output"
onClick="return HideAll();">
<INPUT TYPE="button" VALUE="Show all output"
onClick="return ShowAll();">
<INPUT TYPE="button" VALUE="SetHistory"
onClick="return SetHistoryValue();">
<INPUT TYPE="button" VALUE="SetPrompt" onClick="return SetPromptValue();">
<INPUT TYPE="button" VALUE="NewXMLTerm" onClick="return NewXMLTerm('');">
<BR>
Input Value:
<INPUT SIZE=50 TYPE="text" ID="InputValue"
VALUE="<img src='http:/dmoz.org/img/lizard2a.gif'>"
onFocus="return FormFocus();" onBlur="return FormBlur();">
</FORM>
</TABLE>
<SPAN CLASS="tiphead" ID="tiphead" STYLE="font-weight:bold"> &nbsp; </SPAN>
<SPAN CLASS="tipdata" ID="tipdata"> &nbsp; </SPAN>
<SPAN CLASS="moretips" ID="moretips" onClick="return MoreTips();">
More tips/news
</SPAN>
<P>
<!--
<IFRAME NAME="iframet" SRC="chrome://xmlterm/content/xmltblank.html"
FRAMEBORDER=0>
</IFRAME>
-->
<DIV CLASS="session" ID="session">
</DIV>
</BODY>
</HTML>