Skip to content

Commit

Permalink
Helpers: resetActivePageHeight now accounts for external toolbars
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed Feb 24, 2014
1 parent 0b9186c commit 6dcea68
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion js/jquery.mobile.helpers.js
Expand Up @@ -9,6 +9,36 @@ define( [ "jquery", "./jquery.mobile.ns", "jquery-ui/jquery.ui.core" ], function
//>>excludeEnd("jqmBuildExclude");
(function( $, window, undefined ) {

// Subtract the height of external toolbars from the page height, if the page does not have
// internal toolbars of the same type
var compensateToolbars = function( page, desiredHeight ) {
var pageParent = page.parent(),
toolbarsAffectingHeight = [],
externalHeaders = pageParent.children( ":jqmData(role='header')" ),
internalHeaders = page.children( ":jqmData(role='header')" ),
externalFooters = pageParent.children( ":jqmData(role='footer')" ),
internalFooters = page.children( ":jqmData(role='footer')" );

// If we have no internal headers, but we do have external headers, then their height
// reduces the page height
if ( internalHeaders.length === 0 && externalHeaders.length > 0 ) {
toolbarsAffectingHeight = toolbarsAffectingHeight.concat( externalHeaders.toArray() );
}

// If we have no internal footers, but we do have external footers, then their height
// reduces the page height
if ( internalFooters.length === 0 && externalFooters.length > 0 ) {
toolbarsAffectingHeight = toolbarsAffectingHeight.concat( externalFooters.toArray() );
}

$.each( toolbarsAffectingHeight, function( index, value ) {
desiredHeight -= $( value ).outerHeight();
});

// Height must be at least zero
return Math.max( 0, desiredHeight );
};

$.extend( $.mobile, {
// define the window and the document objects
window: $( window ),
Expand Down Expand Up @@ -139,7 +169,8 @@ define( [ "jquery", "./jquery.mobile.ns", "jquery-ui/jquery.ui.core" ], function
pageHeight = page.height(),
pageOuterHeight = page.outerHeight( true );

height = ( typeof height === "number" ) ? height : $.mobile.getScreenHeight();
height = compensateToolbars( page,
( typeof height === "number" ) ? height : $.mobile.getScreenHeight() );

page.css( "min-height", height - ( pageOuterHeight - pageHeight ) );
},
Expand Down

0 comments on commit 6dcea68

Please sign in to comment.