mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-17 12:51:00 +00:00
Merge remote branch 'origin/master'
Conflicts: js/jquery.mobile.navigation.js
This commit is contained in:
commit
d509404b72
1 changed files with 67 additions and 53 deletions
|
|
@ -27,7 +27,7 @@
|
|||
var splitkey = '&' + $.mobile.subPageUrlKey;
|
||||
return path && path.split( splitkey )[0].split( dialogHashKey )[0];
|
||||
},
|
||||
|
||||
|
||||
//set location hash to path
|
||||
set: function( path ){
|
||||
location.hash = path;
|
||||
|
|
@ -39,80 +39,84 @@
|
|||
setOrigin: function(){
|
||||
path.origin = path.get( location.protocol + '//' + location.host + location.pathname );
|
||||
},
|
||||
|
||||
|
||||
//prefix a relative url with the current path
|
||||
makeAbsolute: function( url ){
|
||||
return path.get() + url;
|
||||
},
|
||||
|
||||
|
||||
//return a url path with the window's location protocol/hostname removed
|
||||
clean: function( url ){
|
||||
return url.replace( location.protocol + "//" + location.host, "");
|
||||
},
|
||||
|
||||
|
||||
//just return the url without an initial #
|
||||
stripHash: function( url ){
|
||||
return url.replace( /^#/, "" );
|
||||
},
|
||||
|
||||
|
||||
//check whether a url is referencing the same domain, or an external domain or different protocol
|
||||
//could be mailto, etc
|
||||
isExternal: function( url ){
|
||||
return path.hasProtocol( path.clean( url ) );
|
||||
},
|
||||
|
||||
|
||||
hasProtocol: function( url ){
|
||||
return /^(:?\w+:)/.test( url );
|
||||
},
|
||||
|
||||
|
||||
//check if the url is relative
|
||||
isRelative: function( url ){
|
||||
return /^[^\/|#]/.test( url ) && !path.hasProtocol( url );
|
||||
},
|
||||
|
||||
isEmbeddedPage: function( url ){
|
||||
return /^#/.test( url );
|
||||
}
|
||||
},
|
||||
|
||||
//will be defined when a link is clicked and given an active class
|
||||
$activeClickedLink = null,
|
||||
|
||||
|
||||
//urlHistory is purely here to make guesses at whether the back or forward button was clicked
|
||||
//and provide an appropriate transition
|
||||
urlHistory = {
|
||||
//array of pages that are visited during a single page load. each has a url and optional transition
|
||||
stack: [],
|
||||
|
||||
|
||||
//maintain an index number for the active page in the stack
|
||||
activeIndex: 0,
|
||||
|
||||
|
||||
//get active
|
||||
getActive: function(){
|
||||
return urlHistory.stack[ urlHistory.activeIndex ];
|
||||
},
|
||||
|
||||
|
||||
getPrev: function(){
|
||||
return urlHistory.stack[ urlHistory.activeIndex - 1 ];
|
||||
},
|
||||
|
||||
|
||||
getNext: function(){
|
||||
return urlHistory.stack[ urlHistory.activeIndex + 1 ];
|
||||
},
|
||||
|
||||
|
||||
// addNew is used whenever a new page is added
|
||||
addNew: function( url, transition ){
|
||||
//if there's forward history, wipe it
|
||||
if( urlHistory.getNext() ){
|
||||
urlHistory.clearForward();
|
||||
}
|
||||
|
||||
|
||||
urlHistory.stack.push( {url : url, transition: transition } );
|
||||
|
||||
|
||||
urlHistory.activeIndex = urlHistory.stack.length - 1;
|
||||
},
|
||||
|
||||
|
||||
//wipe urls ahead of active index
|
||||
clearForward: function(){
|
||||
urlHistory.stack = urlHistory.stack.slice( 0, urlHistory.activeIndex + 1 );
|
||||
},
|
||||
|
||||
|
||||
//enable/disable hashchange event listener
|
||||
//toggled internally when location.hash is updated to match the url of a successful page load
|
||||
listeningEnabled: true
|
||||
|
|
@ -123,7 +127,7 @@
|
|||
|
||||
//contains role for next page, if defined on clicked link via data-rel
|
||||
nextPageRole = null,
|
||||
|
||||
|
||||
//nonsense hash change key for dialogs, so they create a history entry
|
||||
dialogHashKey = "&ui-state=dialog";
|
||||
|
||||
|
|
@ -213,7 +217,8 @@
|
|||
return $(this).one('webkitAnimationEnd', callback);
|
||||
}
|
||||
else{
|
||||
callback();
|
||||
// defer execution for consistency between webkit/non webkit
|
||||
setTimeout(callback, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -224,17 +229,17 @@
|
|||
//update location.hash, with or without triggering hashchange event
|
||||
//TODO - deprecate this one at 1.0
|
||||
$.mobile.updateHash = path.set;
|
||||
|
||||
|
||||
//expose path object on $.mobile
|
||||
$.mobile.path = path;
|
||||
|
||||
|
||||
//expose base object on $.mobile
|
||||
$.mobile.base = base;
|
||||
|
||||
//url stack, useful when plugins need to be aware of previous pages viewed
|
||||
//TODO: deprecate this one at 1.0
|
||||
$.mobile.urlstack = urlHistory.stack;
|
||||
|
||||
|
||||
//history stack
|
||||
$.mobile.urlHistory = urlHistory;
|
||||
|
||||
|
|
@ -254,19 +259,19 @@
|
|||
currPage = urlHistory.getActive(),
|
||||
back = false,
|
||||
forward = false;
|
||||
|
||||
|
||||
|
||||
|
||||
// If we are trying to transition to the same page that we are currently on ignore the request.
|
||||
// an illegal same page request is defined by the current page being the same as the url, as long as there's history
|
||||
// and to is not an array or object (those are allowed to be "same")
|
||||
if( currPage && urlHistory.stack.length > 1 && currPage.url === url && !toIsArray && !toIsObject ) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if the changePage was sent from a hashChange event
|
||||
// guess if it came from the history menu
|
||||
if( fromHashChange ){
|
||||
|
||||
|
||||
// check if url is in history and if it's ahead or behind current page
|
||||
$.each( urlHistory.stack, function( i ){
|
||||
//if the url is in the stack, it's a forward or a back
|
||||
|
|
@ -280,7 +285,7 @@
|
|||
urlHistory.activeIndex = i;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//if it's a back, use reverse animation
|
||||
if( back ){
|
||||
reverse = true;
|
||||
|
|
@ -290,7 +295,7 @@
|
|||
transition = transition || urlHistory.getActive().transition;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( toIsObject && to.url ){
|
||||
url = to.url,
|
||||
|
|
@ -302,7 +307,7 @@
|
|||
if($.type( data ) == "object" ){
|
||||
data = $.param(data);
|
||||
}
|
||||
|
||||
|
||||
url += "?" + data;
|
||||
data = undefined;
|
||||
}
|
||||
|
|
@ -328,8 +333,8 @@
|
|||
var currScroll = $window.scrollTop(),
|
||||
perspectiveTransitions = [ "flip" ],
|
||||
pageContainerClasses = [];
|
||||
|
||||
//support deep-links to generated sub-pages
|
||||
|
||||
//support deep-links to generated sub-pages
|
||||
if( url.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ){
|
||||
to = $( "[data-url='" + url + "']" );
|
||||
}
|
||||
|
|
@ -351,16 +356,17 @@
|
|||
path.set( url );
|
||||
urlHistory.listeningEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
//add page to history stack if it's not back or forward
|
||||
if( !back && !forward ){
|
||||
urlHistory.addNew( url, transition );
|
||||
}
|
||||
|
||||
|
||||
removeActiveLinkClass();
|
||||
|
||||
//jump to top or prev scroll, sometimes on iOS the page has not rendered yet. I could only get by this with a setTimeout, but would like to avoid that.
|
||||
$.mobile.silentScroll( to.data( "lastScroll" ) );
|
||||
|
||||
reFocus( to );
|
||||
|
||||
//trigger show/hide events
|
||||
|
|
@ -394,8 +400,8 @@
|
|||
|
||||
pageContainerClasses = [];
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(transition && (transition !== 'none')){
|
||||
$.mobile.pageLoading( true );
|
||||
|
|
@ -467,7 +473,7 @@
|
|||
fileUrl = toIDfileurl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ensure a transition has been set where pop is undefined
|
||||
defaultTransition();
|
||||
|
||||
|
|
@ -492,23 +498,23 @@
|
|||
type: type,
|
||||
data: data,
|
||||
success: function( html ) {
|
||||
|
||||
//pre-parse html to check for a data-url,
|
||||
|
||||
//pre-parse html to check for a data-url,
|
||||
//use it as the new fileUrl, base path, etc
|
||||
var redirectLoc = / data-url="(.*)"/.test( html ) && RegExp.$1;
|
||||
|
||||
if( redirectLoc ){
|
||||
if(base){
|
||||
base.set( redirectLoc );
|
||||
}
|
||||
}
|
||||
url = fileUrl = path.makeAbsolute( path.getFilePath( redirectLoc ) );
|
||||
}
|
||||
else {
|
||||
if(base){
|
||||
base.set(fileUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var all = $("<div></div>");
|
||||
//workaround to allow scripts to execute when included in page divs
|
||||
all.get(0).innerHTML = html;
|
||||
|
|
@ -529,7 +535,7 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//append to page and enhance
|
||||
to
|
||||
.attr( "data-url", fileUrl )
|
||||
|
|
@ -592,22 +598,30 @@
|
|||
|
||||
//click routing - direct to HTTP or Ajax, accordingly
|
||||
$( "a" ).live( "click", function(event) {
|
||||
|
||||
|
||||
var $this = $(this),
|
||||
//get href, remove same-domain protocol and host
|
||||
url = path.clean( $this.attr( "href" ) ),
|
||||
|
||||
//check if it's external
|
||||
isExternal = path.isExternal( url ) || $this.is( "[rel='external']" ),
|
||||
|
||||
|
||||
//rel set to external
|
||||
isRelExternal = $this.is( "[rel='external']" ),
|
||||
|
||||
//rel set to external
|
||||
isEmbeddedPage = path.isEmbeddedPage( url ),
|
||||
|
||||
//check for protocol or rel and its not an embedded page
|
||||
//TODO overlap in logic from isExternal, rel=external check should be
|
||||
// moved into more comprehensive isExternalLink
|
||||
isExternal = path.isExternal( url ) || isRelExternal && !isEmbeddedPage,
|
||||
|
||||
//if target attr is specified we mimic _blank... for now
|
||||
hasTarget = $this.is( "[target]" );
|
||||
|
||||
|
||||
//if there's a data-rel=back attr, go back in history
|
||||
if( $this.is( "[data-rel='back']" ) ){
|
||||
window.history.back();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( url === "#" ){
|
||||
//for links created purely for interaction - ignore
|
||||
|
|
@ -634,11 +648,11 @@
|
|||
//use ajax
|
||||
var transition = $this.data( "transition" ),
|
||||
direction = $this.data("direction"),
|
||||
reverse = direction && direction == "reverse" ||
|
||||
reverse = direction && direction == "reverse" ||
|
||||
// deprecated - remove by 1.0
|
||||
$this.data( "back" );
|
||||
|
||||
//this may need to be more specific as we use data-rel more
|
||||
|
||||
//this may need to be more specific as we use data-rel more
|
||||
nextPageRole = $this.attr( "data-rel" );
|
||||
|
||||
//if it's a relative href, prefix href with base url
|
||||
|
|
|
|||
Loading…
Reference in a new issue