HTML Integration - Auto Enabling Alpheios
Alpheios Basic Functionality
Auto-Enable Alpheios for only a single block of text on the page:
- a class named "alpheios-enabled-text" (in the 'class' attribute)
- a 'lang' attribute set to the correct language code for the text per the IANA language subtag registry
- Currently only Latin (la) and Ancient Greek (grc) are supported
Or, Auto-Enable Alpheios for the entire page:
- Add <meta name="alpheios-pedagogical-text"> tag to the <head> tag of the html document
- Add a 'lang' attribute to the <html> element, set to the correct language code for the page per the IANA language subtag registry
- Currently only Latin (la) and Ancient Greek (grc) are supported
- Enclose any sections on the page for which you don't want the Alpheios tools to be enabled in a block element which has the class 'alpheios-ignore' assigned in the 'class' attribute
Identify Word Tokens
When identifying the target word for a user selection, the default behavior of the browser is to find the smallest distinct element within the range identified as the target of the mouse event. Alpheios then identifies the word token from within the text content of this range. However, sometimes it may be desirable to have markup within a word, for example to identify fragments of words. To override the default behavior, add a meta tag named "alpheios-word-classes" to the head of a document to identify a list of CSS class names which are applied to elements in the document which represent complete words. Set the content attribute of this meta tag to a comma-separated list of class names used on elements to identify words within the page. It is not necessary to add this class to every word on the page, only those which are fragmented into multiple smaller elements.
For example:
<meta name="alpheios-word-classes" content="word,segmented-word"/>
In this example, if this metadata element is present, when responding to a user selection, the Alpheios tools:
- Check if the selected element's class attribute value includes "word" or "segmented-word"
- If not, check if a parent element has one of these classes, and if it does, widen the scope of the target range to the parent element
- If the metadata element is not present, or if the selection does not have one
of the listed classes assigned to a parent element, the target range is not changed.
By default, the tools will ignore whitespace within a markup element identified by the alpheios-word-classes meta tag. This behavior can be changed by setting the "alpheios-preserve-whitespace" attribute to "true" on the meta tag. E.g.
<meta name="alpheios-word-classes" content="word,segmented-word" alpheios-preserve-whitespace="true"/>
Add Alpheios Hints to the page
For example:
<div class="alpheios-trigger-hint"/>CSS Style rules can be applied to style this element. The Alpheios tools do not impose a style on this text.
Reacting to Alpheios Enabled
<div id="alpheios-enabled-callback" display="none"></div>
<script type="text/javascript">
var alpheios_enabled_called = false;
function on_alpheios_enabled(){
if (alpheios_enabled_called)
{
return;
}
alpheios_enabled_called = true;
// custom code
}
document.getElementById('alpheios-enabled-callback').addEventListener('AlpheiosEnabled',on_alpheios_enabled, false);
</script>
The AlpheiosEnabled event is sent to the client code by the browser when the tools are turned on, that is, when the user loads a page which has been auto-enabled for the Alpheios tools as described above. The user must have the required Alpheios tools for the language installed in their browser for the event to be triggered.
Checking for Alpheios Tools
On every page load (the DOMContentLoaded event), the Alpheios tools install the following meta elements into the <head> of the document loaded in the browser:
Alpheios Basic Libraries:
<meta content="{4816253c-3208-49d8-9557-0745a5508299}:1.0alpha4.2135.20091005" name="_alpheios-installed-version"/>
Alpheios Greek Tools:
<meta content="{0f1d7e06-6ce8-40b0-83f0-9783ee65ab9b}:1.0alpha4.2140.20091005" name="_alpheios-installed-version"/>
Alpheios Latin Tools:
<meta content="{7dd2b42f-3db8-4833-88c4-5a9e3788017b}:1.0alpha4.2139.20091005" name="_alpheios-installed-version"/>
The format of the content attribute in the meta element is <Extension GUID>:<version>
You can add a javascript function to be called from an onload handler on the documents <body> element to check for the installed Alpheios and versions and respond as appropriate for your site.
Note that the function which looks for the meta elements should not be called prior to the body load event as the meta elements will not have been inserted in the page until just before the body loads.
Alpheios Enhanced Text Functionality
Treebank
Integrating a block of HTML text with references to treebank XML data for that text enables the Diagram button on the Alpheios popup and enables the morphology displayed in the Alpheios popup to be specific to that particular usage of the selected form.
To enable this integration:
- An XML document containing the treebanked text must be loaded in the Alpheios repository.
- Each word (from the treebanked text) in the HTML document displaying the source text must be wrapped in a <span> tag (or other valid HTML element) and be linked to the treebank data via a 'tbrefs' attribute on the wrapping element.
- The value of the 'tbrefs' attribute should be set to the sentence and word id of the corresponding element in the XML treebank data, separated by a hyphen (e.g. tbrefs="1-1" for the element from sentence id="1" and word id="1"). The 'tbrefs' attribute is multi-valued (i.e. if the word in the HTML document corresponds to more than one element in the treebank data). Multiple values must be space-separated.
- The <head> element of the document must contain 2 <meta> elements pointing to URLs from which to retrieve the treebank data. For example, to enable disambiguation of the morphology:
<meta content="http://repos.alpheios.net:8080/exist/rest/xq/treebank-getmorph.xq?f=1999.02.0066&w=WORD" name="alpheios-treebank-url"/>
and to enable the treebank diagram:
<meta content="http://repos.alpheios.net:8080/exist/rest/xq/treebank-getsvg.xq?f=1999.02.0066&s=SENTENCE&w=WORD" name="alpheios-treebank-diagram-url"/>
The WORD and SENTENCE placeholders will be replaced by values from the 'tbrefs' attribute at runtime.
Sample Code
See sample HTML and Javascript at http://alpheios.svn.sourceforge.net/viewvc/alpheios/api/trunk/samples/
