diff --git a/js/jquery.mobile.forms.select.js b/js/jquery.mobile.forms.select.js index c2a5c642..ed3a7ff8 100644 --- a/js/jquery.mobile.forms.select.js +++ b/js/jquery.mobile.forms.select.js @@ -70,8 +70,7 @@ $.widget( "mobile.selectmenu", $.mobile.widget, { }) .appendTo( listbox ), - menuType, - currScroll; + menuType; //populate menu with options from select element select.find( "option" ).each(function( i ){ @@ -97,8 +96,16 @@ $.widget( "mobile.selectmenu", $.mobile.widget, { function showmenu(){ - var menuHeight = list.outerHeight(); - currScroll = [ $(window).scrollLeft(), $(window).scrollTop() ]; + var menuHeight = list.outerHeight(), + scrollTop = $(window).scrollTop(), + btnOffset = button.offset().top, + screenHeight = window.innerHeight; + + if( scrollTop == 0 && btnOffset > screenHeight ){ + thisPage.one('pagehide',function(){ + $(this).data('lastScroll', btnOffset); + }); + } if( menuHeight > window.innerHeight - 80 || !$.support.scrollTop ){ menuType = "page"; @@ -142,7 +149,6 @@ $.widget( "mobile.selectmenu", $.mobile.widget, { return false; }) .bind("pagehide", function(){ - window.scrollTo(currScroll[0], currScroll[1]); select.focus(); listbox.append( list ).removeAttr('style'); return false; diff --git a/js/jquery.mobile.js b/js/jquery.mobile.js index 5cbe540d..35fa89f9 100644 --- a/js/jquery.mobile.js +++ b/js/jquery.mobile.js @@ -138,12 +138,12 @@ $.mobile.idStringEscape = idStringEscape; // hide address bar - function hideBrowserChrome() { + function silentScroll( ypos ) { // prevent scrollstart and scrollstop events jQuery.event.special.scrollstart.enabled = false; setTimeout(function() { - window.scrollTo( 0, 0 ); - },0); + window.scrollTo( 0, ypos || 0 ); + },20); setTimeout(function() { jQuery.event.special.scrollstart.enabled = true; }, 150 ); @@ -354,6 +354,12 @@ //kill the keyboard jQuery( window.document.activeElement ).blur(); + //get current scroll distance + var currScroll = $window.scrollTop(); + + //set as data for returning to that spot + from.data('lastScroll', currScroll); + //trigger before show/hide events from.data("page")._trigger("beforehide", {nextPage: to}); to.data("page")._trigger("beforeshow", {prevPage: from}); @@ -374,9 +380,12 @@ if( duplicateCachedPage != null ){ duplicateCachedPage.remove(); } + + //jump to top or prev scroll, if set + silentScroll( to.data( 'lastScroll' ) ); } - if(transition && (transition !== 'none')){ + if(transition && (transition !== 'none')){ $pageContainer.addClass('ui-mobile-viewport-transitioning'); // animate in / out from.addClass( transition + " out " + ( back ? "reverse" : "" ) ); @@ -604,7 +613,7 @@ jQuery.extend({ pageLoading: pageLoading, changePage: changePage, - hideBrowserChrome: hideBrowserChrome + silentScroll: silentScroll }); //dom-ready @@ -633,6 +642,6 @@ $html.removeClass('ui-mobile-rendering'); }); - $window.load(hideBrowserChrome); + $window.load(silentScroll); })( jQuery, this );