en:user:gs3_sample_format_statements
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
en:user:gs3_sample_format_statements [2016/10/09 21:01] – [Linking metadata to a search] kjdon | en:user:gs3_sample_format_statements [2016/10/09 22:51] – [Using javascript to change the display] kjdon | ||
---|---|---|---|
Line 203: | Line 203: | ||
* s1.index=CR | * s1.index=CR | ||
+ | ===== 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 " | ||
+ | |||
+ | 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/ | ||
+ | } | ||
+ | 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 ==== | ||
+ | |||
+ | ==== 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. | ||
+ | |||
+ | < | ||
+ | < | ||
+ | <td valign=" | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | <td valign=" | ||
+ | < | ||
+ | </ | ||
+ | <td> | ||
+ | < | ||
+ | </td> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | We will modify the third <td> element to display a human readable form. | ||
+ | |||
+ | During development, | ||
+ | |||
+ | < | ||
+ | <td> | ||
+ | <script type=" | ||
+ | </td> | ||
+ | </ | ||
en/user/gs3_sample_format_statements.txt · Last modified: 2023/03/13 01:46 by 127.0.0.1