mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-03-16 22:10:25 +00:00
changed hideBrowserChrome function to "silentScroll". Scrolls to a particular location while disabling scroll event listening.
Function accepts a Y positioning argument, or defaults to 0 if undefined. Now page transitions cache their previous scroll position when leaving, and that position will be remembered when revisting that page. This change also includes a fix for webOS to use this new feature and set the previous scroll to the location of the clicked selectmenu (so after using the select, it'll scroll back to its location, even though webOS doesn't support scrolltop) Fixes #355
This commit is contained in:
parent
9dce1c3c02
commit
b1bded6dde
2 changed files with 26 additions and 11 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
Loading…
Reference in a new issue