Merge pull request #1978 from rwldrn/jquery.mobile.support.js

jQuery core style guide conformance: jquery.mobile.support.js
This commit is contained in:
Kin Blas 2011-06-29 08:23:53 -07:00
commit 786d1bf328

View file

@ -2,42 +2,47 @@
* 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
* Note: Code is in draft form and is subject to change
*/
( function( $, undefined ) {
(function( $, undefined ) {
var fakeBody = $( "<body>" ).prependTo( "html" ),
fbCSS = fakeBody[ 0 ].style,
vendors = [ "webkit", "moz", "o" ],
webos = "palmGetResource" in window, //only used to rule out scrollTop
webos = "palmGetResource" in window, //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 ){
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 ){
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(){
// 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 = "";
href = "",
link, rebase;
if ( !base.length ) {
base = fauxEle = $( "<base>", { "href": fauxBase} ).appendTo( "head" );
}
else {
} else {
href = base.attr( "href" );
}
var link = $( "<a href='testurl'></a>" ).prependTo( fakeBody ),
rebase = link[ 0 ].href;
link = $( "<a href='testurl'></a>" ).prependTo( fakeBody );
rebase = link[ 0 ].href;
base[ 0 ].href = href ? href : location.pathname;
if ( fauxEle ) {
fauxEle.remove();
}
@ -48,13 +53,15 @@ function baseTagTest(){
// non-UA-based IE version check by James Padolsey, modified by jdalton - from http://gist.github.com/527683
// allows for inclusion of IE 6+, including Windows Mobile 7
$.mobile.browser = {};
$.mobile.browser.ie = ( function() {
var v = 3,
div = document.createElement( "div" ),
$.mobile.browser.ie = (function() {
var v = 3,
div = document.createElement( "div" ),
a = div.all || [];
while ( div.innerHTML = "<!--[if gt IE " + ( ++v ) + "]><br><![endif]-->", a[ 0 ] );
return v > 4 ? v : !v;
}() );
while ( div.innerHTML = "<!--[if gt IE " + ( ++v ) + "]><br><![endif]-->", a[ 0 ] );
return v > 4 ? v : !v;
})();
$.extend( $.support, {
@ -67,12 +74,15 @@ $.extend( $.support, {
boxShadow: !!propExists( "boxShadow" ) && !bb,
scrollTop: ( "pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[ 0 ] ) && !webos,
dynamicBaseTag: baseTagTest(),
eventCapture: ( "addEventListener" in document ) // This is a weak test. We may want to beef this up later.
} );
// TODO: This is a weak test. We may want to beef this up later.
eventCapture: "addEventListener" in document
});
fakeBody.remove();
// for ruling out shadows via css
if( !$.support.boxShadow ){ $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" ); }
// For ruling out shadows via css
if ( !$.support.boxShadow ){
$( "html" ).addClass( "ui-mobile-nosupport-boxshadow" );
}
} )( jQuery );
})( jQuery );