1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Assorted tests to qualify browsers by detecting features
3 //>>label: Support Tests
7 define( [ "jquery", "./jquery.mobile.media", "./jquery.mobile.core" ], function( $ ) {
8 //>>excludeEnd("jqmBuildExclude");
9 (function( $, undefined ) {
11 var fakeBody = $( "<body>" ).prependTo( "html" ),
12 fbCSS = fakeBody[ 0 ].style,
13 vendors = [ "Webkit", "Moz", "O" ],
14 webos = "palmGetResource" in window, //only used to rule out scrollTop
15 operamini = window.operamini && ({}).toString.call( window.operamini ) === "[object OperaMini]",
16 bb = window.blackberry; //only used to rule out box shadow, as it's filled opaque on BB
19 function propExists( prop ) {
20 var uc_prop = prop.charAt( 0 ).toUpperCase() + prop.substr( 1 ),
21 props = ( prop + " " + vendors.join( uc_prop + " " ) + uc_prop ).split( " " );
23 for ( var v in props ){
24 if ( fbCSS[ props[ v ] ] !== undefined ) {
30 function validStyle( prop, value, check_vend ) {
31 var div = document.createElement('div'),
32 uc = function( txt ) {
33 return txt.charAt( 0 ).toUpperCase() + txt.substr( 1 )
35 vend_pref = function( vend ) {
36 return "-" + vend.charAt( 0 ).toLowerCase() + vend.substr( 1 ) + "-";
38 check_style = function( vend ) {
39 var vend_prop = vend_pref( vend ) + prop + ": " + value + ";",
41 propStyle = uc_vend + uc( prop );
43 div.setAttribute( "style", vend_prop );
45 if( !!div.style[ propStyle ] ) {
49 check_vends = check_vend ? [ check_vend ] : vendors,
52 for( i = 0; i < check_vends.length; i++ ) {
53 check_style( check_vends[i] );
58 // Thanks to Modernizr src for this test idea. `perspective` check is limited to Moz to prevent a false positive for 3D transforms on Android.
59 function transform3dTest() {
60 var prop = "transform-3d";
61 return validStyle( 'perspective', '10px', 'moz' ) || $.mobile.media( "(-" + vendors.join( "-" + prop + "),(-" ) + "-" + prop + "),(" + prop + ")" );
64 // Test for dynamic-updating base tag support ( allows us to avoid href,src attr rewriting )
65 function baseTagTest() {
66 var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/",
67 base = $( "head base" ),
73 base = fauxEle = $( "<base>", { "href": fauxBase }).appendTo( "head" );
75 href = base.attr( "href" );
78 link = $( "<a href='testurl' />" ).prependTo( fakeBody );
79 rebase = link[ 0 ].href;
80 base[ 0 ].href = href || location.pathname;
85 return rebase.indexOf( fauxBase ) === 0;
89 // non-UA-based IE version check by James Padolsey, modified by jdalton - from http://gist.github.com/527683
90 // allows for inclusion of IE 6+, including Windows Mobile 7
91 $.extend( $.mobile, { browser: {} } );
92 $.mobile.browser.ie = (function() {
94 div = document.createElement( "div" ),
97 // added {} to silence closure compiler warnings. registering my dislike of all things
98 // overly clever here for future reference
99 while ( div.innerHTML = "<!--[if gt IE " + ( ++v ) + "]><br><![endif]-->", a[ 0 ] ){};
101 return v > 4 ? v : !v;
105 $.extend( $.support, {
106 orientation: "orientation" in window && "onorientationchange" in window,
107 touch: "ontouchend" in document,
108 cssTransitions: "WebKitTransitionEvent" in window || validStyle( 'transition', 'height 100ms linear' ),
109 pushState: "pushState" in history && "replaceState" in history,
110 mediaquery: $.mobile.media( "only all" ),
111 cssPseudoElement: !!propExists( "content" ),
112 touchOverflow: !!propExists( "overflowScrolling" ),
113 cssTransform3d: transform3dTest(),
114 boxShadow: !!propExists( "boxShadow" ) && !bb,
115 scrollTop: ( "pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[ 0 ] ) && !webos && !operamini,
116 dynamicBaseTag: baseTagTest()
122 // $.mobile.ajaxBlacklist is used to override ajaxEnabled on platforms that have known conflicts with hash history updates (BB5, Symbian)
123 // or that generally work better browsing in regular http for full page refreshes (Opera Mini)
124 // Note: This detection below is used as a last resort.
125 // We recommend only using these detection methods when all other more reliable/forward-looking approaches are not possible
126 var nokiaLTE7_3 = (function(){
128 var ua = window.navigator.userAgent;
130 //The following is an attempt to match Nokia browsers that are running Symbian/s60, with webkit, version 7.3 or older
131 return ua.indexOf( "Nokia" ) > -1 &&
132 ( ua.indexOf( "Symbian/3" ) > -1 || ua.indexOf( "Series60/5" ) > -1 ) &&
133 ua.indexOf( "AppleWebKit" ) > -1 &&
134 ua.match( /(BrowserNG|NokiaBrowser)\/7\.[0-3]/ );
137 // Support conditions that must be met in order to proceed
138 // default enhanced qualifications are media query support OR IE 7+
139 $.mobile.gradeA = function(){
140 return $.support.mediaquery || $.mobile.browser.ie && $.mobile.browser.ie >= 7;
143 $.mobile.ajaxBlacklist =
144 // BlackBerry browsers, pre-webkit
145 window.blackberry && !window.WebKitPoint ||
148 // Symbian webkits pre 7.3
151 // Lastly, this workaround is the only way we've found so far to get pre 7.3 Symbian webkit devices
152 // to render the stylesheets when they're referenced before this script, as we'd recommend doing.
153 // This simply reappends the CSS in place, which for some reason makes it apply
156 $( "head link[rel='stylesheet']" ).attr( "rel", "alternate stylesheet" ).attr( "rel", "stylesheet" );
160 // For ruling out shadows via css
161 if ( !$.support.boxShadow ) {
162 $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" );
166 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
168 //>>excludeEnd("jqmBuildExclude");