horizontal and vertical orientation event

horizontal and vertical orientation event

After I posted a fix suggestion I implemented a event to facilitate my work. When the orientation is horizontal or vertical.
Should be nice if these events come implemented in jquery mobile


My implementations to this:

after including the jquery script, I added..
       
  1. $(function() {
  2.     var setOrientation = function() {
  3.         if (window.orientation === undefined) { // desktop
  4.             return;
  5.         }
  6.        
  7.         if (Math.abs(window.orientation) == 90) { // horizontal
  8.             $(document).triggerHandler('onHorizontalOrientation');
  9.         }
  10.         else { // vertical
  11.             $(document).triggerHandler('onVerticalOrientation'); // meu evento
  12.         }
  13.     };
  14.     var orientationEvent = "onorientationchange" in window ? "orientationchange" : "resize";
  15.     window.addEventListener(orientationEvent, setOrientation, false);
  16.     setOrientation();
  17. });

and my script general file I added..
  1. $(document).bind('onHorizontalOrientation', function(){ alert('horizontal'); });
  2. $(document).bind('onVerticalOrientation', function(){ alert('vertical'); });