Fix preview and resolve issues with classic add citation dialog

This commit is contained in:
Simon Kornblith 2011-09-15 22:24:43 +00:00
parent 051d82fcdf
commit 9e5c9716e2
2 changed files with 32 additions and 9 deletions

View file

@ -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;

View file

@ -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<n; i++) {