Skip to content

Commit d509404

Browse files
author
scottjehl
committed
Merge remote branch 'origin/master'
Conflicts: js/jquery.mobile.navigation.js
2 parents b3a8230 + 9337a3a commit d509404

File tree

1 file changed

+67
-53
lines changed

1 file changed

+67
-53
lines changed

js/jquery.mobile.navigation.js

Lines changed: 67 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var splitkey = '&' + $.mobile.subPageUrlKey;
2828
return path && path.split( splitkey )[0].split( dialogHashKey )[0];
2929
},
30-
30+
3131
//set location hash to path
3232
set: function( path ){
3333
location.hash = path;
@@ -39,80 +39,84 @@
3939
setOrigin: function(){
4040
path.origin = path.get( location.protocol + '//' + location.host + location.pathname );
4141
},
42-
42+
4343
//prefix a relative url with the current path
4444
makeAbsolute: function( url ){
4545
return path.get() + url;
4646
},
47-
47+
4848
//return a url path with the window's location protocol/hostname removed
4949
clean: function( url ){
5050
return url.replace( location.protocol + "//" + location.host, "");
5151
},
52-
52+
5353
//just return the url without an initial #
5454
stripHash: function( url ){
5555
return url.replace( /^#/, "" );
5656
},
57-
57+
5858
//check whether a url is referencing the same domain, or an external domain or different protocol
5959
//could be mailto, etc
6060
isExternal: function( url ){
6161
return path.hasProtocol( path.clean( url ) );
6262
},
63-
63+
6464
hasProtocol: function( url ){
6565
return /^(:?\w+:)/.test( url );
6666
},
67-
67+
6868
//check if the url is relative
6969
isRelative: function( url ){
7070
return /^[^\/|#]/.test( url ) && !path.hasProtocol( url );
71+
},
72+
73+
isEmbeddedPage: function( url ){
74+
return /^#/.test( url );
7175
}
7276
},
7377

7478
//will be defined when a link is clicked and given an active class
7579
$activeClickedLink = null,
76-
80+
7781
//urlHistory is purely here to make guesses at whether the back or forward button was clicked
7882
//and provide an appropriate transition
7983
urlHistory = {
8084
//array of pages that are visited during a single page load. each has a url and optional transition
8185
stack: [],
82-
86+
8387
//maintain an index number for the active page in the stack
8488
activeIndex: 0,
85-
89+
8690
//get active
8791
getActive: function(){
8892
return urlHistory.stack[ urlHistory.activeIndex ];
8993
},
90-
94+
9195
getPrev: function(){
9296
return urlHistory.stack[ urlHistory.activeIndex - 1 ];
9397
},
94-
98+
9599
getNext: function(){
96100
return urlHistory.stack[ urlHistory.activeIndex + 1 ];
97101
},
98-
102+
99103
// addNew is used whenever a new page is added
100104
addNew: function( url, transition ){
101105
//if there's forward history, wipe it
102106
if( urlHistory.getNext() ){
103107
urlHistory.clearForward();
104108
}
105-
109+
106110
urlHistory.stack.push( {url : url, transition: transition } );
107-
111+
108112
urlHistory.activeIndex = urlHistory.stack.length - 1;
109113
},
110-
114+
111115
//wipe urls ahead of active index
112116
clearForward: function(){
113117
urlHistory.stack = urlHistory.stack.slice( 0, urlHistory.activeIndex + 1 );
114118
},
115-
119+
116120
//enable/disable hashchange event listener
117121
//toggled internally when location.hash is updated to match the url of a successful page load
118122
listeningEnabled: true
@@ -123,7 +127,7 @@
123127

124128
//contains role for next page, if defined on clicked link via data-rel
125129
nextPageRole = null,
126-
130+
127131
//nonsense hash change key for dialogs, so they create a history entry
128132
dialogHashKey = "&ui-state=dialog";
129133

@@ -213,7 +217,8 @@
213217
return $(this).one('webkitAnimationEnd', callback);
214218
}
215219
else{
216-
callback();
220+
// defer execution for consistency between webkit/non webkit
221+
setTimeout(callback, 0);
217222
}
218223
};
219224

@@ -224,17 +229,17 @@
224229
//update location.hash, with or without triggering hashchange event
225230
//TODO - deprecate this one at 1.0
226231
$.mobile.updateHash = path.set;
227-
232+
228233
//expose path object on $.mobile
229234
$.mobile.path = path;
230-
235+
231236
//expose base object on $.mobile
232237
$.mobile.base = base;
233238

234239
//url stack, useful when plugins need to be aware of previous pages viewed
235240
//TODO: deprecate this one at 1.0
236241
$.mobile.urlstack = urlHistory.stack;
237-
242+
238243
//history stack
239244
$.mobile.urlHistory = urlHistory;
240245

@@ -254,19 +259,19 @@
254259
currPage = urlHistory.getActive(),
255260
back = false,
256261
forward = false;
257-
258-
262+
263+
259264
// If we are trying to transition to the same page that we are currently on ignore the request.
260265
// an illegal same page request is defined by the current page being the same as the url, as long as there's history
261266
// and to is not an array or object (those are allowed to be "same")
262267
if( currPage && urlHistory.stack.length > 1 && currPage.url === url && !toIsArray && !toIsObject ) {
263268
return;
264-
}
265-
269+
}
270+
266271
// if the changePage was sent from a hashChange event
267272
// guess if it came from the history menu
268273
if( fromHashChange ){
269-
274+
270275
// check if url is in history and if it's ahead or behind current page
271276
$.each( urlHistory.stack, function( i ){
272277
//if the url is in the stack, it's a forward or a back
@@ -280,7 +285,7 @@
280285
urlHistory.activeIndex = i;
281286
}
282287
});
283-
288+
284289
//if it's a back, use reverse animation
285290
if( back ){
286291
reverse = true;
@@ -290,7 +295,7 @@
290295
transition = transition || urlHistory.getActive().transition;
291296
}
292297
}
293-
298+
294299

295300
if( toIsObject && to.url ){
296301
url = to.url,
@@ -302,7 +307,7 @@
302307
if($.type( data ) == "object" ){
303308
data = $.param(data);
304309
}
305-
310+
306311
url += "?" + data;
307312
data = undefined;
308313
}
@@ -328,8 +333,8 @@
328333
var currScroll = $window.scrollTop(),
329334
perspectiveTransitions = [ "flip" ],
330335
pageContainerClasses = [];
331-
332-
//support deep-links to generated sub-pages
336+
337+
//support deep-links to generated sub-pages
333338
if( url.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ){
334339
to = $( "[data-url='" + url + "']" );
335340
}
@@ -351,16 +356,17 @@
351356
path.set( url );
352357
urlHistory.listeningEnabled = true;
353358
}
354-
359+
355360
//add page to history stack if it's not back or forward
356361
if( !back && !forward ){
357362
urlHistory.addNew( url, transition );
358363
}
359-
364+
360365
removeActiveLinkClass();
361366

362367
//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.
363368
$.mobile.silentScroll( to.data( "lastScroll" ) );
369+
364370
reFocus( to );
365371

366372
//trigger show/hide events
@@ -394,8 +400,8 @@
394400

395401
pageContainerClasses = [];
396402
};
397-
398-
403+
404+
399405

400406
if(transition && (transition !== 'none')){
401407
$.mobile.pageLoading( true );
@@ -467,7 +473,7 @@
467473
fileUrl = toIDfileurl;
468474
}
469475
}
470-
476+
471477
// ensure a transition has been set where pop is undefined
472478
defaultTransition();
473479

@@ -492,23 +498,23 @@
492498
type: type,
493499
data: data,
494500
success: function( html ) {
495-
496-
//pre-parse html to check for a data-url,
501+
502+
//pre-parse html to check for a data-url,
497503
//use it as the new fileUrl, base path, etc
498504
var redirectLoc = / data-url="(.*)"/.test( html ) && RegExp.$1;
499505

500506
if( redirectLoc ){
501507
if(base){
502508
base.set( redirectLoc );
503-
}
509+
}
504510
url = fileUrl = path.makeAbsolute( path.getFilePath( redirectLoc ) );
505511
}
506512
else {
507513
if(base){
508514
base.set(fileUrl);
509-
}
515+
}
510516
}
511-
517+
512518
var all = $("<div></div>");
513519
//workaround to allow scripts to execute when included in page divs
514520
all.get(0).innerHTML = html;
@@ -529,7 +535,7 @@
529535
}
530536
});
531537
}
532-
538+
533539
//append to page and enhance
534540
to
535541
.attr( "data-url", fileUrl )
@@ -592,22 +598,30 @@
592598

593599
//click routing - direct to HTTP or Ajax, accordingly
594600
$( "a" ).live( "click", function(event) {
595-
601+
596602
var $this = $(this),
597603
//get href, remove same-domain protocol and host
598604
url = path.clean( $this.attr( "href" ) ),
599-
600-
//check if it's external
601-
isExternal = path.isExternal( url ) || $this.is( "[rel='external']" ),
602-
605+
606+
//rel set to external
607+
isRelExternal = $this.is( "[rel='external']" ),
608+
609+
//rel set to external
610+
isEmbeddedPage = path.isEmbeddedPage( url ),
611+
612+
//check for protocol or rel and its not an embedded page
613+
//TODO overlap in logic from isExternal, rel=external check should be
614+
// moved into more comprehensive isExternalLink
615+
isExternal = path.isExternal( url ) || isRelExternal && !isEmbeddedPage,
616+
603617
//if target attr is specified we mimic _blank... for now
604618
hasTarget = $this.is( "[target]" );
605-
619+
606620
//if there's a data-rel=back attr, go back in history
607621
if( $this.is( "[data-rel='back']" ) ){
608622
window.history.back();
609623
return false;
610-
}
624+
}
611625

612626
if( url === "#" ){
613627
//for links created purely for interaction - ignore
@@ -634,11 +648,11 @@
634648
//use ajax
635649
var transition = $this.data( "transition" ),
636650
direction = $this.data("direction"),
637-
reverse = direction && direction == "reverse" ||
651+
reverse = direction && direction == "reverse" ||
638652
// deprecated - remove by 1.0
639653
$this.data( "back" );
640-
641-
//this may need to be more specific as we use data-rel more
654+
655+
//this may need to be more specific as we use data-rel more
642656
nextPageRole = $this.attr( "data-rel" );
643657

644658
//if it's a relative href, prefix href with base url

0 commit comments

Comments
 (0)