Skip to content

Commit

Permalink
Update dist files
Browse files Browse the repository at this point in the history
  • Loading branch information
richtr committed Nov 18, 2014
1 parent 11117c5 commit 2b7f725
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
86 changes: 50 additions & 36 deletions dist/fulltilt.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ var degToRad = M_PI / 180;
var radToDeg = 180 / M_PI;

// Internal device orientation + motion variables
var orientationActive = false, motionActive = false, screenActive = false;
var orientationCallbacks = [], motionCallbacks = [];
var deviceOrientationData = {}, deviceMotionData = {};
var sensors = {
"orientation": {
active: false,
callbacks: [],
data: undefined
},
"motion": {
active: false,
callbacks: [],
data: undefined
}
};
var screenActive = false;

// Internal screen orientation variables
var hasScreenOrientationAPI = window.screen && window.screen.orientation && window.screen.orientation.angle !== undefined && window.screen.orientation.angle !== null ? true : false;
Expand All @@ -54,15 +64,15 @@ function sign(x) {

///// Promise-based Sensor Data checker //////

function SensorCheck(sensorData) {
function SensorCheck(sensorRootObj) {

var promise = new Promise(function(resolve, reject) {

var runCheck = function (tries) {
var runCheck = function (tries) {

setTimeout(function() {

if (sensorData) {
if (sensorRootObj && sensorRootObj.data) {

resolve();

Expand Down Expand Up @@ -106,25 +116,25 @@ function handleScreenOrientationChange () {

function handleDeviceOrientationChange ( event ) {

deviceOrientationData = event;
sensors.orientation.data = event;

// Fire every callback function each time deviceorientation is updated
for ( var i in orientationCallbacks ) {
for ( var i in sensors.orientation.callbacks ) {

orientationCallbacks[ i ].call( this );
sensors.orientation.callbacks[ i ].call( this );

}

}

function handleDeviceMotionChange ( event ) {

deviceMotionData = event;
sensors.motion.data = event;

// Fire every callback function each time devicemotion is updated
for ( var i in motionCallbacks ) {
for ( var i in sensors.motion.callbacks ) {

motionCallbacks[ i ].call( this );
sensors.motion.callbacks[ i ].call( this );

}

Expand All @@ -146,7 +156,7 @@ FULLTILT.getDeviceOrientation = function(options) {

control.start();

var orientationSensorCheck = new SensorCheck(deviceOrientationData);
var orientationSensorCheck = new SensorCheck(sensors.orientation);

orientationSensorCheck.then(function() {

Expand All @@ -173,7 +183,7 @@ FULLTILT.getDeviceMotion = function(options) {

control.start();

var motionSensorCheck = new SensorCheck(deviceMotionData);
var motionSensorCheck = new SensorCheck(sensors.motion);

motionSensorCheck.then(function() {

Expand Down Expand Up @@ -985,7 +995,7 @@ FULLTILT.DeviceOrientation.prototype = {

if ( callback && Object.prototype.toString.call( callback ) == '[object Function]' ) {

orientationCallbacks.push( callback );
sensors.orientation.callbacks.push( callback );

}

Expand All @@ -1003,23 +1013,23 @@ FULLTILT.DeviceOrientation.prototype = {

}

if ( !orientationActive ) {
if ( !sensors.orientation.active ) {

window.addEventListener( 'deviceorientation', handleDeviceOrientationChange, false );

orientationActive = true;
sensors.orientation.active = true;

}

},

stop: function () {

if ( orientationActive ) {
if ( sensors.orientation.active ) {

window.removeEventListener( 'deviceorientation', handleDeviceOrientationChange, false );

orientationActive = false;
sensors.orientation.active = false;

}

Expand All @@ -1039,7 +1049,9 @@ FULLTILT.DeviceOrientation.prototype = {

return function() {

var adjustedAlpha = deviceOrientationData.alpha;
var orientationData = sensors.orientation.data || { alpha: 0, beta: 0, gamma: 0 };

var adjustedAlpha = orientationData.alpha;

if (this.alphaOffsetDevice) {
matrix.setFromEuler( this.alphaOffsetDevice );
Expand All @@ -1055,8 +1067,8 @@ FULLTILT.DeviceOrientation.prototype = {

euler.set(
adjustedAlpha,
deviceOrientationData.beta,
deviceOrientationData.gamma
orientationData.beta,
orientationData.gamma
);

quaternion.setFromEuler( euler );
Expand Down Expand Up @@ -1091,7 +1103,9 @@ FULLTILT.DeviceOrientation.prototype = {

return function () {

var adjustedAlpha = deviceOrientationData.alpha;
var orientationData = sensors.orientation.data || { alpha: 0, beta: 0, gamma: 0 };

var adjustedAlpha = orientationData.alpha;

if (this.alphaOffsetDevice) {
matrix.setFromEuler( this.alphaOffsetDevice );
Expand All @@ -1107,8 +1121,8 @@ FULLTILT.DeviceOrientation.prototype = {

euler.set(
adjustedAlpha,
deviceOrientationData.beta,
deviceOrientationData.gamma
orientationData.beta,
orientationData.gamma
);

matrix.setFromEuler( euler );
Expand Down Expand Up @@ -1172,7 +1186,7 @@ FULLTILT.DeviceOrientation.prototype = {

isAbsolute: function () {

if ( deviceOrientationData && deviceOrientationData.absolute === true ) {
if ( sensors.orientation.data && sensors.orientation.data.absolute === true ) {
return true;
}

Expand All @@ -1182,7 +1196,7 @@ FULLTILT.DeviceOrientation.prototype = {

getLastRawEventData: function () {

return deviceOrientationData;
return sensors.orientation.data || {};

}

Expand All @@ -1204,7 +1218,7 @@ FULLTILT.DeviceMotion.prototype = {

if ( callback && Object.prototype.toString.call( callback ) == '[object Function]' ) {

motionCallbacks.push( callback );
sensors.motion.callbacks.push( callback );

}

Expand All @@ -1222,23 +1236,23 @@ FULLTILT.DeviceMotion.prototype = {

}

if ( !motionActive ) {
if ( !sensors.motion.active ) {

window.addEventListener( 'devicemotion', handleDeviceMotionChange, false );

motionActive = true;
sensors.motion.active = true;

}

},

stop: function () {

if ( motionActive ) {
if ( sensors.motion.active ) {

window.removeEventListener( 'devicemotion', handleDeviceMotionChange, false );

motionActive = false;
sensors.motion.active = false;

}

Expand All @@ -1252,7 +1266,7 @@ FULLTILT.DeviceMotion.prototype = {

getScreenAdjustedAcceleration: function () {

var accData = deviceMotionData.acceleration || {};
var accData = sensors.motion.data && sensors.motion.data.acceleration ? sensors.motion.data.acceleration : { x: 0, y: 0, z: 0 };
var screenAccData = {};

switch ( screenOrientationAngle ) {
Expand Down Expand Up @@ -1283,7 +1297,7 @@ FULLTILT.DeviceMotion.prototype = {

getScreenAdjustedAccelerationIncludingGravity: function () {

var accGData = deviceMotionData.accelerationIncludingGravity || {};
var accGData = sensors.motion.data && sensors.motion.data.accelerationIncludingGravity ? sensors.motion.data.accelerationIncludingGravity : { x: 0, y: 0, z: 0 };
var screenAccGData = {};

switch ( screenOrientationAngle ) {
Expand Down Expand Up @@ -1314,7 +1328,7 @@ FULLTILT.DeviceMotion.prototype = {

getScreenAdjustedRotationRate: function () {

var rotRateData = deviceMotionData.rotationRate || {};
var rotRateData = sensors.motion.data && sensors.motion.data.rotationRate ? sensors.motion.data.rotationRate : { alpha: 0, beta: 0, gamma: 0 };
var screenRotRateData = {};

switch ( screenOrientationAngle ) {
Expand Down Expand Up @@ -1345,7 +1359,7 @@ FULLTILT.DeviceMotion.prototype = {

getLastRawEventData: function () {

return deviceMotionData;
return sensors.motion.data || {};

}

Expand Down
Loading

0 comments on commit 2b7f725

Please sign in to comment.