Revert "Export"
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / js / jquery.mobile.support.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Assorted tests to qualify browsers by detecting features
3 //>>label: Support Tests
4 //>>group: Core
5 //>>required: true
6
7 define( [  "jquery", "./jquery.mobile.media", "./jquery.mobile.core" ], function( $ ) {
8 //>>excludeEnd("jqmBuildExclude");
9 (function( $, undefined ) {
10
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
17
18 // thx Modernizr
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( " " );
22
23         for ( var v in props ){
24                 if ( fbCSS[ props[ v ] ] !== undefined ) {
25                         return true;
26                 }
27         }
28 }
29
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 )
34                 },
35                 vend_pref = function( vend ) {
36                         return  "-" + vend.charAt( 0 ).toLowerCase() + vend.substr( 1 ) + "-";
37                 },
38                 check_style = function( vend ) {
39                         var vend_prop = vend_pref( vend ) + prop + ": " + value + ";",
40                                 uc_vend = uc( vend ),
41                                 propStyle = uc_vend + uc( prop );
42                 
43                         div.setAttribute( "style", vend_prop );
44                 
45                         if( !!div.style[ propStyle ] ) {
46                                 ret = true;
47                         }
48                 },
49                 check_vends = check_vend ? [ check_vend ] : vendors,
50                 ret;
51
52         for( i = 0; i < check_vends.length; i++ ) {
53                 check_style( check_vends[i] );
54         }
55         return !!ret;
56 }
57
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 + ")" );
62 }
63
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" ),
68                 fauxEle = null,
69                 href = "",
70                 link, rebase;
71
72         if ( !base.length ) {
73                 base = fauxEle = $( "<base>", { "href": fauxBase }).appendTo( "head" );
74         } else {
75                 href = base.attr( "href" );
76         }
77
78         link = $( "<a href='testurl' />" ).prependTo( fakeBody );
79         rebase = link[ 0 ].href;
80         base[ 0 ].href = href || location.pathname;
81
82         if ( fauxEle ) {
83                 fauxEle.remove();
84         }
85         return rebase.indexOf( fauxBase ) === 0;
86 }
87
88
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() {
93         var v = 3,
94         div = document.createElement( "div" ),
95         a = div.all || [];
96
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 ] ){};
100
101         return v > 4 ? v : !v;
102 })();
103
104
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()
117 });
118
119 fakeBody.remove();
120
121
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(){
127
128         var ua = window.navigator.userAgent;
129
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]/ );
135 })();
136
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;
141 };
142
143 $.mobile.ajaxBlacklist =
144                         // BlackBerry browsers, pre-webkit
145                         window.blackberry && !window.WebKitPoint ||
146                         // Opera Mini
147                         operamini ||
148                         // Symbian webkits pre 7.3
149                         nokiaLTE7_3;
150
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
154 if ( nokiaLTE7_3 ) {
155         $(function() {
156                 $( "head link[rel='stylesheet']" ).attr( "rel", "alternate stylesheet" ).attr( "rel", "stylesheet" );
157         });
158 }
159
160 // For ruling out shadows via css
161 if ( !$.support.boxShadow ) {
162         $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" );
163 }
164
165 })( jQuery );
166 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
167 });
168 //>>excludeEnd("jqmBuildExclude");