www

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

commit 51f6e1650d6436d9aae5e14448474c7f793aca06
parent 6a28e8b040583dc17cec49977854cce4362d2385
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon,  1 Jun 2009 20:13:09 +0000

Better (and centralized) DOI parsing


Diffstat:
Mchrome/content/zotero/bindings/itembox.xml | 4++--
Mchrome/content/zotero/overlay.js | 2+-
Mchrome/content/zotero/xpcom/utilities.js | 10++++++++++
3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml @@ -265,7 +265,7 @@ var doi = this.item.getField('DOI'); if (doi) { // Pull out DOI, in case there's a prefix - doi = doi.match(/10\..*/); + doi = Zotero.Utilities.prototype.cleanDOI(doi);; if (doi) { spec = "http://dx.doi.org/" + encodeURIComponent(doi); } @@ -454,7 +454,7 @@ } else if (fieldName == 'DOI' && val) { // Pull out DOI, in case there's a prefix - var doi = val.match(/10\..*/); + var doi = Zotero.Utilities.prototype.cleanDOI(val); if (doi) { doi = "http://dx.doi.org/" + encodeURIComponent(doi); label.setAttribute("isButton", true); diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js @@ -1962,7 +1962,7 @@ var ZoteroPane = new function() var doi = item.getField('DOI'); if (doi) { // Pull out DOI, in case there's a prefix - doi = doi.match(/10\..*/); + doi = Zotero.Utilities.prototype.cleanDOI(doi); if (doi) { uri = "http://dx.doi.org/" + encodeURIComponent(doi); } diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js @@ -143,6 +143,16 @@ Zotero.Utilities.prototype.cleanTags = function(/**String*/ x) { return x.replace(/<[^>]+>/g, ""); } + +Zotero.Utilities.prototype.cleanDOI = function(/**String**/ x) { + if(typeof(x) != "string") { + throw "cleanDOI: argument must be a string"; + } + + return x.match(/10\.[^\s\/]+\/[^\s]+/); +} + + /** * Encode special XML/HTML characters<br/> * <br/>