jquery-mobile/js/jquery.mobile.support.js
Kin Blas 02c9264f0d Fix for issue 613 - Jquery Mobile ignores original 'base' tag defined in HTML
- Fixed baseTagTest() in jquery.mobile.support.js, so that it uses any pre-existing base tag for testing. This fixes the bug on Webkit (Safari) where the relative paths for links were being resolved/expressed with the document path instead of the original base path.

- Modified the base code in jquery.mobile.navigation.js so that it uses the initial path of a pre-existing base tag, instead of always using the document path. This means that a document with a URL such as:

    http://foo.com/a/b/c#docs/pages/index.html

That uses a base tag like:

    <base href="http://foo.com/bar/">

Will resolve properly:

    http://foo.com/bar/docs/pages/index.html

so the mobile page gets loaded properly.

- Reduced the path.get() function down to a couple of regexp replace() calls.
2011-01-18 09:18:22 -08:00

66 lines
No EOL
2 KiB
JavaScript

/*
* jQuery Mobile Framework : support tests
* Copyright (c) jQuery Project
* Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
* Note: Code is in draft form and is subject to change
*/
(function($, undefined ) {
var fakeBody = $( "<body>" ).prependTo( "html" ),
fbCSS = fakeBody[0].style,
vendors = ['webkit','moz','o'],
webos = window.palmGetResource || window.PalmServiceBridge, //only used to rule out scrollTop
bb = window.blackberry; //only used to rule out box shadow, as it's filled opaque on BB
//thx Modernizr
function propExists( prop ){
var uc_prop = prop.charAt(0).toUpperCase() + prop.substr(1),
props = (prop + ' ' + vendors.join(uc_prop + ' ') + uc_prop).split(' ');
for(var v in props){
if( fbCSS[ v ] !== undefined ){
return true;
}
}
};
//test for dynamic-updating base tag support (allows us to avoid href,src attr rewriting)
function baseTagTest(){
var fauxBase = location.protocol + '//' + location.host + location.pathname + "ui-dir/",
base = $("head base"),
fauxEle = null,
href = '';
if (!base.length) {
base = fauxEle = $("<base>", {"href": fauxBase}).appendTo("head");
}
else {
href = base.attr("href");
}
var link = $( "<a href='testurl'></a>" ).prependTo( fakeBody ),
rebase = link[0].href;
base[0].href = href ? href : location.pathname;
if (fauxEle) {
fauxEle.remove();
}
return rebase.indexOf(fauxBase) === 0;
};
$.extend( $.support, {
orientation: "orientation" in window,
touch: "ontouchend" in document,
cssTransitions: "WebKitTransitionEvent" in window,
pushState: !!history.pushState,
mediaquery: $.mobile.media('only all'),
cssPseudoElement: !!propExists('content'),
boxShadow: !!propExists('boxShadow') && !bb,
scrollTop: ("pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[0]) && !webos,
dynamicBaseTag: baseTagTest()
});
fakeBody.remove();
//for ruling out shadows via css
if( !$.support.boxShadow ){ $('html').addClass('ui-mobile-nosupport-boxshadow'); }
})( jQuery );