393eea81a0b55684eae7d9c8f8f3315ae5cfc04c
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / js / jquery.mobile.support.js
1 /*
2 * support tests
3 */
4
5 (function( $, undefined ) {
6
7 var fakeBody = $( "<body>" ).prependTo( "html" ),
8         fbCSS = fakeBody[ 0 ].style,
9         vendors = [ "Webkit", "Moz", "O" ],
10         webos = "palmGetResource" in window, //only used to rule out scrollTop
11         operamini = window.operamini && ({}).toString.call( window.operamini ) === "[object OperaMini]",
12         bb = window.blackberry; //only used to rule out box shadow, as it's filled opaque on BB
13
14 // thx Modernizr
15 function propExists( prop ) {
16         var uc_prop = prop.charAt( 0 ).toUpperCase() + prop.substr( 1 ),
17                 props = ( prop + " " + vendors.join( uc_prop + " " ) + uc_prop ).split( " " );
18
19         for ( var v in props ){
20                 if ( fbCSS[ props[ v ] ] !== undefined ) {
21                         return true;
22                 }
23         }
24 }
25
26 // Test for dynamic-updating base tag support ( allows us to avoid href,src attr rewriting )
27 function baseTagTest() {
28         var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/",
29                 base = $( "head base" ),
30                 fauxEle = null,
31                 href = "",
32                 link, rebase;
33
34         if ( !base.length ) {
35                 base = fauxEle = $( "<base>", { "href": fauxBase }).appendTo( "head" );
36         } else {
37                 href = base.attr( "href" );
38         }
39
40         link = $( "<a href='testurl' />" ).prependTo( fakeBody );
41         rebase = link[ 0 ].href;
42         base[ 0 ].href = href || location.pathname;
43
44         if ( fauxEle ) {
45                 fauxEle.remove();
46         }
47         return rebase.indexOf( fauxBase ) === 0;
48 }
49
50
51 // non-UA-based IE version check by James Padolsey, modified by jdalton - from http://gist.github.com/527683
52 // allows for inclusion of IE 6+, including Windows Mobile 7
53 $.mobile.browser = {};
54 $.mobile.browser.ie = (function() {
55         var v = 3,
56         div = document.createElement( "div" ),
57         a = div.all || [];
58
59         while ( div.innerHTML = "<!--[if gt IE " + ( ++v ) + "]><br><![endif]-->", a[ 0 ] );
60
61         return v > 4 ? v : !v;
62 })();
63
64
65 $.extend( $.support, {
66         orientation: "orientation" in window && "onorientationchange" in window,
67         touch: "ontouchend" in document,
68         cssTransitions: "WebKitTransitionEvent" in window,
69         pushState: "pushState" in history && "replaceState" in history,
70         mediaquery: $.mobile.media( "only all" ),
71         cssPseudoElement: !!propExists( "content" ),
72         touchOverflow: !!propExists( "overflowScrolling" ),
73         boxShadow: !!propExists( "boxShadow" ) && !bb,
74         scrollTop: ( "pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[ 0 ] ) && !webos && !operamini,
75         dynamicBaseTag: baseTagTest()
76 });
77
78 fakeBody.remove();
79
80
81 // $.mobile.ajaxBlacklist is used to override ajaxEnabled on platforms that have known conflicts with hash history updates (BB5, Symbian)
82 // or that generally work better browsing in regular http for full page refreshes (Opera Mini)
83 // Note: This detection below is used as a last resort.
84 // We recommend only using these detection methods when all other more reliable/forward-looking approaches are not possible
85 var nokiaLTE7_3 = (function(){
86
87         var ua = window.navigator.userAgent;
88
89         //The following is an attempt to match Nokia browsers that are running Symbian/s60, with webkit, version 7.3 or older
90         return ua.indexOf( "Nokia" ) > -1 &&
91                         ( ua.indexOf( "Symbian/3" ) > -1 || ua.indexOf( "Series60/5" ) > -1 ) &&
92                         ua.indexOf( "AppleWebKit" ) > -1 &&
93                         ua.match( /(BrowserNG|NokiaBrowser)\/7\.[0-3]/ );
94 })();
95
96 $.mobile.ajaxBlacklist =
97                         // BlackBerry browsers, pre-webkit
98                         window.blackberry && !window.WebKitPoint ||
99                         // Opera Mini
100                         operamini ||
101                         // Symbian webkits pre 7.3
102                         nokiaLTE7_3;
103
104 // Lastly, this workaround is the only way we've found so far to get pre 7.3 Symbian webkit devices
105 // to render the stylesheets when they're referenced before this script, as we'd recommend doing.
106 // This simply reappends the CSS in place, which for some reason makes it apply
107 if ( nokiaLTE7_3 ) {
108         $(function() {
109                 $( "head link[rel='stylesheet']" ).attr( "rel", "alternate stylesheet" ).attr( "rel", "stylesheet" );
110         });
111 }
112
113 // For ruling out shadows via css
114 if ( !$.support.boxShadow ) {
115         $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" );
116 }
117
118 })( jQuery );