restore live updating in csledit.xul
This commit is contained in:
parent
2324992ac3
commit
20f38fa773
2 changed files with 49 additions and 25 deletions
|
@ -76,7 +76,7 @@
|
|||
}
|
||||
function refresh() {
|
||||
var editor = document.getElementById('zotero-csl-editor')
|
||||
generateBibliography(editor.cslID)
|
||||
generateBibliography(editor.value);
|
||||
|
||||
}
|
||||
|
||||
|
@ -117,9 +117,14 @@
|
|||
return;
|
||||
}
|
||||
else {
|
||||
var cslFile = Zotero.Styles.get(editor.cslID).file;
|
||||
styleObject = new Zotero.Style(cslFile);
|
||||
try {
|
||||
styleObject = new Zotero.Style(str);
|
||||
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)];
|
||||
|
@ -152,19 +157,24 @@
|
|||
citations += styleEngine.makeCitationCluster(subcitation) + '<br />';
|
||||
}
|
||||
|
||||
try {
|
||||
var multCitations = '<hr><h1>Multi Citations <span style="font-size:smaller;">(all with position "first")</span></h1>' +
|
||||
styleEngine.previewCitationCluster(citation, [], [], "html");
|
||||
|
||||
// Generate bibliography
|
||||
styleEngine.updateItems(itemIds);
|
||||
var bibData = styleEngine.makeBibliography();
|
||||
var bibliography = '<hr/><h1>Bibliography</h1>' +
|
||||
bibData[0].bibstart + bibData[1].join("") + bibData[0].bibend;
|
||||
Zotero.Cite.makeFormattedBibliography(styleEngine, "html");
|
||||
|
||||
iframe.contentDocument.documentElement.innerHTML =
|
||||
'<div style="white-space: pre-wrap">'
|
||||
+ citations + multCitations + bibliography
|
||||
+ '</div>';
|
||||
} catch(e) {
|
||||
iframe.contentDocument.documentElement.innerHTML = '<div>Error generating citations '+
|
||||
'and bibliography: </div><div>'+e+'</div>';
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -337,16 +337,22 @@ Zotero.Styles = new function() {
|
|||
* @property {Boolean} hidden True if this style is hidden in style selection dialogs, false if it
|
||||
* is not
|
||||
*/
|
||||
Zotero.Style = function(file) {
|
||||
this.file = file;
|
||||
Zotero.Style = function(arg) {
|
||||
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") {
|
||||
this.type = "ens";
|
||||
|
||||
this.styleID = Zotero.Styles.ios.newFileURI(this.file).spec;
|
||||
this.title = file.leafName.substr(0, file.leafName.length-4);
|
||||
this.updated = Zotero.Date.dateToSQL(new Date(file.lastModifiedTime));
|
||||
this.title = this.file.leafName.substr(0, this.file.leafName.length-4);
|
||||
this.updated = Zotero.Date.dateToSQL(new Date(this.file.lastModifiedTime));
|
||||
this._version = "0.8";
|
||||
} else if(extension == ".csl") {
|
||||
// "with ({});" needed to fix default namespace scope issue
|
||||
|
@ -355,7 +361,7 @@ Zotero.Style = function(file) {
|
|||
|
||||
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.title = xml.info.title.toString();
|
||||
|
@ -480,8 +486,10 @@ function() {
|
|||
Zotero.Styles.ios.newFileURI(this.file).spec, null));
|
||||
}
|
||||
return formatCSL.file;
|
||||
}
|
||||
} else if(this.file) {
|
||||
return this.file;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -503,7 +511,9 @@ Zotero.Style.prototype.getXML = function() {
|
|||
|
||||
return XML.toXMLString();
|
||||
} 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
|
||||
*/
|
||||
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
|
||||
var dependentStyles = false;
|
||||
var styles = Zotero.Styles.getAll();
|
||||
|
|
Loading…
Add table
Reference in a new issue