Skip to content

Commit fc0d556

Browse files
committed
Merge branch 'feature/hypothesis-for-pdfs' into develop
[SVCS-645] Closes: #316
2 parents a9a381c + e3681cd commit fc0d556

File tree

7 files changed

+63
-5
lines changed

7 files changed

+63
-5
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ node_modules/
8888

8989
# Asynchronous HTTP
9090
######################
91-
/src/
91+
/src/

mfr/extensions/pdf/render.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ def render(self):
2323
logger.debug('extension::{} supported-list::{}'.format(self.metadata.ext, settings.EXPORT_SUPPORTED))
2424
if self.metadata.ext not in settings.EXPORT_SUPPORTED:
2525
logger.debug('Extension not found in supported list!')
26-
return self.TEMPLATE.render(base=self.assets_url, url=download_url.geturl())
26+
return self.TEMPLATE.render(
27+
base=self.assets_url,
28+
url=download_url.geturl(),
29+
enable_hypothesis=settings.ENABLE_HYPOTHESIS
30+
)
2731

2832
logger.debug('Extension found in supported list!')
2933
exported_url = furl.furl(self.export_url)
@@ -35,9 +39,17 @@ def render(self):
3539
exported_url.args['format'] = settings.EXPORT_TYPE
3640

3741
self.metrics.add('needs_export', True)
38-
return self.TEMPLATE.render(base=self.assets_url, url=exported_url.url)
39-
40-
return self.TEMPLATE.render(base=self.assets_url, url=download_url.geturl())
42+
return self.TEMPLATE.render(
43+
base=self.assets_url,
44+
url=exported_url.url,
45+
enable_hypothesis=settings.ENABLE_HYPOTHESIS
46+
)
47+
48+
return self.TEMPLATE.render(
49+
base=self.assets_url,
50+
url=download_url.geturl(),
51+
enable_hypothesis=settings.ENABLE_HYPOTHESIS
52+
)
4153

4254
@property
4355
def file_required(self):

mfr/extensions/pdf/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
EXPORT_TYPE = config.get('EXPORT_TYPE', 'pdf')
77
EXPORT_MAXIMUM_SIZE = config.get('EXPORT_MAXIMUM_SIZE', '1200x1200')
88

9+
ENABLE_HYPOTHESIS = config.get_bool('ENABLE_HYPOTHESIS', False)
10+
911
# supports multiple files in the form of a space separated string
1012
EXPORT_SUPPORTED = config.get('EXPORT_SUPPORTED', '.tiff .tif').split(' ')
1113
EXPORT_MAX_PAGES = int(config.get('EXPORT_MAX_PAGES', 40))

mfr/extensions/pdf/templates/viewer.mako

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ http://sourceforge.net/adobe/cmap/wiki/License/
3737

3838
<script src="debugger.js"></script>
3939
<script src="viewer.js"></script>
40+
41+
% if enable_hypothesis:
42+
<style>
43+
body.show-hypothesis #toolbarViewer {
44+
position: relative;
45+
margin-right: 36px;
46+
}
47+
</style>
48+
% endif
49+
4050
</head>
4151

4252
<body tabindex="1" class="loadingInProgress">
@@ -413,6 +423,9 @@ http://sourceforge.net/adobe/cmap/wiki/License/
413423
var DEFAULT_URL = '${url}';
414424
window.pymChild.sendMessage('embed', 'embed-responsive-pdf');
415425
</script>
426+
% if enable_hypothesis:
427+
<script src="/static/js/mfr.child.hypothesis.js"></script>
428+
% endif
416429
</body>
417430
</html>
418431

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
;(function() {
22
'use strict';
3+
34
window.pymChild = new pym.Child();
45

56
window.addEventListener('load', function () {

mfr/server/static/js/mfr.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
self.pymParent.sendMessage('resize', 'x');
112112
};
113113

114+
self.startHypothesis = function() {
115+
self.pymParent.sendMessage('startHypothesis');
116+
};
117+
114118
return self;
115119
};
116120

0 commit comments

Comments
 (0)