1
0
Fork 0
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:
Fred Chasen 2016-08-19 16:21:43 +02:00
parent e587bb8429
commit ad45f2ec81
3 changed files with 59 additions and 29 deletions

43
dist/epub.js vendored
View file

@ -11779,17 +11779,21 @@ Rendition.prototype.replacements = function(){
// After all the urls are created // After all the urls are created
return RSVP.all(processing). return RSVP.all(processing).
then(function(replacementUrls) { then(function(replacementUrls) {
var replaced = [];
// Replace Asset Urls in the text of all css files // Replace Asset Urls in the text of all css files
cssUrls.forEach(function(href) { cssUrls.forEach(function(href) {
this.replaceCss(href, urls, replacementUrls); replaced.push(this.replaceCss(href, urls, replacementUrls));
}.bind(this)); }.bind(this));
// Replace Asset Urls in chapters return RSVP.all(replaced).then(function () {
// by registering a hook after the sections contents has been serialized // Replace Asset Urls in chapters
this.book.spine.hooks.serialize.register(function(output, section) { // by registering a hook after the sections contents has been serialized
this.replaceAssets(section, urls, replacementUrls); this.book.spine.hooks.serialize.register(function(output, section) {
}.bind(this)); this.replaceAssets(section, urls, replacementUrls);
}.bind(this));
}.bind(this));
}.bind(this)).catch(function(reason){ }.bind(this)).catch(function(reason){
console.error(reason); console.error(reason);
@ -11820,13 +11824,20 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
// Get the new url // Get the new url
if (this.settings.useBase64) { if (this.settings.useBase64) {
core.createBlobUrl(text, 'text/css', function(newUrl) { return new RSVP.Promise(function(resolve, reject) {
// switch the url in the replacementUrls
indexInUrls = urls.indexOf(href); core.createBase64Url(text, 'text/css', function(newUrl) {
if (indexInUrls > -1) { // switch the url in the replacementUrls
replacementUrls[indexInUrls] = newUrl; indexInUrls = urls.indexOf(href);
} if (indexInUrls > -1) {
}); replacementUrls[indexInUrls] = newUrl;
}
resolve(replacementUrls);
});
});
} else { } else {
newUrl = core.createBlobUrl(text, 'text/css'); newUrl = core.createBlobUrl(text, 'text/css');
@ -11835,6 +11846,10 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
if (indexInUrls > -1) { if (indexInUrls > -1) {
replacementUrls[indexInUrls] = newUrl; replacementUrls[indexInUrls] = newUrl;
} }
return new RSVP.Promise(function(resolve, reject) {
resolve(replacementUrls);
});
} }
}.bind(this)); }.bind(this));

2
dist/epub.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -443,17 +443,21 @@ Rendition.prototype.replacements = function(){
// After all the urls are created // After all the urls are created
return RSVP.all(processing). return RSVP.all(processing).
then(function(replacementUrls) { then(function(replacementUrls) {
var replaced = [];
// Replace Asset Urls in the text of all css files // Replace Asset Urls in the text of all css files
cssUrls.forEach(function(href) { cssUrls.forEach(function(href) {
this.replaceCss(href, urls, replacementUrls); replaced.push(this.replaceCss(href, urls, replacementUrls));
}.bind(this)); }.bind(this));
// Replace Asset Urls in chapters return RSVP.all(replaced).then(function () {
// by registering a hook after the sections contents has been serialized // Replace Asset Urls in chapters
this.book.spine.hooks.serialize.register(function(output, section) { // by registering a hook after the sections contents has been serialized
this.replaceAssets(section, urls, replacementUrls); this.book.spine.hooks.serialize.register(function(output, section) {
}.bind(this)); this.replaceAssets(section, urls, replacementUrls);
}.bind(this));
}.bind(this));
}.bind(this)).catch(function(reason){ }.bind(this)).catch(function(reason){
console.error(reason); console.error(reason);
@ -484,13 +488,20 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
// Get the new url // Get the new url
if (this.settings.useBase64) { if (this.settings.useBase64) {
core.createBlobUrl(text, 'text/css', function(newUrl) { return new RSVP.Promise(function(resolve, reject) {
// switch the url in the replacementUrls
indexInUrls = urls.indexOf(href); core.createBase64Url(text, 'text/css', function(newUrl) {
if (indexInUrls > -1) { // switch the url in the replacementUrls
replacementUrls[indexInUrls] = newUrl; indexInUrls = urls.indexOf(href);
} if (indexInUrls > -1) {
}); replacementUrls[indexInUrls] = newUrl;
}
resolve(replacementUrls);
});
});
} else { } else {
newUrl = core.createBlobUrl(text, 'text/css'); newUrl = core.createBlobUrl(text, 'text/css');
@ -499,6 +510,10 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
if (indexInUrls > -1) { if (indexInUrls > -1) {
replacementUrls[indexInUrls] = newUrl; replacementUrls[indexInUrls] = newUrl;
} }
return new RSVP.Promise(function(resolve, reject) {
resolve(replacementUrls);
});
} }
}.bind(this)); }.bind(this));