Firefox Beispiel 2: Tabelle sortieren
Dies ist eine HTML-Beispieldatei mit einem eingebetteten JavaScript. Für das Beispiel muss das Authentic Browser Plug-In (XPI-Datei) auf Ihrem Computer installiert werden. Beachten Sie, dass die Groß- und Kleinschreibung auf einigen Servern eine Rolle spielt. Wenn eine Datei daher nicht gefunden wird, überprüfen Sie die Groß- und Kleinschreibung von Dateinamen und Befehlen im Code.
Der Code zeigt an:
•wie das Browser Plug-In aufgerufen werden soll. Passen Sie den Code bitte an und geben Sie den Pfad zu Ihrer XPI-Datei und dem Class Identifier (MIME Type) Ihrer Browser Plug-In-Version an (trusted oder untrusted).
•wie eine Datei in das Browser Plug-In geladen werden soll. Passen Sie bitte den Code an und geben Sie den Pfad zu Ihrem Beispieldokument an.
•wie Schaltflächen für einfache Cursor-Positionierungen implementiert werden.
•wie komplexere Befehle wie z.B. die Sortierung von Tabellen implementiert werden.
•wie das SelectionChanged-Ereignis verwendet wird.
<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>