source: main/trunk/greenstone3/web/interfaces/oran/transform/javascript-global-setup.xsl@ 24469

Last change on this file since 24469 was 24469, checked in by sjm84, 9 years ago

Refactored the set up of the gs variable to use less script tags

  • Property svn:executable set to *
File size: 8.4 KB
Line 
1<xsl:stylesheet version="1.0"
2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:java="http://xml.apache.org/xslt/java"
4 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
5 xmlns:gslib="http://www.greenstone.org/skinning"
6 extension-element-prefixes="java util"
7 exclude-result-prefixes="java util">
8
9 <xsl:template name="setup-gs-variable">
10 <script type="text/javascript">
11 gs = new Array();
12 gs.cgiParams = new Array();
13 gs.siteMetadata = new Array();
14 gs.collectionMetadata = new Array();
15 gs.documentMetadata = new Array();
16 gs.imageURLs = new Array();
17 gs.variables = new Array();
18 </script>
19 <xsl:call-template name="populate-cgi-param-values"/>
20 <xsl:call-template name="populate-image-url-values"/>
21 <xsl:call-template name="populate-metadata-values"/>
22 </xsl:template>
23
24 <xsl:template name="populate-cgi-param-values">
25 <script type="text/javascript">
26 var name;
27 var value;
28 <xsl:for-each select="/page/pageRequest/paramList/param">
29 <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
30 <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of select="@value"/><xsl:text disable-output-escaping="yes">";</xsl:text>
31 <xsl:text disable-output-escaping="yes">name = name.replace(".", "_");</xsl:text>
32 gs.cgiParams[name] = value;
33 </xsl:for-each>
34 </script>
35 </xsl:template>
36
37 <xsl:template name="populate-metadata-values">
38 <script type="text/javascript">
39 <xsl:text disable-output-escaping="yes">
40 function addMetadataToList(name, value, list, lang)
41 {
42 name = name.replace(".", "_");
43 if(lang == "" || lang == "en")
44 {
45 list[name] = value;
46 }
47 else
48 {
49 if (list[lang] == undefined)
50 {
51 list[lang] = new Array();
52 }
53 var langList = list[lang];
54 langList[name] = value;
55 }
56 }
57 var name;
58 var value;
59 var lang;
60 </xsl:text>
61 <xsl:for-each select="/page/pageResponse/metadataList/metadata">
62 <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
63 <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
64 <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
65 addMetadataToList(name, value, gs.siteMetadata, lang);
66 </xsl:for-each>
67
68 <xsl:for-each select="/page/pageResponse/collection/metadataList/metadata">
69 <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
70 <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
71 <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
72 addMetadataToList(name, value, gs.collectionMetadata, lang);
73 </xsl:for-each>
74
75 <xsl:for-each select="/page/pageResponse/document/metadataList/metadata">
76 <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
77 <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
78 <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
79 addMetadataToList(name, value, gs.documentMetadata, lang);
80 </xsl:for-each>
81 </script>
82 </xsl:template>
83
84 <xsl:template name="populate-image-url-values">
85 <script type="text/javascript">
86 <xsl:text disable-output-escaping="yes">gs.imageURLs.expand = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'expand_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
87 <xsl:text disable-output-escaping="yes">gs.imageURLs.collapse = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'collapse_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
88 <xsl:text disable-output-escaping="yes">gs.imageURLs.page = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
89 <xsl:text disable-output-escaping="yes">gs.imageURLs.chapter = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'chapter_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
90 <xsl:text disable-output-escaping="yes">gs.imageURLs.realisticBook = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'realistic_books_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
91 <xsl:text disable-output-escaping="yes">gs.imageURLs.highlight = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'highlight_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
92 <xsl:text disable-output-escaping="yes">gs.imageURLs.bookshelf = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
93 <xsl:text disable-output-escaping="yes">gs.imageURLs.book = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
94 <xsl:text disable-output-escaping="yes">gs.imageURLs.loading = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'loading_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
95 <xsl:text disable-output-escaping="yes">gs.imageURLs.pageIcon = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
96 </script>
97 </xsl:template>
98</xsl:stylesheet>
99
100 <!--
101 USEFUL FOR TESTING ASSOCIATIVE ARRAYS
102 function getKeys(obj)
103 {
104 var keys = [];
105 for(var key in obj)
106 {
107 keys.push(key);
108 }
109 return keys;
110 }
111 -->
112
113 <!-- CAN WE FIND SOME WAY TO MAKE THIS WORK?
114 <xsl:call-template name="populate-metadata-values">
115 <xsl:with-param name="path">/page/pageResponse/metadataList/metadata</xsl:with-param>
116 <xsl:with-param name="metadataListName">siteMetadata</xsl:with-param>
117 </xsl:call-template>
118
119 <xsl:call-template name="populate-metadata-values">
120 <xsl:with-param name="path">/page/pageResponse/collection/metadataList/metadata</xsl:with-param>
121 <xsl:with-param name="metadataListName">collectionMetadata</xsl:with-param>
122 </xsl:call-template>
123
124 <xsl:call-template name="populate-metadata-values">
125 <xsl:with-param name="path">/page/pageResponse/document/metadataList/metadata</xsl:with-param>
126 <xsl:with-param name="metadataListName">documentMetadata</xsl:with-param>
127 </xsl:call-template>
128 -->
129
130 <!-- NOT WORKING BUT IT WOULD BE TIDIER IF IT DID
131 <xsl:template name="populate-metadata-values">
132 <xsl:param name="path"/>
133 <xsl:param name="metadataListName"/>
134
135 <xsl:for-each select="$path">
136 <script type="text/javascript">
137 <xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
138 <xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
139 <xsl:text disable-output-escaping="yes">var lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
140 <xsl:text disable-output-escaping="yes">var metadataListName = "</xsl:text><xsl:value-of select="$metadataListName"/><xsl:text disable-output-escaping="yes">";</xsl:text>
141 var list = gs[metadataListName];
142 if(lang == "")
143 {
144 list[name] = value;
145 }
146 else
147 {
148 if (list[lang] == undefined)
149 {
150 list[lang] = new Array();
151 }
152 var langList = list[lang];
153 langList[name] = value;
154 }
155 </script>
156 </xsl:for-each>
157 </xsl:template>
158 -->
Note: See TracBrowser for help on using the repository browser.