Skip to content

Commit

Permalink
Allow custom strings as cite reference
Browse files Browse the repository at this point in the history
Parse if a cite reference is a cts urn - if it's not just display
whatever custom string is present.
  • Loading branch information
LFDM committed Dec 9, 2014
1 parent 57beee2 commit cc3d7e7
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions app/js/arethusa.core/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,39 @@ angular.module('arethusa.core').service('navigator', [
self.getCitation(currentSentenceObjs(), storeCitation);
}

function isCtsUrn(cite) {
return cite.match(/^urn:cts/);
}

function parseCtsUrn(cite, callback) {
var citation;
var citeSplit = splitCiteString(cite);
var doc = citeSplit[0];
var sec = citeSplit[1];
citation = citationCache.get(doc);
if (! citation) {
citeMapper.get({ cite: doc}).then(function(res) {
citation = res.data;
citationCache.put(doc, citation);
callback(citationToString(citation, sec));
});
} else {
callback(citationToString(citation, sec));
}
}

var citationCache = $cacheFactory('citation', { number: 100 });
this.getCitation = function(sentences, callback) {
if (!citeMapper) return;
var sentence = sentences[0];
if (!sentence) return;

var citation;
var cite = sentence.cite;
if (cite) {
var citeSplit = splitCiteString(cite);
var doc = citeSplit[0];
var sec = citeSplit[1];
citation = citationCache.get(doc);
if (! citation) {
citeMapper.get({ cite: doc}).then(function(res) {
citation = res.data;
citationCache.put(doc, citation);
callback(citationToString(citation, sec));
});
if (isCtsUrn(cite)) {
parseCtsUrn(cite, callback);
} else {
callback(citationToString(citation, sec));
callback(cite);
}
}
};
Expand Down

0 comments on commit cc3d7e7

Please sign in to comment.