Permalink
Browse files

This change sets the base tag properly on page load and page changes,…

… corresponding with the recent change to absolute path hash urls. Images and other assets will direct relative to the document in which they reside. This may not cover new path situations Kin has documented, but it does fix the regression so things work as they did before the change. Tested in non-base supporting browsers to verify it works there too. The following page should have an image in the content, verifying the fix http://jquerymobile.com/test/#/test/docs/about/intro.html . Fixes #1508
  • Loading branch information...
scottjehl
scottjehl committed May 6, 2011
1 parent 131cb24 commit 4b4ee54a72493972b55cf559a88d0c290375230b
Showing with 12 additions and 17 deletions.
  1. +12 −17 js/jquery.mobile.navigation.js
@@ -201,33 +201,28 @@
//existing base tag?
$base = $head.children( "base" ),
hostURL = location.protocol + "//" + location.host,
docLocation = path.get( hostURL + location.pathname ),
docBase = docLocation;
//get domain path
//(note: use explicit protocol here, protocol-relative urls won't work as expected on localhost)
docBase = location.protocol + "//" + location.host,
//initialPath for first page load without hash. pathname (href - search)
initialPath = docBase + location.pathname;
//already a base element?
if ( $base.length ) {
var href = $base.attr( "href" );
if ( href ) {
if ( href.search( /^[^:\/]+:\/\/[^\/]+\/?/ ) === -1 ) {
//the href is not absolute, we need to turn it into one
//so that we can turn paths stored in our location hash into
//relative paths.
if ( href.charAt( 0 ) === "/" ) {
//site relative url
docBase = hostURL + href;
}
else {
//the href is a document relative url
docBase = docLocation + href;
//XXX: we need some code here to calculate the final path
// just in case the docBase contains up-level (../) references.
}
docBase = docBase + href;
}
else {
//the href is an absolute url
docBase = href;
}
}
//make sure docBase ends with a slash
docBase = docBase + ( docBase.charAt( docBase.length - 1 ) === "/" ? " " : "/" );
}
@@ -236,7 +231,7 @@
var base = $.support.dynamicBaseTag ? {
//define base element, for use in routing asset urls that are referenced in Ajax-requested markup
element: ( $base.length ? $base : $( "<base>", { href: docBase } ).prependTo( $head ) ),
element: ( $base.length ? $base : $( "<base>", { href: initialPath } ).prependTo( $head ) ),
//set the generated BASE element's href attribute to a new page's base path
set: function( href ) {

4 comments on commit 4b4ee54

@AYZ

This comment has been minimized.

Show comment
Hide comment
@AYZ

AYZ May 18, 2011

When I examine the code that is executed in the test page, it does not appear to the the "latest" build. I guess I could be wrong - it is a bit difficult to check.

AYZ replied May 18, 2011

When I examine the code that is executed in the test page, it does not appear to the the "latest" build. I guess I could be wrong - it is a bit difficult to check.

@toddparker

This comment has been minimized.

Show comment
Hide comment
@toddparker

toddparker May 18, 2011

Contributor

Go to http://jquerymobile.com/test/ then view source, click on the /js/ source and search for the new code. It's there.

Contributor

toddparker replied May 18, 2011

Go to http://jquerymobile.com/test/ then view source, click on the /js/ source and search for the new code. It's there.

@AYZ

This comment has been minimized.

Show comment
Hide comment
@AYZ

AYZ May 18, 2011

AYZ replied May 18, 2011

@toddparker

This comment has been minimized.

Show comment
Hide comment
@toddparker

toddparker May 18, 2011

Contributor

Sorry for the confusion. Both the "latest" JS on the CDN and jquerymobile.com/test/ should be pretty much identical, they are both sync'd with the Git repo every few minutes. The latest CDN link is compressed, while the /js/ folder in /test/ is just concatenated so maybe that's the difference?

Glad you like the blog posts, it's been fun telling people what we're up and how we're thinking about the direction of the library. More to come! Good to hear you agree on the back button too, I'm happy we asked.

Contributor

toddparker replied May 18, 2011

Sorry for the confusion. Both the "latest" JS on the CDN and jquerymobile.com/test/ should be pretty much identical, they are both sync'd with the Git repo every few minutes. The latest CDN link is compressed, while the /js/ folder in /test/ is just concatenated so maybe that's the difference?

Glad you like the blog posts, it's been fun telling people what we're up and how we're thinking about the direction of the library. More to come! Good to hear you agree on the back button too, I'm happy we asked.

Please sign in to comment.