]> _ Git - fluidbook-html5.git/commitdiff
wait #6322 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 28 Sep 2023 15:48:18 +0000 (17:48 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 28 Sep 2023 15:48:18 +0000 (17:48 +0200)
js/libs/fluidbook/cart/fluidbook.cart.joueclub2021.js
js/libs/fluidbook/fluidbook.loader.js

index cc7348160dcc6cfa9dfe4e331d2b28157a54e8ec..d8c916ef234a7066768c0288641851428f38a2b7 100644 (file)
@@ -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) {
index 1324ae9bf0307bb0dab9046b1e0b05483cba5909..3c1ee79f751f3036536088a73404aabda09974a3 100644 (file)
@@ -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;