diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index 82615d3eb..ca6007c45 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -312,7 +312,7 @@ var Zotero_File_Interface = new function() { * * Does not check that items are actual references (and not notes or attachments) */ - function copyItemsToClipboard(items, style) { + function copyItemsToClipboard(items, style, asHTML) { // copy to clipboard var transferable = Components.classes["@mozilla.org/widget/transferable;1"]. createInstance(Components.interfaces.nsITransferable); @@ -329,8 +329,8 @@ var Zotero_File_Interface = new function() { transferable.addDataFlavor("text/html"); transferable.setTransferData("text/html", str, bibliography.length*2); - // add text - var bibliography = csl.formatBibliography(itemSet, "Text"); + // add text (or HTML source) + var bibliography = csl.formatBibliography(itemSet, asHTML ? 'HTML' : 'Text'); var str = Components.classes["@mozilla.org/supports-string;1"]. createInstance(Components.interfaces.nsISupportsString); str.data = bibliography; @@ -345,8 +345,10 @@ var Zotero_File_Interface = new function() { * Copies HTML and text citations for passed items in given style * * Does not check that items are actual references (and not notes or attachments) + * + * if |asHTML| is true, copy HTML source as text */ - function copyCitationToClipboard(items, style) { + function copyCitationToClipboard(items, style, asHTML) { // copy to clipboard var transferable = Components.classes["@mozilla.org/widget/transferable;1"]. createInstance(Components.interfaces.nsITransferable); @@ -369,8 +371,8 @@ var Zotero_File_Interface = new function() { transferable.addDataFlavor("text/html"); transferable.setTransferData("text/html", str, bibliography.length*2); - // add text - var bibliography = csl.formatCitation(citation, "Text"); + // add text (or HTML source) + var bibliography = csl.formatCitation(citation, asHTML ? 'HTML' : 'Text'); var str = Components.classes["@mozilla.org/supports-string;1"]. createInstance(Components.interfaces.nsISupportsString); str.data = bibliography; diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 98ce910a9..13cdc198f 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -1139,13 +1139,14 @@ var ZoteroPane = new function() var url = window.content.location.href; var [mode, format] = Zotero.QuickCopy.getFormatFromURL(url).split('='); + var [mode, contentType] = mode.split('/'); if (mode == 'bibliography') { if (asCitations) { - Zotero_File_Interface.copyCitationToClipboard(items, format); + Zotero_File_Interface.copyCitationToClipboard(items, format, contentType == 'html'); } else { - Zotero_File_Interface.copyItemsToClipboard(items, format); + Zotero_File_Interface.copyItemsToClipboard(items, format, contentType == 'html'); } } else if (mode == 'export') { diff --git a/chrome/content/zotero/preferences/preferences.js b/chrome/content/zotero/preferences/preferences.js index 42a09f8ab..eb5cb0798 100644 --- a/chrome/content/zotero/preferences/preferences.js +++ b/chrome/content/zotero/preferences/preferences.js @@ -134,18 +134,32 @@ function populateOpenURLResolvers() { } +/* + * Builds the main Quick Copy drop-down from the current global pref + */ function populateQuickCopyList() { // Initialize default format drop-down - var formatMenu = document.getElementById("quickCopy-menu"); var format = Zotero.Prefs.get("export.quickCopy.setting"); - buildQuickCopyFormatDropDown(formatMenu, format); - formatMenu.setAttribute('preference', "pref-quickCopy-setting"); + var menulist = document.getElementById("zotero-quickCopy-menu"); + buildQuickCopyFormatDropDown(menulist, Zotero.QuickCopy.getContentType(format), format); + menulist.setAttribute('preference', "pref-quickCopy-setting"); + updateQuickCopyHTMLCheckbox(); refreshQuickCopySiteList(); } -function buildQuickCopyFormatDropDown(menulist, currentFormat) { +/* + * Builds a Quick Copy drop-down + */ +function buildQuickCopyFormatDropDown(menulist, contentType, currentFormat) { + if (!currentFormat) { + currentFormat = menulist.value; + } + // Strip contentType from mode + currentFormat = Zotero.QuickCopy.stripContentType(currentFormat); + + menulist.selectedItem = null; menulist.removeAllItems(); @@ -167,13 +181,15 @@ function buildQuickCopyFormatDropDown(menulist, currentFormat) { // add styles to list var styles = Zotero.Cite.getStyles(); for (var i in styles) { - var val = 'bibliography=' + i; + var baseVal = 'bibliography=' + i; + var val = 'bibliography' + (contentType == 'html' ? '/html' : '') + '=' + i; var itemNode = document.createElement("menuitem"); itemNode.setAttribute("value", val); itemNode.setAttribute("label", styles[i]); + itemNode.setAttribute("oncommand", 'updateQuickCopyHTMLCheckbox()'); popup.appendChild(itemNode); - if (val == currentFormat) { + if (baseVal == currentFormat) { menulist.selectedItem = itemNode; } } @@ -198,6 +214,7 @@ function buildQuickCopyFormatDropDown(menulist, currentFormat) { var itemNode = document.createElement("menuitem"); itemNode.setAttribute("value", val); itemNode.setAttribute("label", translators[i].label); + itemNode.setAttribute("oncommand", 'updateQuickCopyHTMLCheckbox()'); popup.appendChild(itemNode); if (val == currentFormat) { @@ -205,19 +222,37 @@ function buildQuickCopyFormatDropDown(menulist, currentFormat) { } } + menulist.click(); + return popup; } +function updateQuickCopyHTMLCheckbox() { + var format = document.getElementById('zotero-quickCopy-menu').value; + var mode, contentType; + + var checkbox = document.getElementById('zotero-quickCopy-copyAsHTML'); + [mode, format] = format.split('='); + [mode, contentType] = mode.split('/'); + + checkbox.checked = contentType == 'html'; + checkbox.disabled = mode != 'bibliography'; +} + function showQuickCopySiteEditor(index) { var treechildren = document.getElementById('quickCopy-siteSettings-rows'); if (index != undefined && index > -1 && index < treechildren.childNodes.length) { var treerow = treechildren.childNodes[index].firstChild; - var domain = treerow.childNodes[0].getAttribute('label') - var format = treerow.childNodes[1].getAttribute('label') + var domain = treerow.childNodes[0].getAttribute('label'); + var format = treerow.childNodes[1].getAttribute('label'); + var asHTML = treerow.childNodes[2].getAttribute('label') != ''; } var format = Zotero.QuickCopy.getSettingFromFormattedName(format); + if (asHTML) { + format = format.replace('bibliography=', 'bibliography/html='); + } var io = {domain: domain, format: format, ok: false}; window.openDialog('chrome://zotero/content/preferences/quickCopySiteEditor.xul', "zotero-preferences-quickCopySiteEditor", "chrome, modal", io); @@ -254,14 +289,18 @@ function refreshQuickCopySiteList() { var treerow = document.createElement('treerow'); var domainCell = document.createElement('treecell'); var formatCell = document.createElement('treecell'); + var HTMLCell = document.createElement('treecell'); domainCell.setAttribute('label', siteData[i].domainPath); var formatted = Zotero.QuickCopy.getFormattedNameFromSetting(siteData[i].format); formatCell.setAttribute('label', formatted); + var copyAsHTML = Zotero.QuickCopy.getContentType(siteData[i].format) == 'html'; + HTMLCell.setAttribute('label', copyAsHTML ? ' ✓ ' : ''); treerow.appendChild(domainCell); treerow.appendChild(formatCell); + treerow.appendChild(HTMLCell); treeitem.appendChild(treerow); treechildren.appendChild(treeitem); } diff --git a/chrome/content/zotero/preferences/preferences.xul b/chrome/content/zotero/preferences/preferences.xul index eff54e0ca..ef4c81f01 100644 --- a/chrome/content/zotero/preferences/preferences.xul +++ b/chrome/content/zotero/preferences/preferences.xul @@ -262,30 +262,32 @@ To add a new preference: - - +