www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 6efe6c5bd6aea0661d1841d5fba5bd1498eb69ba
parent a6fae941adebb6af862696dc8c6ed950c8d92f34
Author: Simon Kornblith <simon@simonster.com>
Date:   Wed, 27 Mar 2013 23:53:38 -0400

Move "Automatically abbreviate journal titles" setting to document preferences

The setting is disabled by default for existing documents, but enabled by
default for new documents.

Diffstat:
Mchrome/content/zotero/bibliography.js | 56+++++++++++++++++++++++++++++++++++++++++---------------
Mchrome/content/zotero/fileInterface.js | 2+-
Mchrome/content/zotero/integration/integrationDocPrefs.xul | 13+++++++++----
Mchrome/content/zotero/preferences/preferences_cite.xul | 3---
Mchrome/content/zotero/rtfScan.js | 2+-
Mchrome/content/zotero/tools/csledit.xul | 2+-
Mchrome/content/zotero/tools/cslpreview.xul | 2+-
Mchrome/content/zotero/xpcom/cite.js | 304+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mchrome/content/zotero/xpcom/integration.js | 23+++++++++++++++++------
Mchrome/content/zotero/xpcom/quickCopy.js | 2+-
Mchrome/content/zotero/xpcom/style.js | 30+++++++++++++++++++++++++-----
Mchrome/locale/en-US/zotero/preferences.dtd | 1-
Mchrome/locale/en-US/zotero/zotero.dtd | 4++++
Mdefaults/preferences/zotero.js | 2+-
14 files changed, 252 insertions(+), 194 deletions(-)

diff --git a/chrome/content/zotero/bibliography.js b/chrome/content/zotero/bibliography.js @@ -124,10 +124,22 @@ var Zotero_File_Interface_Bibliography = new function() { if(document.getElementById("formatUsing")) { if(_io.fieldType == "Bookmark") document.getElementById("formatUsing").selectedIndex = 1; var formatOption = (_io.primaryFieldType == "ReferenceMark" ? "referenceMarks" : "fields"); - document.getElementById("fields").label = Zotero.getString("integration."+formatOption+".label"); - document.getElementById("fields-caption").textContent = Zotero.getString("integration."+formatOption+".caption"); - document.getElementById("fields-file-format-notice").textContent = Zotero.getString("integration."+formatOption+".fileFormatNotice"); - document.getElementById("bookmarks-file-format-notice").textContent = Zotero.getString("integration.fields.fileFormatNotice"); + document.getElementById("fields").label = + Zotero.getString("integration."+formatOption+".label"); + document.getElementById("fields-caption").textContent = + Zotero.getString("integration."+formatOption+".caption"); + document.getElementById("fields-file-format-notice").textContent = + Zotero.getString("integration."+formatOption+".fileFormatNotice"); + document.getElementById("bookmarks-file-format-notice").textContent = + Zotero.getString("integration.fields.fileFormatNotice"); + } + if(document.getElementById("automaticJournalAbbreviations-checkbox")) { + if(_io.automaticJournalAbbreviations === undefined) { + _io.automaticJournalAbbreviations = Zotero.Prefs.get("cite.automaticJournalAbbreviations"); + } + if(_io.automaticJournalAbbreviations) { + document.getElementById("automaticJournalAbbreviations-checkbox").checked = true; + } } if(document.getElementById("storeReferences")) { if(_io.storeReferences || _io.storeReferences === undefined) { @@ -152,23 +164,30 @@ var Zotero_File_Interface_Bibliography = new function() { var selectedItem = document.getElementById("style-listbox").selectedItem; } - var selectedStyle = selectedItem.getAttribute('value'); + var selectedStyle = selectedItem.getAttribute('value'), + selectedStyleObj = Zotero.Styles.get(selectedStyle); // // For integrationDocPrefs.xul // // update status of displayAs box based on style class - if(document.getElementById("displayAs")) { - var isNote = Zotero.Styles.get(selectedStyle).class == "note"; - document.getElementById("displayAs").disabled = !isNote; + if(document.getElementById("displayAs-groupbox")) { + var isNote = selectedStyleObj.class == "note"; + document.getElementById("displayAs-groupbox").hidden = !isNote; + + // update status of formatUsing box based on style class + if(document.getElementById("formatUsing")) { + if(isNote) document.getElementById("formatUsing").selectedIndex = 0; + document.getElementById("bookmarks").disabled = isNote; + document.getElementById("bookmarks-caption").disabled = isNote; + } } - - // update status of formatUsing box based on style class - if(document.getElementById("formatUsing")) { - if(isNote) document.getElementById("formatUsing").selectedIndex = 0; - document.getElementById("bookmarks").disabled = isNote; - document.getElementById("bookmarks-caption").disabled = isNote; + + // update status of displayAs box based on style class + if(document.getElementById("automaticJournalAbbreviations-vbox")) { + document.getElementById("automaticJournalAbbreviations-vbox").hidden = + !selectedStyleObj.usesAbbreviation; } // @@ -184,6 +203,8 @@ var Zotero_File_Interface_Bibliography = new function() { } document.getElementById("citations").label = label; } + + window.sizeToContent(); } function acceptSelection() { @@ -198,8 +219,13 @@ var Zotero_File_Interface_Bibliography = new function() { JSON.stringify({ mode: _io.mode, method: _io.method })); } - // ONLY FOR integrationDocPrefs.xul: collect displayAs + // ONLY FOR integrationDocPrefs.xul: if(document.getElementById("displayAs")) { + var automaticJournalAbbreviationsEl = document.getElementById("automaticJournalAbbreviations-checkbox"); + _io.automaticJournalAbbreviations = automaticJournalAbbreviationsEl.checked; + if(!automaticJournalAbbreviationsEl.hidden && _saveStyle) { + Zotero.Prefs.set("cite.automaticJournalAbbreviations", _io.automaticJournalAbbreviations); + } _io.useEndnotes = document.getElementById("displayAs").selectedIndex; _io.fieldType = (document.getElementById("formatUsing").selectedIndex == 0 ? _io.primaryFieldType : _io.secondaryFieldType); _io.storeReferences = document.getElementById("storeReferences").checked; diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js @@ -473,7 +473,7 @@ var Zotero_File_Interface = new function() { var clipboardService = Components.classes["@mozilla.org/widget/clipboard;1"]. getService(Components.interfaces.nsIClipboard); - var style = Zotero.Styles.get(style).csl; + var style = Zotero.Styles.get(style).getCiteProc(); var citation = {"citationItems":[{id:item.id} for each(item in items)], properties:{}}; // add HTML diff --git a/chrome/content/zotero/integration/integrationDocPrefs.xul b/chrome/content/zotero/integration/integrationDocPrefs.xul @@ -48,7 +48,7 @@ <listbox id="style-listbox" onselect="Zotero_File_Interface_Bibliography.styleChanged()"/> </groupbox> - <groupbox> + <groupbox id="displayAs-groupbox"> <caption label="&zotero.integration.prefs.displayAs.label;"/> <radiogroup id="displayAs" orient="horizontal"> <radio id="footnotes" label="&zotero.integration.prefs.footnotes.label;" selected="true"/> @@ -67,9 +67,14 @@ <description class="radioDescription" id="bookmarks-caption">&zotero.integration.prefs.bookmarks.caption;</description> <description class="radioDescription" id="bookmarks-file-format-notice"/> </radiogroup> - - <checkbox id="storeReferences" label="&zotero.integration.prefs.storeReferences.label;"/> - <description class="radioDescription">&zotero.integration.prefs.storeReferences.caption;</description> </groupbox> + + <vbox id="automaticJournalAbbreviations-vbox"> + <checkbox id="automaticJournalAbbreviations-checkbox" label="&zotero.integration.prefs.automaticJournalAbbeviations.label;"/> + <description class="radioDescription">&zotero.integration.prefs.automaticJournalAbbeviations.caption;</description> + </vbox> + + <checkbox id="storeReferences" label="&zotero.integration.prefs.storeReferences.label;"/> + <description class="radioDescription">&zotero.integration.prefs.storeReferences.caption;</description> </vbox> </dialog> \ No newline at end of file diff --git a/chrome/content/zotero/preferences/preferences_cite.xul b/chrome/content/zotero/preferences/preferences_cite.xul @@ -35,7 +35,6 @@ <preferences id="zotero-preferences-cite"> <preference id="pref-cite-useClassicAddCitationDialog" name="extensions.zotero.integration.useClassicAddCitationDialog" type="bool"/> <preference id="pref-cite-citePaperJournalArticleURL" name="extensions.zotero.export.citePaperJournalArticleURL" type="bool"/> - <preference id="pref-cite-automaticTitleAbbreviation" name="extensions.zotero.cite.automaticTitleAbbreviation" type="bool"/> </preferences> <tabbox> @@ -81,8 +80,6 @@ <label id="export-citePaperJournalArticleURL" width="45em"> &zotero.preferences.export.citePaperJournalArticleURL.description; </label> - - <checkbox label="&zotero.preferences.cite.styles.automaticTitleAbbreviation;" preference="pref-cite-automaticTitleAbbreviation"/> </groupbox> </tabpanel> </tabpanels> diff --git a/chrome/content/zotero/rtfScan.js b/chrome/content/zotero/rtfScan.js @@ -496,7 +496,7 @@ var Zotero_RTFScan = new function() { function _formatRTF() { // load style and create ItemSet with all items var zStyle = Zotero.Styles.get(document.getElementById("style-listbox").selectedItem.value) - var style = zStyle.csl; + var style = zStyle.getCiteProc(); style.setOutputFormat("rtf"); var isNote = style.class == "note"; diff --git a/chrome/content/zotero/tools/csledit.xul b/chrome/content/zotero/tools/csledit.xul @@ -112,7 +112,7 @@ else { try { styleObject = new Zotero.Style(str); - styleEngine = styleObject.csl; + styleEngine = styleObject.getCiteProc(); } catch(e) { iframe.contentDocument.documentElement.innerHTML = '<div>Error parsing '+ 'style: </div><div>'+e+'</div>'; diff --git a/chrome/content/zotero/tools/cslpreview.xul b/chrome/content/zotero/tools/cslpreview.xul @@ -117,7 +117,7 @@ Zotero.debug("CSL IGNORE this AD"); return ''; } - var styleEngine = style.csl; + var styleEngine = style.getCiteProc(); // Generate multiple citations var citations = styleEngine.previewCitationCluster( diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js @@ -72,7 +72,7 @@ Zotero.Cite = { * @return {String} Bibliography or item list in specified format */ "makeFormattedBibliographyOrCitationList":function(style, items, format, asCitationList) { - var cslEngine = style.csl; + var cslEngine = style.getCiteProc(); cslEngine.setOutputFormat(format); cslEngine.updateItems([item.id for each(item in items)]); @@ -312,10 +312,157 @@ Zotero.Cite = { }; /** + * Get a CSL abbreviation in the format expected by citeproc-js + */ +Zotero.Cite.getAbbreviation = new function() { + var abbreviations, + abbreviationCategories; + + /** + * Initialize abbreviations database. + */ + function init() { + if(!abbreviations) loadAbbreviations(); + } + + function loadAbbreviations() { + var file = Zotero.getZoteroDirectory(); + file.append("abbreviations.json"); + + var json, origin; + if(file.exists()) { + json = Zotero.File.getContents(file); + origin = file.path; + } else { + json = Zotero.File.getContentsFromURL("resource://zotero/schema/abbreviations.json"); + origin = "resource://zotero/schema/abbreviations.json"; + } + + try { + abbreviations = JSON.parse(json); + } catch(e) { + throw new Zotero.Exception.Alert("styles.abbreviations.parseError", origin, + "styles.abbreviations.title", e); + } + + if(!abbreviations.info || !abbreviations.info.name || !abbreviations.info.URI) { + throw new Zotero.Exception.Alert("styles.abbreviations.missingInfo", origin, + "styles.abbreviations.title"); + } + + abbreviationCategories = {}; + for(var jurisdiction in abbreviations) { + for(var category in abbreviations[jurisdiction]) { + abbreviationCategories[category] = true; + } + } + } + + /** + * Normalizes a key + */ + function normalizeKey(key) { + // Strip periods, normalize spacing, and convert to lowercase + return key.toString().toLowerCase(). + replace(/(?:\b|^)(?:and|et|y|und|l[ae]|the|[ld]')(?:\b|$)|[\x21-\x2C.\/\x3A-\x40\x5B-\x60\\\x7B-\x7E]/g, ""). + replace(/\s+/g, " ").trim(); + } + + function lookupKey(key) { + return key.toLowerCase().replace(/\s*\./g, "." ); + } + + /** + * Replace getAbbreviation on citeproc-js with our own handler. + */ + return function getAbbreviation(listname, obj, jurisdiction, category, key) { + if(!Zotero.Prefs.get("cite.automaticTitleAbbreviation")) return; + + init(); + + // Short circuit if we know we don't handle this kind of abbreviation + if(!abbreviationCategories[category] && !abbreviationCategories[category+"-word"]) return; + + var normalizedKey = normalizeKey(key), + lcNormalizedKey = lookupKey(normalizedKey), + abbreviation; + if(!normalizedKey) return; + + var jurisdictions = ["default"]; + if(jurisdiction !== "default" && abbreviations[jurisdiction]) { + jurisdictions.unshift(jurisdiction); + } + + // Look for full abbreviation + var jur, cat; + for(var i=0; i<jurisdictions.length && !abbreviation; i++) { + if((jur = abbreviations[jurisdictions[i]]) && (cat = jur[category])) { + abbreviation = cat[lcNormalizedKey]; + } + } + + if(!abbreviation) { + // Abbreviate words individually + var words = normalizedKey.split(/([ \-])/); + + if(words.length > 1) { + for(var j=0; j<words.length; j+=2) { + var word = words[j], + lcWord = lookupKey(word), + newWord = undefined; + + for(var i=0; i<jurisdictions.length && newWord === undefined; i++) { + if(!(jur = abbreviations[jurisdictions[i]])) continue; + if(!(cat = jur[category+"-word"])) continue; + + // Complete match + if(cat.hasOwnProperty(lcWord)) { + newWord = cat[lcWord]; + } else { + // Partial match + for(var k=1; k<=word.length && newWord === undefined; k++) { + newWord = cat[lcWord.substr(0, k)+"-"]; + if(newWord && word.length - newWord.length < 1) { + newWord = undefined; + } + } + } + } + + // Fall back to full word + if(newWord === undefined ) newWord = word; + + words[j] = newWord.substr(0, 1).toUpperCase() + newWord.substr(1); + } + } + abbreviation = words.join("").replace(/\s+/g, " ").trim(); + } + + if(!abbreviation || abbreviation === key) { + Zotero.debug("No abbreviation found for "+key); + return; + } + Zotero.debug("Abbreviated "+key+" as "+abbreviation); + + // Add to jurisdiction object + if(!obj[jurisdiction]) { + obj[jurisdiction] = new Zotero.CiteProc.CSL.AbbreviationSegments(); + } + obj[jurisdiction][category][key] = abbreviation; + } +}; + +/** * citeproc-js system object - * @namespace + * @class */ -Zotero.Cite.System = { +Zotero.Cite.System = function(automaticJournalAbbreviations) { + if(automaticJournalAbbreviations) { + this.getAbbreviation = Zotero.Cite.getAbbreviation; + } +} + +Zotero.Cite.System.prototype = { /** * citeproc-js system function for getting items * See http://gsl-nagoya-u.net/http/pub/citeproc-doc.html#retrieveitem @@ -471,156 +618,5 @@ Zotero.Cite.System = { converterStream.readString(channel.contentLength, str); converterStream.close(); return str.value; - }, - - /** - * citeproc-js system function for getting abbreviations - * See http://gsl-nagoya-u.net/http/pub/citeproc-doc.html#getabbreviations - * Not currently used because it doesn't scale well to large lists - */ - "getAbbreviations":function getAbbreviations() { - return {}; - } -}; - -/** - * Functions for creating and manipulating field abbreviations - * @namespace - */ -Zotero.Cite.Abbreviations = new function() { - var abbreviations, - abbreviationCategories; - - /** - * Initialize abbreviations database. - */ - function init() { - if(!abbreviations) Zotero.Cite.Abbreviations.loadAbbreviations(); - } - - this.loadAbbreviations = function() { - var file = Zotero.getZoteroDirectory(); - file.append("abbreviations.json"); - - var json, origin; - if(file.exists()) { - json = Zotero.File.getContents(file); - origin = file.path; - } else { - json = Zotero.File.getContentsFromURL("resource://zotero/schema/abbreviations.json"); - origin = "resource://zotero/schema/abbreviations.json"; - } - - try { - abbreviations = JSON.parse(json); - } catch(e) { - throw new Zotero.Exception.Alert("styles.abbreviations.parseError", origin, - "styles.abbreviations.title", e); - } - - if(!abbreviations.info || !abbreviations.info.name || !abbreviations.info.URI) { - throw new Zotero.Exception.Alert("styles.abbreviations.missingInfo", origin, - "styles.abbreviations.title"); - } - - abbreviationCategories = {}; - for(var jurisdiction in abbreviations) { - for(var category in abbreviations[jurisdiction]) { - abbreviationCategories[category] = true; - } - } - } - - /** - * Normalizes a key - */ - function normalizeKey(key) { - // Strip periods, normalize spacing, and convert to lowercase - return key.toString().toLowerCase(). - replace(/(?:\b|^)(?:and|et|y|und|l[ae]|the|[ld]')(?:\b|$)|[\x21-\x2C.\/\x3A-\x40\x5B-\x60\\\x7B-\x7E]/g, ""). - replace(/\s+/g, " ").trim(); - } - - function lookupKey(key) { - return key.toLowerCase().replace(/\s*\./g, "." ); - } - - /** - * Replace getAbbreviation on citeproc-js with our own handler. - */ - Zotero.CiteProc.CSL.getAbbreviation = function getAbbreviation(listname, obj, jurisdiction, category, key) { - if(!Zotero.Prefs.get("cite.automaticTitleAbbreviation")) return; - - init(); - - // Short circuit if we know we don't handle this kind of abbreviation - if(!abbreviationCategories[category] && !abbreviationCategories[category+"-word"]) return; - - var normalizedKey = normalizeKey(key), - lcNormalizedKey = lookupKey(normalizedKey), - abbreviation; - if(!normalizedKey) return; - - var jurisdictions = ["default"]; - if(jurisdiction !== "default" && abbreviations[jurisdiction]) { - jurisdictions.unshift(jurisdiction); - } - - // Look for full abbreviation - var jur, cat; - for(var i=0; i<jurisdictions.length && !abbreviation; i++) { - if((jur = abbreviations[jurisdictions[i]]) && (cat = jur[category])) { - abbreviation = cat[lcNormalizedKey]; - } - } - - if(!abbreviation) { - // Abbreviate words individually - var words = normalizedKey.split(/([ \-])/); - - if(words.length > 1) { - for(var j=0; j<words.length; j+=2) { - var word = words[j], - lcWord = lookupKey(word), - newWord = undefined; - - for(var i=0; i<jurisdictions.length && newWord === undefined; i++) { - if(!(jur = abbreviations[jurisdictions[i]])) continue; - if(!(cat = jur[category+"-word"])) continue; - - // Complete match - if(cat.hasOwnProperty(lcWord)) { - newWord = cat[lcWord]; - } else { - // Partial match - for(var k=1; k<=word.length && newWord === undefined; k++) { - newWord = cat[lcWord.substr(0, k)+"-"]; - if(newWord && word.length - newWord.length < 1) { - newWord = undefined; - } - } - } - } - - // Fall back to full word - if(newWord === undefined ) newWord = word; - - words[j] = newWord.substr(0, 1).toUpperCase() + newWord.substr(1); - } - } - abbreviation = words.join("").replace(/\s+/g, " ").trim(); - } - - if(!abbreviation || abbreviation === key) { - Zotero.debug("No abbreviation found for "+key); - return; - } - Zotero.debug("Abbreviated "+key+" as "+abbreviation); - - // Add to jurisdiction object - if(!obj[jurisdiction]) { - obj[jurisdiction] = new Zotero.CiteProc.CSL.AbbreviationSegments(); - } - obj[jurisdiction][category][key] = abbreviation; } }; \ No newline at end of file diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js @@ -2016,16 +2016,19 @@ Zotero.Integration.Session.prototype.resetRequest = function(doc) { /** * Changes the Session style and data * @param data {Zotero.Integration.DocumentData} + * @param resetStyle {Boolean} Whether to force the style to be reset + * regardless of whether it has changed. This is desirable if the + * automaticJournalAbbreviations has changed. */ -Zotero.Integration.Session.prototype.setData = function(data) { +Zotero.Integration.Session.prototype.setData = function(data, resetStyle) { var oldStyle = (this.data && this.data.style ? this.data.style : false); this.data = data; - if(data.style.styleID && (!oldStyle || oldStyle.styleID != data.style.styleID)) { + if(data.style.styleID && (!oldStyle || oldStyle.styleID != data.style.styleID || resetStyle)) { this.styleID = data.style.styleID; try { var getStyle = Zotero.Styles.get(data.style.styleID); data.style.hasBibliography = getStyle.hasBibliography; - this.style = getStyle.csl; + this.style = getStyle.getCiteProc(data.prefs.automaticJournalAbbreviations); this.style.setOutputFormat("rtf"); this.styleClass = getStyle.class; this.dateModified = new Object(); @@ -2060,6 +2063,7 @@ Zotero.Integration.Session.prototype.setDocPrefs = function(doc, primaryFieldTyp io.primaryFieldType = primaryFieldType; io.secondaryFieldType = secondaryFieldType; io.storeReferences = this.data.prefs.storeReferences; + io.automaticJournalAbbreviations = this.data.prefs.automaticJournalAbbreviations; io.requireStoreReferences = !Zotero.Utilities.isEmpty(this.embeddedItems); } @@ -2078,13 +2082,19 @@ Zotero.Integration.Session.prototype.setDocPrefs = function(doc, primaryFieldTyp data.style.styleID = io.style; data.prefs.fieldType = io.fieldType; data.prefs.storeReferences = io.storeReferences; - me.setData(data); + data.prefs.automaticJournalAbbreviations = io.automaticJournalAbbreviations; + + me.setData(data, oldData && + oldData.prefs.automaticJournalAbbreviations != + data.prefs.automaticJournalAbbreviations); + // need to do this after setting the data so that we know if it's a note style me.data.prefs.noteType = me.style && me.styleClass == "note" ? io.useEndnotes+1 : 0; if(!oldData || oldData.style.styleID != data.style.styleID || oldData.prefs.noteType != data.prefs.noteType - || oldData.prefs.fieldType != data.prefs.fieldType) { + || oldData.prefs.fieldType != data.prefs.fieldType + || oldData.prefs.automaticJournalAbbreviations != data.prefs.automaticJournalAbbreviations) { // This will cause us to regenerate all citations me.oldCitationIDs = {}; } @@ -2170,7 +2180,7 @@ Zotero.Integration.Session.prototype.getCitationField = function(citation) { // add itemData only if requested if(this.data.prefs.storeReferences) { - serializeCitationItem.itemData = Zotero.Cite.System.retrieveItem(citationItem.id); + serializeCitationItem.itemData = this.style.sys.retrieveItem(citationItem.id); addSchema = true; } } @@ -3011,6 +3021,7 @@ Zotero.Integration.DocumentData.prototype.unserializeXML = function(xmlData) { this.prefs[name] = value; } if(this.prefs["storeReferences"] === undefined) this.prefs["storeReferences"] = false; + if(this.prefs["automaticJournalAbbreviations"] === undefined) this.prefs["automaticJournalAbbreviations"] = false; this.zoteroVersion = doc.documentElement.getAttribute("zotero-version"); if(!this.zoteroVersion) this.zoteroVersion = "2.0"; this.dataVersion = doc.documentElement.getAttribute("data-version"); diff --git a/chrome/content/zotero/xpcom/quickCopy.js b/chrome/content/zotero/xpcom/quickCopy.js @@ -330,7 +330,7 @@ Zotero.QuickCopy = new function() { // Copy citations if shift key pressed if (modified) { - var csl = Zotero.Styles.get(format).csl; + var csl = Zotero.Styles.get(format).getCiteProc(); csl.updateItems([item.id for each(item in items)]); var citation = {citationItems:[{id:item.id} for each(item in items)], properties:{}}; var html = csl.previewCitationCluster(citation, [], [], "html"); diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js @@ -430,6 +430,8 @@ Zotero.Style = function(arg) { '/csl:style/csl:info[1]/csl:category', Zotero.Styles.ns)) if(category.hasAttribute("term"))]; this._class = doc.documentElement.getAttribute("class"); + this._usesAbbreviation = !!Zotero.Utilities.xpath(doc, '//csl:text[@form="short"][@variable="container-title"][1]', + Zotero.Styles.ns).length; this._hasBibliography = !!doc.getElementsByTagName("bibliography").length; this._version = doc.documentElement.getAttribute("version"); if(!this._version) this._version = "0.8"; @@ -442,12 +444,11 @@ Zotero.Style = function(arg) { } } -Zotero.Style.prototype.__defineGetter__("csl", /** - * Retrieves the Zotero.CSL object for this style - * @type Zotero.CSL + * Get a citeproc-js CSL.Engine instance + * @param {Boolean} useAutomaticJournalAbbreviations Whether to automatically abbreviate titles */ -function() { +Zotero.Style.prototype.getCiteProc = function(automaticJournalAbbreviations) { var locale = Zotero.Prefs.get('export.bibliographyLocale'); if(!locale) { var locale = Zotero.locale; @@ -498,11 +499,16 @@ function() { } try { - return new Zotero.CiteProc.CSL.Engine(Zotero.Cite.System, xml, locale); + return new Zotero.CiteProc.CSL.Engine(new Zotero.Cite.System(automaticJournalAbbreviations), xml, locale); } catch(e) { Zotero.logError(e); throw e; } +}; + +Zotero.Style.prototype.__defineGetter__("csl", function() { + Zotero.logError("Zotero.Style.csl is deprecated. Use Zotero.Style.getCiteProc()"); + return this.getCiteProc(); }); Zotero.Style.prototype.__defineGetter__("class", @@ -534,6 +540,20 @@ function() { return this._hasBibliography; }); +Zotero.Style.prototype.__defineGetter__("usesAbbreviation", +/** + * Retrieves the style class, either from the metadata that's already loaded or by loading the file + * @type String + */ +function() { + if(this.source) { + var parentStyle = Zotero.Styles.get(this.source); + if(!parentStyle) return false; + return parentStyle.usesAbbreviation; + } + return this._usesAbbreviation; +}); + Zotero.Style.prototype.__defineGetter__("independentFile", /** * Retrieves the file corresponding to the independent CSL diff --git a/chrome/locale/en-US/zotero/preferences.dtd b/chrome/locale/en-US/zotero/preferences.dtd @@ -121,7 +121,6 @@ <!ENTITY zotero.preferences.cite.styles.styleManager.title "Title"> <!ENTITY zotero.preferences.cite.styles.styleManager.updated "Updated"> <!ENTITY zotero.preferences.cite.styles.styleManager.csl "CSL"> -<!ENTITY zotero.preferences.cite.styles.automaticTitleAbbreviation "Automatically abbreviate journal titles"> <!ENTITY zotero.preferences.export.getAdditionalStyles "Get additional styles..."> <!ENTITY zotero.preferences.prefpane.keys "Shortcuts"> diff --git a/chrome/locale/en-US/zotero/zotero.dtd b/chrome/locale/en-US/zotero/zotero.dtd @@ -211,6 +211,10 @@ <!ENTITY zotero.integration.prefs.bookmarks.label "Bookmarks"> <!ENTITY zotero.integration.prefs.bookmarks.caption "Bookmarks are preserved across Microsoft Word and LibreOffice, but may be accidentally modified. For &#xA;compatibility reasons, citations cannot be inserted into footnotes or endnotes when this option is selected."> + +<!ENTITY zotero.integration.prefs.automaticJournalAbbeviations.label "Automatically abbreviate journal titles"> +<!ENTITY zotero.integration.prefs.automaticJournalAbbeviations.caption "MEDLINE journal abbreviations will be automatically generated using journal titles. The &quot;Journal Abbr&quot; field will be ignored."> + <!ENTITY zotero.integration.prefs.storeReferences.label "Store references in document"> <!ENTITY zotero.integration.prefs.storeReferences.caption "Storing references in your document slightly increases file size, but will allow you to share your document with others without using a Zotero group. Zotero 3.0 or later is required to update documents created with this option."> diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js @@ -95,7 +95,7 @@ pref("extensions.zotero.export.bibliographySettings", 'save-as-rtf'); pref("extensions.zotero.export.bibliographyLocale", ''); pref("extensions.zotero.export.displayCharsetOption", false); pref("extensions.zotero.export.citePaperJournalArticleURL", false); -pref("extensions.zotero.cite.automaticTitleAbbreviation", false); +pref("extensions.zotero.cite.automaticJournalAbbreviations", true); pref("extensions.zotero.import.charset", "auto"); pref("extensions.zotero.import.createNewCollection.fromFileOpenHandler", true); pref("extensions.zotero.rtfScan.lastInputFile", "");