Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
improved the address bar hiding logic to support Android as well by d…
Browse files Browse the repository at this point in the history
…etermining up-front which hiding number should be used. Fixes #1673. Fixes #1322. Fixes #1786.
  • Loading branch information
scottjehl committed Jun 19, 2011
1 parent ca0c116 commit a09c53e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion js/jquery.mobile.core.js
Expand Up @@ -96,7 +96,10 @@

//scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
silentScroll: function( ypos ) {
ypos = ypos || 0;
if( $.type( ypos ) !== "number" ){
ypos = $.mobile.defaultHomeScroll;
}

// prevent scrollstart and scrollstop events
$.event.special.scrollstart.enabled = false;

Expand Down
12 changes: 12 additions & 0 deletions js/jquery.mobile.init.js
Expand Up @@ -106,5 +106,17 @@

//window load event
//hide iOS browser chrome on load

//check which scrollTop value should be used by scrolling to 1 immediately
//then check what the scroll top is. Android will report 0... others 1
//note that this initial scroll won't hide the address bar. It's just for the check.
window.scrollTo( 0, 1 );

//if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
//it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
//so if it's 1, use 0 from now on
$.mobile.defaultHomeScroll = ( !$.support.scrollTop || $(window).scrollTop() === 1 ) ? 0 : 1;

//call silentScroll on load to hide addr bar
$window.load( $.mobile.silentScroll );
})( jQuery, this );
4 changes: 2 additions & 2 deletions js/jquery.mobile.navigation.js
Expand Up @@ -388,11 +388,11 @@

//get current scroll distance
var currScroll = $window.scrollTop(),
toScroll = toPage.data( "lastScroll" ) || 0;
toScroll = toPage.data( "lastScroll" ) || $.mobile.defaultHomeScroll;

//if scrolled down, scroll to top
if( currScroll ){
window.scrollTo( 0, 0 );
window.scrollTo( 0, $.mobile.defaultHomeScroll );
}

//if the Y location we're scrolling to is less than 10px, let it go for sake of smoothness
Expand Down

0 comments on commit a09c53e

Please sign in to comment.