]> _ Git - fluidbook-html5.git/commitdiff
wip #2655 @6
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 28 Mar 2019 12:23:53 +0000 (13:23 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 28 Mar 2019 12:23:53 +0000 (13:23 +0100)
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.links.js
js/libs/fluidbook/fluidbook.loader.js
js/libs/fluidbook/fluidbook.networkcontrol.js [new file with mode: 0644]
js/libs/fluidbook/fluidbook.pagetransitions.js
js/libs/fluidbook/fluidbook.stats.js
js/libs/scorm/scorm.js

index c0455908f9227be61523370aa443ceab80a612af..80626b7b1716fc9ea87d3acc73f97c674e6fd9ca 100644 (file)
@@ -21,16 +21,13 @@ Fluidbook.prototype = {
     init: function (datas) {
 
         this.flags = {};
-        this.networkPauseDate = null;
-        this.networkPauseQueue = [];
-        this.networkPausePriorityQueue = [];
-        this.initNetworkPause();
         this.canNavigate = false;
 
         this.initSettings(datas);
         this.singleMode = (this.datas.mobileNavigationType === 'portrait');
 
         this.junk = datas.cacheDate;
+        this.networkControl = new FluidbookNetworkControl(this);
         this.input = new FluidbookInput(this);
         if (this.datas.landingPage != undefined && this.datas.landingPage != '') {
             this.landingpage = new FluidbookLandingPage(this);
@@ -195,10 +192,10 @@ Fluidbook.prototype = {
         if (this.support.transitions3dacc && this.datas.mobileTransitions === 'flip3d') {
             $("#main,#viewOverlay,#view").css('visibility', 'visible');
             resize();
-            this.pauseNetwork(4000);
+            this.networkControl.pause(4000);
             setTimeout(function () {
                 this.fluidbook.pagetransitions.flip3d.performancesTest(function () {
-                    $this.pauseNetwork(-1);
+                    $this.networkControl.resume();
                     $this._hideSplash();
                 })
             }, 500);
@@ -207,6 +204,7 @@ Fluidbook.prototype = {
         }
     },
 
+
     _hideSplash: function () {
         var $this = this;
         var timeout = 1200;
@@ -611,14 +609,12 @@ Fluidbook.prototype = {
     ,
     showAllButtons: function () {
         $("#next,#previous").addClass('help').show();
-    }
-    ,
+    },
     setPageNumbers: function () {
         $("#pagesnumbers .left").html(this.getPageNumberOfSide('left'));
         $("#pagesnumbers .right").html(this.getPageNumberOfSide('right'));
         $("#pagesnumbers").removeClass('hidden');
-    }
-    ,
+    },
     getPhysicalPageNumberOfSide: function (side) { // Side should be 'left' or 'right'
         var pageSide = $("#currentDoublePage").find('.' + side);
         if (pageSide.length == 0) {
@@ -626,16 +622,14 @@ Fluidbook.prototype = {
         }
 
         return $(pageSide).data('page');
-    }
-    ,
+    },
     getPageNumberOfSide: function (side) {
         var physical = this.getPhysicalPageNumberOfSide(side);
         if (!physical || physical === 1) {
             return '';
         }
         return this.physicalToVirtual(physical);
-    }
-    ,
+    },
     clickLogo: function () {
         if (this.datas.url_link == '' || this.datas.url_link == 'http://') {
             return;
@@ -646,8 +640,7 @@ Fluidbook.prototype = {
         } else {
             this.wopen(this.datas.url_link, '_blank');
         }
-    }
-    ,
+    },
 
     addWaiter: function (reset) {
         if (reset == undefined) {
@@ -659,20 +652,16 @@ Fluidbook.prototype = {
         var rand = Math.round(Math.random() * 100000);
         this.waiters.push(rand);
         return rand;
-    }
-    ,
+    },
     waiterActive: function (id) {
         return this.waiters.indexOf(id) > -1;
-    }
-    ,
+    },
     resetWaiters: function () {
         this.waiters = [];
-    }
-    ,
+    },
     physicalToVirtual: function (page) {
         return this.datas.numerotation[page - 1];
-    }
-    ,
+    },
     virtualToPhysical: function (page) {
         if (page === undefined) {
             return false;
@@ -682,30 +671,25 @@ Fluidbook.prototype = {
             return false;
         }
         return i + 1;
-    }
-    ,
+    },
 
     hideMenuItems: function () {
         $('#menuList > ul > li, #shareLinks').fadeOut(100);
-    }
-    ,
+    },
 
     showMenuItems: function () {
         $('#menuList > ul > li, #shareLinks').fadeIn(300);
-    }
-    ,
+    },
 
     print: function (button) {
         this.stats.track(3);
         return this.openPDF(button, true);
-    }
-    ,
+    },
 
     downloadPDF: function (button) {
         this.stats.track(7);
         return this.openPDF(button, false)
-    }
-    ,
+    },
 
     openPDF: function (button, print) {
         var $this = this;
@@ -723,8 +707,7 @@ Fluidbook.prototype = {
         pdfName = e.pop();
 
         this._openFile(pdf, button, 'pdf', pdfName, print);
-    }
-    ,
+    },
 
     _openFile: function (url, e, type, localname, print) {
         if (print === undefined) {
@@ -807,8 +790,7 @@ Fluidbook.prototype = {
         }, function () {
 
         });
-    }
-    ,
+    },
 
     _openFilePhonegap: function (url, e, type) {
         var $this = this;
@@ -899,22 +881,19 @@ Fluidbook.prototype = {
             return true;
         }
         return false;
-    }
-    ,
+    },
 
     relativeToAbsolute: function (relative) {
         var a = document.createElement('a');
         a.href = relative;
         return a.cloneNode(false).href;
-    }
-    ,
+    },
 
     alertInternetRequired: function () {
         navigator.notification.alert('', function () {
 
         }, this.l10n.__('an internet connection is required for this action'));
-    }
-    ,
+    },
 
     touchOffset: function (offset) {
         offset *= $("#currentDoublePage").width();
@@ -922,15 +901,13 @@ Fluidbook.prototype = {
         $("#currentDoublePage").css({
             translateX: offset
         });
-    }
-    ,
+    },
     displayLoader: function () {
         $("#loader").addClass('show');
         if (!this.support.isMobile) {
             $('body').addClass('loading');
         }
-    }
-    ,
+    },
 
     hideLoader: function (delay, force) {
         if (force == undefined) {
@@ -946,8 +923,7 @@ Fluidbook.prototype = {
         setTimeout(function () {
             $this._hideLoader(force);
         }, delay * 1000);
-    }
-    ,
+    },
 
     _hideLoader: function (force) {
         if (force == undefined) {
@@ -960,8 +936,7 @@ Fluidbook.prototype = {
         if (!this.support.isMobile) {
             $('body').removeClass('loading');
         }
-    }
-    ,
+    },
 
     wopen: function (url, target, options, print) {
         var win;
@@ -1042,21 +1017,18 @@ Fluidbook.prototype = {
 
         }
         return w;
-    }
-    ,
+    },
 
     setFlag: function (name, value) {
         if (value === undefined) {
             value = true;
         }
         this.flags[name] = value;
-    }
-    ,
+    },
 
     hasFlag: function (name) {
         return this.flags[name] === true;
-    }
-    ,
+    },
 
     hasFlags: function (names) {
         var res = true;
@@ -1069,77 +1041,12 @@ Fluidbook.prototype = {
             return true;
         });
         return res;
-    }
-    ,
-
-    initNetworkPause: function () {
-        var $this = this;
-        setInterval(function () {
-
-            if ($this.networkPauseDate != null && $this.networkPauseDate < Date.now()) {
-                $this.networkPauseDate = null;
-                $this.flushNetworkQueue();
-            }
-        }, 1000);
-    },
-
-    pauseNetwork: function (during, reset) {
-        if (reset === undefined) {
-            reset = false;
-        }
-        if (during === -1) {
-            this.networkPauseDate = null;
-            this.flushNetworkQueue();
-            return;
-        }
-
-        var date = Date.now() + during + 500;
-        if (this.networkPauseDate == null || reset) {
-            this.networkPauseDate = date;
-        } else {
-            this.networkPauseDate = Math.max(this.networkPauseDate, date);
-        }
-    },
-
-    executeWhenNetwork: function (f,highPriority) {
-        if (highPriority === undefined) {
-            highPriority = false;
-        }
-        if (this.networkPauseDate != null) {
-            if (highPriority) {
-                this.networkPausePriorityQueue.push([f]);
-            } else {
-                this.networkPauseQueue.push([f]);
-            }
-            return;
-        }
-        f();
     },
 
     unlockCurrentPage: function () {
         this.contentlock.unlockCurrentPage();
     },
 
-    flushNetworkQueue: function () {
-        if ((this.networkPausePriorityQueue.length === 0 && this.networkPauseQueue.length === 0) || this.networkPauseDate != null) {
-            return;
-        }
-
-        var f;
-        if (this.networkPausePriorityQueue.length > 0) {
-            f = this.networkPausePriorityQueue.shift();
-        } else {
-            f = this.networkPauseQueue.shift();
-        }
-        f();
-
-        var $this = this;
-        setTimeout(function () {
-            $this.flushNetworkQueue();
-        }, 100);
-    }
-    ,
-
     bugreport: function (e) {
         if (window.confirm('An error occured: ' + e.name + '. Do you want to send a report ?')) {
             var subject = '[Fluidbook error report] ' + e.message;
index 07a28a444d284cb1df234accdd8ed5c6781e4a7b..3b72e4931d3bf0e6f498241de07ee6e4f40d831b 100644 (file)
@@ -193,7 +193,7 @@ FluidbookLinks.prototype = {
         links.find('.rightContainer').append(links.children('.link.odd'));
         links.find('.leftContainer').append(links.children('.link'));
         if (links.find('.link.multimedia iframe').length > 0) {
-            this.fluidbook.pauseNetwork(30000);
+            this.fluidbook.networkControl.pause(30000);
         }
         if (this.lowdef) {
             links.find('iframe[data-ld]').each(function () {
@@ -398,7 +398,7 @@ FluidbookLinks.prototype = {
         });
 
         if (pauseNetworkDelay > 0) {
-            this.fluidbook.pauseNetwork((pauseNetworkDelay + 0.5) * 1000);
+            this.fluidbook.networkControl.pause((pauseNetworkDelay + 0.5) * 1000);
         }
     },
 
index 72b94c589036a4aa8274fc4c1b67828448438bba..f643ff973066d0df5052f2cb03f6d56f6b616474 100644 (file)
@@ -113,7 +113,7 @@ FluidbookLoader.prototype = {
             return;
         }
         var $this = this;
-        this.fluidbook.executeWhenNetwork(function () {
+        this.fluidbook.networkControl.executeWhenNetwork(function (_cb) {
             var preloadingPage = $this.toPreload.shift();
             var callback = function () {
                 if ($this.toPreload.length === 0) {
@@ -121,6 +121,9 @@ FluidbookLoader.prototype = {
                 } else {
                     $this.preloadPages(cb);
                 }
+                if (_cb !== undefined) {
+                    _cb();
+                }
             };
 
             $this._preloadPage(preloadingPage, callback);
diff --git a/js/libs/fluidbook/fluidbook.networkcontrol.js b/js/libs/fluidbook/fluidbook.networkcontrol.js
new file mode 100644 (file)
index 0000000..0837b4f
--- /dev/null
@@ -0,0 +1,96 @@
+function FluidbookNetworkControl(fluidbook) {
+    this.fluidbook = fluidbook;
+    this.pauseDate = null;
+    this.pauseQueue = [];
+    this.pausePriorityQueue = [];
+    this.afterProcessingQueue = [];
+    this.processing = true;
+    this.init();
+}
+
+FluidbookNetworkControl.prototype = {
+    init: function () {
+        var $this = this;
+        setInterval(function () {
+            if ($this.pauseDate != null && $this.pauseDate < Date.now()) {
+                $this.resume();
+            }
+        }, 1000);
+    },
+
+    pause: function (during, reset) {
+        if (reset === undefined) {
+            reset = false;
+        }
+
+        var date = Date.now() + during + 500;
+        if (this.pauseDate == null || reset) {
+            this.pauseDate = date;
+        } else {
+            this.pauseDate = Math.max(this.pauseDate, date);
+        }
+    },
+
+    resume: function () {
+        this.pauseDate = null;
+        this.flushQueue();
+        return;
+    },
+
+    executeWhenNetwork: function (f, highPriority) {
+        if (highPriority === undefined) {
+            highPriority = false;
+        }
+
+        if (highPriority) {
+            this.pausePriorityQueue.push(f);
+        } else {
+            this.pauseQueue.push(f);
+        }
+
+        if (this.pauseDate == null) {
+            this.flushQueue();
+        }
+    },
+
+    executeAfterProcessing: function (f, loader) {
+        this.afterProcessingQueue = [f];
+        if (!this.processing) {
+            this.flushAfterProcessingQueue();
+        } else {
+            if (loader !== undefined && loader === true) {
+                this.fluidbook.displayLoader();
+            }
+        }
+    },
+
+    flushAfterProcessingQueue: function () {
+        $.each(this.afterProcessingQueue, function (k, f) {
+            f();
+        });
+        this.afterProcessingQueue = [];
+    },
+
+    flushQueue: function () {
+        if ((this.pausePriorityQueue.length === 0 && this.pauseQueue.length === 0) || this.pauseDate != null) {
+            this.processing = false;
+            return;
+        }
+
+        this.processing = true;
+        var f;
+        if (this.pausePriorityQueue.length > 0) {
+            f = this.pausePriorityQueue.shift();
+        } else {
+            f = this.pauseQueue.shift();
+        }
+        var $this = this;
+        f(function () {
+            setTimeout(function () {
+                $this.flushAfterProcessingQueue();
+                $this.processing = false;
+                $this.flushQueue();
+            }, 100);
+        });
+    },
+};
\ No newline at end of file
index 4a41bcd32710d41172374d133771171325c71e9f..997a733fa9a934cfee756c6e06e730348a3a6492 100644 (file)
@@ -113,11 +113,11 @@ FluidbookPageTransition.prototype = {
     },
 
     pauseNetworkDuringTransition: function (pageNr) {
-        this.fluidbook.pauseNetwork((this.getTransitionDuration(pageNr)) * 1000, true);
+        this.fluidbook.networkControl.pause((this.getTransitionDuration(pageNr) + 0.5) * 1000, true);
     },
 
     pauseNetworkDuringPagesPreload: function () {
-        this.fluidbook.pauseNetwork(30000);
+        this.fluidbook.networkControl.pause(30000);
     },
 
     pageTransition3D: function (pageNr) {
@@ -193,16 +193,19 @@ FluidbookPageTransition.prototype = {
                 setTimeout(function () {
                     $this.fluidbook.loader.setContentsInDoublePage(currentDoublePage, turning.flat, true, function () {
                         $this.fluidbook.loader.setContentsInDoublePage(doublePage, turning.end, true, function () {
-                            $this.pauseNetworkDuringTransition(pageNr);
-                            $this.flip3d.playTurn(turning.dir, function () {
-                                if ($this.transitionning === false) {
-                                    return;
-                                }
-                                // Remove former part
-                                $("#currentDoublePage").remove();
-                                $(doublePage).attr('id', 'currentDoublePage').removeClass('_3dflip').removeClass('fwd').removeClass('bwd');
-                                $this.afterTransition(pageNr);
-                            });
+                            $this.fluidbook.networkControl.executeAfterProcessing(function () {
+                                $this.pauseNetworkDuringTransition(pageNr);
+                                $this.fluidbook.hideLoader();
+                                $this.flip3d.playTurn(turning.dir, function () {
+                                    if ($this.transitionning === false) {
+                                        return;
+                                    }
+                                    // Remove former part
+                                    $("#currentDoublePage").remove();
+                                    $(doublePage).attr('id', 'currentDoublePage').removeClass('_3dflip').removeClass('fwd').removeClass('bwd');
+                                    $this.afterTransition(pageNr);
+                                });
+                            }, true);
                         });
                     });
                 }, 10);
index 2a5f550a6c1f6b71ea467e4842fc1317b5334e1d..5d32986d1ca884c60da7383fbeba69dc9a207ff0 100644 (file)
@@ -154,10 +154,11 @@ FluidbookStats.prototype = {
         };\r
 \r
         setTimeout(function () {\r
-            $this.fluidbook.executeWhenNetwork(function () {\r
+            $this.fluidbook.networkControl.executeWhenNetwork(function (cb) {\r
                 $this.worker.postMessage(data);\r
+                setTimeout(cb, 100);\r
             }, false);\r
-        }, 500);\r
+        }, 2500);\r
     }\r
 };\r
 \r
index e28ba0a7073cbbdf15afbe593138f277bced343f..00bdf17c4cfe669ffcd994d12c5f96f555040dd0 100644 (file)
@@ -103,8 +103,11 @@ function initScormEvents() {
 
 
     $(fluidbook).on('fluidbook.page.navigation', function (e, page) {
-        fluidbook.executeWhenNetwork(function () {
+        fluidbook.networkControl.executeWhenNetwork(function (cb) {
             scormSaveCurrentPosition(page);
+            if (cb !== undefined) {
+                setTimeout(cb, 100);
+            }
         }, true);
     });
 
@@ -115,8 +118,11 @@ function initScormEvents() {
 
     // Commit data once a minute
     setInterval(function () {
-        fluidbook.executeWhenNetwork(function () {
+        fluidbook.networkControl.executeWhenNetwork(function (cb) {
             pipwerks.SCORM.save();
+            if (cb !== undefined) {
+                setTimeout(cb, 100);
+            }
         }, true);
     }, 5000);
 }