@@ -404,48 +404,22 @@ define( [
404404 getScreenHeight = $ . mobile . getScreenHeight ;
405405
406406 //base element management, defined depending on dynamic base tag support
407- var base = {
407+ var base = $ . support . dynamicBaseTag ? {
408+
408409 //define base element, for use in routing asset urls that are referenced in Ajax-requested markup
409410 element : ( $base . length ? $base : $ ( "<base>" , { href : documentBase . hrefNoHash } ) . prependTo ( $head ) ) ,
410411
411- linkSelector : "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ,
412-
413412 //set the generated BASE element's href attribute to a new page's base path
414- set : function ( href , page ) {
415- // we should do nothing if the user wants to manage their url base manually
416- if ( ! $ . mobile . dynamicBaseEnabled ) {
417- return ;
418- }
419-
420- // we should use the base tag if we can manipulate it dynamically
421- if ( $ . support . dynamicBaseTag ) {
422- base . element . attr ( "href" , path . makeUrlAbsolute ( href , documentBase ) ) ;
423- }
424-
425- // otherwise rewrite src and href attrs to use a base url
426- if ( ! $ . support . dynamicBaseTag && page ) {
427- var newPath = path . get ( href ) ;
428- page . find ( base . linkSelector ) . each ( function ( i , link ) {
429- var thisAttr = $ ( link ) . is ( '[href]' ) ? 'href' : $ ( link ) . is ( '[src]' ) ? 'src' : 'action' ,
430- thisUrl = $ ( link ) . attr ( thisAttr ) ;
431-
432- // XXX_jblas: We need to fix this so that it removes the document
433- // base URL, and then prepends with the new page URL.
434- //if full path exists and is same, chop it - helps IE out
435- thisUrl = thisUrl . replace ( location . protocol + '//' + location . host + location . pathname , '' ) ;
436-
437- if ( ! / ^ ( \w + : | # | \/ ) / . test ( thisUrl ) ) {
438- $ ( link ) . attr ( thisAttr , newPath + thisUrl ) ;
439- }
440- } ) ;
441- }
413+ set : function ( href ) {
414+ base . element . attr ( "href" , path . makeUrlAbsolute ( href , documentBase ) ) ;
442415 } ,
443416
444417 //set the generated BASE element's href attribute to a new page's base path
445418 reset : function ( ) {
446419 base . element . attr ( "href" , documentBase . hrefNoHash ) ;
447420 }
448- } ;
421+
422+ } : undefined ;
449423
450424 /* internal utility functions */
451425
@@ -627,12 +601,6 @@ define( [
627601 $page . page ( ) ;
628602 }
629603
630- // determine the current base url
631- function findBaseWithDefault ( ) {
632- var closestBase = ( $ . mobile . activePage && getClosestBaseUrl ( $ . mobile . activePage ) ) ;
633- return closestBase || documentBase . hrefNoHash ;
634- }
635-
636604 /* exposed $.mobile methods */
637605
638606 //animation complete callback
@@ -658,6 +626,8 @@ define( [
658626
659627 $ . mobile . dialogHashKey = dialogHashKey ;
660628
629+
630+
661631 //enable cross-domain page support
662632 $ . mobile . allowCrossDomainPages = false ;
663633
@@ -710,6 +680,12 @@ define( [
710680 // page is loaded off the network.
711681 dupCachedPage = null ,
712682
683+ // determine the current base url
684+ findBaseWithDefault = function ( ) {
685+ var closestBase = ( $ . mobile . activePage && getClosestBaseUrl ( $ . mobile . activePage ) ) ;
686+ return closestBase || documentBase . hrefNoHash ;
687+ } ,
688+
713689 // The absolute version of the URL passed into the function. This
714690 // version of the URL may contain dialog/subpage params in it.
715691 absUrl = path . makeUrlAbsolute ( url , findBaseWithDefault ( ) ) ;
@@ -857,6 +833,10 @@ define( [
857833 url = fileUrl = path . getFilePath ( $ ( "<div>" + RegExp . $1 + "</div>" ) . text ( ) ) ;
858834 }
859835
836+ if ( base ) {
837+ base . set ( fileUrl ) ;
838+ }
839+
860840 //workaround to allow scripts to execute when included in page divs
861841 all . get ( 0 ) . innerHTML = html ;
862842 page = all . find ( ":jqmData(role='page'), :jqmData(role='dialog')" ) . first ( ) ;
@@ -873,7 +853,24 @@ define( [
873853 page . jqmData ( "title" , newPageTitle ) ;
874854 }
875855
876- base . set ( fileUrl , page ) ;
856+ //rewrite src and href attrs to use a base url
857+ if ( ! $ . support . dynamicBaseTag ) {
858+ var newPath = path . get ( fileUrl ) ;
859+ page . find ( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ) . each ( function ( ) {
860+ var thisAttr = $ ( this ) . is ( '[href]' ) ? 'href' :
861+ $ ( this ) . is ( '[src]' ) ? 'src' : 'action' ,
862+ thisUrl = $ ( this ) . attr ( thisAttr ) ;
863+
864+ // XXX_jblas: We need to fix this so that it removes the document
865+ // base URL, and then prepends with the new page URL.
866+ //if full path exists and is same, chop it - helps IE out
867+ thisUrl = thisUrl . replace ( location . protocol + '//' + location . host + location . pathname , '' ) ;
868+
869+ if ( ! / ^ ( \w + : | # | \/ ) / . test ( thisUrl ) ) {
870+ $ ( this ) . attr ( thisAttr , newPath + thisUrl ) ;
871+ }
872+ } ) ;
873+ }
877874
878875 //append to page and enhance
879876 // TODO taging a page with external to make sure that embedded pages aren't removed
@@ -897,6 +894,7 @@ define( [
897894 }
898895
899896 //bind pageHide to removePage after it's hidden, if the page options specify to do so
897+
900898 // Remove loading message.
901899 if ( settings . showLoadMsg ) {
902900 hideMsg ( ) ;
@@ -914,7 +912,9 @@ define( [
914912 } ,
915913 error : function ( xhr , textStatus , errorThrown ) {
916914 //set base back to current path
917- base . set ( path . get ( ) ) ;
915+ if ( base ) {
916+ base . set ( path . get ( ) ) ;
917+ }
918918
919919 // Add error info to our triggerData.
920920 triggerData . xhr = xhr ;
@@ -975,33 +975,18 @@ define( [
975975 return ;
976976 }
977977
978- var settings = $ . extend ( { } , $ . mobile . changePage . defaults , options ) , isString ;
978+ var settings = $ . extend ( { } , $ . mobile . changePage . defaults , options ) ;
979979
980980 // Make sure we have a pageContainer to work with.
981981 settings . pageContainer = settings . pageContainer || $ . mobile . pageContainer ;
982982
983983 // Make sure we have a fromPage.
984984 settings . fromPage = settings . fromPage || $ . mobile . activePage ;
985985
986- isString = ( typeof toPage === "string" ) ;
987-
988986 var mpc = settings . pageContainer ,
989987 pbcEvent = new $ . Event ( "pagebeforechange" ) ,
990988 triggerData = { toPage : toPage , options : settings } ;
991989
992- // NOTE: preserve the original target as the dataUrl value will be simplified
993- // eg, removing ui-state, and removing query params from the hash
994- // this is so that users who want to use query params have access to them
995- // in the event bindings for the page life cycle See issue #5085
996- if ( isString ) {
997- // if the toPage is a string simply convert it
998- triggerData . absUrl = path . makeUrlAbsolute ( toPage , findBaseWithDefault ( ) ) ;
999- } else {
1000- // if the toPage is a jQuery object grab the absolute url stored
1001- // in the loadPage callback where it exists
1002- triggerData . absUrl = toPage . data ( 'absUrl' ) ;
1003- }
1004-
1005990 // Let listeners know we're about to change the current page.
1006991 mpc . trigger ( pbcEvent , triggerData ) ;
1007992
@@ -1025,15 +1010,17 @@ define( [
10251010 // to make sure it is loaded into the DOM. We'll listen
10261011 // to the promise object it returns so we know when
10271012 // it is done loading or if an error ocurred.
1028- if ( isString ) {
1013+ if ( typeof toPage === "string" ) {
1014+ // preserve the original target as the dataUrl value will be simplified
1015+ // eg, removing ui-state, and removing query params from the hash
1016+ // this is so that users who want to use query params have access to them
1017+ // in the event bindings for the page life cycle See issue #5085
1018+ settings . target = toPage ;
1019+
10291020 $ . mobile . loadPage ( toPage , settings )
10301021 . done ( function ( url , options , newPage , dupCachedPage ) {
10311022 isPageTransitioning = false ;
10321023 options . duplicateCachedPage = dupCachedPage ;
1033-
1034- // store the original absolute url so that it can be provided
1035- // to events in the triggerData of the subsequent changePage call
1036- newPage . data ( 'absUrl' , triggerData . absUrl ) ;
10371024 $ . mobile . changePage ( newPage , options ) ;
10381025 } )
10391026 . fail ( function ( url , options ) {
@@ -1186,7 +1173,6 @@ define( [
11861173 if ( alreadyThere ) {
11871174 urlHistory . activeIndex = Math . max ( 0 , urlHistory . activeIndex - 1 ) ;
11881175 }
1189-
11901176 urlHistory . addNew ( url , settings . transition , pageTitle , pageUrl , settings . role ) ;
11911177 }
11921178
@@ -1237,8 +1223,9 @@ define( [
12371223 allowSamePageTransition : false
12381224 } ;
12391225
1240- /* Event Bindings - hashchange, submit, and click */
1241- function findClosestLink ( ele ) {
1226+ /* Event Bindings - hashchange, submit, and click */
1227+ function findClosestLink ( ele )
1228+ {
12421229 while ( ele ) {
12431230 // Look for the closest element with a nodeName of "a".
12441231 // Note that we are checking if we have a valid nodeName
@@ -1256,16 +1243,17 @@ define( [
12561243 }
12571244
12581245 // The base URL for any given element depends on the page it resides in.
1259- function getClosestBaseUrl ( ele ) {
1246+ function getClosestBaseUrl ( ele )
1247+ {
12601248 // Find the closest page and extract out its url.
12611249 var url = $ ( ele ) . closest ( ".ui-page" ) . jqmData ( "url" ) ,
12621250 base = documentBase . hrefNoHash ;
12631251
1264- if ( ! $ . mobile . dynamicBaseEnabled || ! url || ! path . isPath ( url ) ) {
1252+ if ( ! url || ! path . isPath ( url ) ) {
12651253 url = base ;
12661254 }
12671255
1268- return path . makeUrlAbsolute ( url , base ) ;
1256+ return path . makeUrlAbsolute ( url , base ) ;
12691257 }
12701258
12711259 //The following event bindings should be bound after mobileinit has been triggered
0 commit comments