Commit 027704e9 authored by Randall Leeds's avatar Randall Leeds

Merge pull request #2340 from hypothesis/fix-guest-embedding

Fix guest embedding
parents 249298d2 f1a812fa
...@@ -47,22 +47,13 @@ require('./plugin/textquote'); ...@@ -47,22 +47,13 @@ require('./plugin/textquote');
require('./plugin/textposition'); require('./plugin/textposition');
require('./plugin/textrange'); require('./plugin/textrange');
var Klass = Annotator.Host; var docs = 'https://h.readthedocs.org/en/latest/hacking/customized-embedding.html';
var docs = 'https://github.com/hypothesis/h/blob/master/README.rst#customized-embedding';
var options = { var options = {
app: jQuery('link[type="application/annotator+html"]').attr('href'), app: jQuery('link[type="application/annotator+html"]').attr('href'),
BucketBar: {container: '.annotator-frame'}, BucketBar: {container: '.annotator-frame'},
Toolbar: {container: '.annotator-frame'} Toolbar: {container: '.annotator-frame'}
}; };
if (window.hasOwnProperty('hypothesisRole')) {
if (typeof window.hypothesisRole === 'function') {
Klass = window.hypothesisRole;
} else {
throw new TypeError('hypothesisRole must be a constructor function, see: ' + docs);
}
}
// Simple IE autodetect function // Simple IE autodetect function
// See for example https://stackoverflow.com/questions/19999388/jquery-check-if-user-is-using-ie/21712356#21712356 // See for example https://stackoverflow.com/questions/19999388/jquery-check-if-user-is-using-ie/21712356#21712356
var ua = window.navigator.userAgent; var ua = window.navigator.userAgent;
...@@ -81,5 +72,10 @@ if (window.hasOwnProperty('hypothesisConfig')) { ...@@ -81,5 +72,10 @@ if (window.hasOwnProperty('hypothesisConfig')) {
} }
Annotator.noConflict().$.noConflict(true)(function () { Annotator.noConflict().$.noConflict(true)(function () {
var Klass = Annotator.Host;
if (options.hasOwnProperty('constructor')) {
Klass = options.constructor;
delete options.constructor;
}
window.annotator = new Klass(document.body, options); window.annotator = new Klass(document.body, options);
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment