mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-05-02 03:44:43 +00:00
minor refactors in nav and pushstate for clarity
This commit is contained in:
parent
82cce1fa60
commit
6b010492b2
2 changed files with 42 additions and 27 deletions
|
|
@ -293,9 +293,9 @@
|
|||
this.activeIndex = newActiveIndex !== undefined ? newActiveIndex : this.activeIndex;
|
||||
|
||||
if( back ) {
|
||||
opts.isBack( prev, back );
|
||||
(opts.either || opts.isBack)( back );
|
||||
} else if( forward ) {
|
||||
opts.isForward( prev, back );
|
||||
(opts.either || opts.isForward)( back );
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -1185,12 +1185,14 @@
|
|||
});
|
||||
} );
|
||||
|
||||
$.mobile.handleHashChange = function( hash ) {
|
||||
$.mobile._handleHashChange = function( hash ) {
|
||||
//find first page via hash
|
||||
var reverse, role, to = path.stripHash( hash ),
|
||||
var to = path.stripHash( hash ),
|
||||
//transition is false if it's the first page, undefined otherwise (and may be overridden by default)
|
||||
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
|
||||
changePageOptions = {
|
||||
transition: transition,
|
||||
changeHash: false,
|
||||
|
|
@ -1220,34 +1222,43 @@
|
|||
// prevent changepage
|
||||
return;
|
||||
} else {
|
||||
var setTo = function( previousPage, isBack ) {
|
||||
var active = $.mobile.urlHistory.getActive();
|
||||
|
||||
to = active.pageUrl;
|
||||
role = active.role;
|
||||
transition = active.transition;
|
||||
reverse = isBack;
|
||||
};
|
||||
// if the current active page is a dialog and we're navigating
|
||||
// to a dialog use the dialog objected saved in the stack
|
||||
urlHistory.directHashChange({ currentUrl: to, isBack: setTo, isForward: setTo });
|
||||
urlHistory.directHashChange({
|
||||
currentUrl: to,
|
||||
|
||||
// regardless of the direction of the history change
|
||||
// do the following
|
||||
either: function( isBack ) {
|
||||
var active = $.mobile.urlHistory.getActive();
|
||||
|
||||
to = active.pageUrl;
|
||||
|
||||
// make sure to set the role, transition and reversal
|
||||
// as most of this is lost by the domCache cleaning
|
||||
$.extend( changePageOptions, {
|
||||
role: active.role,
|
||||
transition: active.transition,
|
||||
reverse: isBack
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//if to is defined, load it
|
||||
if ( to ) {
|
||||
to = ( typeof to === "string" && !path.isPath( to ) ) ? ( '#' + to ) : to;
|
||||
$.mobile.changePage( to, { transition: transition, changeHash: false, fromHashChange: true , role: role, reverse: reverse } );
|
||||
}
|
||||
//there's no hash, go to the first page in the dom
|
||||
else {
|
||||
$.mobile.changePage( $.mobile.firstPage, { transition: transition, changeHash: false, fromHashChange: true, roll: roll, reverse: reverse } );
|
||||
$.mobile.changePage( to, changePageOptions );
|
||||
} else {
|
||||
//there's no hash, go to the first page in the dom
|
||||
$.mobile.changePage( $.mobile.firstPage, changePageOptions );
|
||||
}
|
||||
};
|
||||
|
||||
//hashchange event handler
|
||||
$window.bind( "hashchange", function( e, triggered ) {
|
||||
$.mobile.handleHashChange( location.hash );
|
||||
$.mobile._handleHashChange( location.hash );
|
||||
});
|
||||
|
||||
//set page min-heights to be device specific
|
||||
|
|
|
|||
|
|
@ -35,18 +35,20 @@
|
|||
},
|
||||
|
||||
isSubHashPage: function( page ) {
|
||||
// if the page is a dialog, a subpage, or an embedded page
|
||||
// then the hash will have been maintained
|
||||
return page.is( "[role='dialog']" ) ||
|
||||
page.jqmData("url").indexOf( $.mobile.subPageUrlKey ) >= 0;
|
||||
page.jqmData("url").indexOf( $.mobile.subPageUrlKey ) >= 0 ||
|
||||
page.jqmData("url") == page.attr( "id" );
|
||||
},
|
||||
|
||||
resetUIKeys: function( url ) {
|
||||
var dialog = $.mobile.dialogHashKey,
|
||||
subkey = "&" + $.mobile.subPageUrlKey;
|
||||
subkey = "&" + $.mobile.subPageUrlKey,
|
||||
dialogIndex = url.indexOf( dialog );
|
||||
|
||||
if( url.indexOf( dialog ) > -1 ) {
|
||||
var split = url.split( dialog );
|
||||
split.push( "" );
|
||||
url = split[0] + "#" + split.slice( 1, split.length ).join( dialog );
|
||||
if( dialogIndex > -1 ) {
|
||||
url = url.slice( 0, dialogIndex ) + "#" + url.slice( dialogIndex );
|
||||
} else if( url.indexOf( subkey ) > -1 ) {
|
||||
url = url.split( subkey ).join( "#" + subkey );
|
||||
}
|
||||
|
|
@ -88,13 +90,15 @@
|
|||
if( poppedState ) {
|
||||
// can't test the hash directly because the url has already been altered, possibly to
|
||||
// one without a hash, so we check if the page on display is one that would have
|
||||
// generated a hash
|
||||
// generated a hash. Generally speaking a crappy solution.
|
||||
if( self.isSubHashPage( $.mobile.activePage ) ){
|
||||
holdnexthashchange = true;
|
||||
}
|
||||
|
||||
$.mobile.handleHashChange( poppedState.hash );
|
||||
// change the page based on the hash
|
||||
$.mobile._handleHashChange( poppedState.hash );
|
||||
|
||||
// disable the next hash change if the page we came from has a hash
|
||||
$.mobile.urlHistory.ignoreNextHashChange = holdnexthashchange;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue