Skip to content

Commit

Permalink
Merge branch 'feature/hypothesis-for-pdfs' into develop
Browse files Browse the repository at this point in the history
 [SVCS-645]
 Closes: #316
  • Loading branch information
felliott committed Apr 12, 2018
2 parents a9a381c + e3681cd commit fc0d556
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ node_modules/

# Asynchronous HTTP
######################
/src/
/src/
20 changes: 16 additions & 4 deletions mfr/extensions/pdf/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ def render(self):
logger.debug('extension::{} supported-list::{}'.format(self.metadata.ext, settings.EXPORT_SUPPORTED))
if self.metadata.ext not in settings.EXPORT_SUPPORTED:
logger.debug('Extension not found in supported list!')
return self.TEMPLATE.render(base=self.assets_url, url=download_url.geturl())
return self.TEMPLATE.render(
base=self.assets_url,
url=download_url.geturl(),
enable_hypothesis=settings.ENABLE_HYPOTHESIS
)

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

self.metrics.add('needs_export', True)
return self.TEMPLATE.render(base=self.assets_url, url=exported_url.url)

return self.TEMPLATE.render(base=self.assets_url, url=download_url.geturl())
return self.TEMPLATE.render(
base=self.assets_url,
url=exported_url.url,
enable_hypothesis=settings.ENABLE_HYPOTHESIS
)

return self.TEMPLATE.render(
base=self.assets_url,
url=download_url.geturl(),
enable_hypothesis=settings.ENABLE_HYPOTHESIS
)

@property
def file_required(self):
Expand Down
2 changes: 2 additions & 0 deletions mfr/extensions/pdf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
EXPORT_TYPE = config.get('EXPORT_TYPE', 'pdf')
EXPORT_MAXIMUM_SIZE = config.get('EXPORT_MAXIMUM_SIZE', '1200x1200')

ENABLE_HYPOTHESIS = config.get_bool('ENABLE_HYPOTHESIS', False)

# supports multiple files in the form of a space separated string
EXPORT_SUPPORTED = config.get('EXPORT_SUPPORTED', '.tiff .tif').split(' ')
EXPORT_MAX_PAGES = int(config.get('EXPORT_MAX_PAGES', 40))
13 changes: 13 additions & 0 deletions mfr/extensions/pdf/templates/viewer.mako
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ http://sourceforge.net/adobe/cmap/wiki/License/

<script src="debugger.js"></script>
<script src="viewer.js"></script>

% if enable_hypothesis:
<style>
body.show-hypothesis #toolbarViewer {
position: relative;
margin-right: 36px;
}
</style>
% endif

</head>

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

26 changes: 26 additions & 0 deletions mfr/server/static/js/mfr.child.hypothesis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;(function() {
'use strict';

var hypothesisLoaded = false;

window.pymChild.onMessage('startHypothesis', startHypothesis);

window.addEventListener('message', function(event) {
if (event.data === 'startHypothesis') {
startHypothesis(event);
}
});

function startHypothesis(event) {
if (hypothesisLoaded) {
return;
}

var script = window.document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://hypothes.is/embed.js';
window.document.head.appendChild(script);
window.document.body.classList.add('show-hypothesis');
hypothesisLoaded = true;
};
})();
1 change: 1 addition & 0 deletions mfr/server/static/js/mfr.child.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
;(function() {
'use strict';

window.pymChild = new pym.Child();

window.addEventListener('load', function () {
Expand Down
4 changes: 4 additions & 0 deletions mfr/server/static/js/mfr.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
self.pymParent.sendMessage('resize', 'x');
};

self.startHypothesis = function() {
self.pymParent.sendMessage('startHypothesis');
};

return self;
};

Expand Down

0 comments on commit fc0d556

Please sign in to comment.