www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 20f38fa773fea00b9170ac56f559ac2394e83173
parent 2324992ac33b4fb1e65a235ff363e1a8effa3429
Author: Simon Kornblith <simon@simonster.com>
Date:   Mon, 14 Feb 2011 16:56:44 +0000

restore live updating in csledit.xul


Diffstat:
Mchrome/content/zotero/tools/csledit.xul | 44+++++++++++++++++++++++++++-----------------
Mchrome/content/zotero/xpcom/style.js | 30++++++++++++++++++++++--------
2 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/chrome/content/zotero/tools/csledit.xul b/chrome/content/zotero/tools/csledit.xul @@ -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); - styleEngine = styleObject.csl; + 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 />'; } - 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; - - iframe.contentDocument.documentElement.innerHTML = - '<div style="white-space: pre-wrap">' - + citations + multCitations + bibliography - + '</div>'; + 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 bibliography = '<hr/><h1>Bibliography</h1>' + + 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; + } } diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js @@ -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 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();