root/main/trunk/greenstone3/web/interfaces/oran/transform/javascript-global-setup.xsl @ 24520

Revision 24520, 9.1 KB (checked in by sjm84, 8 years ago)

The expanding classifers will now remain open if you press back to revisit the page, also adding xsltParams to the gs variable, also changed Document Maker to Document Basket in the pref.xsl file

  • Property svn:executable set to *
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.xsltParams = new Array();
14            gs.siteMetadata = new Array();
15            gs.collectionMetadata = new Array();
16            gs.documentMetadata = new Array();
17            gs.imageURLs = new Array();
18            gs.variables = new Array();
19        </script>
20        <xsl:call-template name="populate-cgi-param-values"/>
21        <xsl:call-template name="populate-xslt-param-values"/>
22        <xsl:call-template name="populate-image-url-values"/>
23        <xsl:call-template name="populate-metadata-values"/>
24    </xsl:template>
25   
26    <xsl:template name="populate-cgi-param-values">
27        <script type="text/javascript">
28            var name;
29            var value;
30            <xsl:for-each select="/page/pageRequest/paramList/param">
31                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
32                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of select="@value"/><xsl:text disable-output-escaping="yes">";</xsl:text>
33                <xsl:text disable-output-escaping="yes">name = name.replace(".", "_");</xsl:text>
34                gs.cgiParams[name] = value;
35            </xsl:for-each>
36        </script>
37    </xsl:template>
38   
39    <xsl:template name="populate-xslt-param-values">
40        <script type="text/javascript">
41            <xsl:text disable-output-escaping="yes">gs.xsltParams.library_name = "</xsl:text><xsl:value-of select="$library_name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
42            <xsl:text disable-output-escaping="yes">gs.xsltParams.interface_name = "</xsl:text><xsl:value-of select="$interface_name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
43        </script>
44    </xsl:template>
45   
46    <xsl:template name="populate-metadata-values">
47        <script type="text/javascript">
48            <xsl:text disable-output-escaping="yes">
49                function addMetadataToList(name, value, list, lang)
50                {
51                    name = name.replace(".", "_");
52                    if(lang == "" || lang == "en")
53                    {
54                        list[name] = value;
55                    }
56                    else
57                    {
58                        if (list[lang] == undefined)
59                        {
60                            list[lang] = new Array();
61                        }
62                        var langList = list[lang];
63                        langList[name] = value;
64                    }
65                }
66                var name;
67                var value;
68                var lang;
69            </xsl:text>
70            <xsl:for-each select="/page/pageResponse/metadataList/metadata">
71                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
72                <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>
73                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
74                addMetadataToList(name, value, gs.siteMetadata, lang);
75            </xsl:for-each>
76       
77            <xsl:for-each select="/page/pageResponse/collection/metadataList/metadata">
78                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
79                <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>
80                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
81                addMetadataToList(name, value, gs.collectionMetadata, lang);
82            </xsl:for-each>
83       
84            <xsl:for-each select="/page/pageResponse/document/metadataList/metadata">
85                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
86                <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>
87                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
88                addMetadataToList(name, value, gs.documentMetadata, lang);
89            </xsl:for-each>
90        </script>
91    </xsl:template>
92   
93    <xsl:template name="populate-image-url-values">
94        <script type="text/javascript">
95            <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>
96            <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>
97            <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>
98            <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>
99            <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>
100            <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>
101            <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>
102            <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>
103            <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>
104            <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>
105            <xsl:text disable-output-escaping="yes">gs.imageURLs.trashFull = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'trash_full_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
106        </script>
107    </xsl:template>
108</xsl:stylesheet>
109
110    <!--
111    USEFUL FOR TESTING ASSOCIATIVE ARRAYS
112    function getKeys(obj)
113    {
114        var keys = [];
115        for(var key in obj)
116        {
117            keys.push(key);
118        }
119        return keys;
120    }
121    -->
122
123    <!-- CAN WE FIND SOME WAY TO MAKE THIS WORK?
124    <xsl:call-template name="populate-metadata-values">
125        <xsl:with-param name="path">/page/pageResponse/metadataList/metadata</xsl:with-param>
126        <xsl:with-param name="metadataListName">siteMetadata</xsl:with-param>
127    </xsl:call-template>
128   
129    <xsl:call-template name="populate-metadata-values">
130        <xsl:with-param name="path">/page/pageResponse/collection/metadataList/metadata</xsl:with-param>
131        <xsl:with-param name="metadataListName">collectionMetadata</xsl:with-param>
132    </xsl:call-template>
133   
134    <xsl:call-template name="populate-metadata-values">
135        <xsl:with-param name="path">/page/pageResponse/document/metadataList/metadata</xsl:with-param>
136        <xsl:with-param name="metadataListName">documentMetadata</xsl:with-param>
137    </xsl:call-template>
138    -->
139
140    <!-- NOT WORKING BUT IT WOULD BE TIDIER IF IT DID
141    <xsl:template name="populate-metadata-values">
142        <xsl:param name="path"/>
143        <xsl:param name="metadataListName"/>
144       
145        <xsl:for-each select="$path">
146            <script type="text/javascript">
147                <xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
148                <xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
149                <xsl:text disable-output-escaping="yes">var lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
150                <xsl:text disable-output-escaping="yes">var metadataListName = "</xsl:text><xsl:value-of select="$metadataListName"/><xsl:text disable-output-escaping="yes">";</xsl:text>
151                var list = gs[metadataListName];
152                if(lang == "")
153                {
154                    list[name] = value;
155                }
156                else
157                {
158                    if (list[lang] == undefined)
159                    {
160                        list[lang] = new Array();
161                    }
162                    var langList = list[lang];
163                    langList[name] = value;
164                }
165            </script>
166        </xsl:for-each>
167    </xsl:template>
168    -->
Note: See TracBrowser for help on using the browser.