Skip to content

Commit d55fce4

Browse files
committed
Merge branch 'master' of github.com:jquery/jquery-mobile
2 parents 62623ca + 70bba70 commit d55fce4

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

js/jquery.mobile.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
focusable = "[tabindex],a,button:visible,select:visible,input",
5959
nextPageRole = null,
6060
hashListener = true,
61-
unHashedSelectors = '[data-rel=dialog]';
61+
unHashedSelectors = '[data-rel=dialog]',
62+
baseUrl = location.protocol + '//' + location.host + location.pathname;
6263

6364
// TODO: don't expose (temporary during code reorg)
6465
$.mobile.urlStack = urlStack;
@@ -94,13 +95,13 @@
9495
return newBaseURL;
9596
}
9697

97-
function setBaseURL( nonHashPath ){
98+
var setBaseURL = !$.support.dynamicBaseTag ? $.noop : function( nonHashPath ){
9899
//set base url for new page assets
99-
$('#ui-base').attr('href', getBaseURL( nonHashPath ));
100+
$('#ui-base').attr('href', baseUrl + getBaseURL( nonHashPath ));
100101
}
101102

102-
function resetBaseURL(){
103-
$('#ui-base').attr('href', location.pathname);
103+
var resetBaseURL = !$.support.dynamicBaseTag ? $.noop : function(){
104+
$('#ui-base').attr('href', baseUrl);
104105
}
105106

106107

@@ -306,6 +307,24 @@
306307
all.get(0).innerHTML = html;
307308
to = all.find('[data-role="page"]');
308309

310+
//rewrite src and href attrs to use a base url
311+
if( !$.support.dynamicBaseTag ){
312+
var baseUrl = getBaseURL(fileUrl);
313+
to.find('[src],[href]').each(function(){
314+
var thisHref = $(this).attr('href'),
315+
thisSrc = $(this).attr('src'),
316+
thisAttr = thisHref ? 'href' : 'src',
317+
thisUrl = thisHref || thisSrc;
318+
319+
//if full path exists and is same, chop it - helps IE out
320+
thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
321+
322+
if( !/^(\w+:|#|\/)/.test(thisUrl) ){
323+
$(this).attr(thisAttr, baseUrl + thisUrl);
324+
}
325+
});
326+
}
327+
309328
//preserve ID on a retrieved page
310329
if ( to.attr('id') ) {
311330
to = wrapNewPage( to );
@@ -381,9 +400,10 @@
381400
$html.addClass('ui-mobile');
382401

383402
//insert mobile meta - these will need to be configurable somehow.
403+
var headPrepends =
384404
$head.prepend(
385405
'<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />' +
386-
'<base href="" id="ui-base" />'
406+
($.support.dynamicBaseTag ? '<base href="" id="ui-base" />' : '')
387407
);
388408

389409
//set base href to pathname

js/jquery.mobile.support.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ function propExists( prop ){
4242
}
4343
};
4444

45+
//test for dynamic-updating base tag support (allows us to avoid href,src attr rewriting)
46+
function baseTagTest(){
47+
var fauxBase = location.protocol + '//' + location.host + location.pathname + "ui-dir/",
48+
base = $("<base>", {"href": fauxBase}).appendTo("head"),
49+
link = $( "<a href='testurl'></a>" ).prependTo( fakeBody );
50+
$.support.dynamicBaseTag = !!link[0].href.match(fauxBase);
51+
base.remove();
52+
};
53+
54+
baseTagTest();
55+
4556
$.extend( $.support, {
4657
orientation: "orientation" in window,
4758
touch: "ontouchend" in document,

0 commit comments

Comments
 (0)