Skip to content

Commit a0ddaab

Browse files
committed
fix for incorrect portrait of lanscape value
The value attached to the event passed into handlers was based soley on screensize which is problematic given that some implementations (eg Android 2.3) don't change the screensize until after the event is fired. The orientation property appears to report a better value where it is provided so the solution is to prefer what it reports and then fallback to the screensize caculation where necessary.
1 parent a20bb72 commit a0ddaab

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

js/jquery.mobile.event.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,22 @@ $.event.special.swipe = {
242242
// Get the current page orientation. This method is exposed publicly, should it
243243
// be needed, as jQuery.event.special.orientationchange.orientation()
244244
$.event.special.orientationchange.orientation = get_orientation = function() {
245-
var elem = document.documentElement;
246-
return elem && elem.clientWidth / elem.clientHeight < 1.1 ? "portrait" : "landscape";
245+
var isPortrait = true, elem = document.documentElement;
246+
247+
// prefer window orientation to the calculation based on screensize as
248+
// the actual screen resize takes place before or after the orientation change event
249+
// has been fired depending on implementation (eg android 2.3 is before, iphone after).
250+
// More testing is required to determine if a more reliable method of determining the new screensize
251+
// is possible when orientationchange is fired. (eg, use media queries + element + opacity)
252+
if ( $.support.orientation ) {
253+
// if the window orientation registers as 0 or 180 degrees report
254+
// portrait, otherwise landscape
255+
isPortrait = window.orientation % 180 == 0;
256+
} else {
257+
isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
258+
}
259+
260+
return isPortrait ? "portrait" : "landscape";
247261
};
248262

249263
})( jQuery, window );

0 commit comments

Comments
 (0)