diff --git a/examples/hypothesis-spreads.html b/examples/hypothesis-spreads.html index eff5ee5..67c9376 100644 --- a/examples/hypothesis-spreads.html +++ b/examples/hypothesis-spreads.html @@ -20,16 +20,17 @@ - @@ -235,7 +236,14 @@ var href = window.location.href.slice(loc + 5); var hash = decodeURIComponent(href); } - rendition.display(hash || undefined); + + rendition.display(hash || undefined) + .then(function() { + var H_EMBED_URL = 'https://hypothes.is/embed.js'; + var script = document.createElement('script'); + script.setAttribute('src', H_EMBED_URL); + document.head.appendChild(script); + }); var next = document.getElementById("next"); @@ -344,12 +352,14 @@ }); + var tm; function checkForAnnotator(cb, w) { if (!w) { w = window; } - setTimeout(function () { + tm = setTimeout(function () { if (w && w.annotator) { + clearTimeout(tm); cb(); } else { checkForAnnotator(cb, w); @@ -358,7 +368,6 @@ } book.rendition.hooks.content.register(function(contents, view) { - checkForAnnotator(function () { var annotator = contents.window.annotator; @@ -387,41 +396,6 @@ }); - checkForAnnotator(function () { - var main = document.querySelector('#main'); - var target = document.querySelector('.annotator-frame'); - - - if(window.innerWidth < 1400) { - /* - window.annotator.on("show", function () { - main.classList.add("open"); - }); - - window.annotator.on("hide", function () { - main.classList.remove("open"); - }); - */ - - // create an observer instance - var observer = new MutationObserver(function(mutations) { - mutations.forEach(function(mutation) { - if (mutation.attributeName === "class") { - if (target.classList.contains("annotator-collapsed")) { - main.classList.remove("open"); - } else { - main.classList.add("open"); - } - } - }); - }); - - observer.observe(target, { attributes: true }); - - } - - }); - diff --git a/examples/hypothesis.html b/examples/hypothesis.html index d839167..562db28 100644 --- a/examples/hypothesis.html +++ b/examples/hypothesis.html @@ -20,12 +20,16 @@ @@ -359,42 +363,6 @@ }, contents.window); }); - - checkForAnnotator(function () { - var main = document.querySelector('#main'); - var target = document.querySelector('.annotator-frame'); - - - if(window.innerWidth < 1400) { - /* - window.annotator.on("show", function () { - main.classList.add("open"); - }); - - window.annotator.on("hide", function () { - main.classList.remove("open"); - }); - */ - - // create an observer instance - var observer = new MutationObserver(function(mutations) { - mutations.forEach(function(mutation) { - if (mutation.attributeName === "class") { - if (target.classList.contains("annotator-collapsed")) { - main.classList.remove("open"); - } else { - main.classList.add("open"); - } - } - }); - }); - - observer.observe(target, { attributes: true }); - - } - - }); - diff --git a/package.json b/package.json index 4046115..7fa419e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "epubjs", - "version": "0.3.46", + "version": "0.3.47", "description": "Parse and Render Epubs", "main": "lib/index.js", "module": "src/index.js", diff --git a/src/book.js b/src/book.js index 86c20db..c2e351d 100644 --- a/src/book.js +++ b/src/book.js @@ -544,7 +544,11 @@ class Book { var cfi = new EpubCFI(cfiRange); var item = this.spine.get(cfi.spinePos); var _request = this.load.bind(this); - + if (!item) { + return new Promise((resolve, reject) => { + reject("CFI could not be found"); + }); + } return item.load(_request).then(function (contents) { var range = cfi.toRange(item.document); return range; diff --git a/src/managers/default/index.js b/src/managers/default/index.js index 34739dc..375b488 100644 --- a/src/managers/default/index.js +++ b/src/managers/default/index.js @@ -476,10 +476,12 @@ class DefaultViewManager { let sections = visible.map((view) => { let {index, href} = view.section; let position = view.position(); - let startPos = position.top - container.top + offset + used; + let height = view.height(); + + let startPos = offset + container.top - position.top + used; let endPos = startPos + pageHeight - used; - if (endPos > position.bottom - container.top + offset) { - endPos = position.bottom - container.top + offset; + if (endPos > height) { + endPos = height; used = (endPos - startPos); } diff --git a/src/rendition.js b/src/rendition.js index 311472a..25cf86b 100644 --- a/src/rendition.js +++ b/src/rendition.js @@ -76,7 +76,7 @@ class Rendition { this.hooks.content.register(this.passEvents.bind(this)); this.hooks.content.register(this.adjustImages.bind(this)); - this.book.spine.hooks.content.register(this.injectSource.bind(this)); + this.book.spine.hooks.content.register(this.injectIdentifier.bind(this)); if (this.settings.stylesheet) { this.book.spine.hooks.content.register(this.injectStylesheet.bind(this)); @@ -801,10 +801,10 @@ class Rendition { doc.getElementsByTagName("head")[0].appendChild(script); } - injectSource(doc, section) { + injectIdentifier(doc, section) { let ident = this.book.package.metadata.identifier; let meta = doc.createElement("meta"); - meta.setAttribute("property", "dc:source"); + meta.setAttribute("name", "dc.relation.ispartof"); if (ident) { meta.setAttribute("contents", ident); } diff --git a/src/utils/replacements.js b/src/utils/replacements.js index b81be0e..d6cc501 100644 --- a/src/utils/replacements.js +++ b/src/utils/replacements.js @@ -54,13 +54,13 @@ export function replaceMeta(doc, section){ } head = qs(doc, "head"); - meta = qs(head, "link[property='dc:identifier']"); + meta = qs(head, "link[property='dc.identifier']"); if (meta) { meta.setAttribute("content", id); } else { meta = doc.createElement("meta"); - meta.setAttribute("property", "dc:identifier"); + meta.setAttribute("name", "dc.identifier"); meta.setAttribute("content", id); head.appendChild(meta); }