├── README.md ├── gBoxShadow.js └── gBoxShadow.min.js /README.md: -------------------------------------------------------------------------------- 1 | gBoxShadow.js 2 | ============ 3 | ###### Use gravity to update CSS "box-shadow" property. 4 | 5 | gBoxShadow.js uses gravity to alter the CSS "box-shadow" property and seamlessly updates ```offset-x``` and ```offset-y``` values based on the device motion data retrieved from accelerometer & gyroscope of the device to always position the direction of the shadow to the bottom assuming the light source is to your zenith. This adds a natural experience to the UI, especially when used with Material Design. 6 | 7 | The plugin uses ```DeviceMotionEvent``` and ```DeviceOrientationEvent``` Web APIs to detect the moment of your device. gBoxShadow.js is built on top of [gyronorm.js](https://github.com/dorukeker/gyronorm.js) to enable consistency of data across different devices. 8 | 9 | ![Screenshot](http://i.imgur.com/U1iuGjE.gif) 10 | 11 | ###### NOTE: 12 | This is a concept / experimental work. The idea is to re-introduce real-world entity to UI/UX in an much more interactive and intuitive way. [Four Shadows](https://github.com/Gigacore/four-shadows) is one such attempt that I tried last year, but that was time-aware and had nothing to do with physical entity. It is not recommended to use with your production app, but no harm in trying as the fallback will always ensure that nothing breaks though. 13 | 14 | Setup 15 | ============ 16 | 17 | ###### 1. Include jQuery and ```gBoxShadow.js``` into your html file. 18 | 19 | ###### 2. Add the class ```g-enabled``` to the element 20 | 21 | ```HTML 22 |
I am a button
23 | ``` 24 | 25 | ###### 3. Apply ```box-shadow``` styling of your choice to the element in your CSS: 26 | 27 | ```CSS 28 | .btn { 29 | box-shadow: 10px 10px 15px #A01818; 30 | } 31 | ``` 32 | 33 | ###### 4. Ensure to define the same color and blur values in your HTML using ```data-shadow-color``` and ```data-shadow-blur```: 34 | 35 | ```HTML 36 |
I am a button
37 | ``` 38 | 39 | Fallback for unsupported devices 40 | =================== 41 | The plugin applies the effect only to the devices that support ```DeviceMotionEvent``` and ```DeviceOrientationEvent``` Web APIs. To those that doesn't, the ```box-shadow``` property you set in the CSS will be applied. 42 | 43 | ![Screenshot](http://i.imgur.com/HAPTQhT.png) 44 | 45 | 46 | Demos 47 | =================== 48 | Live: http://gigacore.github.io/demos/gBoxShadow/ 49 | 50 | Video: https://youtu.be/vkKDyIstcb0 51 | 52 | License 53 | =================== 54 | The MIT License (MIT) 55 | 56 | MIT © 2015 Santhosh Sundar 57 | -------------------------------------------------------------------------------- /gBoxShadow.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 4 | /*! 5 | * @overview es6-promise - a tiny implementation of Promises/A+. 6 | * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) 7 | * @license Licensed under MIT license 8 | * See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE 9 | * @version 3.0.2 10 | */ 11 | 12 | (function(){"use strict";function lib$es6$promise$utils$$objectOrFunction(x){return typeof x==="function"||typeof x==="object"&&x!==null}function lib$es6$promise$utils$$isFunction(x){return typeof x==="function"}function lib$es6$promise$utils$$isMaybeThenable(x){return typeof x==="object"&&x!==null}var lib$es6$promise$utils$$_isArray;if(!Array.isArray){lib$es6$promise$utils$$_isArray=function(x){return Object.prototype.toString.call(x)==="[object Array]"}}else{lib$es6$promise$utils$$_isArray=Array.isArray}var lib$es6$promise$utils$$isArray=lib$es6$promise$utils$$_isArray;var lib$es6$promise$asap$$len=0;var lib$es6$promise$asap$$toString={}.toString;var lib$es6$promise$asap$$vertxNext;var lib$es6$promise$asap$$customSchedulerFn;var lib$es6$promise$asap$$asap=function asap(callback,arg){lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len]=callback;lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len+1]=arg;lib$es6$promise$asap$$len+=2;if(lib$es6$promise$asap$$len===2){if(lib$es6$promise$asap$$customSchedulerFn){lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush)}else{lib$es6$promise$asap$$scheduleFlush()}}};function lib$es6$promise$asap$$setScheduler(scheduleFn){lib$es6$promise$asap$$customSchedulerFn=scheduleFn}function lib$es6$promise$asap$$setAsap(asapFn){lib$es6$promise$asap$$asap=asapFn}var lib$es6$promise$asap$$browserWindow=typeof window!=="undefined"?window:undefined;var lib$es6$promise$asap$$browserGlobal=lib$es6$promise$asap$$browserWindow||{};var lib$es6$promise$asap$$BrowserMutationObserver=lib$es6$promise$asap$$browserGlobal.MutationObserver||lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;var lib$es6$promise$asap$$isNode=typeof process!=="undefined"&&{}.toString.call(process)==="[object process]";var lib$es6$promise$asap$$isWorker=typeof Uint8ClampedArray!=="undefined"&&typeof importScripts!=="undefined"&&typeof MessageChannel!=="undefined";function lib$es6$promise$asap$$useNextTick(){return function(){process.nextTick(lib$es6$promise$asap$$flush)}}function lib$es6$promise$asap$$useVertxTimer(){return function(){lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush)}}function lib$es6$promise$asap$$useMutationObserver(){var iterations=0;var observer=new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush);var node=document.createTextNode("");observer.observe(node,{characterData:true});return function(){node.data=iterations=++iterations%2}}function lib$es6$promise$asap$$useMessageChannel(){var channel=new MessageChannel;channel.port1.onmessage=lib$es6$promise$asap$$flush;return function(){channel.port2.postMessage(0)}}function lib$es6$promise$asap$$useSetTimeout(){return function(){setTimeout(lib$es6$promise$asap$$flush,1)}}var lib$es6$promise$asap$$queue=new Array(1e3);function lib$es6$promise$asap$$flush(){for(var i=0;i0?1:-1}function c(a){var b=new Promise(function(b,c){var d=function(e){setTimeout(function(){a&&a.data?b():e>=20?c():d(++e)},50)};d(0)});return b}function d(){o=n?(a.screen.orientation.angle||0)*j:(a.orientation||0)*j}function e(a){l.orientation.data=a;for(var b in l.orientation.callbacks)l.orientation.callbacks[b].call(this)}function f(a){l.motion.data=a;for(var b in l.motion.callbacks)l.motion.callbacks[b].call(this)}if(void 0===a.FULLTILT||null===a.FULLTILT){var g=Math.PI,h=g/2,i=2*g,j=g/180,k=180/g,l={orientation:{active:!1,callbacks:[],data:void 0},motion:{active:!1,callbacks:[],data:void 0}},m=!1,n=a.screen&&a.screen.orientation&&void 0!==a.screen.orientation.angle&&null!==a.screen.orientation.angle?!0:!1,o=(n?a.screen.orientation.angle:a.orientation||0)*j,p=h,q=g,r=i/3,s=-h,t={};t.version="0.5.3",t.getDeviceOrientation=function(a){var b=new Promise(function(b,d){var e=new t.DeviceOrientation(a);e.start();var f=new c(l.orientation);f.then(function(){e._alphaAvailable=l.orientation.data.alpha&&null!==l.orientation.data.alpha,e._betaAvailable=l.orientation.data.beta&&null!==l.orientation.data.beta,e._gammaAvailable=l.orientation.data.gamma&&null!==l.orientation.data.gamma,b(e)})["catch"](function(){e.stop(),d("DeviceOrientation is not supported")})});return b},t.getDeviceMotion=function(a){var b=new Promise(function(b,d){var e=new t.DeviceMotion(a);e.start();var f=new c(l.motion);f.then(function(){e._accelerationXAvailable=l.motion.data.acceleration&&l.motion.data.acceleration.x,e._accelerationYAvailable=l.motion.data.acceleration&&l.motion.data.acceleration.y,e._accelerationZAvailable=l.motion.data.acceleration&&l.motion.data.acceleration.z,e._accelerationIncludingGravityXAvailable=l.motion.data.accelerationIncludingGravity&&l.motion.data.accelerationIncludingGravity.x,e._accelerationIncludingGravityYAvailable=l.motion.data.accelerationIncludingGravity&&l.motion.data.accelerationIncludingGravity.y,e._accelerationIncludingGravityZAvailable=l.motion.data.accelerationIncludingGravity&&l.motion.data.accelerationIncludingGravity.z,e._rotationRateAlphaAvailable=l.motion.data.rotationRate&&l.motion.data.rotationRate.alpha,e._rotationRateBetaAvailable=l.motion.data.rotationRate&&l.motion.data.rotationRate.beta,e._rotationRateGammaAvailable=l.motion.data.rotationRate&&l.motion.data.rotationRate.gamma,b(e)})["catch"](function(){e.stop(),d("DeviceMotion is not supported")})});return b},t.Quaternion=function(a,c,d,e){var f;this.set=function(a,b,c,d){this.x=a||0,this.y=b||0,this.z=c||0,this.w=d||1},this.copy=function(a){this.x=a.x,this.y=a.y,this.z=a.z,this.w=a.w},this.setFromEuler=function(){var a,b,c,d,e,f,g,h,i,k,l,m;return function(n){return n=n||{},c=(n.alpha||0)*j,a=(n.beta||0)*j,b=(n.gamma||0)*j,f=c/2,d=a/2,e=b/2,g=Math.cos(d),h=Math.cos(e),i=Math.cos(f),k=Math.sin(d),l=Math.sin(e),m=Math.sin(f),this.set(k*h*i-g*l*m,g*l*i+k*h*m,g*h*m+k*l*i,g*h*i-k*l*m),this.normalize(),this}}(),this.setFromRotationMatrix=function(){var a;return function(c){return a=c.elements,this.set(.5*Math.sqrt(1+a[0]-a[4]-a[8])*b(a[7]-a[5]),.5*Math.sqrt(1-a[0]+a[4]-a[8])*b(a[2]-a[6]),.5*Math.sqrt(1-a[0]-a[4]+a[8])*b(a[3]-a[1]),.5*Math.sqrt(1+a[0]+a[4]+a[8])),this}}(),this.multiply=function(a){return f=t.Quaternion.prototype.multiplyQuaternions(this,a),this.copy(f),this},this.rotateX=function(a){return f=t.Quaternion.prototype.rotateByAxisAngle(this,[1,0,0],a),this.copy(f),this},this.rotateY=function(a){return f=t.Quaternion.prototype.rotateByAxisAngle(this,[0,1,0],a),this.copy(f),this},this.rotateZ=function(a){return f=t.Quaternion.prototype.rotateByAxisAngle(this,[0,0,1],a),this.copy(f),this},this.normalize=function(){return t.Quaternion.prototype.normalize(this)},this.set(a,c,d,e)},t.Quaternion.prototype={constructor:t.Quaternion,multiplyQuaternions:function(){var a=new t.Quaternion;return function(b,c){var d=b.x,e=b.y,f=b.z,g=b.w,h=c.x,i=c.y,j=c.z,k=c.w;return a.set(d*k+g*h+e*j-f*i,e*k+g*i+f*h-d*j,f*k+g*j+d*i-e*h,g*k-d*h-e*i-f*j),a}}(),normalize:function(a){var b=Math.sqrt(a.x*a.x+a.y*a.y+a.z*a.z+a.w*a.w);return 0===b?(a.x=0,a.y=0,a.z=0,a.w=1):(b=1/b,a.x*=b,a.y*=b,a.z*=b,a.w*=b),a},rotateByAxisAngle:function(){var a,b,c=new t.Quaternion,d=new t.Quaternion;return function(e,f,g){return a=(g||0)/2,b=Math.sin(a),d.set((f[0]||0)*b,(f[1]||0)*b,(f[2]||0)*b,Math.cos(a)),c=t.Quaternion.prototype.multiplyQuaternions(e,d),t.Quaternion.prototype.normalize(c)}}()},t.RotationMatrix=function(a,b,c,d,e,f,g,h,i){var k;this.elements=new Float32Array(9),this.identity=function(){return this.set(1,0,0,0,1,0,0,0,1),this},this.set=function(a,b,c,d,e,f,g,h,i){this.elements[0]=a||1,this.elements[1]=b||0,this.elements[2]=c||0,this.elements[3]=d||0,this.elements[4]=e||1,this.elements[5]=f||0,this.elements[6]=g||0,this.elements[7]=h||0,this.elements[8]=i||1},this.copy=function(a){this.elements[0]=a.elements[0],this.elements[1]=a.elements[1],this.elements[2]=a.elements[2],this.elements[3]=a.elements[3],this.elements[4]=a.elements[4],this.elements[5]=a.elements[5],this.elements[6]=a.elements[6],this.elements[7]=a.elements[7],this.elements[8]=a.elements[8]},this.setFromEuler=function(){var a,b,c,d,e,f,g,h,i;return function(k){return k=k||{},c=(k.alpha||0)*j,a=(k.beta||0)*j,b=(k.gamma||0)*j,d=Math.cos(a),e=Math.cos(b),f=Math.cos(c),g=Math.sin(a),h=Math.sin(b),i=Math.sin(c),this.set(f*e-i*g*h,-d*i,e*i*g+f*h,e*i+f*g*h,f*d,i*h-f*e*g,-d*h,g,d*e),this.normalize(),this}}(),this.setFromQuaternion=function(){var a,b,c,d;return function(e){return a=e.w*e.w,b=e.x*e.x,c=e.y*e.y,d=e.z*e.z,this.set(a+b-c-d,2*(e.x*e.y-e.w*e.z),2*(e.x*e.z+e.w*e.y),2*(e.x*e.y+e.w*e.z),a-b+c-d,2*(e.y*e.z-e.w*e.x),2*(e.x*e.z-e.w*e.y),2*(e.y*e.z+e.w*e.x),a-b-c+d),this}}(),this.multiply=function(a){return k=t.RotationMatrix.prototype.multiplyMatrices(this,a),this.copy(k),this},this.rotateX=function(a){return k=t.RotationMatrix.prototype.rotateByAxisAngle(this,[1,0,0],a),this.copy(k),this},this.rotateY=function(a){return k=t.RotationMatrix.prototype.rotateByAxisAngle(this,[0,1,0],a),this.copy(k),this},this.rotateZ=function(a){return k=t.RotationMatrix.prototype.rotateByAxisAngle(this,[0,0,1],a),this.copy(k),this},this.normalize=function(){return t.RotationMatrix.prototype.normalize(this)},this.set(a,b,c,d,e,f,g,h,i)},t.RotationMatrix.prototype={constructor:t.RotationMatrix,multiplyMatrices:function(){var a,b,c=new t.RotationMatrix;return function(d,e){return a=d.elements,b=e.elements,c.set(a[0]*b[0]+a[1]*b[3]+a[2]*b[6],a[0]*b[1]+a[1]*b[4]+a[2]*b[7],a[0]*b[2]+a[1]*b[5]+a[2]*b[8],a[3]*b[0]+a[4]*b[3]+a[5]*b[6],a[3]*b[1]+a[4]*b[4]+a[5]*b[7],a[3]*b[2]+a[4]*b[5]+a[5]*b[8],a[6]*b[0]+a[7]*b[3]+a[8]*b[6],a[6]*b[1]+a[7]*b[4]+a[8]*b[7],a[6]*b[2]+a[7]*b[5]+a[8]*b[8]),c}}(),normalize:function(a){var b=a.elements,c=b[0]*b[4]*b[8]-b[0]*b[5]*b[7]-b[1]*b[3]*b[8]+b[1]*b[5]*b[6]+b[2]*b[3]*b[7]-b[2]*b[4]*b[6];return b[0]/=c,b[1]/=c,b[2]/=c,b[3]/=c,b[4]/=c,b[5]/=c,b[6]/=c,b[7]/=c,b[8]/=c,a.elements=b,a},rotateByAxisAngle:function(){var a,b,c=new t.RotationMatrix,d=new t.RotationMatrix,e=!1;return function(f,g,h){return d.identity(),e=!1,a=Math.sin(h),b=Math.cos(h),1===g[0]&&0===g[1]&&0===g[2]?(e=!0,d.elements[4]=b,d.elements[5]=-a,d.elements[7]=a,d.elements[8]=b):1===g[1]&&0===g[0]&&0===g[2]?(e=!0,d.elements[0]=b,d.elements[2]=a,d.elements[6]=-a,d.elements[8]=b):1===g[2]&&0===g[0]&&0===g[1]&&(e=!0,d.elements[0]=b,d.elements[1]=-a,d.elements[3]=a,d.elements[4]=b),e?(c=t.RotationMatrix.prototype.multiplyMatrices(f,d),c=t.RotationMatrix.prototype.normalize(c)):c=f,c}}()},t.Euler=function(a,b,c){this.set=function(a,b,c){this.alpha=a||0,this.beta=b||0,this.gamma=c||0},this.copy=function(a){this.alpha=a.alpha,this.beta=a.beta,this.gamma=a.gamma},this.setFromRotationMatrix=function(){var a,b,c,d;return function(e){a=e.elements,a[8]>0?(b=Math.atan2(-a[1],a[4]),c=Math.asin(a[7]),d=Math.atan2(-a[6],a[8])):a[8]<0?(b=Math.atan2(a[1],-a[4]),c=-Math.asin(a[7]),c+=c>=0?-g:g,d=Math.atan2(a[6],-a[8])):a[6]>0?(b=Math.atan2(-a[1],a[4]),c=Math.asin(a[7]),d=-h):a[6]<0?(b=Math.atan2(a[1],-a[4]),c=-Math.asin(a[7]),c+=c>=0?-g:g,d=-h):(b=Math.atan2(a[3],a[0]),c=a[7]>0?h:-h,d=0),0>b&&(b+=i),b*=k,c*=k,d*=k,this.set(b,c,d)}}(),this.setFromQuaternion=function(){var a,b,c;return function(d){var e=d.w*d.w,f=d.x*d.x,j=d.y*d.y,l=d.z*d.z,m=e+f+j+l,n=d.w*d.x+d.y*d.z,o=1e-6;if(n>(.5-o)*m)a=2*Math.atan2(d.y,d.w),b=h,c=0;else if((-.5+o)*m>n)a=-2*Math.atan2(d.y,d.w),b=-h,c=0;else{var p=e-f+j-l,q=2*(d.w*d.z-d.x*d.y),r=e-f-j+l,s=2*(d.w*d.y-d.x*d.z);r>0?(a=Math.atan2(q,p),b=Math.asin(2*n/m),c=Math.atan2(s,r)):(a=Math.atan2(-q,-p),b=-Math.asin(2*n/m),b+=0>b?g:-g,c=Math.atan2(-s,-r))}0>a&&(a+=i),a*=k,b*=k,c*=k,this.set(a,b,c)}}(),this.rotateX=function(a){return t.Euler.prototype.rotateByAxisAngle(this,[1,0,0],a),this},this.rotateY=function(a){return t.Euler.prototype.rotateByAxisAngle(this,[0,1,0],a),this},this.rotateZ=function(a){return t.Euler.prototype.rotateByAxisAngle(this,[0,0,1],a),this},this.set(a,b,c)},t.Euler.prototype={constructor:t.Euler,rotateByAxisAngle:function(){var a=new t.RotationMatrix;return function(b,c,d){return a.setFromEuler(b),a=t.RotationMatrix.prototype.rotateByAxisAngle(a,c,d),b.setFromRotationMatrix(a),b}}()},t.DeviceOrientation=function(b){this.options=b||{};var c=0,d=200,e=0,f=10;if(this.alphaOffsetScreen=0,this.alphaOffsetDevice=void 0,"game"===this.options.type){var g=function(b){return null!==b.alpha&&(this.alphaOffsetDevice=new t.Euler(b.alpha,0,0),this.alphaOffsetDevice.rotateZ(-o),++e>=f)?void a.removeEventListener("deviceorientation",g,!1):void(++c>=d&&a.removeEventListener("deviceorientation",g,!1))}.bind(this);a.addEventListener("deviceorientation",g,!1)}else if("world"===this.options.type){var h=function(b){return b.absolute!==!0&&void 0!==b.webkitCompassAccuracy&&null!==b.webkitCompassAccuracy&&+b.webkitCompassAccuracy>=0&&+b.webkitCompassAccuracy<50&&(this.alphaOffsetDevice=new t.Euler(b.webkitCompassHeading,0,0),this.alphaOffsetDevice.rotateZ(o),this.alphaOffsetScreen=o,++e>=f)?void a.removeEventListener("deviceorientation",h,!1):void(++c>=d&&a.removeEventListener("deviceorientation",h,!1))}.bind(this);a.addEventListener("deviceorientation",h,!1)}},t.DeviceOrientation.prototype={constructor:t.DeviceOrientation,start:function(b){b&&"[object Function]"==Object.prototype.toString.call(b)&&l.orientation.callbacks.push(b),m||(n?a.screen.orientation.addEventListener("change",d,!1):a.addEventListener("orientationchange",d,!1)),l.orientation.active||(a.addEventListener("deviceorientation",e,!1),l.orientation.active=!0)},stop:function(){l.orientation.active&&(a.removeEventListener("deviceorientation",e,!1),l.orientation.active=!1)},listen:function(a){this.start(a)},getFixedFrameQuaternion:function(){var a=new t.Euler,b=new t.RotationMatrix,c=new t.Quaternion;return function(){var d=l.orientation.data||{alpha:0,beta:0,gamma:0},e=d.alpha;return this.alphaOffsetDevice&&(b.setFromEuler(this.alphaOffsetDevice),b.rotateZ(-this.alphaOffsetScreen),a.setFromRotationMatrix(b),a.alpha<0&&(a.alpha+=360),a.alpha%=360,e-=a.alpha),a.set(e,d.beta,d.gamma),c.setFromEuler(a),c}}(),getScreenAdjustedQuaternion:function(){var a;return function(){return a=this.getFixedFrameQuaternion(),a.rotateZ(-o),a}}(),getFixedFrameMatrix:function(){var a=new t.Euler,b=new t.RotationMatrix;return function(){var c=l.orientation.data||{alpha:0,beta:0,gamma:0},d=c.alpha;return this.alphaOffsetDevice&&(b.setFromEuler(this.alphaOffsetDevice),b.rotateZ(-this.alphaOffsetScreen),a.setFromRotationMatrix(b),a.alpha<0&&(a.alpha+=360),a.alpha%=360,d-=a.alpha),a.set(d,c.beta,c.gamma),b.setFromEuler(a),b}}(),getScreenAdjustedMatrix:function(){var a;return function(){return a=this.getFixedFrameMatrix(),a.rotateZ(-o),a}}(),getFixedFrameEuler:function(){var a,b=new t.Euler;return function(){return a=this.getFixedFrameMatrix(),b.setFromRotationMatrix(a),b}}(),getScreenAdjustedEuler:function(){var a,b=new t.Euler;return function(){return a=this.getScreenAdjustedMatrix(),b.setFromRotationMatrix(a),b}}(),isAbsolute:function(){return l.orientation.data&&l.orientation.data.absolute===!0?!0:!1},getLastRawEventData:function(){return l.orientation.data||{}},_alphaAvailable:!1,_betaAvailable:!1,_gammaAvailable:!1,isAvailable:function(a){switch(a){case this.ALPHA:return this._alphaAvailable;case this.BETA:return this._betaAvailable;case this.GAMMA:return this._gammaAvailable}},ALPHA:"alpha",BETA:"beta",GAMMA:"gamma"},t.DeviceMotion=function(a){this.options=a||{}},t.DeviceMotion.prototype={constructor:t.DeviceMotion,start:function(b){b&&"[object Function]"==Object.prototype.toString.call(b)&&l.motion.callbacks.push(b),m||(n?a.screen.orientation.addEventListener("change",d,!1):a.addEventListener("orientationchange",d,!1)),l.motion.active||(a.addEventListener("devicemotion",f,!1),l.motion.active=!0)},stop:function(){l.motion.active&&(a.removeEventListener("devicemotion",f,!1),l.motion.active=!1)},listen:function(a){this.start(a)},getScreenAdjustedAcceleration:function(){var a=l.motion.data&&l.motion.data.acceleration?l.motion.data.acceleration:{x:0,y:0,z:0},b={};switch(o){case p:b.x=-a.y,b.y=a.x;break;case q:b.x=-a.x,b.y=-a.y;break;case r:case s:b.x=a.y,b.y=-a.x;break;default:b.x=a.x,b.y=a.y}return b.z=a.z,b},getScreenAdjustedAccelerationIncludingGravity:function(){var a=l.motion.data&&l.motion.data.accelerationIncludingGravity?l.motion.data.accelerationIncludingGravity:{x:0,y:0,z:0},b={};switch(o){case p:b.x=-a.y,b.y=a.x;break;case q:b.x=-a.x,b.y=-a.y;break;case r:case s:b.x=a.y,b.y=-a.x;break;default:b.x=a.x,b.y=a.y}return b.z=a.z,b},getScreenAdjustedRotationRate:function(){var a=l.motion.data&&l.motion.data.rotationRate?l.motion.data.rotationRate:{alpha:0,beta:0,gamma:0},b={};switch(o){case p:b.beta=-a.gamma,b.gamma=a.beta;break;case q:b.beta=-a.beta,b.gamma=-a.gamma;break;case r:case s:b.beta=a.gamma,b.gamma=-a.beta;break;default:b.beta=a.beta,b.gamma=a.gamma}return b.alpha=a.alpha,b},getLastRawEventData:function(){return l.motion.data||{}},_accelerationXAvailable:!1,_accelerationYAvailable:!1,_accelerationZAvailable:!1,_accelerationIncludingGravityXAvailable:!1,_accelerationIncludingGravityYAvailable:!1,_accelerationIncludingGravityZAvailable:!1,_rotationRateAlphaAvailable:!1,_rotationRateBetaAvailable:!1,_rotationRateGammaAvailable:!1,isAvailable:function(a){switch(a){case this.ACCELERATION_X:return this._accelerationXAvailable;case this.ACCELERATION_Y:return this._accelerationYAvailable;case this.ACCELERATION_Z:return this._accelerationZAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_X:return this._accelerationIncludingGravityXAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_Y:return this._accelerationIncludingGravityYAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_Z:return this._accelerationIncludingGravityZAvailable;case this.ROTATION_RATE_ALPHA:return this._rotationRateAlphaAvailable;case this.ROTATION_RATE_BETA:return this._rotationRateBetaAvailable;case this.ROTATION_RATE_GAMMA:return this._rotationRateGammaAvailable}},ACCELERATION_X:"accelerationX",ACCELERATION_Y:"accelerationY",ACCELERATION_Z:"accelerationZ",ACCELERATION_INCLUDING_GRAVITY_X:"accelerationIncludingGravityX",ACCELERATION_INCLUDING_GRAVITY_Y:"accelerationIncludingGravityY",ACCELERATION_INCLUDING_GRAVITY_Z:"accelerationIncludingGravityZ",ROTATION_RATE_ALPHA:"rotationRateAlpha",ROTATION_RATE_BETA:"rotationRateBeta",ROTATION_RATE_GAMMA:"rotationRateGamma"},a.FULLTILT=t}}(window); 14 | /* gyronorm.js v2.0.4 - https://github.com/dorukeker/gyronorm.git*/ 15 | !function(a,b){"function"==typeof define&&define.amd?define(function(){return a.GyroNorm=b()}):"object"==typeof module&&module.exports?module.exports=a.GyroNorm=b():a.GyroNorm=b()}(this,function(){function a(a){return Math.round(a*Math.pow(10,t))/Math.pow(10,t)}function b(){var b={};b=v?o.getScreenAdjustedEuler():o.getFixedFrameEuler();var c=p.getScreenAdjustedAcceleration(),e=p.getScreenAdjustedAccelerationIncludingGravity(),f=p.getScreenAdjustedRotationRate(),g=0;s===d?(g=b.alpha-k,g=0>g?360-Math.abs(g):g):g=b.alpha;var h={"do":{alpha:a(g),beta:a(b.beta),gamma:a(b.gamma),absolute:o.isAbsolute()},dm:{x:a(c.x),y:a(c.y),z:a(c.z),gx:a(e.x),gy:a(e.y),gz:a(e.z),alpha:a(f.alpha),beta:a(f.beta),gamma:a(f.gamma)}};return r&&(h.dm.gx*=l,h.dm.gy*=l,h.dm.gz*=l),h}function c(a){u&&("string"==typeof a&&(a={message:a,code:0}),u(a))}var d="game",e="world",f="deviceorientation",g="acceleration",h="accelerationinludinggravity",i="rotationrate",j=null,k=0,l=0,m=!1,n=!1,o=null,p=null,q=50,r=!0,s=d,t=2,u=null,v=!1,w=function(a){};return w.GAME=d,w.WORLD=e,w.DEVICE_ORIENTATION=f,w.ACCELERATION=g,w.ACCELERATION_INCLUDING_GRAVITY=h,w.ROTATION_RATE=i,w.prototype.init=function(a){a&&a.frequency&&(q=a.frequency),a&&a.gravityNormalized&&(r=a.gravityNormalized),a&&a.orientationBase&&(s=a.orientationBase),a&&a.decimalCount&&(t=a.decimalCount),a&&a.logger&&(u=a.logger),a&&a.screenAdjusted&&(v=a.screenAdjusted);var b=new FULLTILT.getDeviceOrientation({type:s}).then(function(a){o=a}),c=(new FULLTILT.getDeviceMotion).then(function(a){p=a,l=p.getScreenAdjustedAccelerationIncludingGravity().z>0?-1:1});return Promise.all([b,c]).then(function(){n=!0})},w.prototype.end=function(){try{n=!1,this.stop(),p.stop(),o.stop()}catch(a){c(a)}},w.prototype.start=function(a){return n?(j=setInterval(function(){a(b())},q),void(m=!0)):void c({message:'GyroNorm is not initialized yet. First call the "init()" function.',code:1})},w.prototype.stop=function(){j&&(clearInterval(j),m=!1)},w.prototype.normalizeGravity=function(a){r=a?!0:!1},w.prototype.setHeadDirection=function(){return v||s===e?!1:(k=o.getFixedFrameEuler().alpha,!0)},w.prototype.startLogging=function(a){a&&(u=a)},w.prototype.stopLogging=function(){u=null},w.prototype.isAvailable=function(a){var b=o.getScreenAdjustedEuler(),c=p.getScreenAdjustedAcceleration(),d=p.getScreenAdjustedAccelerationIncludingGravity(),e=p.getScreenAdjustedRotationRate();switch(a){case f:return b.alpha&&null!==b.alpha&&b.beta&&null!==b.beta&&b.gamma&&null!==b.gamma;case g:return c&&c.x&&c.y&&c.z;case h:return d&&d.x&&d.y&&d.z;case i:return e&&e.alpha&&e.beta&&e.gamma;default:return{deviceOrientationAvailable:b.alpha&&null!==b.alpha&&b.beta&&null!==b.beta&&b.gamma&&null!==b.gamma,accelerationAvailable:c&&c.x&&c.y&&c.z,accelerationIncludingGravityAvailable:d&&d.x&&d.y&&d.z,rotationRateAvailable:e&&e.alpha&&e.beta&&e.gamma}}},w.prototype.isRunning=function(){return m},w}); 16 | 17 | 18 | // Initiate gyronorm.js and apply shadow based on gravity. 19 | 20 | var gn = new GyroNorm(); 21 | 22 | gn.init().then(function() { 23 | gn.start(function(data) { 24 | $('.g-enabled').each(function() { 25 | if (data.do.alpha > 180 && data.do.beta < 45) { 26 | $(this).css('box-shadow', parseInt(data.dm.gy) * 1 + 'px ' + parseInt(data.dm.gx) * 1 + 'px ' + $(this).data('shadow-blur') + 'px ' + $(this).data('shadow-color')); 27 | } else { 28 | $(this).css('box-shadow', parseInt(data.dm.gx) * 1 + 'px ' + parseInt(-data.dm.gy) * 1 + 'px ' + $(this).data('shadow-blur') + 'px ' + $(this).data('shadow-color')); 29 | } 30 | }); 31 | 32 | }); 33 | }).catch(function(e) { 34 | console.log('Device Motion not supported.'); 35 | }); 36 | 37 | } 38 | 39 | })(); -------------------------------------------------------------------------------- /gBoxShadow.min.js: -------------------------------------------------------------------------------- 1 | !function(){if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){(function(){"use strict";function t(t){return"function"==typeof t||"object"==typeof t&&null!==t}function e(t){return"function"==typeof t}function n(t){return"object"==typeof t&&null!==t}function a(t){Y=t}function i(t){X=t}function o(){return function(){process.nextTick(u)}}function r(){return function(){B(u)}}function s(){var t=0,e=new V(u),n=document.createTextNode("");return e.observe(n,{characterData:!0}),function(){n.data=t=++t%2}}function c(){var t=new MessageChannel;return t.port1.onmessage=u,function(){t.port2.postMessage(0)}}function l(){return function(){setTimeout(u,1)}}function u(){for(var t=0;P>t;t+=2){var e=W[t],n=W[t+1];e(n),W[t]=void 0,W[t+1]=void 0}P=0}function h(){try{var t=require,e=t("vertx");return B=e.runOnLoop||e.runOnContext,r()}catch(n){return l()}}function f(){}function m(){return new TypeError("You cannot resolve a promise with itself")}function p(){return new TypeError("A promises callback cannot return that same promise.")}function d(t){try{return t.then}catch(e){return et.error=e,et}}function v(t,e,n,a){try{t.call(e,n,a)}catch(i){return i}}function y(t,e,n){X(function(t){var a=!1,i=v(n,e,function(n){a||(a=!0,e!==n?b(t,n):x(t,n))},function(e){a||(a=!0,w(t,e))},"Settle: "+(t._label||" unknown promise"));!a&&i&&(a=!0,w(t,i))},t)}function A(t,e){e._state===J?x(t,e._result):e._state===tt?w(t,e._result):M(e,void 0,function(e){b(t,e)},function(e){w(t,e)})}function g(t,n){if(n.constructor===t.constructor)A(t,n);else{var a=d(n);a===et?w(t,et.error):void 0===a?x(t,n):e(a)?y(t,n,a):x(t,n)}}function b(e,n){e===n?w(e,m()):t(n)?g(e,n):x(e,n)}function _(t){t._onerror&&t._onerror(t._result),E(t)}function x(t,e){t._state===K&&(t._result=e,t._state=J,0!==t._subscribers.length&&X(E,t))}function w(t,e){t._state===K&&(t._state=tt,t._result=e,X(_,t))}function M(t,e,n,a){var i=t._subscribers,o=i.length;t._onerror=null,i[o]=e,i[o+J]=n,i[o+tt]=a,0===o&&t._state&&X(E,t)}function E(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var a,i,o=t._result,r=0;rr;r++)M(a.resolve(t[r]),void 0,e,n);return i}function C(t){var e=this;if(t&&"object"==typeof t&&t.constructor===e)return t;var n=new e(f);return b(n,t),n}function N(t){var e=this,n=new e(f);return w(n,t),n}function F(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function D(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function j(t){this._id=ct++,this._state=void 0,this._result=void 0,this._subscribers=[],f!==t&&(e(t)||F(),this instanceof j||D(),O(this,t))}function S(){var t;if("undefined"!=typeof global)t=global;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(e){throw new Error("polyfill failed because global object is unavailable in this environment")}var n=t.Promise;(!n||"[object Promise]"!==Object.prototype.toString.call(n.resolve())||n.cast)&&(t.Promise=lt)}var k;k=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var B,Y,Q,Z=k,P=0,X=({}.toString,function(t,e){W[P]=t,W[P+1]=e,P+=2,2===P&&(Y?Y(u):Q())}),U="undefined"!=typeof window?window:void 0,q=U||{},V=q.MutationObserver||q.WebKitMutationObserver,$="undefined"!=typeof process&&"[object process]"==={}.toString.call(process),H="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,W=new Array(1e3);Q=$?o():V?s():H?c():void 0===U&&"function"==typeof require?h():l();var K=void 0,J=1,tt=2,et=new R,nt=new R;L.prototype._validateInput=function(t){return Z(t)},L.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},L.prototype._init=function(){this._result=new Array(this.length)};var at=L;L.prototype._enumerate=function(){for(var t=this,e=t.length,n=t.promise,a=t._input,i=0;n._state===K&&e>i;i++)t._eachEntry(a[i],i)},L.prototype._eachEntry=function(t,e){var a=this,i=a._instanceConstructor;n(t)?t.constructor===i&&t._state!==K?(t._onerror=null,a._settledAt(t._state,e,t._result)):a._willSettleAt(i.resolve(t),e):(a._remaining--,a._result[e]=t)},L.prototype._settledAt=function(t,e,n){var a=this,i=a.promise;i._state===K&&(a._remaining--,t===tt?w(i,n):a._result[e]=n),0===a._remaining&&x(i,a._result)},L.prototype._willSettleAt=function(t,e){var n=this;M(t,void 0,function(t){n._settledAt(J,e,t)},function(t){n._settledAt(tt,e,t)})};var it=z,ot=G,rt=C,st=N,ct=0,lt=j;j.all=it,j.race=ot,j.resolve=rt,j.reject=st,j._setScheduler=a,j._setAsap=i,j._asap=X,j.prototype={constructor:j,then:function(t,e){var n=this,a=n._state;if(a===J&&!t||a===tt&&!e)return this;var i=new this.constructor(f),o=n._result;if(a){var r=arguments[a-1];X(function(){T(a,i,r,o)})}else M(n,i,t,e);return i},"catch":function(t){return this.then(null,t)}};var ut=S,ht={Promise:lt,polyfill:ut};"function"==typeof define&&define.amd?define(function(){return ht}):"undefined"!=typeof module&&module.exports?module.exports=ht:"undefined"!=typeof this&&(this.ES6Promise=ht),ut()}).call(this),!function(t){function e(t){return t=+t,0===t||isNaN(t)?t:t>0?1:-1}function n(t){var e=new Promise(function(e,n){var a=function(i){setTimeout(function(){t&&t.data?e():i>=20?n():a(++i)},50)};a(0)});return e}function a(){p=m?(t.screen.orientation.angle||0)*l:(t.orientation||0)*l}function i(t){h.orientation.data=t;for(var e in h.orientation.callbacks)h.orientation.callbacks[e].call(this)}function o(t){h.motion.data=t;for(var e in h.motion.callbacks)h.motion.callbacks[e].call(this)}if(void 0===t.FULLTILT||null===t.FULLTILT){var r=Math.PI,s=r/2,c=2*r,l=r/180,u=180/r,h={orientation:{active:!1,callbacks:[],data:void 0},motion:{active:!1,callbacks:[],data:void 0}},f=!1,m=t.screen&&t.screen.orientation&&void 0!==t.screen.orientation.angle&&null!==t.screen.orientation.angle?!0:!1,p=(m?t.screen.orientation.angle:t.orientation||0)*l,d=s,v=r,y=c/3,A=-s,g={};g.version="0.5.3",g.getDeviceOrientation=function(t){var e=new Promise(function(e,a){var i=new g.DeviceOrientation(t);i.start();var o=new n(h.orientation);o.then(function(){i._alphaAvailable=h.orientation.data.alpha&&null!==h.orientation.data.alpha,i._betaAvailable=h.orientation.data.beta&&null!==h.orientation.data.beta,i._gammaAvailable=h.orientation.data.gamma&&null!==h.orientation.data.gamma,e(i)})["catch"](function(){i.stop(),a("DeviceOrientation is not supported")})});return e},g.getDeviceMotion=function(t){var e=new Promise(function(e,a){var i=new g.DeviceMotion(t);i.start();var o=new n(h.motion);o.then(function(){i._accelerationXAvailable=h.motion.data.acceleration&&h.motion.data.acceleration.x,i._accelerationYAvailable=h.motion.data.acceleration&&h.motion.data.acceleration.y,i._accelerationZAvailable=h.motion.data.acceleration&&h.motion.data.acceleration.z,i._accelerationIncludingGravityXAvailable=h.motion.data.accelerationIncludingGravity&&h.motion.data.accelerationIncludingGravity.x,i._accelerationIncludingGravityYAvailable=h.motion.data.accelerationIncludingGravity&&h.motion.data.accelerationIncludingGravity.y,i._accelerationIncludingGravityZAvailable=h.motion.data.accelerationIncludingGravity&&h.motion.data.accelerationIncludingGravity.z,i._rotationRateAlphaAvailable=h.motion.data.rotationRate&&h.motion.data.rotationRate.alpha,i._rotationRateBetaAvailable=h.motion.data.rotationRate&&h.motion.data.rotationRate.beta,i._rotationRateGammaAvailable=h.motion.data.rotationRate&&h.motion.data.rotationRate.gamma,e(i)})["catch"](function(){i.stop(),a("DeviceMotion is not supported")})});return e},g.Quaternion=function(t,n,a,i){var o;this.set=function(t,e,n,a){this.x=t||0,this.y=e||0,this.z=n||0,this.w=a||1},this.copy=function(t){this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w},this.setFromEuler=function(){var t,e,n,a,i,o,r,s,c,u,h,f;return function(m){return m=m||{},n=(m.alpha||0)*l,t=(m.beta||0)*l,e=(m.gamma||0)*l,o=n/2,a=t/2,i=e/2,r=Math.cos(a),s=Math.cos(i),c=Math.cos(o),u=Math.sin(a),h=Math.sin(i),f=Math.sin(o),this.set(u*s*c-r*h*f,r*h*c+u*s*f,r*s*f+u*h*c,r*s*c-u*h*f),this.normalize(),this}}(),this.setFromRotationMatrix=function(){var t;return function(n){return t=n.elements,this.set(.5*Math.sqrt(1+t[0]-t[4]-t[8])*e(t[7]-t[5]),.5*Math.sqrt(1-t[0]+t[4]-t[8])*e(t[2]-t[6]),.5*Math.sqrt(1-t[0]-t[4]+t[8])*e(t[3]-t[1]),.5*Math.sqrt(1+t[0]+t[4]+t[8])),this}}(),this.multiply=function(t){return o=g.Quaternion.prototype.multiplyQuaternions(this,t),this.copy(o),this},this.rotateX=function(t){return o=g.Quaternion.prototype.rotateByAxisAngle(this,[1,0,0],t),this.copy(o),this},this.rotateY=function(t){return o=g.Quaternion.prototype.rotateByAxisAngle(this,[0,1,0],t),this.copy(o),this},this.rotateZ=function(t){return o=g.Quaternion.prototype.rotateByAxisAngle(this,[0,0,1],t),this.copy(o),this},this.normalize=function(){return g.Quaternion.prototype.normalize(this)},this.set(t,n,a,i)},g.Quaternion.prototype={constructor:g.Quaternion,multiplyQuaternions:function(){var t=new g.Quaternion;return function(e,n){var a=e.x,i=e.y,o=e.z,r=e.w,s=n.x,c=n.y,l=n.z,u=n.w;return t.set(a*u+r*s+i*l-o*c,i*u+r*c+o*s-a*l,o*u+r*l+a*c-i*s,r*u-a*s-i*c-o*l),t}}(),normalize:function(t){var e=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w);return 0===e?(t.x=0,t.y=0,t.z=0,t.w=1):(e=1/e,t.x*=e,t.y*=e,t.z*=e,t.w*=e),t},rotateByAxisAngle:function(){var t,e,n=new g.Quaternion,a=new g.Quaternion;return function(i,o,r){return t=(r||0)/2,e=Math.sin(t),a.set((o[0]||0)*e,(o[1]||0)*e,(o[2]||0)*e,Math.cos(t)),n=g.Quaternion.prototype.multiplyQuaternions(i,a),g.Quaternion.prototype.normalize(n)}}()},g.RotationMatrix=function(t,e,n,a,i,o,r,s,c){var u;this.elements=new Float32Array(9),this.identity=function(){return this.set(1,0,0,0,1,0,0,0,1),this},this.set=function(t,e,n,a,i,o,r,s,c){this.elements[0]=t||1,this.elements[1]=e||0,this.elements[2]=n||0,this.elements[3]=a||0,this.elements[4]=i||1,this.elements[5]=o||0,this.elements[6]=r||0,this.elements[7]=s||0,this.elements[8]=c||1},this.copy=function(t){this.elements[0]=t.elements[0],this.elements[1]=t.elements[1],this.elements[2]=t.elements[2],this.elements[3]=t.elements[3],this.elements[4]=t.elements[4],this.elements[5]=t.elements[5],this.elements[6]=t.elements[6],this.elements[7]=t.elements[7],this.elements[8]=t.elements[8]},this.setFromEuler=function(){var t,e,n,a,i,o,r,s,c;return function(u){return u=u||{},n=(u.alpha||0)*l,t=(u.beta||0)*l,e=(u.gamma||0)*l,a=Math.cos(t),i=Math.cos(e),o=Math.cos(n),r=Math.sin(t),s=Math.sin(e),c=Math.sin(n),this.set(o*i-c*r*s,-a*c,i*c*r+o*s,i*c+o*r*s,o*a,c*s-o*i*r,-a*s,r,a*i),this.normalize(),this}}(),this.setFromQuaternion=function(){var t,e,n,a;return function(i){return t=i.w*i.w,e=i.x*i.x,n=i.y*i.y,a=i.z*i.z,this.set(t+e-n-a,2*(i.x*i.y-i.w*i.z),2*(i.x*i.z+i.w*i.y),2*(i.x*i.y+i.w*i.z),t-e+n-a,2*(i.y*i.z-i.w*i.x),2*(i.x*i.z-i.w*i.y),2*(i.y*i.z+i.w*i.x),t-e-n+a),this}}(),this.multiply=function(t){return u=g.RotationMatrix.prototype.multiplyMatrices(this,t),this.copy(u),this},this.rotateX=function(t){return u=g.RotationMatrix.prototype.rotateByAxisAngle(this,[1,0,0],t),this.copy(u),this},this.rotateY=function(t){return u=g.RotationMatrix.prototype.rotateByAxisAngle(this,[0,1,0],t),this.copy(u),this},this.rotateZ=function(t){return u=g.RotationMatrix.prototype.rotateByAxisAngle(this,[0,0,1],t),this.copy(u),this},this.normalize=function(){return g.RotationMatrix.prototype.normalize(this)},this.set(t,e,n,a,i,o,r,s,c)},g.RotationMatrix.prototype={constructor:g.RotationMatrix,multiplyMatrices:function(){var t,e,n=new g.RotationMatrix;return function(a,i){return t=a.elements,e=i.elements,n.set(t[0]*e[0]+t[1]*e[3]+t[2]*e[6],t[0]*e[1]+t[1]*e[4]+t[2]*e[7],t[0]*e[2]+t[1]*e[5]+t[2]*e[8],t[3]*e[0]+t[4]*e[3]+t[5]*e[6],t[3]*e[1]+t[4]*e[4]+t[5]*e[7],t[3]*e[2]+t[4]*e[5]+t[5]*e[8],t[6]*e[0]+t[7]*e[3]+t[8]*e[6],t[6]*e[1]+t[7]*e[4]+t[8]*e[7],t[6]*e[2]+t[7]*e[5]+t[8]*e[8]),n}}(),normalize:function(t){var e=t.elements,n=e[0]*e[4]*e[8]-e[0]*e[5]*e[7]-e[1]*e[3]*e[8]+e[1]*e[5]*e[6]+e[2]*e[3]*e[7]-e[2]*e[4]*e[6];return e[0]/=n,e[1]/=n,e[2]/=n,e[3]/=n,e[4]/=n,e[5]/=n,e[6]/=n,e[7]/=n,e[8]/=n,t.elements=e,t},rotateByAxisAngle:function(){var t,e,n=new g.RotationMatrix,a=new g.RotationMatrix,i=!1;return function(o,r,s){return a.identity(),i=!1,t=Math.sin(s),e=Math.cos(s),1===r[0]&&0===r[1]&&0===r[2]?(i=!0,a.elements[4]=e,a.elements[5]=-t,a.elements[7]=t,a.elements[8]=e):1===r[1]&&0===r[0]&&0===r[2]?(i=!0,a.elements[0]=e,a.elements[2]=t,a.elements[6]=-t,a.elements[8]=e):1===r[2]&&0===r[0]&&0===r[1]&&(i=!0,a.elements[0]=e,a.elements[1]=-t,a.elements[3]=t,a.elements[4]=e),i?(n=g.RotationMatrix.prototype.multiplyMatrices(o,a),n=g.RotationMatrix.prototype.normalize(n)):n=o,n}}()},g.Euler=function(t,e,n){this.set=function(t,e,n){this.alpha=t||0,this.beta=e||0,this.gamma=n||0},this.copy=function(t){this.alpha=t.alpha,this.beta=t.beta,this.gamma=t.gamma},this.setFromRotationMatrix=function(){var t,e,n,a;return function(i){t=i.elements,t[8]>0?(e=Math.atan2(-t[1],t[4]),n=Math.asin(t[7]),a=Math.atan2(-t[6],t[8])):t[8]<0?(e=Math.atan2(t[1],-t[4]),n=-Math.asin(t[7]),n+=n>=0?-r:r,a=Math.atan2(t[6],-t[8])):t[6]>0?(e=Math.atan2(-t[1],t[4]),n=Math.asin(t[7]),a=-s):t[6]<0?(e=Math.atan2(t[1],-t[4]),n=-Math.asin(t[7]),n+=n>=0?-r:r,a=-s):(e=Math.atan2(t[3],t[0]),n=t[7]>0?s:-s,a=0),0>e&&(e+=c),e*=u,n*=u,a*=u,this.set(e,n,a)}}(),this.setFromQuaternion=function(){var t,e,n;return function(a){var i=a.w*a.w,o=a.x*a.x,l=a.y*a.y,h=a.z*a.z,f=i+o+l+h,m=a.w*a.x+a.y*a.z,p=1e-6;if(m>(.5-p)*f)t=2*Math.atan2(a.y,a.w),e=s,n=0;else if((-.5+p)*f>m)t=-2*Math.atan2(a.y,a.w),e=-s,n=0;else{var d=i-o+l-h,v=2*(a.w*a.z-a.x*a.y),y=i-o-l+h,A=2*(a.w*a.y-a.x*a.z);y>0?(t=Math.atan2(v,d),e=Math.asin(2*m/f),n=Math.atan2(A,y)):(t=Math.atan2(-v,-d),e=-Math.asin(2*m/f),e+=0>e?r:-r,n=Math.atan2(-A,-y))}0>t&&(t+=c),t*=u,e*=u,n*=u,this.set(t,e,n)}}(),this.rotateX=function(t){return g.Euler.prototype.rotateByAxisAngle(this,[1,0,0],t),this},this.rotateY=function(t){return g.Euler.prototype.rotateByAxisAngle(this,[0,1,0],t),this},this.rotateZ=function(t){return g.Euler.prototype.rotateByAxisAngle(this,[0,0,1],t),this},this.set(t,e,n)},g.Euler.prototype={constructor:g.Euler,rotateByAxisAngle:function(){var t=new g.RotationMatrix;return function(e,n,a){return t.setFromEuler(e),t=g.RotationMatrix.prototype.rotateByAxisAngle(t,n,a),e.setFromRotationMatrix(t),e}}()},g.DeviceOrientation=function(e){this.options=e||{};var n=0,a=200,i=0,o=10;if(this.alphaOffsetScreen=0,this.alphaOffsetDevice=void 0,"game"===this.options.type){var r=function(e){return null!==e.alpha&&(this.alphaOffsetDevice=new g.Euler(e.alpha,0,0),this.alphaOffsetDevice.rotateZ(-p),++i>=o)?void t.removeEventListener("deviceorientation",r,!1):void(++n>=a&&t.removeEventListener("deviceorientation",r,!1))}.bind(this);t.addEventListener("deviceorientation",r,!1)}else if("world"===this.options.type){var s=function(e){return e.absolute!==!0&&void 0!==e.webkitCompassAccuracy&&null!==e.webkitCompassAccuracy&&+e.webkitCompassAccuracy>=0&&+e.webkitCompassAccuracy<50&&(this.alphaOffsetDevice=new g.Euler(e.webkitCompassHeading,0,0),this.alphaOffsetDevice.rotateZ(p),this.alphaOffsetScreen=p,++i>=o)?void t.removeEventListener("deviceorientation",s,!1):void(++n>=a&&t.removeEventListener("deviceorientation",s,!1))}.bind(this);t.addEventListener("deviceorientation",s,!1)}},g.DeviceOrientation.prototype={constructor:g.DeviceOrientation,start:function(e){e&&"[object Function]"==Object.prototype.toString.call(e)&&h.orientation.callbacks.push(e),f||(m?t.screen.orientation.addEventListener("change",a,!1):t.addEventListener("orientationchange",a,!1)),h.orientation.active||(t.addEventListener("deviceorientation",i,!1),h.orientation.active=!0)},stop:function(){h.orientation.active&&(t.removeEventListener("deviceorientation",i,!1),h.orientation.active=!1)},listen:function(t){this.start(t)},getFixedFrameQuaternion:function(){var t=new g.Euler,e=new g.RotationMatrix,n=new g.Quaternion;return function(){var a=h.orientation.data||{alpha:0,beta:0,gamma:0},i=a.alpha;return this.alphaOffsetDevice&&(e.setFromEuler(this.alphaOffsetDevice),e.rotateZ(-this.alphaOffsetScreen),t.setFromRotationMatrix(e),t.alpha<0&&(t.alpha+=360),t.alpha%=360,i-=t.alpha),t.set(i,a.beta,a.gamma),n.setFromEuler(t),n}}(),getScreenAdjustedQuaternion:function(){var t;return function(){return t=this.getFixedFrameQuaternion(),t.rotateZ(-p),t}}(),getFixedFrameMatrix:function(){var t=new g.Euler,e=new g.RotationMatrix;return function(){var n=h.orientation.data||{alpha:0,beta:0,gamma:0},a=n.alpha;return this.alphaOffsetDevice&&(e.setFromEuler(this.alphaOffsetDevice),e.rotateZ(-this.alphaOffsetScreen),t.setFromRotationMatrix(e),t.alpha<0&&(t.alpha+=360),t.alpha%=360,a-=t.alpha),t.set(a,n.beta,n.gamma),e.setFromEuler(t),e}}(),getScreenAdjustedMatrix:function(){var t;return function(){return t=this.getFixedFrameMatrix(),t.rotateZ(-p),t}}(),getFixedFrameEuler:function(){var t,e=new g.Euler;return function(){return t=this.getFixedFrameMatrix(),e.setFromRotationMatrix(t),e}}(),getScreenAdjustedEuler:function(){var t,e=new g.Euler;return function(){return t=this.getScreenAdjustedMatrix(),e.setFromRotationMatrix(t),e}}(),isAbsolute:function(){return h.orientation.data&&h.orientation.data.absolute===!0?!0:!1},getLastRawEventData:function(){return h.orientation.data||{}},_alphaAvailable:!1,_betaAvailable:!1,_gammaAvailable:!1,isAvailable:function(t){switch(t){case this.ALPHA:return this._alphaAvailable;case this.BETA:return this._betaAvailable;case this.GAMMA:return this._gammaAvailable}},ALPHA:"alpha",BETA:"beta",GAMMA:"gamma"},g.DeviceMotion=function(t){this.options=t||{}},g.DeviceMotion.prototype={constructor:g.DeviceMotion,start:function(e){e&&"[object Function]"==Object.prototype.toString.call(e)&&h.motion.callbacks.push(e),f||(m?t.screen.orientation.addEventListener("change",a,!1):t.addEventListener("orientationchange",a,!1)),h.motion.active||(t.addEventListener("devicemotion",o,!1),h.motion.active=!0)},stop:function(){h.motion.active&&(t.removeEventListener("devicemotion",o,!1),h.motion.active=!1)},listen:function(t){this.start(t)},getScreenAdjustedAcceleration:function(){var t=h.motion.data&&h.motion.data.acceleration?h.motion.data.acceleration:{x:0,y:0,z:0},e={};switch(p){case d:e.x=-t.y,e.y=t.x;break;case v:e.x=-t.x,e.y=-t.y;break;case y:case A:e.x=t.y,e.y=-t.x;break;default:e.x=t.x,e.y=t.y}return e.z=t.z,e},getScreenAdjustedAccelerationIncludingGravity:function(){var t=h.motion.data&&h.motion.data.accelerationIncludingGravity?h.motion.data.accelerationIncludingGravity:{x:0,y:0,z:0},e={};switch(p){case d:e.x=-t.y,e.y=t.x;break;case v:e.x=-t.x,e.y=-t.y;break;case y:case A:e.x=t.y,e.y=-t.x;break;default:e.x=t.x,e.y=t.y}return e.z=t.z,e},getScreenAdjustedRotationRate:function(){var t=h.motion.data&&h.motion.data.rotationRate?h.motion.data.rotationRate:{alpha:0,beta:0,gamma:0},e={};switch(p){case d:e.beta=-t.gamma,e.gamma=t.beta;break;case v:e.beta=-t.beta,e.gamma=-t.gamma;break;case y:case A:e.beta=t.gamma,e.gamma=-t.beta;break;default:e.beta=t.beta,e.gamma=t.gamma}return e.alpha=t.alpha,e},getLastRawEventData:function(){return h.motion.data||{}},_accelerationXAvailable:!1,_accelerationYAvailable:!1,_accelerationZAvailable:!1,_accelerationIncludingGravityXAvailable:!1,_accelerationIncludingGravityYAvailable:!1,_accelerationIncludingGravityZAvailable:!1,_rotationRateAlphaAvailable:!1,_rotationRateBetaAvailable:!1,_rotationRateGammaAvailable:!1,isAvailable:function(t){switch(t){case this.ACCELERATION_X:return this._accelerationXAvailable;case this.ACCELERATION_Y:return this._accelerationYAvailable;case this.ACCELERATION_Z:return this._accelerationZAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_X:return this._accelerationIncludingGravityXAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_Y:return this._accelerationIncludingGravityYAvailable;case this.ACCELERATION_INCLUDING_GRAVITY_Z:return this._accelerationIncludingGravityZAvailable;case this.ROTATION_RATE_ALPHA:return this._rotationRateAlphaAvailable;case this.ROTATION_RATE_BETA:return this._rotationRateBetaAvailable;case this.ROTATION_RATE_GAMMA:return this._rotationRateGammaAvailable}},ACCELERATION_X:"accelerationX",ACCELERATION_Y:"accelerationY",ACCELERATION_Z:"accelerationZ",ACCELERATION_INCLUDING_GRAVITY_X:"accelerationIncludingGravityX",ACCELERATION_INCLUDING_GRAVITY_Y:"accelerationIncludingGravityY",ACCELERATION_INCLUDING_GRAVITY_Z:"accelerationIncludingGravityZ",ROTATION_RATE_ALPHA:"rotationRateAlpha",ROTATION_RATE_BETA:"rotationRateBeta",ROTATION_RATE_GAMMA:"rotationRateGamma"},t.FULLTILT=g}}(window),!function(t,e){"function"==typeof define&&define.amd?define(function(){return t.GyroNorm=e()}):"object"==typeof module&&module.exports?module.exports=t.GyroNorm=e():t.GyroNorm=e()}(this,function(){function t(t){return Math.round(t*Math.pow(10,g))/Math.pow(10,g)}function e(){var e={};e=_?p.getScreenAdjustedEuler():p.getFixedFrameEuler();var n=d.getScreenAdjustedAcceleration(),i=d.getScreenAdjustedAccelerationIncludingGravity(),o=d.getScreenAdjustedRotationRate(),r=0;A===a?(r=e.alpha-u,r=0>r?360-Math.abs(r):r):r=e.alpha;var s={"do":{alpha:t(r),beta:t(e.beta),gamma:t(e.gamma),absolute:p.isAbsolute()},dm:{x:t(n.x),y:t(n.y),z:t(n.z),gx:t(i.x),gy:t(i.y),gz:t(i.z),alpha:t(o.alpha),beta:t(o.beta),gamma:t(o.gamma)}};return y&&(s.dm.gx*=h,s.dm.gy*=h,s.dm.gz*=h),s}function n(t){b&&("string"==typeof t&&(t={message:t,code:0}),b(t))}var a="game",i="world",o="deviceorientation",r="acceleration",s="accelerationinludinggravity",c="rotationrate",l=null,u=0,h=0,f=!1,m=!1,p=null,d=null,v=50,y=!0,A=a,g=2,b=null,_=!1,x=function(t){};return x.GAME=a,x.WORLD=i,x.DEVICE_ORIENTATION=o,x.ACCELERATION=r,x.ACCELERATION_INCLUDING_GRAVITY=s,x.ROTATION_RATE=c,x.prototype.init=function(t){t&&t.frequency&&(v=t.frequency),t&&t.gravityNormalized&&(y=t.gravityNormalized),t&&t.orientationBase&&(A=t.orientationBase),t&&t.decimalCount&&(g=t.decimalCount),t&&t.logger&&(b=t.logger),t&&t.screenAdjusted&&(_=t.screenAdjusted);var e=new FULLTILT.getDeviceOrientation({type:A}).then(function(t){p=t}),n=(new FULLTILT.getDeviceMotion).then(function(t){d=t,h=d.getScreenAdjustedAccelerationIncludingGravity().z>0?-1:1});return Promise.all([e,n]).then(function(){m=!0})},x.prototype.end=function(){try{m=!1,this.stop(),d.stop(),p.stop()}catch(t){n(t)}},x.prototype.start=function(t){return m?(l=setInterval(function(){t(e())},v),void(f=!0)):void n({message:'GyroNorm is not initialized yet. First call the "init()" function.',code:1})},x.prototype.stop=function(){l&&(clearInterval(l),f=!1)},x.prototype.normalizeGravity=function(t){y=t?!0:!1},x.prototype.setHeadDirection=function(){return _||A===i?!1:(u=p.getFixedFrameEuler().alpha,!0)},x.prototype.startLogging=function(t){t&&(b=t)},x.prototype.stopLogging=function(){b=null},x.prototype.isAvailable=function(t){var e=p.getScreenAdjustedEuler(),n=d.getScreenAdjustedAcceleration(),a=d.getScreenAdjustedAccelerationIncludingGravity(),i=d.getScreenAdjustedRotationRate();switch(t){case o:return e.alpha&&null!==e.alpha&&e.beta&&null!==e.beta&&e.gamma&&null!==e.gamma;case r:return n&&n.x&&n.y&&n.z;case s:return a&&a.x&&a.y&&a.z;case c:return i&&i.alpha&&i.beta&&i.gamma;default:return{deviceOrientationAvailable:e.alpha&&null!==e.alpha&&e.beta&&null!==e.beta&&e.gamma&&null!==e.gamma,accelerationAvailable:n&&n.x&&n.y&&n.z,accelerationIncludingGravityAvailable:a&&a.x&&a.y&&a.z,rotationRateAvailable:i&&i.alpha&&i.beta&&i.gamma}}},x.prototype.isRunning=function(){return f},x});var t=new GyroNorm;t.init().then(function(){t.start(function(t){$(".g-enabled").each(function(){t["do"].alpha>180&&t["do"].beta<45?$(this).css("box-shadow",1*parseInt(t.dm.gy)+"px "+1*parseInt(t.dm.gx)+"px "+$(this).data("shadow-blur")+"px "+$(this).data("shadow-color")):$(this).css("box-shadow",1*parseInt(t.dm.gx)+"px "+1*parseInt(-t.dm.gy)+"px "+$(this).data("shadow-blur")+"px "+$(this).data("shadow-color"))})})})["catch"](function(t){console.log("Device Motion not supported.")})}}(); --------------------------------------------------------------------------------