-
Notifications
You must be signed in to change notification settings - Fork 2
/
ir_citation_run.js
71 lines (60 loc) · 2.82 KB
/
ir_citation_run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* @file
* This kicks off the citation process. Currently this module does not support all the disambiguation
* features of citeproc-js, for now to get them you should write your own javascript to overide ir_citation_run.js.
* This is because a new citation engine object is created for each citation.
* @author
* William Panting
*/
Drupal.behaviors.islandora_institutional_repository_cite_make= function (context){
var sys = new ir_citation_sys();
//loop through each citation
ir_citation_jQuery('.ir_citation').each(
/**
* This is a call back function that handles each element with the class ir_citation
* it insertes the processed citation
*/
function(index) {
//get citation style
var citation_style_name = ir_citation_jQuery(this).attr('data-ir_citation_style');
var citation_style = Drupal.settings.ir_citation.csl[citation_style_name];
//create citation engine object
var citation_processor = new CSL.Engine(sys, citation_style);
//add abbreviations if they exist
var abbreviations = ir_citation_jQuery(this).attr('data-ir_citation_abbreviations');
if (abbreviations!=undefined) {
citation_processor.setAbbreviations(abbreviations);
}
//handle bibliography elements
var bibliography_list_key = ir_citation_jQuery(this).attr('data-ir_citation_bibliography_list');
if (bibliography_list_key!=undefined) {
bibliography_list=ir_citation_jQuery.parseJSON(Drupal.settings.ir_citation.bibliography_lists[bibliography_list_key]);
citation_processor.updateItems(bibliography_list);
//output
var bibliography_selector_key = ir_citation_jQuery(this).attr('data-ir_citation_bibliography_selector');
if (bibliography_selector_key != undefined) {//if there is a bibliography selector object
bibliography_selector=ir_citation_jQuery.parseJSON(Drupal.settings.ir_citation.bibliography_selectors[bibliography_selector_key]);
output = citation_processor.makeBibliography(bibliography_selector);
}
else {//no selector object
output = citation_processor.makeBibliography();
}
if (output && output.length && output[1].length){
output = output[0].bibstart + output[1].join("") + output[0].bibend;
ir_citation_jQuery(this).html(output);
}
}
//handle single citation elements
else {
//get citation object
var citation_object_name = ir_citation_jQuery(this).attr('data-ir_citation_object');
var citation_object_string = Drupal.settings.ir_citation.citation_objects[citation_object_name];
var citation_object = ir_citation_jQuery.parseJSON(citation_object_string);
//append citation object to engine
var citation = citation_processor.appendCitationCluster(citation_object);
//insert citation on page
ir_citation_jQuery(this).html(citation[0][1]);
}
}
);
}