mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Add method setting for views
This commit is contained in:
parent
14d69db54a
commit
d77fc06a2e
4 changed files with 21 additions and 10 deletions
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -47,10 +47,6 @@ class Rendition {
|
|||
this.manager = this.settings.manager;
|
||||
}
|
||||
|
||||
this.viewSettings = {
|
||||
ignoreClass: this.settings.ignoreClass
|
||||
};
|
||||
|
||||
this.book = book;
|
||||
|
||||
// this.views = null;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue