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

Inject Script in Rendition, add cfiFromRange to Contents

This commit is contained in:
Fred Chasen 2017-03-08 12:29:47 -05:00
parent 6f092c46e5
commit 78249761c3
3 changed files with 24 additions and 2 deletions

View file

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

View file

@ -633,6 +633,14 @@ class Contents {
return cfi.toRange(this.document, ignoreClass); return cfi.toRange(this.document, ignoreClass);
} }
cfiFromRange(range, ignoreClass){
return new EpubCFI(range, this.cfiBase, ignoreClass).toString();
}
cfiFromNode(node, ignoreClass){
return new EpubCFI(node, this.cfiBase, ignoreClass).toString();
}
map(layout){ map(layout){
var map = new Mapping(layout); var map = new Mapping(layout);
return map.section(); return map.section();

View file

@ -36,7 +36,8 @@ class Rendition {
layout: null, layout: null,
spread: null, spread: null,
minSpreadWidth: 800, minSpreadWidth: 800,
stylesheet: null stylesheet: null,
script: null
}); });
extend(this.settings, options); extend(this.settings, options);
@ -77,6 +78,10 @@ class Rendition {
this.book.spine.hooks.content.register(this.injectStylesheet.bind(this)); this.book.spine.hooks.content.register(this.injectStylesheet.bind(this));
} }
if (this.settings.script) {
this.book.spine.hooks.content.register(this.injectScript.bind(this));
}
// this.hooks.display.register(this.afterDisplay.bind(this)); // this.hooks.display.register(this.afterDisplay.bind(this));
this.themes = new Themes(this); this.themes = new Themes(this);
@ -636,6 +641,15 @@ class Rendition {
style.setAttribute("href", this.settings.stylesheet); style.setAttribute("href", this.settings.stylesheet);
doc.getElementsByTagName("head")[0].appendChild(style); doc.getElementsByTagName("head")[0].appendChild(style);
} }
injectScript(doc, section) {
let script = doc.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", this.settings.script);
script.textContent = " "; // Needed to prevent self closing tag
doc.getElementsByTagName("head")[0].appendChild(script);
}
} }
//-- Enable binding events to Renderer //-- Enable binding events to Renderer