scroll updates

maintains scroll position (css3 scrolling only)
only uses iScroll if touch is supported, otherwise uses browser default
scrolling
This commit is contained in:
Andrew Trice 2012-05-29 21:07:48 -04:00
parent bca792c256
commit 586b4d7293
1 changed files with 38 additions and 24 deletions

View File

@ -267,37 +267,51 @@ ViewNavigator.prototype.updateView = function( viewDescriptor ) {
} }
ViewNavigator.prototype.resetScroller = function() { ViewNavigator.prototype.destroyScroller = function() {
var id = this.contentViewHolder.attr( "id" );
var currentViewDescriptor = this.history[ this.history.length-1];
if ( !this.winPhone ) { if ( !this.winPhone ) {
if ( this.scroller != null ) { if ( this.scroller != null ) {
this.scroller.destroy(); this.scroller.destroy();
this.scroller = null; this.scroller = null;
} }
if ( id && !(currentViewDescriptor && currentViewDescriptor.scroll === false)) { }
}
ViewNavigator.prototype.resetScroller = function() {
var id = this.contentViewHolder.attr( "id" );
var currentViewDescriptor = this.history[ this.history.length-1];
this.destroyScroller();
if ( !this.winPhone ) {
if ( id && !(currentViewDescriptor && currentViewDescriptor.scroll == false)) {
var self = this; var self = this;
if ( this.touchEnabled ){
setTimeout( function() { setTimeout( function() {
//use this to mantain scroll position when scroller is destroyed //use this to mantain scroll position when scroller is destroyed
var targetDiv = $( $("#"+id ).children()[0] ); var targetDiv = $( $("#"+id ).children()[0] );
var scrollY= targetDiv.attr( "scrollY" ); var scrollY= targetDiv.attr( "scrollY" );
var originalTopMargin = targetDiv.attr( "originalTopMargin" ); var originalTopMargin = targetDiv.attr( "originalTopMargin" );
if ( scrollY != undefined && scrollY != "" ){ if ( currentViewDescriptor.maintainScrollPosition !== false && scrollY != undefined && scrollY != "" ){
// console.log( "resetScroller scrollY: " + scrollY) // console.log( "resetScroller scrollY: " + scrollY)
// targetDiv.css( "margin-top", originalTopMargin ); // targetDiv.css( "margin-top", originalTopMargin );
var cssString = "translate3d(0px, "+(originalTopMargin).toString()+"px, 0px)"; var cssString = "translate3d(0px, "+(originalTopMargin).toString()+"px, 0px)";
targetDiv.css( "-webkit-transform", cssString ); targetDiv.css( "-webkit-transform", cssString );
} }
self.scroller = new iScroll( id ); self.scroller = new iScroll( id );
if ( scrollY != undefined && scrollY != "" ) { if ( currentViewDescriptor.maintainScrollPosition !== false && scrollY != undefined && scrollY != "" ) {
self.scroller.scrollTo( 0, parseInt( scrollY ) ); self.scroller.scrollTo( 0, parseInt( scrollY ) );
} }
}, 10 ); }, 10 );
//this.scroller = new iScroll( id ); //this.scroller = new iScroll( id );
} }
else {
var target = $("#"+id );
target.css( "overflow", "auto" );
}
}
} }
} }