mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-22 07:04:43 +00:00
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.
35 lines
1.1 KiB
JavaScript
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");
|