Skip to content

Commit

Permalink
Added in text citation
Browse files Browse the repository at this point in the history
and quick copy functionality
  • Loading branch information
dcartertod committed Apr 30, 2022
1 parent 9700e03 commit e980ea5
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 13 deletions.
Binary file added ZoteroAbstractCleaner.xpi.2021-08-17-11-19.bak
Binary file not shown.
Binary file added ZoteroAbstractCleaner.xpi.2022-02-09-08-57.bak
Binary file not shown.
Binary file added ZoteroAbstractCleaner.xpi.2022-02-09-08-59.bak
Binary file not shown.
Binary file modified ZoteroPreview.xpi
Binary file not shown.
Binary file added ZoteroPreview.xpi.2022-02-11-05-00.bak
Binary file not shown.
Binary file added ZoteroPreview.xpi.2022-04-03-11-53.bak
Binary file not shown.
Binary file added ZoteroPreview.xpi.2022-04-30-11-51.bak
Binary file not shown.
15 changes: 12 additions & 3 deletions ZoteroPreview/chrome/content/overlay.xul
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://zoteropreview/skin/overlay.css" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://zoteropreview/locale/zoteropreview.dtd">

<!DOCTYPE overlay [
<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd"> %globalDTD;
<!ENTITY % zoteroDTD SYSTEM "chrome://zotero/locale/zotero.dtd"> %zoteroDTD;
<!ENTITY % zoteroPreviewDTD SYSTEM "chrome://zoteropreview/locale/zoteropreview.dtd"> %zoteroPreviewDTD;
]>

<overlay id="zoteropreview-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
Expand All @@ -21,8 +26,12 @@
<tabpanel id="preview-pane" class="preview-pane" orient="vertical">
<vbox style="width:100%;">
<iframe id="zoteropreview-preview-box" style="padding: 0 1em; background:white;width:100%;height:95%" overflow="auto" type="content"/>
<label id="zoteropreview-options" class="text-link"
onclick="Zotero.zoteropreview.openPreferenceWindow();">&#9881; &zoteropreview.stylechooser;</label>
<button id="zoteropreview-options" class="zotero-tb-button"
onclick="Zotero.zoteropreview.openPreferenceWindow();">&#9881; &zoteropreview.stylechooser;</button>
<button id="zoteropreview-options1" class="zotero-tb-button"
onclick="Zotero.zoteropreview.copyCitation(true);">Copy Citation</button>
<button id="zoteropreview-options2" class="zotero-tb-button"
onclick="Zotero.zoteropreview.copyCitation(false);">Copy Bibliography</button>
</vbox>
</tabpanel>
</tabpanels>
Expand Down
84 changes: 76 additions & 8 deletions ZoteroPreview/chrome/content/zoteropreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,38 +96,89 @@ Zotero.zoteropreview = new function() {
if (items.length == 1 && Zotero.getActiveZoteroPane().document.getElementById('zotero-view-tabbox').selectedIndex == 4){
Zotero.debug("zoteropreview: updating citation");
var qc = Zotero.QuickCopy;
var format = Zotero.Prefs.get("export.quickCopy.setting");
var format = qc.getFormatFromURL(qc.lastActiveURL);
format = Zotero.QuickCopy.unserializeSetting(format);

Zotero.debug("zoteropreview: " + format);

if (format.mode == ""){
format.mode = "bibliography";
}

var userpref = Zotero.Prefs.get('extensions.zoteropreview.citationstyle', true);
// get the font size preference from the global setting
var fontSizePref = Zotero.Prefs.get('fontSize');
// Zotero.debug("format is: " + format);
// Zotero.debug("userpref is: " + userpref);
Zotero.debug("userpref is: " + userpref);

if ( userpref != "" ){
format = "bibliography=" + userpref;
Zotero.debug("format: " + format["id"]);
Zotero.debug("setting userpref");
format.id = userpref;
}
// Zotero.debug("format is now: " + format);
Zotero.debug("format is now: " + format);

var msg = "No bibliography style is chosen in the settings for QuickCopy.";

// added a pane in overlay.xul
var iframe = Zotero.getActiveZoteroPane().document.getElementById('zoteropreview-preview-box');

if (format.split("=")[0] !== "bibliography") {
if (format.id == "") {
iframe.contentDocument.documentElement.innerHTML = msg;
this.openPreferenceWindow();
return;
}

var biblio = qc.getContentFromItems(items, format);
msg = biblio.html;
msg = '<h3>' + Zotero.getString('styles.bibliography') + '</h3>' + biblio.html;
//msg += "<p><a href=\"#\" onclick=\"Zotero.zoteropreview.copyCitation(true);\">" + Zotero.getString('general.copy') + "</a></p>";

Zotero.debug("zoteropreview: " + msg);

var locale = format.locale ? format.locale : Zotero.Prefs.get('export.quickCopy.locale');

Zotero.debug("format is: " + format);

var style = Zotero.Styles.get(format.id);
var styleEngine = style.getCiteProc(locale, 'html');

var citations = styleEngine.previewCitationCluster(
{
citationItems: items.map(item => ({ id: item.id })),
properties: {}
},
[], [], "html"
);
styleEngine.free();

msg += '<hr><h3>' + Zotero.getString('styles.editor.output.individualCitations') + '</h3>' + citations;
// msg += "<p><a href=\"#\" onclick=\"Zotero.zoteropreview.copyCitation(false);\">" + Zotero.getString('general.copy') + "</a></p>";
Zotero.debug("zoteropreview: " + msg);


// working on copy

// var asCitations = true; // in text
// Zotero_File_Interface.copyItemsToClipboard(
// items, format.id, locale, format.contentType == 'html', asCitations
// );
// asCitations = false; // bibliography
// Zotero_File_Interface.copyItemsToClipboard(
// items, format.id, locale, format.contentType == 'html', asCitations
// );

// wrap the output in a div that has the font size preference
msg = "<div style=\"font-size: " + fontSizePref + "em\">" + msg + "</div>";
// Zotero.debug(msg);

// https://github.com/zotero/zotero/blob/master/chrome/content/zotero/tools/cslpreview.js
// https://github.com/zotero/zotero/blob/master/chrome/content/zotero/tools/cslpreview.xul

iframe.contentDocument.documentElement.innerHTML = msg;

// Zotero_CSL_Editor.generateBibliography(styleEngine);

if (iframe.contentDocument.documentElement.innerHTML != msg){
iframe.contentDocument.documentElement.innerHTML = msg;
}
}
Zotero.debug('zoteropreview: getCitationPreview done');
Zotero.debug('-------------------');
Expand All @@ -145,6 +196,23 @@ Zotero.zoteropreview = new function() {
'zoteropreview-stylechooser',
'chrome,centerscreen,scrollbars=yes,resizable=yes');
};

this.copyCitation = function(asCitations){
// true = citation
// false = bib
var qc = Zotero.QuickCopy;
var items = Zotero.getActiveZoteroPane().getSelectedItems();
var format = qc.getFormatFromURL(qc.lastActiveURL);
format = qc.unserializeSetting(format);
var locale = format.locale ? format.locale : Zotero.Prefs.get('export.quickCopy.locale');
var userpref = Zotero.Prefs.get('extensions.zoteropreview.citationstyle', true);
if ( userpref != "" ){
format.id = userpref;
}
Zotero_File_Interface.copyItemsToClipboard(
items, format.id, locale, format.contentType == 'html', asCitations
);
}

};

Expand Down
3 changes: 3 additions & 0 deletions ZoteroPreview/chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!ENTITY zoteropreview.menuitem "Preview">
<!ENTITY zoteropreview.stylechooser "Choose Preview Style">
<!ENTITY zoteropreview.stylelabel "Choose Preview Style">
2 changes: 1 addition & 1 deletion ZoteroPreview/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<em:id>[email protected]</em:id>
<em:type>2</em:type> <!-- type=extension -->
<em:name>ZoteroPreview</em:name>
<em:version>0.1.1</em:version>
<em:version>0.1.2</em:version>
<em:creator>David Tod</em:creator>
<em:description>Citation preview pane for Zotero.</em:description>
<em:homepageURL>https://github.com/dcartertod/zotero-plugins</em:homepageURL>
Expand Down
2 changes: 1 addition & 1 deletion ZoteroPreview/zoteropreview-update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ so you update this file when there's a new release to point to the new release -
<rdf:Seq>
<rdf:li>
<rdf:Description>
<em:version>0.1.1</em:version>
<em:version>0.1.2</em:version>
<em:targetApplication>
<rdf:Description>
<em:id>[email protected]</em:id>
Expand Down

0 comments on commit e980ea5

Please sign in to comment.