|
386 | 386 | //function for transitioning between two existing pages
|
387 | 387 | function transitionPages( toPage, fromPage, transition, reverse ) {
|
388 | 388 |
|
389 |
| - |
390 | 389 | //get current scroll distance
|
391 | 390 | var currScroll = $window.scrollTop(),
|
392 | 391 | toScroll = toPage.data( "lastScroll" ) || 0;
|
393 | 392 |
|
394 |
| - $.mobile.silentScroll(); |
395 |
| - |
| 393 | + //if scrolled down, scroll to top |
| 394 | + if( currScroll ){ |
| 395 | + window.scrollTo( 0, 0 ); |
| 396 | + } |
| 397 | + |
| 398 | + //if the Y location we're scrolling to is less than 10px, let it go for sake of smoothness |
| 399 | + if( toScroll < 20 ){ |
| 400 | + toScroll = 0; |
| 401 | + } |
| 402 | + |
396 | 403 | if( fromPage ) {
|
397 | 404 | //set as data for returning to that spot
|
398 | 405 | fromPage
|
399 | 406 | .height( screen.height )
|
400 | 407 | .jqmData( "lastScroll", currScroll )
|
401 | 408 | .jqmData( "lastClicked", $activeClickedLink );
|
| 409 | + |
402 | 410 | //trigger before show/hide events
|
403 | 411 | fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
|
404 | 412 | }
|
|
416 | 424 | promise = th( transition, reverse, toPage, fromPage );
|
417 | 425 |
|
418 | 426 | promise.done(function() {
|
| 427 | + //reset toPage height bac |
| 428 | + toPage.height( "" ); |
| 429 | + |
419 | 430 | //jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
|
420 |
| - $.mobile.silentScroll( toPage.jqmData( "lastScroll" ) || 0 ); |
421 |
| - $( document ).one( "silentscroll", function() { reFocus( toPage ); } ); |
| 431 | + if( toScroll ){ |
| 432 | + $.mobile.silentScroll( toScroll ); |
| 433 | + $( document ).one( "silentscroll", function() { reFocus( toPage ); } ); |
| 434 | + } |
| 435 | + else{ |
| 436 | + reFocus( toPage ); |
| 437 | + } |
422 | 438 |
|
423 | 439 | //trigger show/hide events
|
424 | 440 | if( fromPage ) {
|
425 | 441 | fromPage.height("").data( "page" )._trigger( "hide", null, { nextPage: toPage } );
|
426 | 442 | }
|
| 443 | + |
427 | 444 | //trigger pageshow, define prevPage as either fromPage or empty jQuery obj
|
428 |
| - toPage.height("").data( "page" )._trigger( "show", null, { prevPage: fromPage || $( "" ) } ); |
| 445 | + toPage.data( "page" )._trigger( "show", null, { prevPage: fromPage || $( "" ) } ); |
429 | 446 |
|
430 | 447 | });
|
431 | 448 |
|
|
0 commit comments