update epub.js
This commit is contained in:
parent
3c12da48d3
commit
c0190bd7d1
9 changed files with 118 additions and 104 deletions
|
|
@ -1,8 +1,13 @@
|
|||
// Hypothesis Customized embedding
|
||||
// This hypothesis config function returns a new constructor which modifies
|
||||
// annotator for a better integration. Below we create our own EpubAnnotationSidebar
|
||||
// Constructor, customizing the show and hide function to take acount for the reader UI.
|
||||
|
||||
window.hypothesisConfig = function() {
|
||||
var Annotator = window.Annotator;
|
||||
var $main = $("#main");
|
||||
|
||||
function MySidebar(elem, options) {
|
||||
function EpubAnnotationSidebar(elem, options) {
|
||||
options = {
|
||||
server: true,
|
||||
origin: true,
|
||||
|
|
@ -13,9 +18,9 @@ window.hypothesisConfig = function() {
|
|||
Annotator.Host.call(this, elem, options);
|
||||
}
|
||||
|
||||
MySidebar.prototype = Object.create(Annotator.Host.prototype);
|
||||
EpubAnnotationSidebar.prototype = Object.create(Annotator.Host.prototype);
|
||||
|
||||
MySidebar.prototype.show = function() {
|
||||
EpubAnnotationSidebar.prototype.show = function() {
|
||||
this.frame.css({
|
||||
'margin-left': (-1 * this.frame.width()) + "px"
|
||||
});
|
||||
|
|
@ -27,7 +32,7 @@ window.hypothesisConfig = function() {
|
|||
}
|
||||
};
|
||||
|
||||
MySidebar.prototype.hide = function() {
|
||||
EpubAnnotationSidebar.prototype.hide = function() {
|
||||
this.frame.css({
|
||||
'margin-left': ''
|
||||
});
|
||||
|
|
@ -40,54 +45,36 @@ window.hypothesisConfig = function() {
|
|||
};
|
||||
|
||||
return {
|
||||
constructor: MySidebar,
|
||||
constructor: EpubAnnotationSidebar,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// This is the Epub.js plugin. Annotations are updated on location change.
|
||||
EPUBJS.reader.plugins.HypothesisController = function (Book) {
|
||||
var reader = this;
|
||||
var $main = $("#main");
|
||||
var reader = this;
|
||||
var $main = $("#main");
|
||||
|
||||
var updateAnnotations = function () {
|
||||
var annotator = Book.renderer.render.window.annotator;
|
||||
if (annotator && annotator.constructor.$) {
|
||||
var annotations = getVisibleAnnotations(annotator.constructor.$);
|
||||
annotator.showAnnotations(annotations)
|
||||
}
|
||||
};
|
||||
var updateAnnotations = function () {
|
||||
var annotator = Book.renderer.render.window.annotator;
|
||||
if (annotator && annotator.constructor.$) {
|
||||
var annotations = getVisibleAnnotations(annotator.constructor.$);
|
||||
annotator.showAnnotations(annotations)
|
||||
}
|
||||
};
|
||||
|
||||
var getVisibleAnnotations = function ($) {
|
||||
var width = Book.renderer.render.iframe.clientWidth;
|
||||
return $('.annotator-hl').map(function() {
|
||||
var $this = $(this),
|
||||
left = this.getBoundingClientRect().left;
|
||||
var getVisibleAnnotations = function ($) {
|
||||
var width = Book.renderer.render.iframe.clientWidth;
|
||||
return $('.annotator-hl').map(function() {
|
||||
var $this = $(this),
|
||||
left = this.getBoundingClientRect().left;
|
||||
|
||||
if (left >= 0 && left <= width) {
|
||||
return $this.data('annotation');
|
||||
}
|
||||
}).get();
|
||||
};
|
||||
if (left >= 0 && left <= width) {
|
||||
return $this.data('annotation');
|
||||
}
|
||||
}).get();
|
||||
};
|
||||
|
||||
// $("#annotations").on("click", function () {
|
||||
// var annotator = Book.renderer.render.window.annotator;
|
||||
// var currentPosition = Book.getCurrentLocationCfi();
|
||||
Book.on("renderer:locationChanged", updateAnnotations);
|
||||
|
||||
// if ($main.hasClass("single")) {
|
||||
// $main.removeClass("single");
|
||||
// annotator.setVisibleHighlights(false);
|
||||
// } else {
|
||||
// $main.addClass("single");
|
||||
// annotator.setVisibleHighlights(true);
|
||||
// }
|
||||
|
||||
// $main.one("transitionend", function(){
|
||||
// Book.gotoCfi(currentPosition);
|
||||
// });
|
||||
// });
|
||||
|
||||
Book.on("renderer:locationChanged", updateAnnotations);
|
||||
// Book.on("renderer:chapterDisplayed", updateAnnotations);
|
||||
|
||||
return {}
|
||||
return {}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue