From: Vincent Vanwaelscappel Date: Thu, 28 Sep 2023 15:48:18 +0000 (+0200) Subject: wait #6322 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=e76757b5e974af0801d554c7dfbff9b78881dedf;p=fluidbook-html5.git wait #6322 @0.25 --- diff --git a/js/libs/fluidbook/cart/fluidbook.cart.joueclub2021.js b/js/libs/fluidbook/cart/fluidbook.cart.joueclub2021.js index cc734816..d8c916ef 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.joueclub2021.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.joueclub2021.js @@ -152,7 +152,7 @@ FluidbookCartJoueClub2021.prototype = { sendCartAsEmail: function () { var $this = this; - var subject = 'Catalogue Jouéclub Noël 2021 - Ma liste de cadeaux' + var subject = 'Catalogue Jouéclub Noël - Ma liste de cadeaux' var body = ''; $.each(this.getItems(), function (i, ref) { diff --git a/js/libs/fluidbook/fluidbook.loader.js b/js/libs/fluidbook/fluidbook.loader.js index 1324ae9b..3c1ee79f 100644 --- a/js/libs/fluidbook/fluidbook.loader.js +++ b/js/libs/fluidbook/fluidbook.loader.js @@ -19,6 +19,7 @@ function FluidbookLoader(fluidbook) { this._needSeparateTextures = []; this.loadbalancing = false; this._loadbalancingServerURL = {}; + this._textureAssetsCache = {}; } FluidbookLoader.prototype = { @@ -39,6 +40,10 @@ FluidbookLoader.prototype = { } else { this.loadShades(callback); } + + setInterval(function () { + $this.cleanCaches(); + }, 30000); }, loadShades: function (callback) { @@ -601,8 +606,11 @@ FluidbookLoader.prototype = { } nb++; var i = $(this).data('id'); - var url = $(this).data('image').replace(/^\.\./, 'data') + '?j=' + (new Date()).getTime(); - textures[i] = $this.loadImage($this.getURL(url), null, null, null, null, cb, 'i_' + i); + var url = $(this).data('image').replace(/^\.\./, 'data'); + + $this._getTextureLinkAsset(url, i, function (datauri) { + textures[i] = $this.loadImage(datauri, null, null, null, 'i_' + i, cb); + }); }); if (nb === 0) { @@ -611,6 +619,50 @@ FluidbookLoader.prototype = { } }, + _getTextureLinkAsset: function (url, id, callback) { + let $this = this; + if (this._textureAssetsCache[url] === undefined || this._textureAssetsCache[url] === null) { + this.toDataURL($this.getURL(url), function (res) { + $this._textureAssetsCache[url] = {content: res, lastAccess: Date.now()}; + callback(res); + }); + return; + } + this._textureAssetsCache[url].lastAccess = Date.now(); + callback(this._textureAssetsCache[url].content); + }, + + cleanCaches: function () { + let limit = Date.now() - 120000; // 2 min + let urlToDelete = []; + for (var url in this._textureAssetsCache) { + if (this._textureAssetsCache[url].lastAccess < limit) { + urlToDelete.push(url); + } + } + + for (var i in urlToDelete) { + delete this._textureAssetsCache[urlToDelete[i]]; + } + }, + + toDataURL: function (url, callback) { + var xhr = new XMLHttpRequest(); + xhr.open('get', url); + xhr.responseType = 'blob'; + xhr.onload = function () { + var fr = new FileReader(); + + fr.onload = function () { + callback(this.result); + }; + + fr.readAsDataURL(xhr.response); // async call + }; + + xhr.send(); + }, + _loadTexture: function (page, callback, enter) { if (enter === undefined) { enter = true;