From 460ad7197c4461bb20914c00f946fbb7089820d9 Mon Sep 17 00:00:00 2001 From: scottjehl Date: Thu, 19 Jan 2012 20:59:21 +0700 Subject: [PATCH] This change brings the iOS orientationchange bug workaround up to the latest code from that external project, with an experimental attempt at iOS4.3 support on the 3GS using the devicemotion event, which may be a bad idea to use unthrottled - not sure yet. This code needs to be tested on a device with iOS5, and I imagine the check for deviceorientation will also need a check for the value of evt.gamma. At that point, we may decide to only support iOS5 for this workaround, and the code can bind only to deviceorientation and be more concise. --- js/jquery.mobile.zoom.iosorientationfix.js | 38 +++++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/js/jquery.mobile.zoom.iosorientationfix.js b/js/jquery.mobile.zoom.iosorientationfix.js index 16e6c643..077b8610 100644 --- a/js/jquery.mobile.zoom.iosorientationfix.js +++ b/js/jquery.mobile.zoom.iosorientationfix.js @@ -5,29 +5,35 @@ define( [ "jquery", "jquery.mobile.core", "jquery.mobile.zoom" ], function( $ ) { //>>excludeEnd("jqmBuildExclude"); ( function( $, window ) { - var orientation = window.orientation, - rotation = 0; - + var zoom = $.mobile.zoom, + rotation = 0, + x = y = z = 0, + orientation, aig; + function checkTilt( e ){ - e = e.originalEvent; - orientation = Math.abs( window.orientation ); - rotation = Math.abs( e.gamma ); + evt = e.originalEvent; + orientation = window.orientation; + aig = evt.accelerationIncludingGravity; + + if( aig ){ + x = Math.abs( aig.x ); + y = Math.abs( aig.y ); + z = Math.abs( aig.z ); + } - if( rotation > 8 && orientation === 0 ){ - if( $.mobile.zoom.enabled ){ - $.mobile.zoom.disable(); - } + if( orientation === 0 && ( e.type === "deviceorientation" || x > 7 || ( z > 4 && ( x > 6 || y > 6 ) ) ) ){ + if( zoom.enabled ){ + zoom.disable(); + } } - else { - if( !$.mobile.zoom.enabled ){ - $.mobile.zoom.enable(); - } + else if( !zoom.enabled ){ + zoom.enable(); } } $( window ) - .bind( "orientationchange", $.mobile.zoom.enable ) - .bind( "deviceorientation", checkTilt ); + .bind( "orientationchange", zoom.enable ) + .bind( "deviceorientation devicemotion", checkTilt ); }( jQuery, this )); //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);