Permalink
Browse files

fix for transitions

  • Loading branch information...
johnbender committed Dec 3, 2012
1 parent 8ee4318 commit 921bf778d63c91f2e7f915892c45e3d25dc58f38
@@ -66,6 +66,7 @@ define( [
//set the generated BASE element's href attribute to a new page's base path
set: function( href ) {
href = path.parseUrl(href).hrefNoHash;
base.element.attr( "href", path.makeUrlAbsolute( href, documentBase ) );
},
@@ -792,7 +793,14 @@ define( [
// Normally, we tack on a dialog hash key, but if this is the location of a stale dialog,
// we reuse the URL from the entry
url = ( active.url || "" ) + ( alreadyThere ? "" : dialogHashKey );
url = ( active.url || "" );
// account for absolute urls instead of just relative urls use as hashes
if( !alreadyThere && url.indexOf("#") > -1 ) {
url += dialogHashKey;
} else {
url += "#" + dialogHashKey;
}
// tack on another dialogHashKey if this is the same as the initial hash
// this makes sure that a history entry is created for this dialog
@@ -1123,9 +1131,10 @@ define( [
transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined,
// default options for the changPage calls made after examining the current state
// of the page and the hash
// of the page and the hash, NOTE that the transition is derived from the previous
// history entry
changePageOptions = {
transition: transition,
transition: (urlHistory.getLast() || {}).transition || transition,
changeHash: false,
fromHashChange: true,
reverse: data.direction === "back"
View
@@ -17,21 +17,34 @@ define([
// so that end users don't have to think about it. Punting for now
// TODO !! move the event bindings into callbacks on the navigate event
$.navigate = function( url, data, noEvents ) {
var state, href, parsed, hash,
resolutionUrl = path.isPath(url) ? path.getLocation() : $.mobile.getDocumentUrl();
var state, href, parsed, loc, hash,
resolutionUrl = path.isPath( url ) ? path.getLocation() : $.mobile.getDocumentUrl();
// Get the url as it would look squashed on to the current resolution url
href = path.squash( url, resolutionUrl );
href = path.squash( url );
// Grab the hash for recording. If the passed url is a path
// we used the parsed version of the squashed url to reconstruct,
// otherwise we assume it's a hash and store it directly
parsed = path.parseUrl( href );
hash = path.isPath(url) ? parsed.pathname + parsed.search : url;
parsed = path.parseUrl( url );
loc = path.parseLocation();
if( loc.pathname + loc.search === parsed.pathname + parsed.search ) {
// If the pathname and search of the passed url is identical to the current loc
// then we must use the hash. Otherwise there will be no event
// eg, url = "/foo/bar?baz#bang", location.href = "http://example.com/foo/bar?baz"
hash = parsed.hash ? parsed.hash : parsed.pathname + parsed.search;
} else if ( path.isPath(url) ) {
var resolved = path.parseUrl( href );
// If the passed url is a path, make it domain relative and remove any trailing hash
hash = resolved.pathname + resolved.search;
} else {
hash = url;
}
// Here we prevent the next hash change or popstate event from doing any
// history management. In the case of hashchange we don't swallow it
// if there will be not hashchange fired (since that won't reset the value)
// if there will be no hashchange fired (since that won't reset the value)
// and will swallow the following hashchange
history.ignoreNextHashChange = true;
if( noEvents && hash !== path.stripHash(path.parseLocation().hash) ) {
@@ -76,7 +89,7 @@ define([
// record the history entry so that the information can be included
// in hashchange event driven navigate events in a similar fashion to
// the state that's provided by popstate
history.add( url, state );
history.add( state.url, state );
};
// TODO this whole method is absolute trash :(
@@ -172,7 +185,7 @@ define([
// If all else fails this is a popstate that comes from the back or forward buttons
// make sure to set the state of our history stack properly, and record the directionality
history.direct({
url: (event.originalEvent.state || {}).hash || hash,
url: (event.originalEvent.state || {}).url || hash,
// When the url is either forward or backward in history include the entry
// as data on the event object for merging as data in the navigate event
@@ -264,14 +277,18 @@ define([
return this.stack[ this.activeIndex ];
},
getPrev: function() {
return this.stack[ this.activeIndex - 1 ];
getLast: function() {
return this.stack[ this.previousIndex ];
},
getNext: function() {
return this.stack[ this.activeIndex + 1 ];
},
getPrev: function() {
return this.stack[ this.activeIndex - 1 ];
},
// addNew is used whenever a new page is added
add: function( url, data ){
data = data || {};
@@ -341,7 +358,11 @@ define([
var newActiveIndex = this.closest( opts.url ), a = this.activeIndex;
// save new page index, null check to prevent falsey 0 result
this.activeIndex = newActiveIndex !== undefined ? newActiveIndex : this.activeIndex;
// record the previous index for reference
if( newActiveIndex !== undefined ) {
this.activeIndex = newActiveIndex;
this.previousIndex = a;
}
// invoke callbacks where appropriate
//
@@ -350,10 +371,6 @@ define([
( opts.present || opts.back || $.noop )( this.getActive(), 'back' );
} else if ( newActiveIndex > a ) {
( opts.present || opts.forward || $.noop )( this.getActive(), 'forward' );
} else if ( newActiveIndex === a ) {
if( opts.current ) {
opts.current( this.getActiveIndex );
}
} else if ( newActiveIndex === undefined && opts.missing ){
opts.missing( this.getActive() );
}
View
@@ -292,20 +292,6 @@ define([
reqUrl.search( /^https?:/ ) !== -1;
},
resetUIKeys: function( url ) {
var dialog = $.mobile.dialogHashKey,
subkey = "&" + $.mobile.subPageUrlKey,
dialogIndex = url.indexOf( dialog );
if ( dialogIndex > -1 ) {
url = url.slice( 0, dialogIndex ).replace("#", "") + "#" + url.slice( dialogIndex );
} else if ( url.indexOf( subkey ) > -1 ) {
url = url.split( subkey ).join( "#" + subkey );
}
return url;
},
mergeSearch: function( first, second ) {
var firstSearch, secondSearch,
resolvedSearch = {},
@@ -360,12 +346,18 @@ define([
// Get a hash where possible and, as long as it's not a path
// preserve it on the current url
preservedHash = (hashUri.hash || path.parseLocation().hash);
preservedHash = path.isPath( preservedHash ) ? "" : preservedHash;
if( path.isPath( preservedHash )) {
preservedHash = "";
}
if( preservedHash.indexOf( "#" ) == -1 && preservedHash !== "" ){
preservedHash = "#" + preservedHash;
}
// reconstruct each of the pieces with the new search string and hash
href = path.parseUrl( href );
href = href.protocol + "//" + href.host + href.pathname + hashUri.search + preservedHash;
href = path.resetUIKeys( href );
}
return href;
@@ -189,5 +189,13 @@ $.testHelper.setPushState();
$.navigate.squash( url.pathname + url.search );
});
test( "navigating with an absolute url matching the current url save for the hash should transplant the hash", function() {
var loc = $.mobile.path.parseLocation();
$.navigate( loc.hrefNoHash + loc.hash + "foo" );
equal( location.hash, loc.hash + "foo", "the hash is set properly" );
});
}
})( jQuery );
@@ -79,10 +79,13 @@
});
// Navigate to an internal page.
console.log( $("#content-page-2 .ip1") );
window.foo = true;
$("#content-page-2 .ip1").click();
},
function(){
window.foo = false;
// Verify that we are on the expected page.
// the hash based nav result (hash:) is dictate by the fact that #internal-page-1
// is the original root page element
@@ -126,8 +126,6 @@ $.testHelper.delayStart();
asyncTest( "external page is cached in the DOM after pagehide", function(){
$.testHelper.pageSequence([
navigateTestRoot,
function(){
$.mobile.changePage( "cached-external.html" );
},
@@ -148,8 +146,6 @@ $.testHelper.delayStart();
asyncTest( "external page is cached in the DOM after pagehide when option is set globally", function(){
$.testHelper.pageSequence([
navigateTestRoot,
function(){
$.mobile.page.prototype.options.domCache = true;
$.mobile.changePage( "external.html" );

0 comments on commit 921bf77

Please sign in to comment.