Skip to content
This repository
Browse code

scroll updates

maintains scroll position (css3 scrolling only)
only uses iScroll if touch is supported, otherwise uses browser default
scrolling
  • Loading branch information...
commit 586b4d729386e69b1096e0ffa005898211c02e81 1 parent bca792c
Andrew Trice authored

Showing 1 changed file with 37 additions and 23 deletions. Show diff stats Hide diff stats

  1. +37 23 src/viewnavigator/viewnavigator.js
60 src/viewnavigator/viewnavigator.js
@@ -267,36 +267,50 @@ ViewNavigator.prototype.updateView = function( viewDescriptor ) {
267 267 }
268 268
269 269
  270 +ViewNavigator.prototype.destroyScroller = function() {
  271 +
  272 + if ( !this.winPhone ) {
  273 + if ( this.scroller != null ) {
  274 + this.scroller.destroy();
  275 + this.scroller = null;
  276 + }
  277 + }
  278 +}
  279 +
  280 +
270 281 ViewNavigator.prototype.resetScroller = function() {
271 282
272 283 var id = this.contentViewHolder.attr( "id" );
273 284 var currentViewDescriptor = this.history[ this.history.length-1];
  285 + this.destroyScroller();
274 286
275 287 if ( !this.winPhone ) {
276   - if ( this.scroller != null ) {
277   - this.scroller.destroy();
278   - this.scroller = null;
279   - }
280   - if ( id && !(currentViewDescriptor && currentViewDescriptor.scroll === false)) {
  288 + if ( id && !(currentViewDescriptor && currentViewDescriptor.scroll == false)) {
281 289 var self = this;
282   - setTimeout( function() {
283   -
284   - //use this to mantain scroll position when scroller is destroyed
285   - var targetDiv = $( $("#"+id ).children()[0] );
286   - var scrollY= targetDiv.attr( "scrollY" );
287   - var originalTopMargin = targetDiv.attr( "originalTopMargin" );
288   - if ( scrollY != undefined && scrollY != "" ){
289   - // console.log( "resetScroller scrollY: " + scrollY)
290   - // targetDiv.css( "margin-top", originalTopMargin );
291   - var cssString = "translate3d(0px, "+(originalTopMargin).toString()+"px, 0px)";
292   - targetDiv.css( "-webkit-transform", cssString );
293   - }
294   - self.scroller = new iScroll( id );
295   - if ( scrollY != undefined && scrollY != "" ) {
296   - self.scroller.scrollTo( 0, parseInt( scrollY ) );
297   - }
298   - }, 10 );
299   - //this.scroller = new iScroll( id );
  290 + if ( this.touchEnabled ){
  291 + setTimeout( function() {
  292 +
  293 + //use this to mantain scroll position when scroller is destroyed
  294 + var targetDiv = $( $("#"+id ).children()[0] );
  295 + var scrollY= targetDiv.attr( "scrollY" );
  296 + var originalTopMargin = targetDiv.attr( "originalTopMargin" );
  297 + if ( currentViewDescriptor.maintainScrollPosition !== false && scrollY != undefined && scrollY != "" ){
  298 + // console.log( "resetScroller scrollY: " + scrollY)
  299 + // targetDiv.css( "margin-top", originalTopMargin );
  300 + var cssString = "translate3d(0px, "+(originalTopMargin).toString()+"px, 0px)";
  301 + targetDiv.css( "-webkit-transform", cssString );
  302 + }
  303 + self.scroller = new iScroll( id );
  304 + if ( currentViewDescriptor.maintainScrollPosition !== false && scrollY != undefined && scrollY != "" ) {
  305 + self.scroller.scrollTo( 0, parseInt( scrollY ) );
  306 + }
  307 + }, 10 );
  308 + //this.scroller = new iScroll( id );
  309 + }
  310 + else {
  311 + var target = $("#"+id );
  312 + target.css( "overflow", "auto" );
  313 + }
300 314 }
301 315 }
302 316 }

0 comments on commit 586b4d7

Please sign in to comment.
Something went wrong with that request. Please try again.