==== Image Display Example ====
{{ :en:imagedisplay.png?direct&500 |}}
-
Author:
-
Subjects:
- Image size:
px x px
This code provides a nice way to display images with their metadata on the document display page. Provides an example of gsf:switch and gsf:when statements, as well as linking to a CSS file.
This format statement will display any document with a FileFormat (ex.FileFormat) of
"jpeg" as shown in the image. All other documents are displayed with the
dc.Title as a heading and the document text.
If you have images of many different formats (png, jpg, jpeg, gif), you could replace the lines:
With the following:
For the image display to appear as shown in the image,
you must include the following CSS in a file called imageDisplay.css in your collection's style folder:
div.separating-line {
border-bottom: 1px solid #d8d8d8;
padding: 5px;
clear: both;
}
div.doc-image {
float: left;
margin-left: 10px;
padding-right: 10px;
}
div.doc-image img {
border: 1px solid #5d5f60;
padding: 5px;
}
div.doc-quote p {
width: 500px;
}
div.doc-info h4 {
margin-top: 15px;
margin-bottom: 5px;
}
div.doc-info ul {
list-style-type: none;
color: #5d5f60;
margin-top: 0px;
}
div.doc-info ul li {
line-height: 20px;
}
==== Adjusting view for paged image documents ====
By default, paged image documents will display the image with the associated text underneath. A "view selector" offers **default** (both image and text) and **image** only and **text** only options.
These can be customised in the
*To set the default view to image:
===== Handling multi-valued metadata =====
==== Displaying values in a bulleted list ====
Say we want to display all the authors of a document in a bulleted list. We can't just use
<li><b>
</b></li>
This will produce output like:
You can see from this example that the dc.Creator index got the shortname "CR". You will need this shortname to construct the search URL.
Next you need to modify your format statement to add in the search links. If you want these links to appear on the document page, select the "display" format item. (If you wanted them in search results, or on classifier pages, select the "search/browse/CLx" format items)
The default XML for the display format item contains several commented out templates. Say you have simple documents (ie ones with no internal structure eg images), you can add the links to the "documentHeading" or "documentContent" templates. If you have structured documents with sections, then perhaps add it to the start of the "topLevelSectionContent" template.
The XML for the links looks something like the following:
Search for Authors:
/TextQuery?qs=1&rt=rd&
amp;s1.level=Doc&startPage=1&s1.query= &s1.index=CR
,
s1.query=" "
The parameters are:
* qs=1 - this search is a quick search. Can omit if you want to be taken to the TextQuery search page (equivalent to clicking the TextQuery link under the quick search form)
* rt=rd - this determines, for a query, if you are displaying the search form, and performing the search or not. If you have qs=1, then you really only need rt=r here. But without qs=1, having the r will perform the search, and having the d will display the search form too.
* startPage=1 - start at the first page of search results
* s1.level=Doc - s1 params go to the query service itself. level is Doc or Sec.
* s1.query - the query term, in this case the metadata value
* s1.index=CR - the index to search in, in this case the CR dc.Creator index.
===== Using javascript to change the display =====
As an example of using javascript, we will see how to output the document filesize in a human readable form. For example, instead of displaying "834716 bytes", it will display "815 KB".
A basic javascript method to do this is the following:
function humanReadableFileSize(bytes)
{
var filesize = bytes + " bytes";
if (bytes > 1048576) {
filesize = Math.round(bytes / 1048576.0) + " MB";
}
else if (bytes > 1024) {
filesize = Math.round(bytes/1024.0)+ " KB";
}
return filesize;
}
So, we have a javascript function, but how do we get it into the page? And how do we call it?
==== Adding javascript into a page ====
To add the javascript into an XSL file, you encase it in script tags. And because XSL will escape double quotes by default, you need to put it inside **
There are multiple places you can use to add some javascript into your library.
* **All pages, all collections**
**web/interfaces/default/transform/layouts/header.xsl** contains global templates used in the headers of all pages in the library. The **create-html-header** template sets up the header for each page. If you add your script element into here, it will appear in all pages in your library.
* **Only classifier pages, all collections**
The **create-html-header** template calls an additional template **additionalHeaderContent**, which can be used to customise which pages get the extra javascript. For example, if we only want this function to be available for classifier pages, we can edit **web/interfaces/default/transform/pages/classifier.xsl**. Copy the **
* **single page, single collection**
Say you just want to use this new javascript on the classifier pages, then add the template into the main classifier format element. Or add it into the format element of a specific classifier and it will only be available for that single classifier.
==== Using the javascript in the format statement ====
Now that we have the function included in the page, we can use it to modify our filesize display.
Lets modify a classifier format statement to use this function. The following is a simple format statement that displays an icon linking to the document, the title, and the filesize.
We will modify the third
This lets us check that our function is correct and we are getting the right metadata. However, using "document.write" is not considered good practice. And if you are adding this in a classifier which has bookshelves, then it ends up replacing the entire page with the filesize!
Instead, we will need to add to the html of the td element. This means we need to give the td element an id so we can find it again.
If the
-fs
However, if this
-fs
...other content here...
Element ids need to be unique, so in this case we will use the document id (**