From e2f1f354f345a557dfe510cb6bbe9a19a1fe874f Mon Sep 17 00:00:00 2001 From: rmzelle Date: Sat, 6 Dec 2014 21:34:34 -0500 Subject: [PATCH] Update Zotero Preview pane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove splitter * Add explanation of how Zotero Preview pane works * Limit filtering to citation format Also add support for “citation-format” attribute of CSL 1.0 * Remove redundant warning (already happens on this.refresh) * Use "items" instead of "references" * Clean up HTML a little * Fix some JSHint warnings --- chrome/content/zotero/tools/cslpreview.xul | 78 +++++++++------------- chrome/content/zotero/xpcom/style.js | 22 ++++-- 2 files changed, 47 insertions(+), 53 deletions(-) diff --git a/chrome/content/zotero/tools/cslpreview.xul b/chrome/content/zotero/tools/cslpreview.xul index 4b7251e115..49f29c7ceb 100644 --- a/chrome/content/zotero/tools/cslpreview.xul +++ b/chrome/content/zotero/tools/cslpreview.xul @@ -43,26 +43,29 @@ this.generateBibliography = generateBibliography; function init() { - //refresh(); + //refresh(); + + var iframe = document.getElementById('zotero-csl-preview-box'); + iframe.contentDocument.documentElement.innerHTML = '

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.

'; } function refresh() { var iframe = document.getElementById('zotero-csl-preview-box'); var items = Zotero.getActiveZoteroPane().getSelectedItems(); - if (items.length == 0) { - iframe.contentDocument.documentElement.innerHTML = '

No references selected in Zotero.

'; + if (items.length === 0) { + iframe.contentDocument.documentElement.innerHTML = '

No items selected in Zotero.

'; return; } var progressWin = new Zotero.ProgressWindow(); // XXX needs its own string really! progressWin.changeHeadline(Zotero.getString("pane.items.menu.createBib.multiple")); var icon = 'chrome://zotero/skin/treeitem-attachment-file.png'; - progressWin.addLines(document.title, icon) + progressWin.addLines(document.title, icon); progressWin.show(); progressWin.startCloseTimer(); var f = function() { var styles = Zotero.Styles.getAll(); // XXX needs its own string really for the title! - var str = '

Citation/Bibliography list

'; + var str = ''; for each(var style in styles) { if (style.source) { continue; @@ -70,14 +73,15 @@ Zotero.debug("Generate Bib for " + style.title); var cite = generateBibliography(style); if (cite) { - str += '

' + style.title + '

'; + str += '

' + style.title + '

'; str += cite; + str += '
'; } } str += ''; iframe.contentDocument.documentElement.innerHTML = str; - } + }; // Give progress window time to appear setTimeout(f, 100); } @@ -86,33 +90,13 @@ var iframe = document.getElementById('zotero-csl-preview-box'); var items = Zotero.getActiveZoteroPane().getSelectedItems(); - if (items.length == 0) { - iframe.contentDocument.documentElement.innerHTML = '

No references selected in Zotero.

'; + if (items.length === 0) { return ''; } - var authordate = document.getElementById("format-author-date"); - var numeric = document.getElementById("format-numeric"); - Zotero.debug("style class is " + style.class); - 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"); + var citationFormat = document.getElementById("citation-format").selectedItem.value; + if (citationFormat != "all" && citationFormat != style.categories) { + Zotero.debug("CSL IGNORE: citation format is " + style.categories); return ''; } var styleEngine = style.getCiteProc(); @@ -123,19 +107,17 @@ [], [], "html"); // Generate bibliography - if(!style.hasBibliography) { - var bibliography = ''; - } else { + var bibliography = ''; + if(style.hasBibliography) { styleEngine.updateItems([item.id for each(item in items)]); - var bibliography = '

' + Zotero.Cite.makeFormattedBibliography(styleEngine, "html"); + bibliography = Zotero.Cite.makeFormattedBibliography(styleEngine, "html"); } - return '

' + - citations + bibliography + '
'; + return '

' + citations + '

' + bibliography; } - } + }(); ]]> @@ -144,18 +126,20 @@