|
58 | 58 | focusable = "[tabindex],a,button:visible,select:visible,input", |
59 | 59 | nextPageRole = null, |
60 | 60 | hashListener = true, |
61 | | - unHashedSelectors = '[data-rel=dialog]'; |
| 61 | + unHashedSelectors = '[data-rel=dialog]', |
| 62 | + baseUrl = location.protocol + '//' + location.host + location.pathname; |
62 | 63 |
|
63 | 64 | // TODO: don't expose (temporary during code reorg) |
64 | 65 | $.mobile.urlStack = urlStack; |
|
94 | 95 | return newBaseURL; |
95 | 96 | } |
96 | 97 |
|
97 | | - function setBaseURL( nonHashPath ){ |
| 98 | + var setBaseURL = !$.support.dynamicBaseTag ? $.noop : function( nonHashPath ){ |
98 | 99 | //set base url for new page assets |
99 | | - $('#ui-base').attr('href', getBaseURL( nonHashPath )); |
| 100 | + $('#ui-base').attr('href', baseUrl + getBaseURL( nonHashPath )); |
100 | 101 | } |
101 | 102 |
|
102 | | - function resetBaseURL(){ |
103 | | - $('#ui-base').attr('href', location.pathname); |
| 103 | + var resetBaseURL = !$.support.dynamicBaseTag ? $.noop : function(){ |
| 104 | + $('#ui-base').attr('href', baseUrl); |
104 | 105 | } |
105 | 106 |
|
106 | 107 |
|
|
306 | 307 | all.get(0).innerHTML = html; |
307 | 308 | to = all.find('[data-role="page"]'); |
308 | 309 |
|
| 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 | + |
309 | 328 | //preserve ID on a retrieved page |
310 | 329 | if ( to.attr('id') ) { |
311 | 330 | to = wrapNewPage( to ); |
|
381 | 400 | $html.addClass('ui-mobile'); |
382 | 401 |
|
383 | 402 | //insert mobile meta - these will need to be configurable somehow. |
| 403 | + var headPrepends = |
384 | 404 | $head.prepend( |
385 | 405 | '<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" />' : '') |
387 | 407 | ); |
388 | 408 |
|
389 | 409 | //set base href to pathname |
|
0 commit comments