@@ -404,22 +404,48 @@ define( [
404404 getScreenHeight = $ . mobile . getScreenHeight ;
405405
406406 //base element management, defined depending on dynamic base tag support
407- var base = $ . support . dynamicBaseTag ? {
408-
407+ var base = {
409408 //define base element, for use in routing asset urls that are referenced in Ajax-requested markup
410409 element : ( $base . length ? $base : $ ( "<base>" , { href : documentBase . hrefNoHash } ) . prependTo ( $head ) ) ,
411410
411+ linkSelector : "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ,
412+
412413 //set the generated BASE element's href attribute to a new page's base path
413- set : function ( href ) {
414- base . element . attr ( "href" , path . makeUrlAbsolute ( href , documentBase ) ) ;
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+ }
415442 } ,
416443
417444 //set the generated BASE element's href attribute to a new page's base path
418445 reset : function ( ) {
419446 base . element . attr ( "href" , documentBase . hrefNoHash ) ;
420447 }
421-
422- } : undefined ;
448+ } ;
423449
424450 /* internal utility functions */
425451
@@ -752,6 +778,11 @@ define( [
752778 }
753779 }
754780
781+ // Reset base to the default document base.
782+ if ( $ . support . dynamicBaseTag ) {
783+ base . reset ( ) ;
784+ }
785+
755786 // If the page we are interested in is already in the DOM,
756787 // and the caller did not indicate that we should force a
757788 // reload of the file, we are done. Otherwise, track the
@@ -831,10 +862,6 @@ define( [
831862 url = fileUrl = path . getFilePath ( $ ( "<div>" + RegExp . $1 + "</div>" ) . text ( ) ) ;
832863 }
833864
834- if ( base ) {
835- base . set ( fileUrl ) ;
836- }
837-
838865 //workaround to allow scripts to execute when included in page divs
839866 all . get ( 0 ) . innerHTML = html ;
840867 page = all . find ( ":jqmData(role='page'), :jqmData(role='dialog')" ) . first ( ) ;
@@ -851,24 +878,7 @@ define( [
851878 page . jqmData ( "title" , newPageTitle ) ;
852879 }
853880
854- //rewrite src and href attrs to use a base url
855- if ( ! $ . support . dynamicBaseTag ) {
856- var newPath = path . get ( fileUrl ) ;
857- page . find ( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ) . each ( function ( ) {
858- var thisAttr = $ ( this ) . is ( '[href]' ) ? 'href' :
859- $ ( this ) . is ( '[src]' ) ? 'src' : 'action' ,
860- thisUrl = $ ( this ) . attr ( thisAttr ) ;
861-
862- // XXX_jblas: We need to fix this so that it removes the document
863- // base URL, and then prepends with the new page URL.
864- //if full path exists and is same, chop it - helps IE out
865- thisUrl = thisUrl . replace ( location . protocol + '//' + location . host + location . pathname , '' ) ;
866-
867- if ( ! / ^ ( \w + : | # | \/ ) / . test ( thisUrl ) ) {
868- $ ( this ) . attr ( thisAttr , newPath + thisUrl ) ;
869- }
870- } ) ;
871- }
881+ base . set ( fileUrl , page ) ;
872882
873883 //append to page and enhance
874884 // TODO taging a page with external to make sure that embedded pages aren't removed
@@ -892,7 +902,6 @@ define( [
892902 }
893903
894904 //bind pageHide to removePage after it's hidden, if the page options specify to do so
895-
896905 // Remove loading message.
897906 if ( settings . showLoadMsg ) {
898907 hideMsg ( ) ;
@@ -910,9 +919,7 @@ define( [
910919 } ,
911920 error : function ( xhr , textStatus , errorThrown ) {
912921 //set base back to current path
913- if ( base ) {
914- base . set ( path . get ( ) ) ;
915- }
922+ base . set ( path . get ( ) ) ;
916923
917924 // Add error info to our triggerData.
918925 triggerData . xhr = xhr ;
@@ -1184,6 +1191,7 @@ define( [
11841191 if ( alreadyThere ) {
11851192 urlHistory . activeIndex = Math . max ( 0 , urlHistory . activeIndex - 1 ) ;
11861193 }
1194+
11871195 urlHistory . addNew ( url , settings . transition , pageTitle , pageUrl , settings . role ) ;
11881196 }
11891197
0 commit comments