]> _ Git - fluidbook-html5.git/commitdiff
done #1346 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 13 Apr 2017 17:12:34 +0000 (19:12 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 13 Apr 2017 17:12:34 +0000 (19:12 +0200)
js/libs/fluidbook/fluidbook.resize.js
js/libs/fluidbook/fluidbook.support.js
js/libs/orientationchangeend.js [new file with mode: 0644]

index 079aaf748dd04ba9c98135810248bf545bab5e93..9281837a0ace565f390c13a386672950ab6a4cc6 100644 (file)
@@ -231,6 +231,7 @@ FluidbookResize.prototype = {
 
         $("#main").show();
 
+        $(window).scrollTop(0);
         $(window).trigger('fluidbookresize');
     },
     resizeNav: function (interfaceScale) {
@@ -346,9 +347,10 @@ FluidbookResize.prototype = {
         });
     },
     updateWindow: function () {
+        fb('update window size');
         this.ww = $(window).width();
         this.hh = $(window).height();
-        if (window.innerHeight && window.innerHeight > this.hh) {
+        if (window.innerHeight && window.innerHeight != this.hh) {
             this.hh = window.innerHeight;
         }
     },
index 91023156cccfd32e4acbb837fe74df083aa10bd5..d24071da83b762a16677177b1eeecbcc62284587 100644 (file)
@@ -92,14 +92,10 @@ FluidbookSupport.prototype = {
 
             if ("onorientationchange" in window) {
                 window.addEventListener('orientationchange', function () {
-                    if ($this.iOS) {
+                    resize();
+                    setTimeout(function () {
                         resize();
-                    } else {
-                        resize();
-                        setTimeout(function () {
-                            resize();
-                        }, 750);
-                    }
+                    }, 750);
                 }, false);
             } else {
                 setInterval(function () {
diff --git a/js/libs/orientationchangeend.js b/js/libs/orientationchangeend.js
new file mode 100644 (file)
index 0000000..df18b86
--- /dev/null
@@ -0,0 +1,93 @@
+var Event,
+    Sister = require('sister');
+
+Event = function Event (config) {
+    var event,
+        lastEnd,
+        eventEmitter;
+
+    if (!(this instanceof Event)) {
+        return new Event(config);
+    }
+
+    eventEmitter = Sister();
+
+    event = this;
+    event.on = eventEmitter.on;
+
+    config = config || {};
+
+    /**
+     * @var {Number} Number of iterations the subject of interval inspection must not mutate to fire "orientationchangeend".
+     */
+    config.noChangeCountToEnd = config.noChangeCountToEnd || 100;
+    /**
+     * @var {Number} Number of milliseconds after which fire the "orientationchangeend" if interval inspection did not do it before.
+     */
+    config.noEndTimeout = 1000 || config.noEndTimeout;
+    /**
+     * @var {Boolean} Enables logging of the events.
+     */
+    config.debug = config.debug || false;
+
+    global
+        .addEventListener('orientationchange', function () {
+            var interval,
+                timeout,
+                end,
+                lastInnerWidth,
+                lastInnerHeight,
+                noChangeCount;
+
+            end = function (dispatchEvent) {
+                clearInterval(interval);
+                clearTimeout(timeout);
+
+                interval = null;
+                timeout = null;
+
+                if (dispatchEvent) {
+                    eventEmitter.trigger('orientationchangeend');
+                }
+            };
+
+            // If there is a series of orientationchange events fired one after another,
+            // where n event orientationchangeend event has not been fired before the n+2 orientationchange,
+            // then orientationchangeend will fire only for the last orientationchange event in the series.
+            if (lastEnd) {
+                lastEnd(false);
+            }
+
+            lastEnd = end;
+
+            interval = setInterval(function () {
+                if (global.innerWidth === lastInnerWidth && global.innerHeight === lastInnerHeight) {
+                    noChangeCount++;
+
+                    if (noChangeCount === config.noChangeCountToEnd) {
+                        if (config.debug) {
+                            console.debug('setInterval');
+                        }
+
+                        end(true);
+                    }
+                } else {
+                    lastInnerWidth = global.innerWidth;
+                    lastInnerHeight = global.innerHeight;
+                    noChangeCount = 0;
+                }
+            });
+            timeout = setTimeout(function () {
+                if (config.debug) {
+                    console.debug('setTimeout');
+                }
+
+                end(true);
+            }, config.noEndTimeout);
+        });
+}
+
+global.gajus = global.gajus || {};
+global.gajus.orientationchangeend = Event;
+
+module.exports = Event;
\ No newline at end of file