From e7269f4df27f5931bfbd2858bdcd3d8d0ac31e64 Mon Sep 17 00:00:00 2001 From: scottjehl Date: Wed, 17 Nov 2010 11:54:32 -0500 Subject: [PATCH] moved orientationchange event trigger over to media js file. Cleaned up event bindings where orientation and breakpoint classes are applied. --- js/jquery.mobile.js | 3 --- js/jquery.mobile.media.js | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/js/jquery.mobile.js b/js/jquery.mobile.js index 9284a922..389f1ce0 100644 --- a/js/jquery.mobile.js +++ b/js/jquery.mobile.js @@ -581,9 +581,6 @@ //trigger a new hashchange, hash or not $window.trigger( "hashchange", [ true ] ); - //update orientation - $window.trigger( "orientationchange.htmlclass" ); - //remove rendering class $html.removeClass('ui-mobile-rendering'); }); diff --git a/js/jquery.mobile.media.js b/js/jquery.mobile.media.js index 1502db6b..427fcd39 100644 --- a/js/jquery.mobile.media.js +++ b/js/jquery.mobile.media.js @@ -86,16 +86,24 @@ $.mobile.addResolutionBreakpoints = function( newbps ){ } resolutionBreakpoints.sort(function(a,b){ return a-b; }) detectResolutionBreakpoints(); -} +} - -/* bind to orientationchange, resize, and mobileinit -to add classes to HTML element for min/max breakpoints and orientation */ -$window.bind( "orientationchange.htmlclass resize.htmlclass mobileinit.htmlclass", function( event ) { - //add orientation class to HTML element on flip/resize. - $html.removeClass( "portrait landscape" ).addClass( event.orientation ); - //add breakpoint classes for min/max widths - detectResolutionBreakpoints(); +/* on mobileinit, add classes to HTML element + and set handlers to update those on orientationchange and resize*/ +$(document).bind("mobileinit.htmlclass", function(){ + /* bind to orientationchange and resize + to add classes to HTML element for min/max breakpoints and orientation */ + $window.bind("orientationchange.htmlclass resize.htmlclass", function(event){ + //add orientation class to HTML element on flip/resize. + if(event.orientation){ + $html.removeClass( "portrait landscape" ).addClass( event.orientation ); + } + //add classes to HTML element for min/max breakpoints + detectResolutionBreakpoints(); + }); + + //trigger event manually + $window.trigger( "orientationchange.htmlclass" ); }); })(jQuery); \ No newline at end of file