Merge pull request #593 from rmzelle/update-csl-preview
Update cslpreview.xul
This commit is contained in:
commit
ee389f106e
|
@ -44,25 +44,28 @@
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
//refresh();
|
//refresh();
|
||||||
|
|
||||||
|
var iframe = document.getElementById('zotero-csl-preview-box');
|
||||||
|
iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p>Select one or more items in Zotero and click the "Refresh" button to see how these items are rendered by the installed CSL citation styles.</p></body></html>';
|
||||||
}
|
}
|
||||||
function refresh() {
|
function refresh() {
|
||||||
var iframe = document.getElementById('zotero-csl-preview-box');
|
var iframe = document.getElementById('zotero-csl-preview-box');
|
||||||
var items = Zotero.getActiveZoteroPane().getSelectedItems();
|
var items = Zotero.getActiveZoteroPane().getSelectedItems();
|
||||||
if (items.length == 0) {
|
if (items.length === 0) {
|
||||||
iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p style="color: red">No references selected in Zotero.</p></body></html>';
|
iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p style="color: red">No items selected in Zotero.</p></body></html>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var progressWin = new Zotero.ProgressWindow();
|
var progressWin = new Zotero.ProgressWindow();
|
||||||
// XXX needs its own string really!
|
// XXX needs its own string really!
|
||||||
progressWin.changeHeadline(Zotero.getString("pane.items.menu.createBib.multiple"));
|
progressWin.changeHeadline(Zotero.getString("pane.items.menu.createBib.multiple"));
|
||||||
var icon = 'chrome://zotero/skin/treeitem-attachment-file.png';
|
var icon = 'chrome://zotero/skin/treeitem-attachment-file.png';
|
||||||
progressWin.addLines(document.title, icon)
|
progressWin.addLines(document.title, icon);
|
||||||
progressWin.show();
|
progressWin.show();
|
||||||
progressWin.startCloseTimer();
|
progressWin.startCloseTimer();
|
||||||
var f = function() {
|
var f = function() {
|
||||||
var styles = Zotero.Styles.getAll();
|
var styles = Zotero.Styles.getAll();
|
||||||
// XXX needs its own string really for the title!
|
// XXX needs its own string really for the title!
|
||||||
var str = '<html><head><title></title></head><body><h1>Citation/Bibliography list<h1>';
|
var str = '<html><head><title></title></head><body>';
|
||||||
for each(var style in styles) {
|
for each(var style in styles) {
|
||||||
if (style.source) {
|
if (style.source) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -70,14 +73,15 @@
|
||||||
Zotero.debug("Generate Bib for " + style.title);
|
Zotero.debug("Generate Bib for " + style.title);
|
||||||
var cite = generateBibliography(style);
|
var cite = generateBibliography(style);
|
||||||
if (cite) {
|
if (cite) {
|
||||||
str += '<hr><h2>' + style.title + '</h2>';
|
str += '<h3>' + style.title + '</h3>';
|
||||||
str += cite;
|
str += cite;
|
||||||
|
str += '<hr>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
str += '</body></html>';
|
str += '</body></html>';
|
||||||
iframe.contentDocument.documentElement.innerHTML = str;
|
iframe.contentDocument.documentElement.innerHTML = str;
|
||||||
}
|
};
|
||||||
// Give progress window time to appear
|
// Give progress window time to appear
|
||||||
setTimeout(f, 100);
|
setTimeout(f, 100);
|
||||||
}
|
}
|
||||||
|
@ -86,33 +90,13 @@
|
||||||
var iframe = document.getElementById('zotero-csl-preview-box');
|
var iframe = document.getElementById('zotero-csl-preview-box');
|
||||||
|
|
||||||
var items = Zotero.getActiveZoteroPane().getSelectedItems();
|
var items = Zotero.getActiveZoteroPane().getSelectedItems();
|
||||||
if (items.length == 0) {
|
if (items.length === 0) {
|
||||||
iframe.contentDocument.documentElement.innerHTML = '<html><head><title></title></head><body><p style="color: red">No references selected in Zotero.</p></body></html>';
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
var authordate = document.getElementById("format-author-date");
|
var citationFormat = document.getElementById("citation-format").selectedItem.value;
|
||||||
var numeric = document.getElementById("format-numeric");
|
if (citationFormat != "all" && citationFormat != style.categories) {
|
||||||
Zotero.debug("style class is " + style.class);
|
Zotero.debug("CSL IGNORE: citation format is " + style.categories);
|
||||||
if (document.getElementById("format-note").checked == false && style.class == "note") {
|
|
||||||
Zotero.debug("CSL IGNORE NOTE one");
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
if (document.getElementById("format-in-text").checked == false && style.class == "in-text") {
|
|
||||||
Zotero.debug("CSL IGNORE IN-TEXT one");
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
var terms = new Object();
|
|
||||||
for each(var cat in style.categories) {
|
|
||||||
Zotero.debug("TERM is " + cat.toString());
|
|
||||||
terms[cat.toString()] = true;
|
|
||||||
}
|
|
||||||
if (!numeric.checked && terms["numeric"]) {
|
|
||||||
Zotero.debug("CSL IGNORE this numeric");
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
if (!authordate.checked && terms["author-date"]) {
|
|
||||||
Zotero.debug("CSL IGNORE this AD");
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
var styleEngine = style.getCiteProc();
|
var styleEngine = style.getCiteProc();
|
||||||
|
@ -123,19 +107,17 @@
|
||||||
[], [], "html");
|
[], [], "html");
|
||||||
|
|
||||||
// Generate bibliography
|
// Generate bibliography
|
||||||
if(!style.hasBibliography) {
|
|
||||||
var bibliography = '';
|
var bibliography = '';
|
||||||
} else {
|
if(style.hasBibliography) {
|
||||||
styleEngine.updateItems([item.id for each(item in items)]);
|
styleEngine.updateItems([item.id for each(item in items)]);
|
||||||
var bibliography = '<p>' + Zotero.Cite.makeFormattedBibliography(styleEngine, "html");
|
bibliography = Zotero.Cite.makeFormattedBibliography(styleEngine, "html");
|
||||||
}
|
}
|
||||||
|
|
||||||
return '<div>' +
|
return '<p>' + citations + '</p>' + bibliography;
|
||||||
citations + bibliography + '</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}();
|
||||||
]]>
|
]]>
|
||||||
</script>
|
</script>
|
||||||
<!-- NEEDS LOCALISING -->
|
<!-- NEEDS LOCALISING -->
|
||||||
|
@ -144,18 +126,20 @@
|
||||||
<hbox align="center">
|
<hbox align="center">
|
||||||
<button id="preview-refresh-button" label="Refresh" oncommand="Zotero_CSL_Preview.refresh()"/>
|
<button id="preview-refresh-button" label="Refresh" oncommand="Zotero_CSL_Preview.refresh()"/>
|
||||||
<groupbox orient="horizontal" align="center">
|
<groupbox orient="horizontal" align="center">
|
||||||
<label value="Class:"/>
|
<label value="Citation format:" />
|
||||||
<checkbox id="format-in-text" label="In-Text" checked="true"/>
|
<menulist id="citation-format" oncommand="Zotero_CSL_Preview.refresh()">
|
||||||
<checkbox id="format-note" label="Notes" checked="true"/>
|
<menupopup>
|
||||||
</groupbox>
|
<menuitem label="all" value="all"/>
|
||||||
<groupbox orient="horizontal" align="center">
|
<menuitem label="author" value="author"/>
|
||||||
<label value="Citation form:"/>
|
<menuitem label="author-date" value="author-date"/>
|
||||||
<checkbox id="format-author-date" label="Author Date" checked="true"/>
|
<menuitem label="label" value="label"/>
|
||||||
<checkbox id="format-numeric" label="Numeric" checked="true"/>
|
<menuitem label="note" value="note"/>
|
||||||
|
<menuitem label="numeric" value="numeric"/>
|
||||||
|
</menupopup>
|
||||||
|
</menulist>
|
||||||
</groupbox>
|
</groupbox>
|
||||||
</hbox>
|
</hbox>
|
||||||
</hbox>
|
</hbox>
|
||||||
<splitter/>
|
|
||||||
<iframe id="zotero-csl-preview-box" flex="1" style="padding: 0 1em; background:white;" overflow="auto" type="content"/>
|
<iframe id="zotero-csl-preview-box" flex="1" style="padding: 0 1em; background:white;" overflow="auto" type="content"/>
|
||||||
</vbox>
|
</vbox>
|
||||||
|
|
||||||
|
|
|
@ -444,10 +444,6 @@ Zotero.Style = function(arg) {
|
||||||
Zotero.Styles.ns);
|
Zotero.Styles.ns);
|
||||||
this.updated = Zotero.Utilities.xpathText(doc, '/csl:style/csl:info[1]/csl:updated[1]',
|
this.updated = Zotero.Utilities.xpathText(doc, '/csl:style/csl:info[1]/csl:updated[1]',
|
||||||
Zotero.Styles.ns).replace(/(.+)T([^\+]+)\+?.*/, "$1 $2");
|
Zotero.Styles.ns).replace(/(.+)T([^\+]+)\+?.*/, "$1 $2");
|
||||||
this.categories = [category.getAttribute("term")
|
|
||||||
for each(category in Zotero.Utilities.xpath(doc,
|
|
||||||
'/csl:style/csl:info[1]/csl:category', Zotero.Styles.ns))
|
|
||||||
if(category.hasAttribute("term"))];
|
|
||||||
this.locale = Zotero.Utilities.xpathText(doc, '/csl:style/@default-locale',
|
this.locale = Zotero.Utilities.xpathText(doc, '/csl:style/@default-locale',
|
||||||
Zotero.Styles.ns) || null;
|
Zotero.Styles.ns) || null;
|
||||||
this._class = doc.documentElement.getAttribute("class");
|
this._class = doc.documentElement.getAttribute("class");
|
||||||
|
@ -456,7 +452,21 @@ Zotero.Style = function(arg) {
|
||||||
Zotero.Styles.ns).length;
|
Zotero.Styles.ns).length;
|
||||||
this._hasBibliography = !!doc.getElementsByTagName("bibliography").length;
|
this._hasBibliography = !!doc.getElementsByTagName("bibliography").length;
|
||||||
this._version = doc.documentElement.getAttribute("version");
|
this._version = doc.documentElement.getAttribute("version");
|
||||||
if(!this._version) this._version = "0.8";
|
if(!this._version) {
|
||||||
|
this._version = "0.8";
|
||||||
|
|
||||||
|
//In CSL 0.8.1, the "term" attribute on cs:category stored both
|
||||||
|
//citation formats and fields.
|
||||||
|
this.categories = [category.getAttribute("term")
|
||||||
|
for each(category in Zotero.Utilities.xpath(doc,
|
||||||
|
'/csl:style/csl:info[1]/csl:category', Zotero.Styles.ns))
|
||||||
|
if(category.hasAttribute("term"))];
|
||||||
|
} else {
|
||||||
|
//CSL 1.0 introduced a dedicated "citation-format" attribute on cs:category
|
||||||
|
this.categories = Zotero.Utilities.xpathText(doc,
|
||||||
|
'/csl:style/csl:info[1]/csl:category[@citation-format][1]/@citation-format',
|
||||||
|
Zotero.Styles.ns);
|
||||||
|
}
|
||||||
|
|
||||||
this.source = Zotero.Utilities.xpathText(doc,
|
this.source = Zotero.Utilities.xpathText(doc,
|
||||||
'/csl:style/csl:info[1]/csl:link[@rel="source" or @rel="independent-parent"][1]/@href',
|
'/csl:style/csl:info[1]/csl:link[@rel="source" or @rel="independent-parent"][1]/@href',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user