lookup

A <lookup> element can be used to specify an external source of values for attributes or elements. The source can be any HTML document. The document will be opened by Xopus when a value for the attribute can be specified. The HTML document can return its value using script.

<x:config version="1.0" xmlns:x="http://www.xopus.com/xmlns/config">

  <x:lookupConfig>

    <x:lookup 
      parentPattern="self::picture" 
      name="source"
      url="lookup/image/index.html" 
      forceLookup="true" 
      autoOpen="true"/>

    <x:lookup 
      parentPattern="self::a" 
      name="href"
      url="lookup/link/index.html" 
      forceLookup="false" 
      autoOpen="true"/>

  </x:lookupConfig>

</x:config>

Or, with nodeConfig:

<x:node match="a/@href">

  <x:lookup 
    url="lookup/link/index.html"
    forceLookup="true"
    autoOpen="true"/>   

</x:node>

There are two ways to use this. You can create a simple lookup, following the example below. This includes the script media/lookup.js which uses the table structure below it to look up the value. Or you can write your own thing on the API.

<html>
  <head>
    <link rel="stylesheet" type="text/css" href="../../../../../xopus/media/lookup.css" />
    <script language="JavaScript" src="../../../../../xopus/media/lookup.js"></script>
  </head>
  <body>
    <h1 selectable="true">
      <script language="JavaScript">
        document.writeln(top.dialogArguments.title);
      </script>
    </h1>
    <table class="xopus-lookup" border="0" cellspacing="0" cellpadding="0" align="center">
      <tr id="http://www.q42.nl">
        <td>1. Q42</td>
        <td>http://www.q42.nl</td>
      </tr>
      <tr id="http://xopus.com">
        <td>2. Xopus</td>
        <td>http://www.xopus.com</td>
      </tr>
    
      etc...

    </table>
    <script language="JavaScript">
      initLookupTables();
    </script>
  </body>
</html>

The dialog is passed a number of arguments through dialogArguments:

  • name (the name of the attribute that is being looked up)

  • value (the current value)

  • node (the node that represents the attribute)

  • canvas (the canvas element)

  • attributes

The id attributes on the table-data elementes are the values that will be passed back to the script. You can create your own table of values. At the end of the example is the line "initLookupTables()" which initiates the table as something clickable.

The other way to use this, is to create an HTML page of your own, and to construct the JavaScript yourself. You can find the following in media/lookup.js, and this shows you what happens. What is important here is the results object, the names and values that are set on it, and the call to top.choose(results) where the results object is passed back to Xopus. Here an HTML element is passed to the function.

//Construct name/value pairs to send
var results = {};  

//set the property on the object and give it its value.
results[window.dialogArguments.name] = el.id;

// Get value elements
var valueEls = el.getElementsByTagName('value'); 
 
for (var i=0; i<valueEls.length; i++)  
{    
  var valueEl = valueEls[i];
  
  //add to results
  results[valueEl.name] = valueEl.innerHTML;
} 
 
top.choose(results);

As you can see, top.choose(results) is called. The results object var is passed to Xopus and set on the element indicated in the lookup. You can re-write the HTML lookup page and the script above any way you like as long as you pass a similar results object to top.choose in the end.

top.choose(results); is very important here as it signals the top window to choose something.

Note: It is not possible to create cross-domain lookups, as it is impossible for JavaScript from one domain to access windows or iframes therefore, on other domains.


lookup element

Namespace: http://www.xopus.com/xmlns/config

Attributes

url
Specifiy the page on the server to load in the lookup dialog.
forceLookup
When forceLookup attribute is set to true, authors cannot edit the attribute for which the lookup dialog was specified manually using the properties editor; the input field will be disabled. (Optional)
autoOpen
When set to true, it specifies that the lookup dialog should be opened automatically when appropriate. For example, no other attribute can be edited, the lookup dialog will be opened instead of the attribute editor. (Optional)
parentPattern
(Only applies to <x:lookup> in <x:lookupConfig>) The owner element of the lookup attribute. parentPattern contains an XPath query, using the owner element as context. Nota bene: this means that instead of link, self::link must be used to select an attribute on a <link> element.
name
(Only applies to <x:lookup> in <x:lookupConfig>) Name of the lookup attribute.

Parent Elements

node
lookupConfig

History

version event
Xopus 3 Introduction.
Xopus 3 Change. When autoOpen is set to true, the lookup will open for optional attributes too.