| 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 | 2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
11×
94×
16×
1×
1×
1×
1×
1×
1×
1×
25×
25×
25×
25×
25×
94×
94×
94×
94×
94×
94×
| var ArbitraryHtmlAndMath, BookContentMixin, GetPositionMixin, React, ReferenceBookExerciseActions, ReferenceBookExerciseShell, ReferenceBookExerciseStore, ReferenceBookPageStore, ReferenceBookStore, SpyMode, _, classnames, ref, ref1;
React = require('react');
SpyMode = require('openstax-react-components').SpyMode;
_ = require('underscore');
classnames = require('classnames');
BookContentMixin = require('../book-content-mixin').BookContentMixin;
ref = require('openstax-react-components'), ArbitraryHtmlAndMath = ref.ArbitraryHtmlAndMath, GetPositionMixin = ref.GetPositionMixin;
ReferenceBookExerciseShell = require('./exercise').ReferenceBookExerciseShell;
ReferenceBookPageStore = require('../../flux/reference-book-page').ReferenceBookPageStore;
ReferenceBookStore = require('../../flux/reference-book').ReferenceBookStore;
ref1 = require('../../flux/reference-book-exercise'), ReferenceBookExerciseActions = ref1.ReferenceBookExerciseActions, ReferenceBookExerciseStore = ref1.ReferenceBookExerciseStore;
module.exports = React.createClass({
displayName: 'ReferenceBookPage',
propTypes: {
cnxId: React.PropTypes.string.isRequired
},
mixins: [BookContentMixin, GetPositionMixin],
componentWillMount: function() {
return this.setState({
skipZeros: false
});
},
getSplashTitle: function() {
return ReferenceBookStore.getPageTitle(this.props);
},
shouldOpenNewTab: function() {
return true;
},
waitToScrollToSelector: function(hash) {
var i, image, images, imagesToLoad, len, onImageLoad;
images = this.getDOMNode().querySelectorAll('img');
imagesToLoad = images.length;
onImageLoad = (function(_this) {
return function() {
imagesToLoad -= 1;
if (imagesToLoad === 0) {
return _this.scrollToSelector(hash);
}
};
})(this);
for (i = 0, len = images.length; i < len; i++) {
image = images[i];
image.addEventListener('load', onImageLoad);
}
return images.length > 0;
},
renderExercises: function(exerciseLinks) {
var allExercises, multipleUrl;
ReferenceBookExerciseStore.setMaxListeners(exerciseLinks.length);
allExercises = _.pluck(exerciseLinks, 'href');
multipleUrl = ReferenceBookExerciseStore.getMultipleUrl(allExercises);
Eif (!ReferenceBookExerciseStore.isLoaded(multipleUrl)) {
ReferenceBookExerciseActions.load(multipleUrl);
}
return _.each(exerciseLinks, this.renderExercise);
},
renderExercise: function(link) {
var exerciseAPIUrl, exerciseNode;
exerciseAPIUrl = link.href;
exerciseNode = link.parentNode.parentNode;
Eif (exerciseNode != null) {
return React.render(React.createElement(ReferenceBookExerciseShell, {
"exerciseAPIUrl": exerciseAPIUrl
}), exerciseNode);
}
},
render: function() {
var cnxId, courseId, ecosystemId, html, page, ref2;
ref2 = this.props, courseId = ref2.courseId, cnxId = ref2.cnxId, ecosystemId = ref2.ecosystemId;
page = ReferenceBookPageStore.get(cnxId);
html = page.content_html;
html = html.replace(/^[\s\S]*<body[\s\S]*?>/, '').replace(/<\/body>[\s\S]*$/, '');
return React.createElement("div", {
"className": classnames('page-wrapper', this.props.className)
}, this.props.children, React.createElement(ArbitraryHtmlAndMath, {
"className": 'page center-panel',
"block": true,
"html": html
}), React.createElement(SpyMode.Content, {
"className": "ecosystem-info"
}, "PageId: ", this.props.cnxId, ", Ecosystem: ", page.spy));
}
});
|