this.format = fluidbook.settings.imageFormat;
this.imageMimeType = this.format === 'jpg' ? 'image/jpeg' : 'image/png';
this._needSeparateTextures = [];
-
- this.init();
+ this.loadbalancing = false;
}
FluidbookLoader.prototype = {
- init: function () {
- this.shadeLeft = this.loadImage('images/shadows/pages/left.png');
- this.shadeRight = this.loadImage('images/shadows/pages/right.png');
+ init: function (callback) {
+ let $this = this;
+ if (this.fluidbook.settings.hosting_loadbalancer) {
+ $.ajax("https://toolbox.fluidbook.com/lb.json").done(function (data) {
+ $this.loadbalancing = data;
+ $this.loadShades(callback);
+ }).fail(function () {
+ $this.loadbalancing = false;
+ $this.loadShades(callback);
+ });
+ } else {
+ this.loadShades(callback);
+ }
+ },
+
+ loadShades: function (callback) {
+ console.log('load shades');
+ this.shadeLeft = this.loadImage(this.getURL('images/shadows/pages/left.png'));
+ this.shadeRight = this.loadImage(this.getURL('images/shadows/pages/right.png'));
+ if (callback) {
+ callback();
+ }
},
getPageDimensions: function (page, width) {
},
preloadStart: function (callback) {
- if (this.fluidbook.shortLoading) {
- this.toPreload = [1];
- } else {
- this.toPreload = [1, 2, 3];
+ let $this = this;
+ this.init(function () {
+ $this.fluidbook.sound.preloadSounds();
+ if ($this.fluidbook.shortLoading) {
+ $this.toPreload = [1];
+ } else {
+ $this.toPreload = [1, 2, 3];
+ }
+ $this.preloaded = $this.toPreload.slice(0);
+ $this.preloadPages(callback);
+ });
+ },
+
+ balanceLinkAssets(links) {
+ if (!this.loadbalancing) {
+ return links;
}
- this.preloaded = this.toPreload.slice(0);
- this.preloadPages(callback);
+ let $this = this;
+ return links.replace(/data\/[^"]*/gm, function (matched) {
+ return $this.getURL(matched);
+ });
},
preloadPagesBeforeTransition: function (pages, callback) {
this.backgrounds[page] = null;
$__callback();
} else {
- this.backgrounds[page] = this.loadImage(backgroundURL, null, null, null, page, function () {
+ this.backgrounds[page] = this.loadImage(this.getURL(backgroundURL), null, null, null, page, function () {
$__callback();
});
}
}
$("#loadedcontents [data-page='" + page + "']").remove();
- }, setContentsInDoublePage: function (doublePage, pages, immediate, callback) {
+ },
+
+ setContentsInDoublePage: function (doublePage, pages, immediate, callback) {
var $this = this;
var leftPage = pages[0];
var ext = this.fluidbook.settings.actualHtmlExtension;
if (ext === undefined || ext === null || ext === 'html') {
- return content;
+ return this.balanceLinkAssets(content);
}
var res = content.replace(/data\/([^"]*)\.html/gm, "data/$1." + ext);
- return res;
+ return this.balanceLinkAssets(res);
},
loadPageShade: function (position) {
- return this.loadImage('images/shadows/pages/' + position + '.png', this.fluidbook.settings.width / 4, this.fluidbook.settings.height);
- }, loadLeftPage: function (page, doublePage, callback) {
+ return this.loadImage(this.getURL('images/shadows/pages/' + position + '.png'), this.fluidbook.settings.width / 4, this.fluidbook.settings.height);
+ },
+
+ loadLeftPage: function (page, doublePage, callback) {
if (page > 0 && page <= this.fluidbook.contentlock.getMaxPage()) {
this.loadPage(page, doublePage, 'left', callback);
} else {
$(doublePage).find('.left').remove();
callback();
}
- }, loadRightPage: function (page, doublePage, callback) {
+ },
+
+ loadRightPage: function (page, doublePage, callback) {
if (!this.fluidbook.displayOnePage && page <= this.fluidbook.contentlock.getMaxPage() && page > 0) {
this.loadPage(page, doublePage, 'right', callback);
} else {
$(doublePage).find('.right').remove();
callback();
}
- }, getBackgroundURL: function (page) {
+ },
+
+ getBackgroundURL: function (page) {
var version = this.getVersionToLoad(page);
if (version === 'vector') {
return false;
callback();
return false;
}
- this.backgrounds[page] = this.loadImage(url, null, null, null, page, callback);
+ this.backgrounds[page] = this.loadImage(this.getURL(url), null, null, null, page, callback);
},
needSeparateTextures: function (page) {
nb++;
var i = $(this).data('id');
var url = $(this).data('image').replace(/^\.\./, 'data') + '?j=' + (new Date()).getTime();
- textures[i] = loadImage(url, cb, 'i_' + i);
+ textures[i] = loadImage(this.getURL(url), cb, 'i_' + i);
});
if (nb === 0) {
}
}
- if($(this).is('[data-layer="bothsvg"]')){
+ if ($(this).is('[data-layer="bothsvg"]')) {
ctx.fillStyle = '#ffffff';
ctx.fillRect(left, top, width, height);
}
});
},
+ getURL(url) {
+ if (!this.loadbalancing) {
+ return url;
+ }
+ let server = this.loadbalancing[Math.floor(Math.random() * this.loadbalancing.length)];
+ return 'https://' + server + '/' + this.fluidbook.settings.id + '_' + this.fluidbook.settings.hash + '/' + url;
+ },
+
getTexture: function (page, callback, enter) {
if (enter === undefined) {
enter = true;
callback();
});
} else {
- this.texts[pageNr] = this.loadImage(url, null, null, 'image/svg+xml', pageNr, callback);
+ this.texts[pageNr] = this.loadImage(this.getURL(url), null, null, 'image/svg+xml', pageNr, callback);
}
- }, loadDatas: function (pageNr, callback) {
+ },
+
+ loadDatas: function (pageNr, callback) {
var $this = this;
this.loadTexts(pageNr, function () {
$this.setBackground(pageNr, function () {
callback();
});
});
- }, getImage: function (src, width, height, type, callback) {
+ },
+
+ getImage: function (src, width, height, type, callback) {
var img = this.loadImage(src, width, height, type, null, callback);
return $(img).get(0).outerHTML;
},
}
callback();
};
- var img = this.loadImage('data/thumbnails/p' + pageNr + '.' + this.format, null, null, this.imageMimeType, pageNr, cb);
+ var img = this.loadImage(this.getURL('data/thumbnails/p' + pageNr + '.' + this.format), null, null, this.imageMimeType, pageNr, cb);
this.thumbnails[pageNr] = img;
return img;
},