mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Wait for css replacements to finish
This commit is contained in:
parent
e587bb8429
commit
ad45f2ec81
3 changed files with 59 additions and 29 deletions
21
dist/epub.js
vendored
21
dist/epub.js
vendored
|
@ -11779,18 +11779,22 @@ Rendition.prototype.replacements = function(){
|
|||
// After all the urls are created
|
||||
return RSVP.all(processing).
|
||||
then(function(replacementUrls) {
|
||||
|
||||
var replaced = [];
|
||||
// Replace Asset Urls in the text of all css files
|
||||
cssUrls.forEach(function(href) {
|
||||
this.replaceCss(href, urls, replacementUrls);
|
||||
replaced.push(this.replaceCss(href, urls, replacementUrls));
|
||||
}.bind(this));
|
||||
|
||||
return RSVP.all(replaced).then(function () {
|
||||
// Replace Asset Urls in chapters
|
||||
// by registering a hook after the sections contents has been serialized
|
||||
this.book.spine.hooks.serialize.register(function(output, section) {
|
||||
this.replaceAssets(section, urls, replacementUrls);
|
||||
}.bind(this));
|
||||
|
||||
}.bind(this));
|
||||
|
||||
|
||||
}.bind(this)).catch(function(reason){
|
||||
console.error(reason);
|
||||
});
|
||||
|
@ -11820,13 +11824,20 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
|
||||
// Get the new url
|
||||
if (this.settings.useBase64) {
|
||||
core.createBlobUrl(text, 'text/css', function(newUrl) {
|
||||
return new RSVP.Promise(function(resolve, reject) {
|
||||
|
||||
core.createBase64Url(text, 'text/css', function(newUrl) {
|
||||
// switch the url in the replacementUrls
|
||||
indexInUrls = urls.indexOf(href);
|
||||
if (indexInUrls > -1) {
|
||||
replacementUrls[indexInUrls] = newUrl;
|
||||
}
|
||||
|
||||
resolve(replacementUrls);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
newUrl = core.createBlobUrl(text, 'text/css');
|
||||
|
||||
|
@ -11835,6 +11846,10 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
if (indexInUrls > -1) {
|
||||
replacementUrls[indexInUrls] = newUrl;
|
||||
}
|
||||
|
||||
return new RSVP.Promise(function(resolve, reject) {
|
||||
resolve(replacementUrls);
|
||||
});
|
||||
}
|
||||
|
||||
}.bind(this));
|
||||
|
|
2
dist/epub.js.map
vendored
2
dist/epub.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -443,18 +443,22 @@ Rendition.prototype.replacements = function(){
|
|||
// After all the urls are created
|
||||
return RSVP.all(processing).
|
||||
then(function(replacementUrls) {
|
||||
|
||||
var replaced = [];
|
||||
// Replace Asset Urls in the text of all css files
|
||||
cssUrls.forEach(function(href) {
|
||||
this.replaceCss(href, urls, replacementUrls);
|
||||
replaced.push(this.replaceCss(href, urls, replacementUrls));
|
||||
}.bind(this));
|
||||
|
||||
return RSVP.all(replaced).then(function () {
|
||||
// Replace Asset Urls in chapters
|
||||
// by registering a hook after the sections contents has been serialized
|
||||
this.book.spine.hooks.serialize.register(function(output, section) {
|
||||
this.replaceAssets(section, urls, replacementUrls);
|
||||
}.bind(this));
|
||||
|
||||
}.bind(this));
|
||||
|
||||
|
||||
}.bind(this)).catch(function(reason){
|
||||
console.error(reason);
|
||||
});
|
||||
|
@ -484,13 +488,20 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
|
||||
// Get the new url
|
||||
if (this.settings.useBase64) {
|
||||
core.createBlobUrl(text, 'text/css', function(newUrl) {
|
||||
return new RSVP.Promise(function(resolve, reject) {
|
||||
|
||||
core.createBase64Url(text, 'text/css', function(newUrl) {
|
||||
// switch the url in the replacementUrls
|
||||
indexInUrls = urls.indexOf(href);
|
||||
if (indexInUrls > -1) {
|
||||
replacementUrls[indexInUrls] = newUrl;
|
||||
}
|
||||
|
||||
resolve(replacementUrls);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
newUrl = core.createBlobUrl(text, 'text/css');
|
||||
|
||||
|
@ -499,6 +510,10 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
|
|||
if (indexInUrls > -1) {
|
||||
replacementUrls[indexInUrls] = newUrl;
|
||||
}
|
||||
|
||||
return new RSVP.Promise(function(resolve, reject) {
|
||||
resolve(replacementUrls);
|
||||
});
|
||||
}
|
||||
|
||||
}.bind(this));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue