-
Notifications
You must be signed in to change notification settings - Fork 7
/
component.js
47 lines (39 loc) · 1.23 KB
/
component.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
import Ember from 'ember';
import LazyLoader from 'tahi/lib/lazy-loader';
import ENV from 'tahi/config/environment';
export default Ember.Component.extend({
paper: null, // passed-in
classNames: ['manuscript'],
loadJournalStyles() {
//paper's journal is async
this.get('paper.journal').then((journal) => {
const style = journal.get('manuscriptCss');
this.$().attr('style', style);
});
},
didInsertElement() {
this._super(...arguments);
Ember.run.scheduleOnce('afterRender', this, this.loadJournalStyles);
},
didRender() {
this._super(...arguments);
Ember.run.scheduleOnce('afterRender', this, this.refreshEquations);
},
updateEquations: Ember.observer('paper.body', function() {
Ember.run.scheduleOnce('afterRender', this, this.refreshEquations);
}),
loadMathJax: function() {
LazyLoader.loadScripts([ENV.mathjax.url]).then(() => {
this.refreshEquations();
});
},
refreshEquations: function() {
if(this.get('isDestroying')) { return; }
if (!window.MathJax) { this.loadMathJax(); return; }
else if (!window.MathJax.Hub) { return; }
var view = this.$()[0];
Ember.run.next(() => {
MathJax.Hub.Queue(['Typeset', MathJax.Hub, view]);
});
}
});