Skip to content

Commit e3681cd

Browse files
committed
move hypothesis loader into a separate file
* Allows it to properly be controlled by an envvar, and avoids making it automatically available to all renderers.
1 parent 63ebf1a commit e3681cd

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

mfr/extensions/pdf/templates/viewer.mako

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ http://sourceforge.net/adobe/cmap/wiki/License/
423423
var DEFAULT_URL = '${url}';
424424
window.pymChild.sendMessage('embed', 'embed-responsive-pdf');
425425
</script>
426+
% if enable_hypothesis:
427+
<script src="/static/js/mfr.child.hypothesis.js"></script>
428+
% endif
426429
</body>
427430
</html>
428431

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
;(function() {
2+
'use strict';
3+
4+
var hypothesisLoaded = false;
5+
6+
window.pymChild.onMessage('startHypothesis', startHypothesis);
7+
8+
window.addEventListener('message', function(event) {
9+
if (event.data === 'startHypothesis') {
10+
startHypothesis(event);
11+
}
12+
});
13+
14+
function startHypothesis(event) {
15+
if (hypothesisLoaded) {
16+
return;
17+
}
18+
19+
var script = window.document.createElement('script');
20+
script.type = 'text/javascript';
21+
script.src = 'https://hypothes.is/embed.js';
22+
window.document.head.appendChild(script);
23+
window.document.body.classList.add('show-hypothesis');
24+
hypothesisLoaded = true;
25+
};
26+
})();

mfr/server/static/js/mfr.child.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,4 @@
2626
window.pymChild.onMessage('resize', function () {
2727
window.pymChild.sendHeight();
2828
});
29-
30-
var hypothesisLoaded = false;
31-
32-
window.pymChild.onMessage('startHypothesis', startHypothesis);
33-
34-
window.addEventListener('message', function(event) {
35-
if (event.data === 'startHypothesis') {
36-
startHypothesis(event);
37-
}
38-
});
39-
40-
function startHypothesis(event) {
41-
if (hypothesisLoaded) {
42-
return;
43-
}
44-
45-
var script = window.document.createElement('script');
46-
script.type = 'text/javascript';
47-
script.src = 'https://hypothes.is/embed.js';
48-
window.document.head.appendChild(script);
49-
window.document.body.classList.add('show-hypothesis');
50-
hypothesisLoaded = true;
51-
};
5229
})();

0 commit comments

Comments
 (0)