-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresearch-article.js
178 lines (146 loc) · 4.99 KB
/
research-article.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Polymer({
attached: function() {
this.url = window.location.href;
this.doi = $('head > meta[name=citation_doi]').attr('content');
this.github = $('[rel=source][data-github]').data('github');
this.async(this.references);
this.async(this.figures);
this.async(this.orcid);
this.async(this.mathjax);
this.async(this.releases);
},
references: function() {
var referencesList = $('#references > ul');
var references = referencesList.find('li');
// build an index of URLs in the reference list
var referenceLinks = {};
references.each(function(i) {
$(this).find('a[href]').each(function() {
referenceLinks[this.href] = i;
});
});
// start from the bottom, so the reference list gets re-ordered correctly
var links = $('section a').get().reverse();
// move each reference to the top of the list
$(links).each(function() {
var referenceIndex = referenceLinks[this.href];
if (typeof referenceIndex === 'undefined') {
references.eq(referenceIndex).prependTo(referencesList);
}
});
// add a popover to each link in the article
$(links).each(function() {
$(this).popover({
trigger: 'hover',
delay: {
show: 250,
hide: 100
},
placement: 'right',
container: 'body',
html: true,
title: this.getAttribute('title'),
content: function() {
var referenceIndex = referenceLinks[this.href];
if (typeof referenceIndex !== 'undefined') {
return references.eq(referenceIndex).html();
}
var node = document.createElement('article-reference');
node.originalTitle = this.getAttribute('data-original-title');
node.originalText = this.getAttribute('data-original-text');
node.url = this.href;
return node.go() ? node : '';
}
});
});
// update numbered references
var inlineCitations = $('section a').filter(function() {
if (['👍', '👎'].indexOf(this.textContent) !== -1) {
return true;
}
if (/^cito:/.test(this.textContent)) {
return true;
}
return false;
});
var citedURLs = [];
inlineCitations.each(function() {
var url = this.href;
var text = this.textContent.trim();
var index = citedURLs.indexOf(url);
if (index === -1) {
citedURLs.push(url);
index = citedURLs.length;
}
$(this).attr('data-original-text', text).text(index).addClass('citation');
});
},
figures: function() {
var modal = $('<div id="figure-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" hidden-print><div class="modal-dialog modal-lg"><div class="modal-content"></div></div></div>');
modal.appendTo(document.body).modal({ show: false });
var content = modal.find('.modal-content').text('Loading…');
modal.on('hidden.bs.modal', function() {
content.html('Loading…');
});
$(this).on('click', 'a.figure-link', function() {
modal.modal('show');
content.load(this.href + ' figure');
return false;
});
},
orcid: function() {
var modal = $('<div id="orcid-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" hidden-print><div class="modal-dialog modal-lg"><div class="modal-content"></div></div></div>');
modal.appendTo(document.body).modal({ show: false });
var content = modal.find('.modal-content').text('Loading…');
modal.on('hidden.bs.modal', function() {
content.html('Loading…');
});
$('a[data-orcid]').tooltip({
placement: 'bottom'
}).on('click', function() {
modal.modal('show');
var element = $('<orcid-profile/>').attr('orcid', $(this).data('orcid'));
content.html(element);
return false;
});
},
releases: function() {
var link = $('[rel=source][data-github]');
if (!link.length) {
return;
}
var container = link.parent();
var url = this.url;
var button = $('<button/>', {
type: 'button',
html: '↓ show version history'
});
var showVersionHistory = function() {
var node = document.createElement('version-history');
node.github = link.data('github');
node.url = url;
container.append(node);
$(this).remove();
};
button.addClass('btn btn-link btn-mini').on('click', showVersionHistory).appendTo(container);
},
mathjax: function() {
window.MathJax = {
messageStyle: 'none',
'HTML-CSS': {
linebreaks: { automatic: true },
scale: 80
},
menuSettings: {
zoom: 'Click'
},
elements: this.children
};
this.addScript('https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe');
},
addScript: function(src) {
var script = document.createElement('script');
script.src = src;
document.querySelector('head').appendChild(script);
}
});