Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit eb3901d

Browse files
committed
Added an option, rewriteBase, that can enable (by default) or disable the rewriting of the base element or urls.
1 parent 8e2f6fa commit eb3901d

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

js/jquery.mobile.core.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
// Automatically handle clicks and form submissions through Ajax, when same-domain
3030
ajaxEnabled: true,
31+
32+
//Automatically rewrite the base element, or if not supported, rewrite the urls
33+
rewriteBase: true,
3134

3235
// Automatically load and show pages based on location.hash
3336
hashListeningEnabled: true,

js/jquery.mobile.navigation.js

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -348,23 +348,27 @@
348348
//cache the comparison once.
349349
documentBaseDiffers = ( documentUrl.hrefNoHash !== documentBase.hrefNoHash );
350350

351-
//base element management, defined depending on dynamic base tag support
352-
var base = $.support.dynamicBaseTag ? {
351+
//base element management, defined depending on dynamic base tag support and if rewriteBase is enabled
352+
if ($.mobile.rewriteBase) {
353+
var base = $.support.dynamicBaseTag ? {
353354

354-
//define base element, for use in routing asset urls that are referenced in Ajax-requested markup
355-
element: ( $base.length ? $base : $( "<base>", { href: documentBase.hrefNoHash } ).prependTo( $head ) ),
355+
//define base element, for use in routing asset urls that are referenced in Ajax-requested markup
356+
element: ( $base.length ? $base : $( "<base>", { href: documentBase.hrefNoHash } ).prependTo( $head ) ),
356357

357-
//set the generated BASE element's href attribute to a new page's base path
358-
set: function( href ) {
359-
base.element.attr( "href", path.makeUrlAbsolute( href, documentBase ) );
360-
},
358+
//set the generated BASE element's href attribute to a new page's base path
359+
set: function( href ) {
360+
base.element.attr( "href", path.makeUrlAbsolute( href, documentBase ) );
361+
},
361362

362-
//set the generated BASE element's href attribute to a new page's base path
363-
reset: function() {
364-
base.element.attr( "href", documentBase.hrefNoHash );
365-
}
363+
//set the generated BASE element's href attribute to a new page's base path
364+
reset: function() {
365+
base.element.attr( "href", documentBase.hrefNoHash );
366+
}
366367

367-
} : undefined;
368+
} : undefined;
369+
} else {
370+
var base = jQuery("head base").attr("href");
371+
}
368372

369373
/*
370374
internal utility functions
@@ -837,23 +841,25 @@
837841
page.jqmData( "title", newPageTitle );
838842
}
839843

840-
//rewrite src and href attrs to use a base url
841-
if( !$.support.dynamicBaseTag ) {
842-
var newPath = path.get( fileUrl );
843-
page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() {
844-
var thisAttr = $( this ).is( '[href]' ) ? 'href' :
845-
$(this).is('[src]') ? 'src' : 'action',
846-
thisUrl = $( this ).attr( thisAttr );
847-
848-
// XXX_jblas: We need to fix this so that it removes the document
849-
// base URL, and then prepends with the new page URL.
850-
//if full path exists and is same, chop it - helps IE out
851-
thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
852-
853-
if( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
854-
$( this ).attr( thisAttr, newPath + thisUrl );
855-
}
856-
});
844+
//rewrite src and href attrs to use a base url if rewriteBase is enabled
845+
if ($.mobile.rewriteBase) {
846+
if( !$.support.dynamicBaseTag ) {
847+
var newPath = path.get( fileUrl );
848+
page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() {
849+
var thisAttr = $( this ).is( '[href]' ) ? 'href' :
850+
$(this).is('[src]') ? 'src' : 'action',
851+
thisUrl = $( this ).attr( thisAttr );
852+
853+
// XXX_jblas: We need to fix this so that it removes the document
854+
// base URL, and then prepends with the new page URL.
855+
//if full path exists and is same, chop it - helps IE out
856+
thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
857+
858+
if( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
859+
$( this ).attr( thisAttr, newPath + thisUrl );
860+
}
861+
});
862+
}
857863
}
858864

859865
//append to page and enhance

0 commit comments

Comments
 (0)