1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00
* Fix for https://github.com/futurepress/epub.js/issues/537

Following are the changes for getting IE and Firefox working:
• src doc is not supported in IE which was used to render the page content. Now changed the condition if src doc is supported or not and if not we are writing html string to the iframe using iframe.write api.

• Was using page response as xml(responseXML property of xhr), which was creating issue of self closing tags in IE and page was not getting rendered.
Now we have done changes to make use of string output of response to render(using responseText property of xhr) which don't have self closing tags.

• We were not able to load the css and js present in the page contents if they carried a relative URL.
To fix it we have added base tag into the html head so that the js and css links can be found.

• Was using treewalker dom api. In IE expects that acceptNode param should be a function but other browsers expects it to be an object. We have fixed it .

• treewalker dom api has problem with IE if we are passing a text node as root node(throws exception on treewalker.nextNode(), other browsers it returns null). Have added a condition to fix it(if text node do not create treewalker)

* Review change: removed base tag as its being added using hook

* PR changes: reverted the request method implementation and xmlSerialization implementation

* reverted the request method changes to return the response object, now xml is returned

* Updated the condition for IE to use xmldom

Review comment change: To resolve IE self closing tag issue(which causes rendering issue in IE), made use of xmldom npm package.
This commit is contained in:
Sunil-bb 2017-06-29 06:07:38 +05:30 committed by Fred Chasen
parent fd9510f190
commit 9131777fa3
4 changed files with 29 additions and 18 deletions

View file

@ -102,7 +102,8 @@ class IframeView {
// Firefox has trouble with baseURI and srcdoc
// TODO: Disable for now in firefox
if("srcdoc" in this.iframe) {
if(("srcdoc" in this.iframe)) {
this.supportsSrcdoc = true;
} else {
this.supportsSrcdoc = false;

View file

@ -44,16 +44,27 @@ class Mapping {
}
walk(root, func) {
//IE11 has strange issue, if root is text node IE throws exception on
//calling treeWalker.nextNode(), saying
//Unexpected call to method or property access instead of returing null value
if(root && root.nodeType === Node.TEXT_NODE) {
return;
}
//safeFilter is required so that it can work in IE as filter is a function for IE
// and for other browser filter is an object.
var filter = {
acceptNode: function(node) {
if (node.data.trim().length > 0) {
return NodeFilter.FILTER_ACCEPT;
} else {
return NodeFilter.FILTER_REJECT;
}
}
};
var safeFilter = filter.acceptNode;
safeFilter.acceptNode = filter.acceptNode;
//var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_TEXT, null, false);
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
acceptNode: function (node) {
if ( node.data.trim().length > 0 ) {
return NodeFilter.FILTER_ACCEPT;
} else {
return NodeFilter.FILTER_REJECT;
}
}
}, false);
var treeWalker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, safeFilter, false);
var node;
var result;
while ((node = treeWalker.nextNode())) {

View file

@ -54,7 +54,7 @@ class Section {
// var directory = new Url(this.url).directory;
this.document = xml;
this.contents = xml.documentElement;
this.contents = xml.documentElement;
return this.hooks.content.trigger(this.document, this);
}.bind(this))
@ -89,16 +89,16 @@ class Section {
this.load(_request).
then(function(contents){
var serializer;
var userAgent = (typeof navigator !== 'undefined' && navigator.userAgent) || '';
var isIE = userAgent.indexOf('Trident') >= 0;
var Serializer;
if (typeof XMLSerializer === "undefined") {
if (typeof XMLSerializer === "undefined" || isIE) {
Serializer = require("xmldom").XMLSerializer;
} else {
Serializer = XMLSerializer;
}
serializer = new Serializer();
this.output = serializer.serializeToString(contents);
var serializer = new Serializer();
this.output = serializer.serializeToString(contents);
return this.output;
}.bind(this)).
then(function(){

View file

@ -101,7 +101,6 @@ function request(url, type, withCredentials, headers) {
});
return deferred.promise;
}
if(responseXML){
r = this.responseXML;
} else