From f0f22009c49790c38d5ea72a3cffc2af11eca0bd Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sat, 5 Jun 2010 17:49:04 +0000 Subject: [PATCH] - fix (most) unnecessary citation update issues - switch Zotero.JSON to native Firefox JSON support - update to citeproc-js 1.0.21 From Frank's announcement: In this release: - Tighten up internal "NUMERIC" update_mode to mean styles that render citation-number in citations (renderings in the bibliography are now ignored for purposes of setting this flag). - The numeric styles fix introduced at version 1.0.17 broke with styles that sort the bibliography on anything other than citation- number (i.e. document first-reference order). With this release, arbitrary sorts of the bibliography work with numeric styles. - Position evaluation code is now invoked only in styles that make use of position testing (to save a few cycles). - Numeric styles now perform targetted citation updates correctly. --- chrome/content/zotero/xpcom/citeproc.js | 25 ++-- chrome/content/zotero/xpcom/integration.js | 76 +++++------ chrome/content/zotero/xpcom/zotero.js | 140 +-------------------- 3 files changed, 62 insertions(+), 179 deletions(-) diff --git a/chrome/content/zotero/xpcom/citeproc.js b/chrome/content/zotero/xpcom/citeproc.js index 4c617b164..59f5a238c 100644 --- a/chrome/content/zotero/xpcom/citeproc.js +++ b/chrome/content/zotero/xpcom/citeproc.js @@ -1432,7 +1432,7 @@ CSL.dateParser = function (txt) { }; CSL.Engine = function (sys, style, lang, xmlmode) { var attrs, langspec, localexml, locale; - this.processor_version = "1.0.20"; + this.processor_version = "1.0.21"; this.csl_version = "1.0"; this.sys = sys; this.sys.xml = new CSL.System.Xml.Parsing(); @@ -2224,7 +2224,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, sortedItems.push(newitem); citation.citationItems[pos].item = Item; } - if (!this[this.tmp.area].opt["citation-number-sort"] && sortedItems && sortedItems.length > 1 && this.citation_sort.tokens.length > 0) { + if (!this.citation.opt["citation-number-sort"] && sortedItems && sortedItems.length > 1 && this.citation_sort.tokens.length > 0) { len = sortedItems.length; for (pos = 0; pos < len; pos += 1) { sortedItems[pos][1].sortkeys = CSL.getSortKeys.call(this, sortedItems[pos][0], "citation_sort"); @@ -2248,7 +2248,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, } this.registry.citationreg.citationByIndex = citationByIndex; this.registry.citationreg.citationsByItemId = {}; - if (this.opt.update_mode === CSL.POSITION || true) { + if (this.opt.update_mode === CSL.POSITION) { textCitations = []; noteCitations = []; } @@ -2267,7 +2267,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, this.registry.citationreg.citationsByItemId[item[1].id].push(citationByIndex[pos]); } } - if (this.opt.update_mode === CSL.POSITION || true) { + if (this.opt.update_mode === CSL.POSITION) { if (citationByIndex[pos].properties.noteIndex) { noteCitations.push(citationByIndex[pos]); } else { @@ -2278,7 +2278,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, if (!has_bibliography) { this.updateItems(update_items); } - if (this.opt.update_mode === CSL.POSITION || true) { + if (this.opt.update_mode === CSL.POSITION) { for (pos = 0; pos < 2; pos += 1) { citations = [textCitations, noteCitations][pos]; first_ref = {}; @@ -2385,7 +2385,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre, } } } - if (this[this.tmp.area].opt["citation-number-sort"] && sortedItems && sortedItems.length > 1 && this.citation_sort.tokens.length > 0) { + if (this.citation.opt["citation-number-sort"] && sortedItems && sortedItems.length > 1 && this.citation_sort.tokens.length > 0) { len = sortedItems.length; for (pos = 0; pos < len; pos += 1) { sortedItems[pos][1].sortkeys = CSL.getSortKeys.call(this, sortedItems[pos][0], "citation_sort"); @@ -4188,7 +4188,9 @@ CSL.Node.text = { } if ("citation-number" === variable || "year-suffix" === variable || "citation-label" === variable) { if (variable === "citation-number") { - state.opt.update_mode = CSL.NUMERIC; + if (state.build.area === "citation") { + state.opt.update_mode = CSL.NUMERIC; + } if ("citation-number" === state[state.tmp.area].opt.collapse) { this.range_prefix = "-"; } @@ -7032,6 +7034,7 @@ CSL.Registry = function (state) { this.uncited = []; this.refreshes = {}; this.akeys = {}; + this.oldseq = {}; this.ambigcites = {}; this.sorter = new CSL.Registry.Comparifier(state, "bibliography_sort"); this.modes = CSL.getModes.call(this.state); @@ -7047,6 +7050,7 @@ CSL.Registry = function (state) { }; CSL.Registry.prototype.init = function (myitems, uncited_flag) { var len, pos; + this.oldseq = {}; if (uncited_flag && this.mylist && this.mylist.length) { this.uncited = myitems; for (pos = 0, len = myitems.length; pos < len; pos += 1) { @@ -7139,6 +7143,7 @@ CSL.Registry.prototype.rebuildlist = function () { for (pos = 0; pos < len; pos += 1) { item = this.mylist[pos]; this.reflist.push(this.registry[item]); + this.oldseq[item] = this.registry[item].seq; this.registry[item].seq = (pos + 1); } }; @@ -7200,10 +7205,10 @@ CSL.Registry.prototype.renumber = function () { len = this.reflist.length; for (pos = 0; pos < len; pos += 1) { item = this.reflist[pos]; - if (this.state.opt.update_mode === CSL.NUMERIC && this.state.tmp.taintedItemIDs && item.seq !== (pos + 1)) { + item.seq = (pos + 1); + if (this.state.opt.update_mode === CSL.NUMERIC && this.state.tmp.taintedItemIDs && item.seq !== this.oldseq[item.id]) { this.state.tmp.taintedItemIDs[item.id] = true; } - item.seq = (pos + 1); } }; CSL.Registry.prototype.yearsuffix = function () { @@ -7893,4 +7898,4 @@ CSL.getModes = function () { CSL.Registry.CitationReg = function (state) { this.citationById = {}; this.citationByIndex = []; -}; \ No newline at end of file +}; diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index dfe37b353..22cb32531 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -557,12 +557,6 @@ Zotero.Integration.Document.prototype._updateSession = function(newField, editFi } var endTime = (new Date()).getTime(); Zotero.debug("Collected "+this._fields.length+" fields in "+(endTime-collectFieldsTime)/1000+"; "+1000/((endTime-collectFieldsTime)/this._fields.length)+" fields/second"); - - // if we are reloading this session, assume no item IDs to be updated except for edited items - if(this._reloadSession) { - this._session.updateItemIDs = {}; - this._session.bibliographyHasChanged = false; - } // load uncited items from bibliography if(bibliographyData && !this._session.bibliographyData) { @@ -588,7 +582,13 @@ Zotero.Integration.Document.prototype._updateSession = function(newField, editFi } } - this._session.updateCitations(true); + // if we are reloading this session, assume no item IDs to be updated except for edited items + if(this._reloadSession) { + this._session.updateCitations(); + this._session.updateIndices = {}; + this._session.updateItemIDs = {}; + this._session.bibliographyHasChanged = false; + } // create new citation or edit existing citation if(editFieldIndex) { @@ -886,7 +886,6 @@ Zotero.Integration.Session.prototype.setData = function(data) { this.data = data; if(data.style.styleID && oldStyleID != data.style.styleID) { this.styleID = data.style.styleID; - Zotero.debug("style is "+data.style.styleID); try { var getStyle = Zotero.Styles.get(data.style.styleID); data.style.hasBibliography = getStyle.hasBibliography; @@ -990,12 +989,15 @@ Zotero.Integration.Session.prototype.getCitationField = function(citation) { var type; var field = []; - field.push('"citationID":'+Zotero.JSON.serialize(citation.citationID)); + field.push('"citationID":'+uneval(citation.citationID)); var properties = []; for(var j=0; j