1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

Fixed scrolled location, updated hypothesis examples

This commit is contained in:
Fred Chasen 2017-08-25 14:16:45 -04:00
parent ced1bf89ff
commit 576a5b81dc
7 changed files with 43 additions and 95 deletions

View file

@ -20,16 +20,17 @@
<script type="text/javascript"> <script type="text/javascript">
window.hypothesisConfig = function () { window.hypothesisConfig = function () {
return { return {
// Open the sidebar when the page loads openSidebar: false,
openSidebar: true,
// Needed for multi frame support
enableMultiFrameSupport: true, enableMultiFrameSupport: true,
embedScriptUrl: "https://cdn.hypothes.is/hypothesis" onLayoutChange: function(state) {
var nav = document.getElementById("navigation");
if (state.expanded === true) {
nav.classList.remove("open");
}
}
}; };
}; };
</script> </script>
<script src="https://cdn.hypothes.is/hypothesis"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="examples.css"> <link rel="stylesheet" type="text/css" href="examples.css">
@ -235,7 +236,14 @@
var href = window.location.href.slice(loc + 5); var href = window.location.href.slice(loc + 5);
var hash = decodeURIComponent(href); 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"); var next = document.getElementById("next");
@ -344,12 +352,14 @@
}); });
var tm;
function checkForAnnotator(cb, w) { function checkForAnnotator(cb, w) {
if (!w) { if (!w) {
w = window; w = window;
} }
setTimeout(function () { tm = setTimeout(function () {
if (w && w.annotator) { if (w && w.annotator) {
clearTimeout(tm);
cb(); cb();
} else { } else {
checkForAnnotator(cb, w); checkForAnnotator(cb, w);
@ -358,7 +368,6 @@
} }
book.rendition.hooks.content.register(function(contents, view) { book.rendition.hooks.content.register(function(contents, view) {
checkForAnnotator(function () { checkForAnnotator(function () {
var annotator = contents.window.annotator; 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 });
}
});
</script> </script>
</body> </body>

View file

@ -20,12 +20,16 @@
<script type="text/javascript"> <script type="text/javascript">
window.hypothesisConfig = function () { window.hypothesisConfig = function () {
return { return {
// Open the sidebar when the page loads openSidebar: false,
openSidebar: true,
// Needed for multi frame support
enableMultiFrameSupport: true, enableMultiFrameSupport: true,
embedScriptUrl: "https://cdn.hypothes.is/hypothesis" onLayoutChange: function(state) {
var main = document.querySelector('#main');
if (state.expanded === true) {
main.classList.add("open");
} else {
main.classList.remove("open");
}
}
}; };
}; };
</script> </script>
@ -359,42 +363,6 @@
}, contents.window); }, 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 });
}
});
</script> </script>
</body> </body>

View file

@ -1,6 +1,6 @@
{ {
"name": "epubjs", "name": "epubjs",
"version": "0.3.46", "version": "0.3.47",
"description": "Parse and Render Epubs", "description": "Parse and Render Epubs",
"main": "lib/index.js", "main": "lib/index.js",
"module": "src/index.js", "module": "src/index.js",

View file

@ -544,7 +544,11 @@ class Book {
var cfi = new EpubCFI(cfiRange); var cfi = new EpubCFI(cfiRange);
var item = this.spine.get(cfi.spinePos); var item = this.spine.get(cfi.spinePos);
var _request = this.load.bind(this); 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) { return item.load(_request).then(function (contents) {
var range = cfi.toRange(item.document); var range = cfi.toRange(item.document);
return range; return range;

View file

@ -476,10 +476,12 @@ class DefaultViewManager {
let sections = visible.map((view) => { let sections = visible.map((view) => {
let {index, href} = view.section; let {index, href} = view.section;
let position = view.position(); 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; let endPos = startPos + pageHeight - used;
if (endPos > position.bottom - container.top + offset) { if (endPos > height) {
endPos = position.bottom - container.top + offset; endPos = height;
used = (endPos - startPos); used = (endPos - startPos);
} }

View file

@ -76,7 +76,7 @@ class Rendition {
this.hooks.content.register(this.passEvents.bind(this)); this.hooks.content.register(this.passEvents.bind(this));
this.hooks.content.register(this.adjustImages.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) { if (this.settings.stylesheet) {
this.book.spine.hooks.content.register(this.injectStylesheet.bind(this)); this.book.spine.hooks.content.register(this.injectStylesheet.bind(this));
@ -801,10 +801,10 @@ class Rendition {
doc.getElementsByTagName("head")[0].appendChild(script); doc.getElementsByTagName("head")[0].appendChild(script);
} }
injectSource(doc, section) { injectIdentifier(doc, section) {
let ident = this.book.package.metadata.identifier; let ident = this.book.package.metadata.identifier;
let meta = doc.createElement("meta"); let meta = doc.createElement("meta");
meta.setAttribute("property", "dc:source"); meta.setAttribute("name", "dc.relation.ispartof");
if (ident) { if (ident) {
meta.setAttribute("contents", ident); meta.setAttribute("contents", ident);
} }

View file

@ -54,13 +54,13 @@ export function replaceMeta(doc, section){
} }
head = qs(doc, "head"); head = qs(doc, "head");
meta = qs(head, "link[property='dc:identifier']"); meta = qs(head, "link[property='dc.identifier']");
if (meta) { if (meta) {
meta.setAttribute("content", id); meta.setAttribute("content", id);
} else { } else {
meta = doc.createElement("meta"); meta = doc.createElement("meta");
meta.setAttribute("property", "dc:identifier"); meta.setAttribute("name", "dc.identifier");
meta.setAttribute("content", id); meta.setAttribute("content", id);
head.appendChild(meta); head.appendChild(meta);
} }