Skip to content

Commit b645781

Browse files
author
scottjehl
committed
implemented native overflow scrolling based on support for -[prefix]-overflow-scrolling: touch. True fixed headers and footers come supported as well.
1 parent bb4e1ca commit b645781

File tree

9 files changed

+135
-23
lines changed

9 files changed

+135
-23
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ JSFILES = js/jquery.ui.widget.js \
6767
js/jquery.mobile.controlGroup.js \
6868
js/jquery.mobile.links.js \
6969
js/jquery.mobile.fixHeaderFooter.js \
70+
js/jquery.mobile.fixHeaderFooter.native.js \
7071
js/jquery.mobile.media.classes.js \
7172
js/jquery.mobile.init.js
7273

build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
jquery.mobile.controlGroup.js,
5252
jquery.mobile.links.js,
5353
jquery.mobile.fixHeaderFooter.js,
54+
jquery.mobile.fixHeaderFooter.native.js,
5455
jquery.mobile.media.classes.js,
5556
jquery.mobile.init.js"/>
5657

docs/_assets/css/jqm-docs.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dt code, dd code { font-size:1.3em; line-height:150%; }
2121
pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; }
2222

2323
#jqm-homeheader img { width: 235px; }
24+
img { max-width: 100%; }
2425

2526
.ui-header .jqm-home { top:0.65em; }
2627
nav { margin: 0; }

js/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'jquery.mobile.controlGroup.js',
3434
'jquery.mobile.links.js',
3535
'jquery.mobile.fixHeaderFooter.js',
36+
'jquery.mobile.fixHeaderFooter.native.js',
3637
'jquery.mobile.media.classes.js',
3738
'jquery.mobile.init.js'
3839
);

js/jquery.mobile.fixHeaderFooter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $.fn.fixHeaderFooter = function( options ) {
3737
// single controller for all showing,hiding,toggling
3838
$.mobile.fixedToolbars = (function() {
3939

40-
if ( !$.support.scrollTop ) {
40+
if ( !$.support.scrollTop || $.support.touchOverflow ) {
4141
return;
4242
}
4343

@@ -361,7 +361,7 @@ $( document ).bind( "pagecreate create", function( event ) {
361361

362362
$( event.target ).each(function() {
363363

364-
if ( !$.support.scrollTop ) {
364+
if ( !$.support.scrollTop || $.support.touchOverflow ) {
365365
return this;
366366
}
367367

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* jQuery Mobile Framework : "fixHeaderFooter" native plugin - Behavior for "fixed" headers,footers, and scrolling inner content
3+
* Copyright (c) jQuery Project
4+
* Dual licensed under the MIT or GPL Version 2 licenses.
5+
* http://jquery.org/license
6+
*/
7+
8+
(function( $, undefined ) {
9+
10+
$.mobile.touchOverflowEnabled = true;
11+
12+
$( document ).bind( "pagecreate", function( event ) {
13+
if( $.support.touchOverflow && $.mobile.touchOverflowEnabled ){
14+
15+
var $target = $( event.target ),
16+
scrollStartY = 0;
17+
18+
if( $target.is( ":jqmData(role='page')" ) ){
19+
20+
$target.each(function() {
21+
var $page = $( this ),
22+
$fixies = $page.find( ":jqmData(role='header'), :jqmData(role='footer')" ).filter( ":jqmData(position='fixed')" ),
23+
fullScreen = $page.jqmData( "fullscreen" ),
24+
$scrollElem = $fixies.length ? $page.find( ".ui-content" ) : $page;
25+
26+
$page.addClass( "ui-mobile-touch-overflow" );
27+
28+
$scrollElem.bind( "scrollstop", function(){
29+
if( $scrollElem.scrollTop() > 0 ){
30+
window.scrollTo( 0, $.mobile.defaultHomeScroll );
31+
}
32+
});
33+
34+
if( $fixies.length ){
35+
36+
$page.addClass( "ui-native-fixed" );
37+
38+
if( fullScreen ){
39+
40+
$page.addClass( "ui-native-fullscreen" );
41+
42+
$fixies.addClass( "fade in" );
43+
44+
$( document ).bind( "vclick", function(){
45+
$fixies
46+
.removeClass( "ui-native-bars-hidden" )
47+
.toggleClass( "in out" )
48+
.animationComplete(function(){
49+
$(this).not( ".in" ).addClass( "ui-native-bars-hidden" );
50+
});
51+
} );
52+
}
53+
}
54+
});
55+
}
56+
}
57+
});
58+
59+
})( jQuery );

js/jquery.mobile.navigation.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,17 @@
409409

410410
lastScrollEnabled = false;
411411

412-
var active = $.mobile.urlHistory.getActive();
412+
var active = $.mobile.urlHistory.getActive(),
413+
activePage = $( ".ui-page-active" ),
414+
scrollElem = $( window ),
415+
touchOverflow = $.support.touchOverflow && $.mobile.touchOverflowEnabled;
416+
417+
if( touchOverflow ){
418+
scrollElem = activePage.is( ".ui-native-fixed" ) ? activePage.find( ".ui-content" ) : activePage;
419+
}
413420

414421
if( active ){
415-
var lastScroll = $.support.touchOverflow ? $( ".ui-page-active" ).scrollTop() : $( window ).scrollTop();
422+
var lastScroll = scrollElem.scrollTop();
416423

417424
// Set active page's lastScroll prop.
418425
// If the Y location we're scrolling to is less than minScrollBack, let it go.
@@ -429,11 +436,13 @@
429436
// Make the iOS clock quick-scroll work again if we're using native overflow scrolling
430437
/*
431438
if( $.support.touchOverflow ){
432-
$( window ).bind( "scrollstop", function(){
433-
if( $( this ).scrollTop() === 0 ){
434-
$.mobile.activePage.scrollTop( 0 );
435-
}
436-
});
439+
if( $.mobile.touchOverflowEnabled ){
440+
$( window ).bind( "scrollstop", function(){
441+
if( $( this ).scrollTop() === 0 ){
442+
$.mobile.activePage.scrollTop( 0 );
443+
}
444+
});
445+
}
437446
}
438447
*/
439448

@@ -442,9 +451,10 @@
442451

443452
//get current scroll distance
444453
var active = $.mobile.urlHistory.getActive(),
445-
toScroll = active.lastScroll || ( $.support.touchOverflow ? 0 : $.mobile.defaultHomeScroll ),
454+
touchOverflow = $.support.touchOverflow && $.mobile.touchOverflowEnabled,
455+
toScroll = active.lastScroll || ( touchOverflow ? 0 : $.mobile.defaultHomeScroll ),
446456
screenHeight = getScreenHeight();
447-
457+
448458
// Scroll to top, hide addr bar
449459
window.scrollTo( 0, $.mobile.defaultHomeScroll );
450460

@@ -453,7 +463,7 @@
453463
fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
454464
}
455465

456-
if( !$.support.touchOverflow ){
466+
if( !touchOverflow){
457467
toPage.height( screenHeight + toScroll );
458468
}
459469

@@ -462,13 +472,19 @@
462472
//clear page loader
463473
$.mobile.hidePageLoadingMsg();
464474

465-
if( $.support.touchOverflow && toScroll ){
475+
if( touchOverflow && toScroll ){
476+
466477
toPage.addClass( "ui-mobile-pre-transition" );
467478
// Send focus to page as it is now display: block
468479
reFocus( toPage );
469480

470481
//set page's scrollTop to remembered distance
471-
toPage.scrollTop( toScroll );
482+
if( toPage.is( ".ui-native-fixed" ) ){
483+
toPage.find( ".ui-content" ).scrollTop( toScroll );
484+
}
485+
else{
486+
toPage.scrollTop( toScroll );
487+
}
472488
}
473489

474490
//find the transition handler for the specified transition. If there
@@ -479,20 +495,20 @@
479495

480496
promise.done(function() {
481497
//reset toPage height back
482-
if( !$.support.touchOverflow ){
498+
if( !touchOverflow ){
483499
toPage.height( "" );
484500
// Send focus to the newly shown page
485501
reFocus( toPage );
486502
}
487503

488504
// Jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
489-
if( !$.support.touchOverflow ){
505+
if( !touchOverflow ){
490506
$.mobile.silentScroll( toScroll );
491507
}
492508

493509
//trigger show/hide events
494510
if( fromPage ) {
495-
if( !$.support.touchOverflow ){
511+
if( !touchOverflow ){
496512
fromPage.height( "" );
497513
}
498514

js/jquery.mobile.support.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,4 @@ if ( !$.support.boxShadow ) {
118118
$( "html" ).addClass( "ui-mobile-nosupport-boxshadow" );
119119
}
120120

121-
// For opting into touch overflow scrolling
122-
if( $.support.touchOverflow ){
123-
$( "html" ).addClass( "ui-mobile-touch-overflow" );
124-
}
125-
126121
})( jQuery );

themes/default/jquery.mobile.core.css

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
.landscape .ui-page { min-height: 300px; }
2424

2525
/* native overflow scrolling */
26-
.ui-mobile.ui-mobile-touch-overflow .ui-page {
26+
.ui-page.ui-mobile-touch-overflow,
27+
.ui-mobile-touch-overflow.ui-native-fixed .ui-content {
2728
overflow: auto;
2829
height: 100%;
2930
-webkit-overflow-scrolling: touch;
@@ -62,6 +63,43 @@
6263
.ui-content { border-width: 0; overflow: visible; overflow-x: hidden; padding: 15px; }
6364
.ui-page-fullscreen .ui-content { padding:0; }
6465

66+
/* native fixed headers and footers */
67+
.ui-mobile-touch-overflow.ui-page.ui-native-fixed,
68+
.ui-mobile-touch-overflow.ui-page.ui-native-fullscreen {
69+
overflow: visible;
70+
}
71+
.ui-mobile-touch-overflow.ui-native-fixed .ui-header,
72+
.ui-mobile-touch-overflow.ui-native-fixed .ui-footer {
73+
position: fixed;
74+
left: 0;
75+
right: 0;
76+
top: 0;
77+
z-index: 200;
78+
}
79+
.ui-mobile-touch-overflow.ui-page.ui-native-fixed .ui-footer {
80+
top: auto;
81+
bottom: 0;
82+
}
83+
.ui-mobile-touch-overflow.ui-native-fixed .ui-content {
84+
padding-top: 2.5em;
85+
padding-bottom: 3em;
86+
top: 0;
87+
bottom: 0;
88+
height: auto;
89+
position: absolute;
90+
}
91+
.ui-mobile-touch-overflow.ui-native-fullscreen .ui-content {
92+
padding-top: 0;
93+
padding-bottom: 0;
94+
}
95+
.ui-mobile-touch-overflow.ui-native-fullscreen .ui-header,
96+
.ui-mobile-touch-overflow.ui-native-fullscreen .ui-footer {
97+
opacity: .9;
98+
}
99+
.ui-native-bars-hidden {
100+
display: none;
101+
}
102+
65103
/* icons sizing */
66104
.ui-icon { width: 18px; height: 18px; }
67105

0 commit comments

Comments
 (0)