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

@ -36,7 +36,8 @@ class Rendition {
layout: null,
spread: null,
minSpreadWidth: 800,
stylesheet: null
stylesheet: null,
script: null
});
extend(this.settings, options);
@ -77,6 +78,10 @@ class Rendition {
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.themes = new Themes(this);
@ -636,6 +641,15 @@ class Rendition {
style.setAttribute("href", this.settings.stylesheet);
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