Firefox Example 2: Sort a Table
This is an example HTML page with an embedded JavaScript. The sample requires the Authentic Browser Plug-in (XPI file) to be installed on your computer. Note that case-sensitivity might be an issue with some servers, so if there is a problem locating a file, check the casing of filenames and of commands in the code.
The code shows:
•How to access the browser plug-in. Modify the code to refer to your XPI file and the class identifier (MIME Type) of your browser plug-in version (trusted or untrusted).
•How to load a file into the browser plug-in. Modify the code to refer to your sample document.
•Implement buttons for simple cursor positioning.
•Implement more complex commands like the sorting of tables.
•How to use the SelectionChanged event.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test Page For Authentic Browser Plug-in</title>
</head>
<!-- to disable the fast-back cache in Firefox, define an unload handler -->
<BODY id="bodyId" onunload="Unload()">
<embed
id="objPlugIn"
type="application/x-authentic-scriptable-plugin"
width="100%"
height="60%"
PLUGINSPAGE="http://your-server-including-path/AuthenticFirefoxPlugin_trusted.xpi"
EntryHelpersEnabled="TRUE"
SaveButtonAutoEnable="TRUE" >
</embed>
<TABLE>
<SCRIPT LANGUAGE="javascript">
var objCurrentRange = null;
var objPlugIn = document.getElementById('objPlugIn');
function BtnDocumentBegin() { objPlugIn.AuthenticView.DocumentBegin.Select(); }
function BtnDocumentEnd() { objPlugIn.AuthenticView.DocumentEnd.Select(); }
function BtnWholeDocument() { objPlugIn.AuthenticView.WholeDocument.Select(); }
function BtnSelectNextWord() { objPlugIn.AuthenticView.Selection.SelectNext(1).Select(); }
function BtnSortDepartmentOnClick()
{
var objCursor = null;
var objTableStart = null;
var objBubble = null;
var strField1 = "";
var strField1 = "";
var nColIndex = 0;
var nRows = 0;
objCursor = objPlugIn.AuthenticView.Selection;
if (objCursor.IsInDynamicTable())
{
// calculate current column index
nColIndex = 0;
bContinue = true;
while ( bContinue )
{
try { objCursor.GotoPrevious(11); }
catch (err) { bContinue = false; nColIndex--; }
nColIndex++;
}
// GoTo begin of table
objTableStart = objCursor.ExpandTo(9).CollapsToBegin().Clone();
// count number of table rows
nRows = 1;
bContinue = true;
while ( bContinue )
{
try { objTableStart.GotoNext(10); }
catch (err) { bContinue = false; }
nRows++;
}
// bubble sort through table
for ( i = 0; i < nRows - 1; i++) {
for( j = 0; j < nRows-i-1; j++) {
objBubble = objCursor.ExpandTo(9).CollapsToBegin().Clone();
// Select correct column in jth table row
objBubble.GotoNext(6).Goto(10,j,2).Goto(11,nColIndex,2).ExpandTo(6);
strField1 = objBubble.Text;
try
{
strField2 = objBubble.GotoNext(10).Goto(11,nColIndex,2).ExpandTo(6).Text;
}
catch ( err ) { continue; };
if(strField1 > strField2) {
if(!objBubble.MoveRowUp()) {
alert('Table row move is not allowed!');
return;
}
}
}
}
}
}
function InitAuthenticPluginPage( )
{
var serverstr='your-server/';
var basedir='Authentic/';
objPlugIn.SchemaLoadObject.URL = 'http://' + serverstr + basedir + 'OrgChart.xsd';
objPlugIn.XMLDataLoadObject.URL = 'http://' + serverstr + basedir + 'OrgChart.xml' ;
objPlugIn.DesignDataLoadObject.URL = 'http://' + serverstr + basedir + 'OrgChart.sps';
objPlugIn.StartEditing();
}
function Unload()
{
}
function OnSelectionChanged()
{
var CurrentSelection = null;
CurrentSelection = objPlugIn.AuthenticView.Selection;
SelTable_FirstTextPosition.innerHTML = CurrentSelection.FirstTextPosition;
SelTable_LastTextPosition.innerHTML = CurrentSelection.LastTextPosition;
SelTable_FirstXMLData.innerHTML = CurrentSelection.FirstXMLData.Parent.Name;
SelTable_FirstXMLDataOffset.innerHTML = CurrentSelection.FirstXMLDataOffset;
SelTable_LastXMLData.innerHTML = CurrentSelection.LastXMLData.Parent.Name;
SelTable_LastXMLDataOffset.innerHTML = CurrentSelection.LastXMLDataOffset;
}
objPlugIn.addEventListener("selectionchanged", OnSelectionChanged, false)
// event subscription if running on Firefox
objPlugIn.addEventListener("ControlInitialized", InitAuthenticPluginPage, false);
</SCRIPT>
<TR>
<TD><Input Type="button" value="Goto Begin" id="B1" onclick="BtnDocumentBegin()"></TD>
<TD><Input Type="button" value="Goto End" name="B2" onclick="BtnDocumentEnd()"></TD>
<TD><Input Type="button" value="Whole Document" name="B3" onclick="BtnWholeDocument()"></TD>
<TD><Input Type="button" value="Select Next Word" name="B4" onclick="BtnSelectNextWord()"></TD>
</TR>
<TR>
<TD><Input Type="button" value="Sort Table by this Column" id="B6" onclick="BtnSortDepartmentOnClick()"</TD>
</TR>
</TABLE>
<TABLE id=SelTable border=1>
<TR><TD id=SelTable_FirstTextPosition></TD><TD id=SelTable_LastTextPosition></TD></TR>
<TR><TD id=SelTable_FirstXMLData></TD><TD id=SelTable_FirstXMLDataOffset></TD></TR>
<TR><TD id=SelTable_LastXMLData></TD><TD id=SelTable_LastXMLDataOffset></TD></TR>
<TR><TD id=SelTable_Text></TD></TR>
</TABLE>
</body>
</html>