jquery-mobileios-simulatororientationbrowser-detectionjammit

jquery mobile orientation detection


I am using jquery-mobile and it seems it doesn't detect the landscape setting. What I am using:

iphone simulator Version 4.3 (238.2) from Xcode Version 4.1 Build 4B110 jquery mobile

I tried to do this in my mobile.js

$(window).bind('orientationchange resize', function(event){
  alert(event.orientation)
})

and turning the simulator around just keeps giving me an alert that says "portrait" when it clearly should be landscape.

am i doing something wrong here? I also tried using media queries in our jammit call:

<%= include_stylesheet :landscape, :media => "all and (orientation: landscape)" %>

but to no avail. AM i doing something wrong here?

The main bug btw is that even when turning the iphone, the display still stays at portrait width for us.


Solution

  • I found this in the jQM b2 js file:

    JS:

    alert('Orientation: ' + jQuery.event.special.orientationchange.orientation());
    

    Here is the function itself:

    // Get the current page orientation. This method is exposed publicly, should it
    // be needed, as jQuery.event.special.orientationchange.orientation()
    $.event.special.orientationchange.orientation = get_orientation = function() {
        var elem = document.documentElement;
        return elem && elem.clientWidth / elem.clientHeight < 1.1 ? "portrait" : "landscape";
    };