Skip to content

Commit 460ad71

Browse files
author
scottjehl
committed
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.
1 parent 4e2c8ef commit 460ad71

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

js/jquery.mobile.zoom.iosorientationfix.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,35 @@
55
define( [ "jquery", "jquery.mobile.core", "jquery.mobile.zoom" ], function( $ ) {
66
//>>excludeEnd("jqmBuildExclude");
77
( function( $, window ) {
8-
var orientation = window.orientation,
9-
rotation = 0;
10-
8+
var zoom = $.mobile.zoom,
9+
rotation = 0,
10+
x = y = z = 0,
11+
orientation, aig;
12+
1113
function checkTilt( e ){
12-
e = e.originalEvent;
13-
orientation = Math.abs( window.orientation );
14-
rotation = Math.abs( e.gamma );
14+
evt = e.originalEvent;
15+
orientation = window.orientation;
16+
aig = evt.accelerationIncludingGravity;
17+
18+
if( aig ){
19+
x = Math.abs( aig.x );
20+
y = Math.abs( aig.y );
21+
z = Math.abs( aig.z );
22+
}
1523

16-
if( rotation > 8 && orientation === 0 ){
17-
if( $.mobile.zoom.enabled ){
18-
$.mobile.zoom.disable();
19-
}
24+
if( orientation === 0 && ( e.type === "deviceorientation" || x > 7 || ( z > 4 && ( x > 6 || y > 6 ) ) ) ){
25+
if( zoom.enabled ){
26+
zoom.disable();
27+
}
2028
}
21-
else {
22-
if( !$.mobile.zoom.enabled ){
23-
$.mobile.zoom.enable();
24-
}
29+
else if( !zoom.enabled ){
30+
zoom.enable();
2531
}
2632
}
2733

2834
$( window )
29-
.bind( "orientationchange", $.mobile.zoom.enable )
30-
.bind( "deviceorientation", checkTilt );
35+
.bind( "orientationchange", zoom.enable )
36+
.bind( "deviceorientation devicemotion", checkTilt );
3137

3238
}( jQuery, this ));
3339
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);

0 commit comments

Comments
 (0)