A Juice Metadef is a named description, associated with a particular User Interface type, of where information to be used by Juice extensions can be identified on a html page. The description is identified by a name that can then be used within an extension to access the data displayed on the page.
Following the theme of all Juice components, the Metadef for a particular interface type is contained in a separate JavaScript file. The convention being that the file will be of the format xxx_metadef.js.
The first step in creating a Metadef is to first check if one has already been created. As the layout of interfaces for a particular product all tend to share the same format, it is possible that someone else has already created one that you can use.
Lets take a look at an example Metadef - in this case the one for the Talis Aspire Resource List system.
function talis_aspire_metadef(){
juice.findMeta("isbns","#isbn10 > .fieldValue, #isbn13 > .fieldValue ",juice.stringToAlphnumAray);
juice.findMeta("author","#authors > .fieldValue ");
juice.findMeta("title","#itemDetailsContainer > h1 ");
}The Metadef is contained in a single, appropriately named, function talis_aspire_metadef().
In this example we create three definitions - 'isbns', 'author', and 'title'. For each one we create an instance of the JuiceMeta class. The constructor of which has three arguments:
For information on jQuery selectors check out the jQuery documentation on selectors, but for example the title definition in our example is selecting the contents of the <h1> element contained within an element with an id attribute of itemDetailsContainer.
Remember that a jQuery selector can return multiple values, a feature used in the isbns meta in our example. This also highlights the optional filterFunc - a JavaScript function used to filter or change the values of the returned before storing them. juice.stringToAlphnumAray is a utility which removes words which contain non alphanumeric characters from a string and then returns the remaining words as an array which is stored in the instance of JuiceMeta.
JuiceMeta will retrieve and store the contents of a document element from the html page. If you need to retrieve a value held in an element attribute you should use the associated class - JuiceMetaAttr. It's constructor takes one extra argument defining the name of the attribute:
JuiceMetaAttr(id, selector, attName, filterFunc)
In our example the constructed instances of JuiceMeta are passed to the Juice function juice.addMeta. This makes them available to other components of the Juice framework.
If you enabled debugging, a list of all defined Metadefs and their selected content can be showed:
juice.setDebug(true); juice.debugMeta();