mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
updated to new JSZip api
This commit is contained in:
parent
874cabe510
commit
45885fc039
10 changed files with 94 additions and 60 deletions
|
@ -30,6 +30,12 @@ Get the minified code from the build folder:
|
|||
<script src="../dist/epub.min.js"></script>
|
||||
```
|
||||
|
||||
If using archived `.epub` files include JSZip:
|
||||
|
||||
```html
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.1/jszip.min.js"></script>
|
||||
```
|
||||
|
||||
Setup a element to render to:
|
||||
|
||||
```html
|
||||
|
|
40
dist/epub.js
vendored
40
dist/epub.js
vendored
|
@ -11779,7 +11779,7 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
var fileUri = URI(href);
|
||||
var absolute = fileUri.absoluteTo(this.book.baseUrl).toString();
|
||||
// Get the text of the css file from the archive
|
||||
var text = this.book.archive.getText(absolute);
|
||||
var textResponse = this.book.archive.getText(absolute);
|
||||
// Get asset links relative to css file
|
||||
var relUrls = urls.
|
||||
map(function(assetHref) {
|
||||
|
@ -11788,6 +11788,7 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
return relative;
|
||||
}.bind(this));
|
||||
|
||||
return textResponse.then(function (text) {
|
||||
// Replacements in the css text
|
||||
text = replace.substitute(text, relUrls, replacementUrls);
|
||||
|
||||
|
@ -11799,6 +11800,8 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
if (indexInUrls > -1) {
|
||||
replacementUrls[indexInUrls] = newUrl;
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
Rendition.prototype.replaceAssets = function(section, urls, replacementUrls){
|
||||
|
@ -12657,15 +12660,17 @@ Unarchive.prototype.checkRequirements = function(callback){
|
|||
|
||||
Unarchive.prototype.open = function(zipUrl){
|
||||
if (zipUrl instanceof ArrayBuffer) {
|
||||
return new RSVP.Promise(function(resolve, reject) {
|
||||
this.zip = new JSZip(zipUrl);
|
||||
resolve(this.zip);
|
||||
});
|
||||
// return new RSVP.Promise(function(resolve, reject) {
|
||||
// this.zip = new JSZip(zipUrl);
|
||||
// resolve(this.zip);
|
||||
// });
|
||||
return this.zip.loadAsync(zipUrl);
|
||||
} else {
|
||||
return request(zipUrl, "binary")
|
||||
.then(function(data){
|
||||
this.zip = new JSZip(data);
|
||||
return this.zip;
|
||||
// this.zip = new JSZip(data);
|
||||
// return this.zip;
|
||||
return this.zip.loadAsync(data);
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
@ -12688,8 +12693,10 @@ Unarchive.prototype.request = function(url, type){
|
|||
}
|
||||
|
||||
if (response) {
|
||||
r = this.handleResponse(response, type);
|
||||
deferred.resolve(r);
|
||||
response.then(function (r) {
|
||||
result = this.handleResponse(r, type);
|
||||
deferred.resolve(result);
|
||||
}.bind(this));
|
||||
} else {
|
||||
deferred.reject({
|
||||
message : "File not found in the epub: " + url,
|
||||
|
@ -12730,7 +12737,9 @@ Unarchive.prototype.getBlob = function(url, _mimeType){
|
|||
|
||||
if(entry) {
|
||||
mimeType = _mimeType || mime.lookup(entry.name);
|
||||
return new Blob([entry.asUint8Array()], {type : mimeType});
|
||||
return entry.async("uint8array").then(function(uint8array) {
|
||||
return new Blob([uint8array], {type : mimeType});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -12739,7 +12748,9 @@ Unarchive.prototype.getText = function(url, encoding){
|
|||
var entry = this.zip.file(decodededUrl);
|
||||
|
||||
if(entry) {
|
||||
return entry.asText();
|
||||
return entry.async("string").then(function(text) {
|
||||
return text;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -12748,18 +12759,21 @@ Unarchive.prototype.createUrl = function(url, mime){
|
|||
var _URL = window.URL || window.webkitURL || window.mozURL;
|
||||
var tempUrl;
|
||||
var blob;
|
||||
var response;
|
||||
|
||||
if(url in this.urlCache) {
|
||||
deferred.resolve(this.urlCache[url]);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
blob = this.getBlob(url);
|
||||
response = this.getBlob(url);
|
||||
|
||||
if (blob) {
|
||||
if (response) {
|
||||
response.then(function(blob) {
|
||||
tempUrl = _URL.createObjectURL(blob);
|
||||
deferred.resolve(tempUrl);
|
||||
this.urlCache[url] = tempUrl;
|
||||
}.bind(this));
|
||||
} else {
|
||||
deferred.reject({
|
||||
message : "File not found in the epub: " + url,
|
||||
|
|
2
dist/epub.js.map
vendored
2
dist/epub.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -5,7 +5,7 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>EPUB.js Annotator Example</title>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.1/jszip.min.js"></script>
|
||||
<script src="../dist/epub.js"></script>
|
||||
|
||||
<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/annotator/1.2.9/annotator.min.js"></script> -->
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>EPUB.js Pagination Example</title>
|
||||
|
||||
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script> -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.1/jszip.min.js"></script>
|
||||
<script src="../libs/jszip/jszip.js"></script>
|
||||
<script src="../dist/epub.js"></script>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
<script src="../dist/epub.js"></script>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.1/jszip.min.js"></script>
|
||||
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-core.js"></script>
|
||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-classapplier.js"></script>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>EPUB.js + Hypothes.is Example</title>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.1/jszip.min.js"></script>
|
||||
<script src="../dist/epub.js"></script>
|
||||
|
||||
<script>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>EPUB.js Pagination Example</title>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.1/jszip.min.js"></script>
|
||||
<script src="../dist/epub.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
|
|
|
@ -468,7 +468,7 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
var fileUri = URI(href);
|
||||
var absolute = fileUri.absoluteTo(this.book.baseUrl).toString();
|
||||
// Get the text of the css file from the archive
|
||||
var text = this.book.archive.getText(absolute);
|
||||
var textResponse = this.book.archive.getText(absolute);
|
||||
// Get asset links relative to css file
|
||||
var relUrls = urls.
|
||||
map(function(assetHref) {
|
||||
|
@ -477,6 +477,7 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
return relative;
|
||||
}.bind(this));
|
||||
|
||||
return textResponse.then(function (text) {
|
||||
// Replacements in the css text
|
||||
text = replace.substitute(text, relUrls, replacementUrls);
|
||||
|
||||
|
@ -488,6 +489,8 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
if (indexInUrls > -1) {
|
||||
replacementUrls[indexInUrls] = newUrl;
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
Rendition.prototype.replaceAssets = function(section, urls, replacementUrls){
|
||||
|
|
|
@ -26,15 +26,17 @@ Unarchive.prototype.checkRequirements = function(callback){
|
|||
|
||||
Unarchive.prototype.open = function(zipUrl){
|
||||
if (zipUrl instanceof ArrayBuffer) {
|
||||
return new RSVP.Promise(function(resolve, reject) {
|
||||
this.zip = new JSZip(zipUrl);
|
||||
resolve(this.zip);
|
||||
});
|
||||
// return new RSVP.Promise(function(resolve, reject) {
|
||||
// this.zip = new JSZip(zipUrl);
|
||||
// resolve(this.zip);
|
||||
// });
|
||||
return this.zip.loadAsync(zipUrl);
|
||||
} else {
|
||||
return request(zipUrl, "binary")
|
||||
.then(function(data){
|
||||
this.zip = new JSZip(data);
|
||||
return this.zip;
|
||||
// this.zip = new JSZip(data);
|
||||
// return this.zip;
|
||||
return this.zip.loadAsync(data);
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
@ -57,8 +59,10 @@ Unarchive.prototype.request = function(url, type){
|
|||
}
|
||||
|
||||
if (response) {
|
||||
r = this.handleResponse(response, type);
|
||||
deferred.resolve(r);
|
||||
response.then(function (r) {
|
||||
result = this.handleResponse(r, type);
|
||||
deferred.resolve(result);
|
||||
}.bind(this));
|
||||
} else {
|
||||
deferred.reject({
|
||||
message : "File not found in the epub: " + url,
|
||||
|
@ -99,7 +103,9 @@ Unarchive.prototype.getBlob = function(url, _mimeType){
|
|||
|
||||
if(entry) {
|
||||
mimeType = _mimeType || mime.lookup(entry.name);
|
||||
return new Blob([entry.asUint8Array()], {type : mimeType});
|
||||
return entry.async("uint8array").then(function(uint8array) {
|
||||
return new Blob([uint8array], {type : mimeType});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -108,7 +114,9 @@ Unarchive.prototype.getText = function(url, encoding){
|
|||
var entry = this.zip.file(decodededUrl);
|
||||
|
||||
if(entry) {
|
||||
return entry.asText();
|
||||
return entry.async("string").then(function(text) {
|
||||
return text;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -117,18 +125,21 @@ Unarchive.prototype.createUrl = function(url, mime){
|
|||
var _URL = window.URL || window.webkitURL || window.mozURL;
|
||||
var tempUrl;
|
||||
var blob;
|
||||
var response;
|
||||
|
||||
if(url in this.urlCache) {
|
||||
deferred.resolve(this.urlCache[url]);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
blob = this.getBlob(url);
|
||||
response = this.getBlob(url);
|
||||
|
||||
if (blob) {
|
||||
if (response) {
|
||||
response.then(function(blob) {
|
||||
tempUrl = _URL.createObjectURL(blob);
|
||||
deferred.resolve(tempUrl);
|
||||
this.urlCache[url] = tempUrl;
|
||||
}.bind(this));
|
||||
} else {
|
||||
deferred.reject({
|
||||
message : "File not found in the epub: " + url,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue