Ticket #817: cslpreview.xul

File cslpreview.xul, 5.8 KB (added by codec, 9 years ago)

CSL Preview screen

Line 
1<?xml version="1.0"?>
2<!--
3    ***** BEGIN LICENSE BLOCK *****
4   
5    Copyright (c) 2006  Center for History and New Media
6                        George Mason University, Fairfax, Virginia, USA
7                        http://chnm.gmu.edu
8   
9    Licensed under the Educational Community License, Version 1.0 (the "License");
10    you may not use this file except in compliance with the License.
11    You may obtain a copy of the License at
12   
13    http://www.opensource.org/licenses/ecl1.php
14   
15    Unless required by applicable law or agreed to in writing, software
16    distributed under the License is distributed on an "AS IS" BASIS,
17    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18    See the License for the specific language governing permissions and
19    limitations under the License.
20   
21    ***** END LICENSE BLOCK *****
22    Contributed by Julian Onions
23-->
24<?xml-stylesheet href="chrome://global/skin/global.css"?>
25<?xml-stylesheet href="chrome://zotero/skin/zotero.css" type="text/css"?>
26
27<window
28        id="csl-preview"
29        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
30        onload="Zotero_CSL_Preview.init();"
31        title="Zotero Preview pane">
32       
33        <script src="chrome://zotero/content/include.js"/>
34       
35        <script>
36        <![CDATA[
37                default xml namespace = "http://purl.org/net/xbiblio/csl";
38
39                var Zotero_CSL_Preview = new function() {
40                        var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
41                                .getInterface(Components.interfaces.nsIWebNavigation)
42                                .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
43                                .rootTreeItem
44                                .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
45                                .getInterface(Components.interfaces.nsIDOMWindow);
46                       
47                        this.init = init;
48                        this.refresh = refresh;
49                        this.generateBibliography = generateBibliography;
50
51                        function init() {
52                                //refresh();
53                        }
54                        function refresh() {
55                                var iframe = document.getElementById('zotero-csl-preview-box');
56                                var items = mainWindow.ZoteroPane.getSelectedItems();
57                                if (items.length == 0) {
58                                        iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p style="color: red">No references selected in Zotero.</p></body></html>';
59                                        return;
60                                }
61                                var progressWin = new Zotero.ProgressWindow();
62                                // XXX needs its own string really!
63                                progressWin.changeHeadline(Zotero.getString("pane.items.menu.createBib.multiple"));
64                                var icon = 'chrome://zotero/skin/treeitem-attachment-file.png';
65                                progressWin.addLines(window.content.document.title, icon)
66                                progressWin.show();
67                                progressWin.startCloseTimer();
68                                var f = function() {
69                                        var csls = Zotero.DB.query("SELECT title, csl FROM csl ORDER BY title");
70                                        // XXX needs its own string really for the title!
71                                        var str = '<html><head><title></title></head><body><h1>Citation/Bibliography list<h1>';
72                                        for (var i=0; i<csls.length; i++) {
73                                                Zotero.debug("Generate Bib for " + csls[i].title);
74                                                var cite = generateBibliography(csls[i].csl);
75                                                if (cite) {
76                                                        str += '<hr><h2>' + csls[i].title + '</h2>';
77                                                        str += cite;
78                                                }
79                                        }
80
81                                        str += '</body></html>';
82                                        iframe.contentDocument.documentElement.innerHTML = str;                 
83                                }
84                                // Give progress window time to appear
85                                setTimeout(f, 100);
86                        }
87                         
88                        function generateBibliography(str) {
89                                var iframe = document.getElementById('zotero-csl-preview-box');
90                               
91                                var items = mainWindow.ZoteroPane.getSelectedItems();
92                                if (items.length == 0) {
93                                        iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p style="color: red">No references selected in Zotero.</p></body></html>';
94                                        return;
95                                }
96                               
97                                if (str.indexOf("<defaults") != -1) {
98                                        csl = new Zotero.CSL.Compat(str);
99                                }
100                                else {
101                                        csl = new Zotero.CSL(str);
102                                }
103                                var authordate = document.getElementById("format-author-date");
104                                var numeric = document.getElementById("format-numeric");
105                                Zotero.debug("style class is " + csl.class);
106                                if (document.getElementById("format-note").checked == false && csl.class == "note") {
107                                        Zotero.debug("CSL IGNORE NOTE one");
108                                        return;
109                                }
110                                if (document.getElementById("format-in-text").checked == false && csl.class == "in-text") {
111                                        Zotero.debug("CSL IGNORE IN-TEXT one");
112                                        return;
113                                }
114                                var xmlinfo = csl._csl.info;
115                                var terms = new Object();
116                                for each(var cat in xmlinfo.category.@term) {
117                                        Zotero.debug("TERM is " + cat.toString());
118                                        terms[cat.toString()] = true;
119                                }
120                                if (!numeric.checked && terms["numeric"]) {
121                                        Zotero.debug("CSL IGNORE this numeric");
122                                        return;
123                                }
124                                if (!authordate.checked && terms["author-date"]) {
125                                        Zotero.debug("CSL IGNORE this AD");
126                                        return;
127                                }
128                                var itemSet = csl.createItemSet(items);
129                               
130                                // Generate multiple citations
131                                var citation = csl.createCitation(itemSet.items);
132                                var citations = csl.formatCitation(citation, "HTML");
133                       
134                                // Generate bibliography
135                                var bibliography = '<p>' + csl.formatBibliography(itemSet, "HTML");
136                                return citations + bibliography;
137                        }
138                       
139                       
140                }
141        ]]>
142        </script>
143        <!-- NEEDS LOCALISING -->
144        <vbox flex="1">
145           <hbox >
146                <hbox align="center">
147                        <button id="preview-refresh-button" label="Refresh" oncommand="Zotero_CSL_Preview.refresh()"/>
148                        <groupbox orient="horizontal" align="center">
149                                <label value="Class:"/>
150                                <checkbox id="format-in-text" label="In-Text" checked="true"/>
151                                <checkbox id="format-note" label="Notes" checked="true"/>
152                        </groupbox>
153                        <groupbox orient="horizontal" align="center">
154                                <label value="Citation form:"/>
155                                <checkbox id="format-author-date" label="Author Date" checked="true"/>
156                                <checkbox id="format-numeric" label="Numeric" checked="true"/>
157                        </groupbox>
158                </hbox>
159           </hbox>
160           <splitter/>
161           <iframe id="zotero-csl-preview-box" flex="1" style="padding: 0 1em; background:white;" overflow="auto"/>
162        </vbox>
163       
164</window>