Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added deviceorientationabsolute so absolute positioning with Android Chrome works #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 16 additions & 11 deletions dist/fulltilt.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ if ( window.FULLTILT !== undefined && window.FULLTILT !== null ) {
return;
}

var orientationChangeAbsolute = undefined;

var M_PI = Math.PI;
var M_PI_2 = M_PI / 2;
var M_2_PI = 2 * M_PI;
Expand Down Expand Up @@ -100,6 +102,7 @@ function SensorCheck(sensorRootObj) {

////// Internal Event Handlers //////


function handleScreenOrientationChange () {

if ( hasScreenOrientationAPI ) {
Expand All @@ -115,16 +118,17 @@ function handleScreenOrientationChange () {
}

function handleDeviceOrientationChange ( event ) {
if (event.absolute === true) {
orientationChangeAbsolute = true;
}
if (event.absolute == orientationChangeAbsolute) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaks support for non-absolute browsers, like firefox mobile

sensors.orientation.data = event;

sensors.orientation.data = event;

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

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

}

// Fire every callback function each time deviceorientation is updated
for ( var i in sensors.orientation.callbacks ) {
sensors.orientation.callbacks[ i ].call( this );
}
}
}

function handleDeviceMotionChange ( event ) {
Expand Down Expand Up @@ -1015,7 +1019,7 @@ FULLTILT.DeviceOrientation.prototype = {
}

if ( !sensors.orientation.active ) {

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

sensors.orientation.active = true;
Expand All @@ -1028,6 +1032,7 @@ FULLTILT.DeviceOrientation.prototype = {

if ( sensors.orientation.active ) {

window.removeEventListener( 'deviceorientationabsolute', handleDeviceOrientationChange, false );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix issues with firefox mobile, needs to be like this

				if ('ondeviceorientationabsolute' in window) {
					window.addEventListener( 'deviceorientationabsolute', handleDeviceOrientationChange, false );
				} else if ('ondeviceorientation' in window) {
					window.addEventListener( 'deviceorientation', handleDeviceOrientationChange, false );
				}

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

sensors.orientation.active = false;
Expand Down Expand Up @@ -1380,4 +1385,4 @@ FULLTILT.DeviceMotion.prototype = {

window.FULLTILT = FULLTILT;

})( window );
})( window );
2 changes: 0 additions & 2 deletions dist/fulltilt.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fulltilt",
"title": "Full Tilt",
"version": "0.7.0",
"version": "0.8.0",
"description": "Standalone device orientation + device motion normalization and conversion library",
"homepage": "http://github.com/richtr/Full-Tilt",
"author": {
Expand Down
4 changes: 2 additions & 2 deletions src/DeviceOrientation.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ FULLTILT.DeviceOrientation.prototype = {
}

if ( !sensors.orientation.active ) {

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

sensors.orientation.active = true;
Expand All @@ -104,7 +104,7 @@ FULLTILT.DeviceOrientation.prototype = {
stop: function () {

if ( sensors.orientation.active ) {

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

sensors.orientation.active = false;
Expand Down
14 changes: 7 additions & 7 deletions src/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ function handleScreenOrientationChange () {
}

function handleDeviceOrientationChange ( event ) {
if (event.absolute) {
sensors.orientation.data = event;

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

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

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

}
}

}

function handleDeviceMotionChange ( event ) {
Expand All @@ -38,4 +38,4 @@ function handleDeviceMotionChange ( event ) {

}

}
}