From 8e639b87dea09ba90c9c739e8c9408f689edc0e2 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 8 Apr 2022 17:11:14 +0200 Subject: [PATCH] wip #5221 @0.75 --- js/libs/fluidbook/fluidbook.parallax.js | 43 +++++++++++++++++++++++-- js/libs/modernizr/modernizr.min.js | 4 +-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.parallax.js b/js/libs/fluidbook/fluidbook.parallax.js index 0e95dc74..e1a223c6 100644 --- a/js/libs/fluidbook/fluidbook.parallax.js +++ b/js/libs/fluidbook/fluidbook.parallax.js @@ -1,5 +1,8 @@ function FluidbookParallax(fluidbook) { this.fluidbook = fluidbook; + this.calibrateBeta = null; + this.calibrateGamma = null; + this.orientationStatus = 0; this.init(); } @@ -37,8 +40,20 @@ FluidbookParallax.prototype = { this.y = 0; this.update(); - if (Modernizr.hasEvent('deviceOrientation')) { - + if (Modernizr.deviceorientation && !this.fluidbook.input.hasMouse) { + window.addEventListener("deviceorientation", function (e) { + let beta = e.beta + let gamma = e.gamma + if (beta !== null && gamma !== null) { + if ($this.calibrateBeta === null) { + $this.calibrateBeta = beta; + } + if ($this.calibrateGamma === null) { + $this.calibrateGamma = null; + } + $this.rotate(beta - $this.calibrateBeta, gamma - $this.calibrateGamma) + } + }, true); } else { $(window).on('pointermove', function (e) { $this.x = -1 * $this.normalize((e.clientX - $this.fluidbook.resize.ww / 2) / $this.fluidbook.resize.ww); @@ -48,6 +63,30 @@ FluidbookParallax.prototype = { } }, + rotate: function (beta, gamma) { + const MAGIC_NUMBER = 90; + // Extract Rotation + let x = (gamma || 0) / MAGIC_NUMBER, // -90 :: 90 + y = (beta || 0) / MAGIC_NUMBER // -180 :: 180 + + // Detect Orientation Change + let portrait = this.windowHeight > this.windowWidth + if (this.portrait !== portrait) { + this.portrait = portrait; + this.calibrationFlag = true; + } + + if (this.calibrationFlag) { + this.calibrationFlag = false; + this.calibrationX = x; + this.calibrationY = y; + } + + this.x = -1 * x; + this.y = -1 * y; + this.update(); + }, + update: function () { var $this = this; $("[data-parallax]").each(function () { diff --git a/js/libs/modernizr/modernizr.min.js b/js/libs/modernizr/modernizr.min.js index 5b8dd75b..19eacd2e 100644 --- a/js/libs/modernizr/modernizr.min.js +++ b/js/libs/modernizr/modernizr.min.js @@ -1,3 +1,3 @@ /*! modernizr 3.6.0 (Custom Build) | MIT * - * https://modernizr.com/download/?-applicationcache-audio-csstransforms-csstransforms3d-csstransitions-fullscreen-localstorage-passiveeventlisteners-preserve3d-sessionstorage-svg-touchevents-video-webgl-addtest-atrule-domprefixes-hasevent-mq-prefixed-prefixedcss-prefixedcssvalue-prefixes-setclasses-testallprops-testprop-teststyles !*/ -!function(e,t,n){function r(e){var t=x.className,n=Modernizr._config.classPrefix||"";if(_&&(t=t.baseVal),Modernizr._config.enableJSClass){var r=new RegExp("(^|\\s)"+n+"no-js(\\s|$)");t=t.replace(r,"$1"+n+"js$2")}Modernizr._config.enableClasses&&(t+=" "+n+e.join(" "+n),_?x.className.baseVal=t:x.className=t)}function o(e,t){return typeof e===t}function a(){var e,t,n,r,a,i,s;for(var l in T)if(T.hasOwnProperty(l)){if(e=[],t=T[l],t.name&&(e.push(t.name.toLowerCase()),t.options&&t.options.aliases&&t.options.aliases.length))for(n=0;np;p++)if(v=e[p],m=B.style[v],d(v,"-")&&(v=l(v)),B.style[v]!==n){if(a||o(r,"undefined"))return i(),"pfx"==t?v:!0;try{B.style[v]=r}catch(h){}if(B.style[v]!=m)return i(),"pfx"==t?v:!0}return i(),!1}function h(e,t,n,r,a){var i=e.charAt(0).toUpperCase()+e.slice(1),s=(e+" "+A.join(i+" ")+i).split(" ");return o(t,"string")||o(t,"undefined")?g(s,t,r,a):(s=(e+" "+E.join(i+" ")+i).split(" "),v(s,t,n))}function S(e,t,r){return h(e,n,n,t,r)}var C=[],T=[],w={_version:"3.6.0",_config:{classPrefix:"",enableClasses:!0,enableJSClass:!0,usePrefixes:!0},_q:[],on:function(e,t){var n=this;setTimeout(function(){t(n[e])},0)},addTest:function(e,t,n){T.push({name:e,fn:t,options:n})},addAsyncTest:function(e){T.push({name:null,fn:e})}},Modernizr=function(){};Modernizr.prototype=w,Modernizr=new Modernizr,Modernizr.addTest("applicationcache","applicationCache"in e),Modernizr.addTest("svg",!!t.createElementNS&&!!t.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect),Modernizr.addTest("passiveeventlisteners",function(){var t=!1;try{var n=Object.defineProperty({},"passive",{get:function(){t=!0}});e.addEventListener("test",null,n)}catch(r){}return t}),Modernizr.addTest("localstorage",function(){var e="modernizr";try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(t){return!1}}),Modernizr.addTest("sessionstorage",function(){var e="modernizr";try{return sessionStorage.setItem(e,e),sessionStorage.removeItem(e),!0}catch(t){return!1}});var b=w._config.usePrefixes?" -webkit- -moz- -o- -ms- ".split(" "):["",""];w._prefixes=b;var x=t.documentElement,_="svg"===x.nodeName.toLowerCase(),P="Moz O ms Webkit",E=w._config.usePrefixes?P.toLowerCase().split(" "):[];w._domPrefixes=E;var z;!function(){var e={}.hasOwnProperty;z=o(e,"undefined")||o(e.call,"undefined")?function(e,t){return t in e&&o(e.constructor.prototype[t],"undefined")}:function(t,n){return e.call(t,n)}}(),w._l={},w.on=function(e,t){this._l[e]||(this._l[e]=[]),this._l[e].push(t),Modernizr.hasOwnProperty(e)&&setTimeout(function(){Modernizr._trigger(e,Modernizr[e])},0)},w._trigger=function(e,t){if(this._l[e]){var n=this._l[e];setTimeout(function(){var e,r;for(e=0;ei;i++){var s=b[i],l=s.toUpperCase()+"_"+r;if(l in a)return"@-"+s.toLowerCase()+"-"+t}return!1};w.atRule=L;var N="CSS"in e&&"supports"in e.CSS,k="supportsCSS"in e;Modernizr.addTest("supports",N||k);var O=function(){var t=e.matchMedia||e.msMatchMedia;return t?function(e){var n=t(e);return n&&n.matches||!1}:function(t){var n=!1;return p("@media "+t+" { #modernizr { position: absolute; } }",function(t){n="absolute"==(e.getComputedStyle?e.getComputedStyle(t,null):t.currentStyle).position}),n}}();w.mq=O;var R=w.testStyles=p;Modernizr.addTest("touchevents",function(){var n;if("ontouchstart"in e||e.DocumentTouch&&t instanceof DocumentTouch)n=!0;else{var r=["@media (",b.join("touch-enabled),("),"heartz",")","{#modernizr{top:9px;position:absolute}}"].join("");R(r,function(e){n=9===e.offsetTop})}return n});var q={elem:s("modernizr")};Modernizr._q.push(function(){delete q.elem});var B={style:q.elem.style};Modernizr._q.unshift(function(){delete B.style});w.testProp=function(e,t,r){return g([e],n,t,r)};w.testAllProps=h;var I=w.prefixed=function(e,t,n){return 0===e.indexOf("@")?L(e):(-1!=e.indexOf("-")&&(e=l(e)),t?h(e,t,n):h(e,"pfx"))};w.prefixedCSS=function(e){var t=I(e);return t&&u(t)};Modernizr.addTest("fullscreen",!(!I("exitFullscreen",t,!1)&&!I("cancelFullScreen",t,!1))),w.testAllProps=S,Modernizr.addTest("csstransforms",function(){return-1===navigator.userAgent.indexOf("Android 2.")&&S("transform","scale(1)",!0)}),Modernizr.addTest("csstransforms3d",function(){return!!S("perspective","1px",!0)}),Modernizr.addTest("csstransitions",S("transition","all",!0)),a(),r(C),delete w.addTest,delete w.addAsyncTest;for(var U=0;Ud;d++)if(v=e[d],m=B.style[v],p(v,"-")&&(v=l(v)),B.style[v]!==n){if(i||r(o,"undefined"))return a(),"pfx"==t?v:!0;try{B.style[v]=o}catch(h){}if(B.style[v]!=m)return a(),"pfx"==t?v:!0}return a(),!1}function h(e,t,n,o,i){var a=e.charAt(0).toUpperCase()+e.slice(1),s=(e+" "+$.join(a+" ")+a).split(" ");return r(t,"string")||r(t,"undefined")?g(s,t,o,i):(s=(e+" "+E.join(a+" ")+a).split(" "),v(s,t,n))}function S(e,t,r){return h(e,n,n,t,r)}var C=[],T=[],w={_version:"3.6.0",_config:{classPrefix:"",enableClasses:!0,enableJSClass:!0,usePrefixes:!0},_q:[],on:function(e,t){var n=this;setTimeout(function(){t(n[e])},0)},addTest:function(e,t,n){T.push({name:e,fn:t,options:n})},addAsyncTest:function(e){T.push({name:null,fn:e})}},Modernizr=function(){};Modernizr.prototype=w,Modernizr=new Modernizr,Modernizr.addTest("applicationcache","applicationCache"in e),Modernizr.addTest("svg",!!t.createElementNS&&!!t.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect),Modernizr.addTest("passiveeventlisteners",function(){var t=!1;try{var n=Object.defineProperty({},"passive",{get:function(){t=!0}});e.addEventListener("test",null,n)}catch(r){}return t}),Modernizr.addTest("devicemotion","DeviceMotionEvent"in e),Modernizr.addTest("deviceorientation","DeviceOrientationEvent"in e),Modernizr.addTest("localstorage",function(){var e="modernizr";try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(t){return!1}}),Modernizr.addTest("sessionstorage",function(){var e="modernizr";try{return sessionStorage.setItem(e,e),sessionStorage.removeItem(e),!0}catch(t){return!1}});var b=w._config.usePrefixes?" -webkit- -moz- -o- -ms- ".split(" "):["",""];w._prefixes=b;var x=t.documentElement,_="svg"===x.nodeName.toLowerCase(),P="Moz O ms Webkit",E=w._config.usePrefixes?P.toLowerCase().split(" "):[];w._domPrefixes=E;var z;!function(){var e={}.hasOwnProperty;z=r(e,"undefined")||r(e.call,"undefined")?function(e,t){return t in e&&r(e.constructor.prototype[t],"undefined")}:function(t,n){return e.call(t,n)}}(),w._l={},w.on=function(e,t){this._l[e]||(this._l[e]=[]),this._l[e].push(t),Modernizr.hasOwnProperty(e)&&setTimeout(function(){Modernizr._trigger(e,Modernizr[e])},0)},w._trigger=function(e,t){if(this._l[e]){var n=this._l[e];setTimeout(function(){var e,r;for(e=0;ea;a++){var s=b[a],l=s.toUpperCase()+"_"+r;if(l in i)return"@-"+s.toLowerCase()+"-"+t}return!1};w.atRule=j;var A=function(){function e(e,t){var o;return e?(t&&"string"!=typeof t||(t=s(t||"div")),e="on"+e,o=e in t,!o&&r&&(t.setAttribute||(t=s("div")),t.setAttribute(e,""),o="function"==typeof t[e],t[e]!==n&&(t[e]=n),t.removeAttribute(e)),o):!1}var r=!("onblur"in t.documentElement);return e}();w.hasEvent=A;var L=function(e,t){var n=!1,r=s("div"),o=r.style;if(e in o){var i=E.length;for(o[e]=t,n=o[e];i--&&!n;)o[e]="-"+E[i]+"-"+t,n=o[e]}return""===n&&(n=!1),n};w.prefixedCSSValue=L,Modernizr.addTest("audio",function(){var e=s("audio"),t=!1;try{t=!!e.canPlayType,t&&(t=new Boolean(t),t.ogg=e.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),t.mp3=e.canPlayType('audio/mpeg; codecs="mp3"').replace(/^no$/,""),t.opus=e.canPlayType('audio/ogg; codecs="opus"')||e.canPlayType('audio/webm; codecs="opus"').replace(/^no$/,""),t.wav=e.canPlayType('audio/wav; codecs="1"').replace(/^no$/,""),t.m4a=(e.canPlayType("audio/x-m4a;")||e.canPlayType("audio/aac;")).replace(/^no$/,""))}catch(n){}return t}),Modernizr.addTest("video",function(){var e=s("video"),t=!1;try{t=!!e.canPlayType,t&&(t=new Boolean(t),t.ogg=e.canPlayType('video/ogg; codecs="theora"').replace(/^no$/,""),t.h264=e.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/,""),t.webm=e.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/,""),t.vp9=e.canPlayType('video/webm; codecs="vp9"').replace(/^no$/,""),t.hls=e.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(/^no$/,""))}catch(n){}return t}),Modernizr.addTest("webgl",function(){var t=s("canvas"),n="probablySupportsContext"in t?"probablySupportsContext":"supportsContext";return n in t?t[n]("webgl")||t[n]("experimental-webgl"):"WebGLRenderingContext"in e}),Modernizr.addTest("preserve3d",function(){var t,n,r=e.CSS,o=!1;return r&&r.supports&&r.supports("(transform-style: preserve-3d)")?!0:(t=s("a"),n=s("a"),t.style.cssText="display: block; transform-style: preserve-3d; transform-origin: right; transform: rotateY(40deg);",n.style.cssText="display: block; width: 9px; height: 1px; background: #000; transform-origin: right; transform: rotateY(40deg);",t.appendChild(n),x.appendChild(t),o=n.getBoundingClientRect(),x.removeChild(t),o=o.width&&o.width<4)});var N="CSS"in e&&"supports"in e.CSS,O="supportsCSS"in e;Modernizr.addTest("supports",N||O);var k=function(){var t=e.matchMedia||e.msMatchMedia;return t?function(e){var n=t(e);return n&&n.matches||!1}:function(t){var n=!1;return d("@media "+t+" { #modernizr { position: absolute; } }",function(t){n="absolute"==(e.getComputedStyle?e.getComputedStyle(t,null):t.currentStyle).position}),n}}();w.mq=k;var R=w.testStyles=d;Modernizr.addTest("touchevents",function(){var n;if("ontouchstart"in e||e.DocumentTouch&&t instanceof DocumentTouch)n=!0;else{var r=["@media (",b.join("touch-enabled),("),"heartz",")","{#modernizr{top:9px;position:absolute}}"].join("");R(r,function(e){n=9===e.offsetTop})}return n});var q={elem:s("modernizr")};Modernizr._q.push(function(){delete q.elem});var B={style:q.elem.style};Modernizr._q.unshift(function(){delete B.style});w.testProp=function(e,t,r){return g([e],n,t,r)};w.testAllProps=h;var I=w.prefixed=function(e,t,n){return 0===e.indexOf("@")?j(e):(-1!=e.indexOf("-")&&(e=l(e)),t?h(e,t,n):h(e,"pfx"))};w.prefixedCSS=function(e){var t=I(e);return t&&u(t)};Modernizr.addTest("fullscreen",!(!I("exitFullscreen",t,!1)&&!I("cancelFullScreen",t,!1))),w.testAllProps=S,Modernizr.addTest("csstransforms",function(){return-1===navigator.userAgent.indexOf("Android 2.")&&S("transform","scale(1)",!0)}),Modernizr.addTest("csstransforms3d",function(){return!!S("perspective","1px",!0)}),Modernizr.addTest("csstransitions",S("transition","all",!0)),o(),i(C),delete w.addTest,delete w.addAsyncTest;for(var M=0;M