User Tools

Site Tools


en:user:gs3_sample_format_statements

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:user:gs3_sample_format_statements [2016/10/09 23:05] – [Using the javascript in the format statement] kjdonen:user:gs3_sample_format_statements [2016/10/09 23:11] – [Adding javascript into a page] kjdon
Line 227: Line 227:
 ==== Adding javascript into a page ==== ==== Adding javascript into a page ====
  
 +There are multiple places you can use to add some javascript into your library.
 +
 +  * All pages, everywhere
 +
 +web/interfaces/default/transform/layouts/header.xsl contains global templates used in the headers of all pages in the library.
 ==== Using the javascript in the format statement ==== ==== Using the javascript in the format statement ====
  
Line 251: Line 256:
 We will modify the third <td> element to display a human readable form. We will modify the third <td> element to display a human readable form.
  
-During development, we can use the simple document.write() method to output the result:+During development, we can use the simple **document.write()** method to output the result:
  
 <code> <code>
Line 273: Line 278:
 </code> </code>
  
-Element ids need to be unique, so in this case we will use the document id (<gsf:OID/>) with "-fsjust in case the OID has been used as an id elsewhere in the page. Because we are not assigning a simple string to the id attribute, we need to use the <xsl:attribute> element. We cannot write +Element ids need to be unique, so in this case we will use the document id (**<gsf:OID/>**) with **-fs** just in case the OID has been used as an id elsewhere in the page. Because we are not assigning a simple string to the id attribute, we need to use the **<xsl:attribute>** element. We cannot write 
-<td id="<gsf:OID/>">.+**<td id="<gsf:OID/>">**.
  
-To set an element's text, we use document.getElementById("id").innerHTML = "xxx"+To set an element's text, we use **document.getElementById("id").innerHTML = "xxx"**
-document.getElementById finds the specified element, and element.innerHTML = "xxx" sets its text.+**document.getElementById** finds the specified element, and **element.innerHTML = "xxx"** sets its text.
  
 We set the text to be the result of calling our function on the filesize metadata. We set the text to be the result of calling our function on the filesize metadata.
  
-One further tricky part. We want to write document.getElementById("<gsf:OID/>-fs"). However, the XSL transform process will escape the double quotes with &quot; and then the javascript will be invalid. To get around this, we use <xsl:text disable-output-escaping="yes">"</xsl:text>. +One further tricky part. We want to write **document.getElementById("<gsf:OID/>-fs")**. However, the XSL transform process will escape the double quotes with &quot; and then the javascript will be invalid. To get around this, we use **<xsl:text disable-output-escaping="yes">"</xsl:text>**.
- +
-i.e. document.getElementById(<xsl:text disable-output-escaping="yes">"</xsl:text><gsf:OID/>-fs<xsl:text disable-output-escaping="yes">"</xsl:text>)+
  
-Greenstone provides a shorthand: <gsf:html>"</gsf:html>, which gets resolved to the above <xsl:text> construction.+i.e. **document.getElementById(<xsl:text disable-output-escaping="yes">"</xsl:text><gsf:OID/>-fs<xsl:text disable-output-escaping="yes">"</xsl:text>
 +** 
 +Greenstone provides a shorthand: **<gsf:html>"</gsf:html>**, which gets resolved to <xsl:text> with the disable-output-escaping attribute set
  
  
en/user/gs3_sample_format_statements.txt · Last modified: 2023/03/13 01:46 by 127.0.0.1