| //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude); |
| //>>description: Assorted tests to qualify browsers by detecting features |
| //>>label: Support Tests |
| //>>group: Core |
| define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.media" ], function( jQuery ) { |
| //>>excludeEnd("jqmBuildExclude"); |
| (function( $, undefined ) { |
| |
| // 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[ props[ v ] ] !== undefined ) { |
| return true; |
| } |
| } |
| } |
| |
| var fakeBody = $( "<body>" ).prependTo( "html" ), |
| fbCSS = fakeBody[ 0 ].style, |
| vendors = [ "Webkit", "Moz", "O" ], |
| webos = "palmGetResource" in window, //only used to rule out scrollTop |
| opera = window.opera, |
| operamini = window.operamini && ({}).toString.call( window.operamini ) === "[object OperaMini]", |
| bb = window.blackberry && !propExists( "-webkit-transform" ); //only used to rule out box shadow, as it's filled opaque on BB 5 and lower |
| |
| |
| function validStyle( prop, value, check_vend ) { |
| var div = document.createElement( 'div' ), |
| uc = function( txt ) { |
| return txt.charAt( 0 ).toUpperCase() + txt.substr( 1 ); |
| }, |
| vend_pref = function( vend ) { |
| return "-" + vend.charAt( 0 ).toLowerCase() + vend.substr( 1 ) + "-"; |
| }, |
| check_style = function( vend ) { |
| var vend_prop = vend_pref( vend ) + prop + ": " + value + ";", |
| uc_vend = uc( vend ), |
| propStyle = uc_vend + uc( prop ); |
| |
| div.setAttribute( "style", vend_prop ); |
| |
| if ( !!div.style[ propStyle ] ) { |
| ret = true; |
| } |
| }, |
| check_vends = check_vend ? [ check_vend ] : vendors, |
| ret; |
| |
| for( var i = 0; i < check_vends.length; i++ ) { |
| check_style( check_vends[i] ); |
| } |
| return !!ret; |
| } |
| |
| // Thanks to Modernizr src for this test idea. `perspective` check is limited to Moz to prevent a false positive for 3D transforms on Android. |
| function transform3dTest() { |
| var prop = "transform-3d"; |
| return validStyle( 'perspective', '10px', 'moz' ) || $.mobile.media( "(-" + vendors.join( "-" + prop + "),(-" ) + "-" + prop + "),(" + prop + ")" ); |
| } |
| |
| // 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 = "", |
| link, rebase; |
| |
| if ( !base.length ) { |
| base = fauxEle = $( "<base>", { "href": fauxBase }).appendTo( "head" ); |
| } else { |
| href = base.attr( "href" ); |
| } |
| |
| link = $( "<a href='testurl' />" ).prependTo( fakeBody ); |
| rebase = link[ 0 ].href; |
| base[ 0 ].href = href || location.pathname; |
| |
| if ( fauxEle ) { |
| fauxEle.remove(); |
| } |
| return rebase.indexOf( fauxBase ) === 0; |
| } |
| |
| // Thanks Modernizr |
| function cssPointerEventsTest() { |
| var element = document.createElement( 'x' ), |
| documentElement = document.documentElement, |
| getComputedStyle = window.getComputedStyle, |
| supports; |
| |
| if ( !( 'pointerEvents' in element.style ) ) { |
| return false; |
| } |
| |
| element.style.pointerEvents = 'auto'; |
| element.style.pointerEvents = 'x'; |
| documentElement.appendChild( element ); |
| supports = getComputedStyle && |
| getComputedStyle( element, '' ).pointerEvents === 'auto'; |
| documentElement.removeChild( element ); |
| return !!supports; |
| } |
| |
| function boundingRect() { |
| var div = document.createElement( "div" ); |
| return typeof div.getBoundingClientRect !== "undefined"; |
| } |
| |
| // 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 |
| $.extend( $.mobile, { browser: {} } ); |
| $.mobile.browser.ie = (function() { |
| var v = 3, |
| div = document.createElement( "div" ), |
| a = div.all || []; |
| |
| do { |
| div.innerHTML = "<!--[if gt IE " + ( ++v ) + "]><br><![endif]-->"; |
| } while( a[0] ); |
| |
| return v > 4 ? v : !v; |
| })(); |
| |
| |
| $.extend( $.support, { |
| cssTransitions: "WebKitTransitionEvent" in window || validStyle( 'transition', 'height 100ms linear' ) && !opera, |
| pushState: "pushState" in history && "replaceState" in history, |
| mediaquery: $.mobile.media( "only all" ), |
| cssPseudoElement: !!propExists( "content" ), |
| touchOverflow: !!propExists( "overflowScrolling" ), |
| cssTransform3d: transform3dTest(), |
| boxShadow: !!propExists( "boxShadow" ) && !bb, |
| scrollTop: ( "pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[ 0 ] ) && !webos && !operamini, |
| dynamicBaseTag: baseTagTest(), |
| cssPointerEvents: cssPointerEventsTest(), |
| boundingRect: boundingRect() |
| }); |
| |
| fakeBody.remove(); |
| |
| |
| // $.mobile.ajaxBlacklist is used to override ajaxEnabled on platforms that have known conflicts with hash history updates (BB5, Symbian) |
| // or that generally work better browsing in regular http for full page refreshes (Opera Mini) |
| // Note: This detection below is used as a last resort. |
| // We recommend only using these detection methods when all other more reliable/forward-looking approaches are not possible |
| var nokiaLTE7_3 = (function() { |
| |
| var ua = window.navigator.userAgent; |
| |
| //The following is an attempt to match Nokia browsers that are running Symbian/s60, with webkit, version 7.3 or older |
| return ua.indexOf( "Nokia" ) > -1 && |
| ( ua.indexOf( "Symbian/3" ) > -1 || ua.indexOf( "Series60/5" ) > -1 ) && |
| ua.indexOf( "AppleWebKit" ) > -1 && |
| ua.match( /(BrowserNG|NokiaBrowser)\/7\.[0-3]/ ); |
| })(); |
| |
| // Support conditions that must be met in order to proceed |
| // default enhanced qualifications are media query support OR IE 7+ |
| |
| $.mobile.gradeA = function() { |
| return ( $.support.mediaquery || $.mobile.browser.ie && $.mobile.browser.ie >= 7 ) && ( $.support.boundingRect || $.fn.jquery.match(/1\.[0-7+]\.[0-9+]?/) !== null ); |
| }; |
| |
| $.mobile.ajaxBlacklist = |
| // BlackBerry browsers, pre-webkit |
| window.blackberry && !window.WebKitPoint || |
| // Opera Mini |
| operamini || |
| // Symbian webkits pre 7.3 |
| nokiaLTE7_3; |
| |
| // Lastly, this workaround is the only way we've found so far to get pre 7.3 Symbian webkit devices |
| // to render the stylesheets when they're referenced before this script, as we'd recommend doing. |
| // This simply reappends the CSS in place, which for some reason makes it apply |
| if ( nokiaLTE7_3 ) { |
| $(function() { |
| $( "head link[rel='stylesheet']" ).attr( "rel", "alternate stylesheet" ).attr( "rel", "stylesheet" ); |
| }); |
| } |
| |
| // For ruling out shadows via css |
| if ( !$.support.boxShadow ) { |
| $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" ); |
| } |
| |
| })( jQuery ); |
| //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude); |
| }); |
| //>>excludeEnd("jqmBuildExclude"); |