diff --git a/src/managers/default/index.js b/src/managers/default/index.js index 2c5b2de..66b34d9 100644 --- a/src/managers/default/index.js +++ b/src/managers/default/index.js @@ -31,6 +31,7 @@ class DefaultViewManager { ignoreClass: this.settings.ignoreClass, axis: this.settings.axis, layout: this.layout, + method: this.settings.method, // srcdoc, blobUrl, write width: 0, height: 0 }; diff --git a/src/managers/views/iframe.js b/src/managers/views/iframe.js index 75793c0..7267094 100644 --- a/src/managers/views/iframe.js +++ b/src/managers/views/iframe.js @@ -1,5 +1,5 @@ import EventEmitter from "event-emitter"; -import {extend, borders, uuid, isNumber, bounds, defer} from "../../utils/core"; +import {extend, borders, uuid, isNumber, bounds, defer, createBlobUrl, revokeBlobUrl} from "../../utils/core"; import EpubCFI from "../../epubcfi"; import Contents from "../../contents"; import { Pane, Highlight, Underline } from "marks-pane"; @@ -13,6 +13,7 @@ class IframeView { height: 0, layout: undefined, globalLayoutProperties: {}, + method: undefined }, options || {}); this.id = "epubjs-view-" + uuid(); @@ -112,9 +113,6 @@ class IframeView { // this.iframeBounds = bounds(this.iframe); // } - // Firefox has trouble with baseURI and srcdoc - // TODO: Disable for now in firefox - if(("srcdoc" in this.iframe)) { this.supportsSrcdoc = true; @@ -122,6 +120,10 @@ class IframeView { this.supportsSrcdoc = false; } + if (!this.settings.method) { + this.settings.method = this.supportsSrcdoc ? "srcdoc" : "write"; + } + return this.iframe; } @@ -331,7 +333,10 @@ class IframeView { }.bind(this); - if(this.supportsSrcdoc){ + if (this.settings.method === "blobUrl") { + this.blobUrl = createBlobUrl(contents, "application/xhtml+xml"); + this.iframe.src = this.blobUrl; + } else if(this.settings.method === "srcdoc"){ this.iframe.srcdoc = contents; } else { @@ -654,6 +659,10 @@ class IframeView { this.unmark(cfiRange); } + if (this.blobUrl) { + revokeBlobUrl(this.blobUrl); + } + if(this.displayed){ this.displayed = false; diff --git a/src/rendition.js b/src/rendition.js index 7c204be..756a702 100644 --- a/src/rendition.js +++ b/src/rendition.js @@ -47,10 +47,6 @@ class Rendition { this.manager = this.settings.manager; } - this.viewSettings = { - ignoreClass: this.settings.ignoreClass - }; - this.book = book; // this.views = null; diff --git a/src/utils/core.js b/src/utils/core.js index 4a7a335..ae4ea6e 100644 --- a/src/utils/core.js +++ b/src/utils/core.js @@ -3,6 +3,7 @@ const ELEMENT_NODE = 1; const TEXT_NODE = 3; const COMMENT_NODE = 8; const DOCUMENT_NODE = 9; +const _URL = URL || (typeof window != "undefined" ? (window.URL || window.webkitURL || window.mozURL) : undefined); export function isElement(obj) { return !!(obj && obj.nodeType == 1); @@ -261,7 +262,6 @@ export function createBlob(content, mime){ } export function createBlobUrl(content, mime){ - var _URL = window.URL || window.webkitURL || window.mozURL; var tempUrl; var blob = createBlob(content, mime); @@ -270,6 +270,11 @@ export function createBlobUrl(content, mime){ return tempUrl; } + +export function revokeBlobUrl(url){ + return _URL.revokeObjectURL(url); +} + export function createBase64Url(content, mime){ var data; var datauri;