Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Issue #4535: Modified click handler to remove the call to window.history... #4536

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 43 additions & 6 deletions js/jquery.mobile.navigation.js
Expand Up @@ -1114,6 +1114,9 @@ define( [
toPage.jqmData( "title", pageTitle );
}

// This sets the scrollTo value for the page we're transitioning to
toPage.toPageScrollTo = settings.toPageScrollPosition;

// Make sure we have a transition defined.
settings.transition = settings.transition ||
( ( historyDir && !activeIsInitialPage ) ? active.transition : undefined ) ||
Expand Down Expand Up @@ -1309,17 +1312,51 @@ define( [
window.setTimeout( function() { removeActiveLinkClass( true ); }, 200 );
};

//if there's a data-rel=back attr, go back in history
if( $link.is( ":jqmData(rel='back')" ) ) {
window.history.back();
return false;
}
// set up defaults for the new data-rel='back' link handling
var prev = null;
var toPageScrollTo = 0;

//if there's a data-rel=back attr, go back in history
if( $link.is( ":jqmData(rel='back')" ) ) {

// Instead of calling window.history.back() let's use the urlHistory object to get the
// previous url. This fixes a bounce down to the scrollTo of the previous page caused
// by the call to window.history.back()
prev = $.mobile.urlHistory.getPrev();
}

var baseUrl = getClosestBaseUrl( $link ),

//get href, if defined, otherwise default to empty hash
href = path.makeUrlAbsolute( $link.attr( "href" ) || "#", baseUrl );

// if prev is not null, then we must be going back
if ( prev != null ) {

var lastChar = href.substring(href.length - 1, href.length);

if ( lastChar === "#" ) {

href = path.makeUrlAbsolute( href + prev.url );

} else {

href = path.makeUrlAbsolute( prev.url );
}

// We need this so we can pass it as a changePage setting
toPageScrollTo = prev.lastScroll;

// removing the currently active entry from urlHistory
removed_active = $.mobile.urlHistory.stack.pop();

// removing previous item from stack too since we already have the url and it will be added back on the stack when we get there
removed_previous = $.mobile.urlHistory.stack.pop();

// decrement urlHistory activeIndex
$.mobile.urlHistory.activeIndex = $.mobile.urlHistory.activeIndex - 1;
}

//if ajax is disabled, exit early
if( !$.mobile.ajaxEnabled && !path.isEmbeddedPage( href ) ){
httpCleanup();
Expand Down Expand Up @@ -1386,7 +1423,7 @@ define( [
$.mobile.popup.handleLink( $link );
}
else {
$.mobile.changePage( href, { transition: transition, reverse: reverse, role: role } );
$.mobile.changePage( href, { transition: transition, reverse: reverse, role: role, toPageScrollPosition: toPageScrollTo } );
}
event.preventDefault();
});
Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.transition.js
Expand Up @@ -22,7 +22,7 @@ var createHandler = function( sequential ){
var deferred = new $.Deferred(),
reverseClass = reverse ? " reverse" : "",
active = $.mobile.urlHistory.getActive(),
toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
toScroll = ( $to.toPageScrollTo || active.lastScroll ) || $.mobile.defaultHomeScroll,
screenHeight = $.mobile.getScreenHeight(),
maxTransitionOverride = $.mobile.maxTransitionWidth !== false && $( window ).width() > $.mobile.maxTransitionWidth,
none = !$.support.cssTransitions || maxTransitionOverride || !name || name === "none",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/popup/popup_core.js
Expand Up @@ -365,7 +365,7 @@
closed: { src: $( "#test-popup" ), event: "closed.openCloseQuickStep1" },
hashchange1: { src: $( window ), event: "hashchange.openCloseQuickStep1a" },
hashchange2: { src: $( window ), event: "hashchange.openCloseQuickStep1b" },
timeout: { src: null, length: 600 }
timeout: { src: null, length: 700 }
},

function( result ) {
Expand Down