jquery-mobile/experiments/scrollview/scrollview.js

55 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2011-11-04 21:43:27 +00:00
function ResizePageContentHeight(page) {
var $page = $(page),
$content = $page.children( ".ui-content" ),
2011-11-08 02:14:29 +00:00
hh = $page.children( ".ui-header" ).outerHeight() || 0,
fh = $page.children( ".ui-footer" ).outerHeight() || 0,
pt = parseFloat($content.css( "padding-top" )),
pb = parseFloat($content.css( "padding-bottom" )),
2011-11-04 21:43:27 +00:00
wh = window.innerHeight;
$content.height(wh - (hh + fh) - (pt + pb));
}
$( ":jqmData(role='page')" ).live( "pageshow", function(event) {
2011-11-04 21:43:27 +00:00
var $page = $( this );
// For the demos that use this script, we want the content area of each
// page to be scrollable in the 'y' direction.
2011-11-04 21:43:27 +00:00
$page.find( ".ui-content" ).attr( "data-" + $.mobile.ns + "scroll", "y" );
// This code that looks for [data-scroll] will eventually be folded
// into the jqm page processing code when scrollview support is "official"
// instead of "experimental".
$page.find( ":jqmData(scroll):not(.ui-scrollview-clip)" ).each(function () {
2011-11-04 21:43:27 +00:00
var $this = $( this );
// XXX: Remove this check for ui-scrolllistview once we've
// integrated list divider support into the main scrollview class.
2011-11-04 21:43:27 +00:00
if ( $this.hasClass( "ui-scrolllistview" ) ) {
$this.scrolllistview();
2011-11-04 21:43:27 +00:00
} else {
var st = $this.jqmData( "scroll" ) + "",
paging = st && st.search(/^[xy]p$/) != -1,
2011-11-04 21:43:27 +00:00
dir = st && st.search(/^[xy]/) != -1 ? st.charAt(0) : null,
2011-11-04 21:43:27 +00:00
opts = {
direction: dir || undefined,
paging: paging || undefined,
scrollMethod: $this.jqmData("scroll-method") || undefined
};
$this.scrollview( opts );
}
});
// For the demos, we want to make sure the page being shown has a content
// area that is sized to fit completely within the viewport. This should
// also handle the case where pages are loaded dynamically.
ResizePageContentHeight( event.target );
});
$( window ).bind( "orientationchange", function( event ) {
ResizePageContentHeight( $( ".ui-page" ) );
2011-11-04 21:43:27 +00:00
});