restore live updating in csledit.xul

This commit is contained in:
Simon Kornblith 2011-02-14 16:56:44 +00:00
parent 2324992ac3
commit 20f38fa773
2 changed files with 49 additions and 25 deletions

View file

@ -76,7 +76,7 @@
} }
function refresh() { function refresh() {
var editor = document.getElementById('zotero-csl-editor') var editor = document.getElementById('zotero-csl-editor')
generateBibliography(editor.cslID) generateBibliography(editor.value);
} }
@ -117,9 +117,14 @@
return; return;
} }
else { else {
var cslFile = Zotero.Styles.get(editor.cslID).file; try {
styleObject = new Zotero.Style(cslFile); styleObject = new Zotero.Style(str);
styleEngine = styleObject.csl; styleEngine = styleObject.csl;
} catch(e) {
iframe.contentDocument.documentElement.innerHTML = '<div>Error parsing '+
'style: </div><div>'+e+'</div>';
throw e;
}
} }
var itemIds = [items[i].id for (i in items)]; var itemIds = [items[i].id for (i in items)];
@ -152,19 +157,24 @@
citations += styleEngine.makeCitationCluster(subcitation) + '<br />'; citations += styleEngine.makeCitationCluster(subcitation) + '<br />';
} }
try {
var multCitations = '<hr><h1>Multi Citations <span style="font-size:smaller;">(all with position "first")</span></h1>' + var multCitations = '<hr><h1>Multi Citations <span style="font-size:smaller;">(all with position "first")</span></h1>' +
styleEngine.previewCitationCluster(citation, [], [], "html"); styleEngine.previewCitationCluster(citation, [], [], "html");
// Generate bibliography // Generate bibliography
styleEngine.updateItems(itemIds); styleEngine.updateItems(itemIds);
var bibData = styleEngine.makeBibliography();
var bibliography = '<hr/><h1>Bibliography</h1>' + var bibliography = '<hr/><h1>Bibliography</h1>' +
bibData[0].bibstart + bibData[1].join("") + bibData[0].bibend; Zotero.Cite.makeFormattedBibliography(styleEngine, "html");
iframe.contentDocument.documentElement.innerHTML = iframe.contentDocument.documentElement.innerHTML =
'<div style="white-space: pre-wrap">' '<div style="white-space: pre-wrap">'
+ citations + multCitations + bibliography + citations + multCitations + bibliography
+ '</div>'; + '</div>';
} catch(e) {
iframe.contentDocument.documentElement.innerHTML = '<div>Error generating citations '+
'and bibliography: </div><div>'+e+'</div>';
throw e;
}
} }

View file

@ -337,16 +337,22 @@ Zotero.Styles = new function() {
* @property {Boolean} hidden True if this style is hidden in style selection dialogs, false if it * @property {Boolean} hidden True if this style is hidden in style selection dialogs, false if it
* is not * is not
*/ */
Zotero.Style = function(file) { Zotero.Style = function(arg) {
this.file = file; if(typeof arg === "string") {
this.string = arg;
} else if(typeof arg === "object") {
this.file = arg;
} else {
throw "Invalid argument passed to Zotero.Style";
}
var extension = file.leafName.substr(-4).toLowerCase(); var extension = (typeof arg === "string" ? ".csl" : arg.leafName.substr(-4).toLowerCase());
if(extension == ".ens") { if(extension == ".ens") {
this.type = "ens"; this.type = "ens";
this.styleID = Zotero.Styles.ios.newFileURI(this.file).spec; this.styleID = Zotero.Styles.ios.newFileURI(this.file).spec;
this.title = file.leafName.substr(0, file.leafName.length-4); this.title = this.file.leafName.substr(0, this.file.leafName.length-4);
this.updated = Zotero.Date.dateToSQL(new Date(file.lastModifiedTime)); this.updated = Zotero.Date.dateToSQL(new Date(this.file.lastModifiedTime));
this._version = "0.8"; this._version = "0.8";
} else if(extension == ".csl") { } else if(extension == ".csl") {
// "with ({});" needed to fix default namespace scope issue // "with ({});" needed to fix default namespace scope issue
@ -355,7 +361,7 @@ Zotero.Style = function(file) {
this.type = "csl"; this.type = "csl";
var xml = Zotero.Styles.cleanXML(Zotero.File.getContents(file)); var xml = Zotero.Styles.cleanXML(typeof arg === "string" ? arg : Zotero.File.getContents(arg));
this.styleID = xml.info.id.toString(); this.styleID = xml.info.id.toString();
this.title = xml.info.title.toString(); this.title = xml.info.title.toString();
@ -480,8 +486,10 @@ function() {
Zotero.Styles.ios.newFileURI(this.file).spec, null)); Zotero.Styles.ios.newFileURI(this.file).spec, null));
} }
return formatCSL.file; return formatCSL.file;
} } else if(this.file) {
return this.file; return this.file;
}
return null;
}); });
/** /**
@ -503,7 +511,9 @@ Zotero.Style.prototype.getXML = function() {
return XML.toXMLString(); return XML.toXMLString();
} else { } else {
return Zotero.File.getContents(this.independentFile); var indepFile = this.independentFile;
if(indepFile) return Zotero.File.getContents(indepFile);
return this.string;
} }
}; };
@ -511,6 +521,10 @@ Zotero.Style.prototype.getXML = function() {
* Deletes a style * Deletes a style
*/ */
Zotero.Style.prototype.remove = function() { Zotero.Style.prototype.remove = function() {
if(!this.file) {
throw "Cannot delete a style with no associated file."
}
// make sure no styles depend on this one // make sure no styles depend on this one
var dependentStyles = false; var dependentStyles = false;
var styles = Zotero.Styles.getAll(); var styles = Zotero.Styles.getAll();