Skip to content

Commit

Permalink
Move hypothesisRole into the hypothesisConfig.
Browse files Browse the repository at this point in the history
To prevent an Annotator is undefined error, the Constructor class is set
by the object returned from the hypothesisConfig function. The link to the
docs has also been updated. This unbreaks Epub.js.
  • Loading branch information
JakeHartnell committed Jun 30, 2015
1 parent daa12db commit 46374e2
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions h/static/scripts/annotator/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,14 @@ require('./plugin/textquote');
require('./plugin/textposition');
require('./plugin/textrange');

var Klass = Annotator.Host;
var docs = 'https://github.com/hypothesis/h/blob/master/README.rst#customized-embedding';
var docs = 'https://h.readthedocs.org/en/latest/hacking/customized-embedding.html';
var options = {
app: jQuery('link[type="application/annotator+html"]').attr('href'),
BucketBar: {container: '.annotator-frame'},
Toolbar: {container: '.annotator-frame'}
Toolbar: {container: '.annotator-frame'},
Constructor: Annotator.Host
};

if (window.hasOwnProperty('hypothesisRole')) {
if (window.hypothesisRole === "Guest") {
Klass = Annotator.Guest;
} else {
throw new TypeError('hypothesisRole must be a constructor function, see: ' + docs);
}
}

// Simple IE autodetect function
// See for example https://stackoverflow.com/questions/19999388/jquery-check-if-user-is-using-ie/21712356#21712356
var ua = window.navigator.userAgent;
Expand All @@ -81,5 +73,5 @@ if (window.hasOwnProperty('hypothesisConfig')) {
}

Annotator.noConflict().$.noConflict(true)(function () {
window.annotator = new Klass(document.body, options);
window.annotator = new options.Constructor(document.body, options);
});

0 comments on commit 46374e2

Please sign in to comment.