From: Vincent Vanwaelscappel Date: Thu, 13 Apr 2017 17:12:34 +0000 (+0200) Subject: done #1346 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=28b2902637717b4decd637d545bce0a3772c8de9;p=fluidbook-html5.git done #1346 @2 --- diff --git a/js/libs/fluidbook/fluidbook.resize.js b/js/libs/fluidbook/fluidbook.resize.js index 079aaf74..9281837a 100644 --- a/js/libs/fluidbook/fluidbook.resize.js +++ b/js/libs/fluidbook/fluidbook.resize.js @@ -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; } }, diff --git a/js/libs/fluidbook/fluidbook.support.js b/js/libs/fluidbook/fluidbook.support.js index 91023156..d24071da 100644 --- a/js/libs/fluidbook/fluidbook.support.js +++ b/js/libs/fluidbook/fluidbook.support.js @@ -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 index 00000000..df18b86e --- /dev/null +++ b/js/libs/orientationchangeend.js @@ -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