Skip to content

Instantly share code, notes, and snippets.

@remy
Created December 18, 2009 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remy/259520 to your computer and use it in GitHub Desktop.
Save remy/259520 to your computer and use it in GitHub Desktop.
onorientationchange
// jQuery based patch for onorientationchange
(function () {
var w = window.innerWidth, h = window.innerHeight, el = $('body')[0];
if (!('onorientationchange' in el)) {
if (el.setAttribute) {
el.setAttribute('onorientationchange', 'return;');
if (!typeof element[eventName] == 'function') {
// patch support for the onorientationchange event via onresize
$(window).resize(function () {
var portraitSwitch = (window.innerWidth < w && window.innerHeight > h) && (window.innerWidth < window.innerHeight),
landscapeSwitch = (window.innerWidth > w && window.innerHeight < h) && (window.innerWidth > window.innerHeight);
if (portraitSwitch || landscapeSwitch) {
$('body').trigger('orientationchange');
w = window.innerWidth;
h = window.innerHeight;
}
}
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment