Merge branch 'master' of github.com:jquery/jquery-mobile

This commit is contained in:
scottjehl 2011-01-24 13:05:04 -05:00
commit 80b0d9ef4b
2 changed files with 61 additions and 15 deletions

View file

@ -145,10 +145,12 @@
//scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
silentScroll: function( ypos ) {
ypos = ypos || 0;
// prevent scrollstart and scrollstop events
$.event.special.scrollstart.enabled = false;
setTimeout(function() {
window.scrollTo( 0, ypos || 0 );
window.scrollTo( 0, ypos );
$(document).trigger("silentscroll", { x: 0, y: ypos });
},20);
setTimeout(function() {
$.event.special.scrollstart.enabled = true;

View file

@ -21,6 +21,8 @@ $.fn.fixHeaderFooter = function(options){
$.fixedToolbars = (function(){
if( !$.support.scrollTop ){ return; }
var currentstate = 'inline',
autoHideMode = false,
showDelay = 100,
delayTimer,
ignoreTargets = 'a,input,textarea,select,button,label,.ui-header-fixed,.ui-footer-fixed',
toolbarSelector = '.ui-header-fixed:first, .ui-footer-fixed:not(.ui-footer-duplicate):last',
@ -32,6 +34,24 @@ $.fixedToolbars = (function(){
scrollTriggered = false,
touchToggleEnabled = true;
function showEventCallback(event)
{
// An event that affects the dimensions of the visual viewport has
// been triggered. If the header and/or footer for the current page are in overlay
// mode, we want to hide them, and then fire off a timer to show them at a later
// point. Events like a resize can be triggered continuously during a scroll, on
// some platforms, so the timer is used to delay the actual positioning until the
// flood of events have subsided.
//
// If we are in autoHideMode, we don't do anything because we know the scroll
// callbacks for the plugin will fire off a show when the scrolling has stopped.
if (!autoHideMode && currentstate == 'overlay') {
if (!delayTimer)
$.fixedToolbars.hide(true);
$.fixedToolbars.startShowTimer();
}
}
$(function() {
$(document)
.bind(touchStartEvent,function(event){
@ -40,14 +60,6 @@ $.fixedToolbars = (function(){
stateBefore = currentstate;
}
})
.bind('scrollstart',function(event){
if( $(event.target).closest(ignoreTargets).length ){ return; } //because it could be a touchmove...
scrollTriggered = true;
if(stateBefore == null){ stateBefore = currentstate; }
if (stateBefore == 'overlay') {
$.fixedToolbars.hide(true);
}
})
.bind(touchStopEvent,function(event){
if( touchToggleEnabled ) {
if( $(event.target).closest(ignoreTargets).length ){ return; }
@ -57,14 +69,36 @@ $.fixedToolbars = (function(){
}
}
})
.bind('scrollstart',function(event){
if( $(event.target).closest(ignoreTargets).length ){ return; } //because it could be a touchmove...
scrollTriggered = true;
if(stateBefore == null){ stateBefore = currentstate; }
// We only enter autoHideMode if the headers/footers are in
// an overlay state or the show timer was started. If the
// show timer is set, clear it so the headers/footers don't
// show up until after we're done scrolling.
var isOverlayState = stateBefore == 'overlay';
autoHideMode = isOverlayState || !!delayTimer;
if (autoHideMode){
$.fixedToolbars.clearShowTimer();
if (isOverlayState) {
$.fixedToolbars.hide(true);
}
}
})
.bind('scrollstop',function(event){
if( $(event.target).closest(ignoreTargets).length ){ return; }
scrollTriggered = false;
if (stateBefore == 'overlay') {
$.fixedToolbars.show();
if (autoHideMode) {
autoHideMode = false;
$.fixedToolbars.startShowTimer();
}
stateBefore = null;
});
})
.bind('silentscroll', showEventCallback);
$(window).bind('resize', showEventCallback);
});
//before page is shown, check for duplicate footer
@ -152,6 +186,7 @@ $.fixedToolbars = (function(){
//exposed methods
return {
show: function(immediately, page){
$.fixedToolbars.clearShowTimer();
currentstate = 'overlay';
var $ap = page ? $(page) : ($.mobile.activePage ? $.mobile.activePage : $(".ui-page-active"));
return $ap.children( toolbarSelector ).each(function(){
@ -201,10 +236,19 @@ $.fixedToolbars = (function(){
}
});
},
hideAfterDelay: function(){
startShowTimer: function(){
$.fixedToolbars.clearShowTimer();
var args = $.makeArray(arguments);
delayTimer = setTimeout(function(){
$.fixedToolbars.hide();
}, 3000);
delayTimer = undefined;
$.fixedToolbars.show.apply(null, args);
}, showDelay);
},
clearShowTimer: function() {
if (delayTimer) {
clearTimeout(delayTimer);
}
delayTimer = undefined;
},
toggle: function(from){
if(from){ currentstate = from; }