Revert "Export"
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / js / jquery.mobile.zoom.iosorientationfix.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Fixes the orientation change bug in iOS when switching between landspace and portrait
3 //>>label: iOS Orientation Change Fix
4 //>>group: Utilities
5
6 define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.zoom" ], function( $ ) {
7 //>>excludeEnd("jqmBuildExclude");
8 ( function( $, window ) {
9         
10         // This fix addresses an iOS bug, so return early if the UA claims it's something else.
11         if( !(/iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1 ) ){
12                 return;
13         }
14         
15     var zoom = $.mobile.zoom,
16                 evt, x, y, z, aig;
17         
18     function checkTilt( e ){
19                 evt = e.originalEvent;
20                 aig = evt.accelerationIncludingGravity;
21                 
22                 x = Math.abs( aig.x );
23                 y = Math.abs( aig.y );
24                 z = Math.abs( aig.z );
25                                 
26                 // If portrait orientation and in one of the danger zones
27         if( !window.orientation && ( x > 7 || ( ( z > 6 && y < 8 || z < 8 && y > 6 ) && x > 5 ) ) ){
28                         if( zoom.enabled ){
29                                 zoom.disable();
30                         }               
31         }
32                 else if( !zoom.enabled ){
33                         zoom.enable();
34         }
35     }
36
37     $( window )
38                 .bind( "orientationchange.iosorientationfix", zoom.enable )
39                 .bind( "devicemotion.iosorientationfix", checkTilt );
40
41 }( jQuery, this ));
42 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
43 });
44 //>>excludeEnd("jqmBuildExclude");