diff --git a/js/jquery.mobile.event.js b/js/jquery.mobile.event.js index 6a58cefa..d0e105f5 100644 --- a/js/jquery.mobile.event.js +++ b/js/jquery.mobile.event.js @@ -242,8 +242,22 @@ $.event.special.swipe = { // 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"; + var isPortrait = true, elem = document.documentElement; + + // prefer window orientation to the calculation based on screensize as + // the actual screen resize takes place before or after the orientation change event + // has been fired depending on implementation (eg android 2.3 is before, iphone after). + // More testing is required to determine if a more reliable method of determining the new screensize + // is possible when orientationchange is fired. (eg, use media queries + element + opacity) + if ( $.support.orientation ) { + // if the window orientation registers as 0 or 180 degrees report + // portrait, otherwise landscape + isPortrait = window.orientation % 180 == 0; + } else { + isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1; + } + + return isPortrait ? "portrait" : "landscape"; }; })( jQuery, window );