mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Updates Request to detect file types inorder to handle both xhtml and html
This commit is contained in:
parent
f5f71977ae
commit
a729c5a461
18 changed files with 1682 additions and 1597 deletions
2
books
2
books
|
@ -1 +1 @@
|
|||
Subproject commit 8d6c46ef23ca637d89e66b18b2146ccef93c1ac4
|
||||
Subproject commit e9790315c2510315e270a7a4c4921825e9918039
|
1553
build/epub.js
1553
build/epub.js
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
10
build/epub.min.js
vendored
10
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -8,5 +8,5 @@
|
|||
"hooks/default/transculsions.js"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;AC9JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;ACxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;ACrEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A"
|
||||
"mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"
|
||||
}
|
File diff suppressed because one or more lines are too long
2
build/reader.min.js
vendored
2
build/reader.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -14,7 +14,7 @@
|
|||
"rdf+xml" : "rdf",
|
||||
"smil" : [ "smi", "smil" ],
|
||||
"xhtml+xml" : [ "xhtml", "xht" ],
|
||||
"xml" : [ "xml", "xsl", "xsd" ],
|
||||
"xml" : [ "xml", "xsl", "xsd", "opf" ],
|
||||
"zip" : "zip",
|
||||
"x-httpd-eruby" : "rhtml",
|
||||
"x-latex" : "latex",
|
||||
|
@ -30,7 +30,7 @@
|
|||
"mathml+xml" : "mathml",
|
||||
"metalink+xml" : "metalink",
|
||||
"mp4" : "mp4s",
|
||||
"oebps-package+xml" : "opf",
|
||||
// "oebps-package+xml" : "opf",
|
||||
"omdoc+xml" : "omdoc",
|
||||
"oxps" : "oxps",
|
||||
"vnd.amazon.ebook" : "azw",
|
||||
|
@ -195,4 +195,4 @@
|
|||
return filename && mimeTypes[filename.split(".").pop().toLowerCase()] || defaultValue;
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
File diff suppressed because one or more lines are too long
1551
reader/js/epub.min.js
vendored
1551
reader/js/epub.min.js
vendored
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
2
reader/js/reader.min.js
vendored
2
reader/js/reader.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -540,7 +540,7 @@ EPUBJS.Book.prototype.loadChange = function(url){
|
|||
EPUBJS.Book.prototype.unlistenToRenderer = function(renderer){
|
||||
renderer.Events.forEach(function(eventName){
|
||||
renderer.off(eventName);
|
||||
} );
|
||||
});
|
||||
};
|
||||
|
||||
//-- Choose between a request from store or a request from network
|
||||
|
|
|
@ -31,7 +31,7 @@ EPUBJS.Chapter.prototype.load = function(_store, _credentials){
|
|||
if(store){
|
||||
promise = store.getXml(this.absolute);
|
||||
}else{
|
||||
promise = EPUBJS.core.request(this.absolute, 'xml', credentials);
|
||||
promise = EPUBJS.core.request(this.absolute, false, credentials);
|
||||
}
|
||||
|
||||
promise.then(function(xml){
|
||||
|
@ -89,15 +89,6 @@ EPUBJS.Chapter.prototype.url = function(_store){
|
|||
url = this.absolute;
|
||||
deferred.resolve(url);
|
||||
}
|
||||
/*
|
||||
loaded = EPUBJS.core.request(url, 'xml', false);
|
||||
loaded.then(function(contents){
|
||||
chapter.contents = contents;
|
||||
deferred.resolve(chapter.absolute);
|
||||
}, function(error){
|
||||
deferred.reject(error);
|
||||
});
|
||||
*/
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
|
121
src/core.js
121
src/core.js
|
@ -14,26 +14,83 @@ EPUBJS.core.getEls = function(classes) {
|
|||
EPUBJS.core.request = function(url, type, withCredentials) {
|
||||
var supportsURL = window.URL;
|
||||
var BLOB_RESPONSE = supportsURL ? "blob" : "arraybuffer";
|
||||
|
||||
var deferred = new RSVP.defer();
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
var uri;
|
||||
|
||||
//-- Check from PDF.js:
|
||||
// https://github.com/mozilla/pdf.js/blob/master/web/compatibility.js
|
||||
var xhrPrototype = XMLHttpRequest.prototype;
|
||||
|
||||
var handler = function() {
|
||||
var r;
|
||||
|
||||
if (this.readyState != this.DONE) return;
|
||||
|
||||
if (this.status === 200 || (this.status === 0 && this.response) ) { // Android & Firefox reporting 0 for local & blob urls
|
||||
if(type == 'xml'){
|
||||
// If this.responseXML wasn't set, try to parse using a DOMParser from text
|
||||
if(!this.responseXML){
|
||||
r = new DOMParser().parseFromString(this.response, "application/xml");
|
||||
} else {
|
||||
r = this.responseXML;
|
||||
}
|
||||
}else
|
||||
if(type == 'xhtml'){
|
||||
if(!this.responseXML){
|
||||
r = new DOMParser().parseFromString(this.response, "application/xhtml+xml");
|
||||
} else {
|
||||
r = this.responseXML;
|
||||
}
|
||||
}else
|
||||
if(type == 'html'){
|
||||
if(!this.responseXML){
|
||||
r = new DOMParser().parseFromString(this.response, "text/html");
|
||||
} else {
|
||||
r = this.responseXML;
|
||||
}
|
||||
} else
|
||||
if(type == 'json'){
|
||||
r = JSON.parse(this.response);
|
||||
}else
|
||||
if(type == 'blob'){
|
||||
|
||||
if(supportsURL) {
|
||||
r = this.response;
|
||||
} else {
|
||||
//-- Safari doesn't support responseType blob, so create a blob from arraybuffer
|
||||
r = new Blob([this.response]);
|
||||
}
|
||||
|
||||
}else{
|
||||
r = this.response;
|
||||
}
|
||||
|
||||
deferred.resolve(r);
|
||||
} else {
|
||||
deferred.reject({
|
||||
message : this.response,
|
||||
stack : new Error().stack
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (!('overrideMimeType' in xhrPrototype)) {
|
||||
// IE10 might have response, but not overrideMimeType
|
||||
Object.defineProperty(xhrPrototype, 'overrideMimeType', {
|
||||
value: function xmlHttpRequestOverrideMimeType(mimeType) {}
|
||||
});
|
||||
}
|
||||
|
||||
if(withCredentials) {
|
||||
xhr.withCredentials = true;
|
||||
}
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onreadystatechange = handler;
|
||||
|
||||
// If type isn't set, determine it from the file extension
|
||||
if(!type) {
|
||||
uri = EPUBJS.core.uri(url);
|
||||
type = uri.extension;
|
||||
}
|
||||
|
||||
if(type == 'blob'){
|
||||
xhr.responseType = BLOB_RESPONSE;
|
||||
|
@ -44,56 +101,26 @@ EPUBJS.core.request = function(url, type, withCredentials) {
|
|||
}
|
||||
|
||||
if(type == 'xml') {
|
||||
xhr.overrideMimeType('text/xml');
|
||||
xhr.responseType = "document";
|
||||
xhr.overrideMimeType('text/xml'); // for OPF parsing
|
||||
}
|
||||
|
||||
if(type == 'xhtml') {
|
||||
xhr.responseType = "document";
|
||||
}
|
||||
|
||||
if(type == 'html') {
|
||||
xhr.responseType = "document";
|
||||
}
|
||||
|
||||
if(type == "binary") {
|
||||
xhr.responseType = "arraybuffer";
|
||||
}
|
||||
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onreadystatechange = handler;
|
||||
xhr.send();
|
||||
|
||||
function handler() {
|
||||
if (this.readyState === this.DONE) {
|
||||
if (this.status === 200 || (this.status === 0 && this.response) ) { // Android & Firefox reporting 0 for local & blob urls
|
||||
var r;
|
||||
|
||||
if(type == 'xml'){
|
||||
|
||||
// If this.responseXML wasn't set, try to parse using a DOMParser from text
|
||||
if(!this.responseXML){
|
||||
r = new DOMParser().parseFromString(this.response, "text/xml");
|
||||
} else {
|
||||
r = this.responseXML;
|
||||
}
|
||||
|
||||
}else
|
||||
if(type == 'json'){
|
||||
r = JSON.parse(this.response);
|
||||
}else
|
||||
if(type == 'blob'){
|
||||
|
||||
if(supportsURL) {
|
||||
r = this.response;
|
||||
} else {
|
||||
//-- Safari doesn't support responseType blob, so create a blob from arraybuffer
|
||||
r = new Blob([this.response]);
|
||||
}
|
||||
|
||||
}else{
|
||||
r = this.response;
|
||||
}
|
||||
|
||||
deferred.resolve(r);
|
||||
} else {
|
||||
deferred.reject({
|
||||
message : this.response,
|
||||
stack : new Error().stack
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
|
@ -598,4 +625,4 @@ EPUBJS.core.values = function(object) {
|
|||
result[index] = object[props[index]];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -28,7 +28,8 @@ EPUBJS.Unarchiver.prototype.getXml = function(url, encoding){
|
|||
return this.getText(decodededUrl, encoding).
|
||||
then(function(text){
|
||||
var parser = new DOMParser();
|
||||
return parser.parseFromString(text, "text/xml");
|
||||
var mimeType = EPUBJS.core.getMimeType(url);
|
||||
return parser.parseFromString(text, mimeType);
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -41,7 +42,7 @@ EPUBJS.Unarchiver.prototype.getUrl = function(url, mime){
|
|||
var _URL = window.URL || window.webkitURL || window.mozURL;
|
||||
var tempUrl;
|
||||
var blob;
|
||||
|
||||
|
||||
if(!entry) {
|
||||
deferred.reject({
|
||||
message : "File not found in the epub: " + url,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue