From 9e5c9716e2c0e09feeb0e81edcf8face2f0b4922 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 15 Sep 2011 22:24:43 +0000 Subject: [PATCH] Fix preview and resolve issues with classic add citation dialog --- .../zotero/integration/addCitationDialog.js | 6 ++-- chrome/content/zotero/xpcom/integration.js | 35 +++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/integration/addCitationDialog.js b/chrome/content/zotero/integration/addCitationDialog.js index a169c8b6cc..e58488bb10 100644 --- a/chrome/content/zotero/integration/addCitationDialog.js +++ b/chrome/content/zotero/integration/addCitationDialog.js @@ -565,7 +565,7 @@ var Zotero_Citation_Dialog = new function () { if(_previewShown) { document.documentElement.getButton("extra2").label = Zotero.getString("citation.hideEditor"); if(text) { - _originalHTML = io.previewFunction(); + _originalHTML = io.preview(); editor.value = text; } else { _updatePreview(); @@ -599,6 +599,7 @@ var Zotero_Citation_Dialog = new function () { io.citation.properties.custom = citation; } + io.accept(); return true; } @@ -607,6 +608,7 @@ var Zotero_Citation_Dialog = new function () { */ function cancel() { io.citation.citationItems = new Array(); + io.accept(); } /* @@ -618,7 +620,7 @@ var Zotero_Citation_Dialog = new function () { _getCitation(); editor.readonly = !io.citation.citationItems.length; - editor.value = (io.citation.citationItems.length ? io.previewFunction() : ""); + editor.value = (io.citation.citationItems.length ? io.preview() : ""); if(editor.initialized) { _originalHTML = editor.value; diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 7e27bae33c..fa05396484 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -1266,12 +1266,33 @@ Zotero.Integration.Fields.prototype.addEditCitation = function(field, callback) citation = io.citation = {"citationItems":{}, "properties":{}}; } + var sessionUpdated = false; + var previewing = false; + // assign preview function - io.previewFunction = function() { - throw "Not yet implemented"; - citation.properties.zoteroIndex = parseInt(index, 10); - citation.properties.noteIndex = parseInt(noteIndex, 10); - return me._session.previewCitation(io.citation); + io.preview = function() { + if(previewing) return; + previewing = true; + + var returnVal; + me.get(function() { + if(!sessionUpdated) { + me.updateSession(); + sessionUpdated = true; + } + + // fieldIndex will already be set by the time we get here + citation.properties.zoteroIndex = fieldIndex; + citation.properties.noteIndex = field.getNoteIndex(); + returnVal = me._session.previewCitation(citation); + }); + + // wait until we get the preview + while(returnVal === undefined) Zotero.mainThread.processNextEvent(true); + + // return the preview + return returnVal; + previewing = false; } // assign sort function io.sort = function() { @@ -1284,7 +1305,7 @@ Zotero.Integration.Fields.prototype.addEditCitation = function(field, callback) if(io.citation.citationItems.length) { // Citation added me.get(function() { - me.updateSession(); + if(!sessionUpdated) me.updateSession(); if(fieldIndex !== undefined) { session.addCitation(fieldIndex, field.getNoteIndex(), io.citation); } @@ -1305,7 +1326,7 @@ Zotero.Integration.Fields.prototype.addEditCitation = function(field, callback) // citeproc-js style object for use of third-party extension io.style = session.style; - // Find this citation + // Start finding this citation this citation var fieldIndex; this.get(function(fields) { for(var i=0, n=fields.length; i