Permalink
Browse files

scroll updates

maintains scroll position (css3 scrolling only)
only uses iScroll if touch is supported, otherwise uses browser default
scrolling
  • Loading branch information...
1 parent bca792c commit 586b4d729386e69b1096e0ffa005898211c02e81 @triceam committed May 30, 2012
Showing with 37 additions and 23 deletions.
  1. +37 −23 src/viewnavigator/viewnavigator.js
@@ -267,36 +267,50 @@ ViewNavigator.prototype.updateView = function( viewDescriptor ) {
}
+ViewNavigator.prototype.destroyScroller = function() {
+
+ if ( !this.winPhone ) {
+ if ( this.scroller != null ) {
+ this.scroller.destroy();
+ this.scroller = null;
+ }
+ }
+}
+
+
ViewNavigator.prototype.resetScroller = function() {
var id = this.contentViewHolder.attr( "id" );
var currentViewDescriptor = this.history[ this.history.length-1];
+ this.destroyScroller();
if ( !this.winPhone ) {
- if ( this.scroller != null ) {
- this.scroller.destroy();
- this.scroller = null;
- }
- if ( id && !(currentViewDescriptor && currentViewDescriptor.scroll === false)) {
+ if ( id && !(currentViewDescriptor && currentViewDescriptor.scroll == false)) {
var self = this;
- setTimeout( function() {
-
- //use this to mantain scroll position when scroller is destroyed
- var targetDiv = $( $("#"+id ).children()[0] );
- var scrollY= targetDiv.attr( "scrollY" );
- var originalTopMargin = targetDiv.attr( "originalTopMargin" );
- if ( scrollY != undefined && scrollY != "" ){
- // console.log( "resetScroller scrollY: " + scrollY)
- // targetDiv.css( "margin-top", originalTopMargin );
- var cssString = "translate3d(0px, "+(originalTopMargin).toString()+"px, 0px)";
- targetDiv.css( "-webkit-transform", cssString );
- }
- self.scroller = new iScroll( id );
- if ( scrollY != undefined && scrollY != "" ) {
- self.scroller.scrollTo( 0, parseInt( scrollY ) );
- }
- }, 10 );
- //this.scroller = new iScroll( id );
+ if ( this.touchEnabled ){
+ setTimeout( function() {
+
+ //use this to mantain scroll position when scroller is destroyed
+ var targetDiv = $( $("#"+id ).children()[0] );
+ var scrollY= targetDiv.attr( "scrollY" );
+ var originalTopMargin = targetDiv.attr( "originalTopMargin" );
+ if ( currentViewDescriptor.maintainScrollPosition !== false && scrollY != undefined && scrollY != "" ){
+ // console.log( "resetScroller scrollY: " + scrollY)
+ // targetDiv.css( "margin-top", originalTopMargin );
+ var cssString = "translate3d(0px, "+(originalTopMargin).toString()+"px, 0px)";
+ targetDiv.css( "-webkit-transform", cssString );
+ }
+ self.scroller = new iScroll( id );
+ if ( currentViewDescriptor.maintainScrollPosition !== false && scrollY != undefined && scrollY != "" ) {
+ self.scroller.scrollTo( 0, parseInt( scrollY ) );
+ }
+ }, 10 );
+ //this.scroller = new iScroll( id );
+ }
+ else {
+ var target = $("#"+id );
+ target.css( "overflow", "auto" );
+ }
}
}
}

0 comments on commit 586b4d7

Please sign in to comment.