jquery-mobile/js/jquery.mobile.zoom.iosorientationfix.js
scottjehl 66be09d2de A new utility: $.mobile.zoom, which as 3 members: enabled [bool], disable [function], and enable [function].
This simple utility is used to disable user scaling in devices like iOS. The disable() method disables user-scaling. The enable() method enables user-scaling. The enabled property keeps track of state.

Two other utilites are included here as well.

First, there's zoom.iosfocusfix.js, which disables zoom as a select or input element is focused, preventing iOS from zooming into that element and cropping the viewport. Zoom is restored just after the focus event fires (a half second timeout).

Then there's zoom.iosorientationfix.js, which is intended to fix the iOS orientationchange zoom bug, following the approach from this project https://github.com/scottjehl/iOS-Orientationchange-Fix. This may not  be working yet. Needs testing, and it may require that we change the values of the meta content to use maximum-scale instead of user-scalable.

Lastly, fixedtoolbar, once it lands, should use this utility to disable/enable zoom, rather than the one that's currently included in its own source.
2012-01-24 17:31:05 +07:00

35 lines
1.1 KiB
JavaScript

//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Fixes the iOS orientation change bug using a jQM version of this technique https://github.com/scottjehl/iOS-Orientationchange-Fix
//>>label: iOS orientation change bugfix
define( [ "jquery", "jquery.mobile.core", "jquery.mobile.zoom" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
( function( $, window ) {
var orientation = window.orientation,
rotation = 0;
function checkTilt( e ){
e = e.originalEvent;
orientation = Math.abs( window.orientation );
rotation = Math.abs( e.gamma );
if( rotation > 8 && orientation === 0 ){
if( $.mobile.zoom.enabled ){
$.mobile.zoom.disable();
}
}
else {
if( !$.mobile.zoom.enabled ){
$.mobile.zoom.enable();
}
}
}
$( window )
.bind( "orientationchange", $.mobile.zoom.enable )
.bind( "deviceorientation", checkTilt );
}( jQuery, this ));
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");