6209a7fe962be95abe12e4f1088dd3734ac45d30
[samples/web/ImageRotation.git] / tizen-web-ui-fw / latest / js / src / jquery.mobile.support.js
1 (function( $, undefined ) {
2
3 // thx Modernizr
4 function propExists( prop ) {
5         var uc_prop = prop.charAt( 0 ).toUpperCase() + prop.substr( 1 ),
6                 props = ( prop + " " + vendors.join( uc_prop + " " ) + uc_prop ).split( " " );
7
8         for ( var v in props ) {
9                 if ( fbCSS[ props[ v ] ] !== undefined ) {
10                         return true;
11                 }
12         }
13 }
14
15 var fakeBody = $( "<body>" ).prependTo( "html" ),
16         fbCSS = fakeBody[ 0 ].style,
17         vendors = [ "Webkit", "Moz", "O" ],
18         webos = "palmGetResource" in window, //only used to rule out scrollTop
19         opera = window.opera,
20         operamini = window.operamini && ({}).toString.call( window.operamini ) === "[object OperaMini]",
21         bb = window.blackberry && !propExists( "-webkit-transform" ); //only used to rule out box shadow, as it's filled opaque on BB 5 and lower
22
23
24 function validStyle( prop, value, check_vend ) {
25         var div = document.createElement( 'div' ),
26                 uc = function( txt ) {
27                         return txt.charAt( 0 ).toUpperCase() + txt.substr( 1 );
28                 },
29                 vend_pref = function( vend ) {
30                         return  "-" + vend.charAt( 0 ).toLowerCase() + vend.substr( 1 ) + "-";
31                 },
32                 check_style = function( vend ) {
33                         var vend_prop = vend_pref( vend ) + prop + ": " + value + ";",
34                                 uc_vend = uc( vend ),
35                                 propStyle = uc_vend + uc( prop );
36
37                         div.setAttribute( "style", vend_prop );
38
39                         if ( !!div.style[ propStyle ] ) {
40                                 ret = true;
41                         }
42                 },
43                 check_vends = check_vend ? [ check_vend ] : vendors,
44                 ret;
45
46         for( var i = 0; i < check_vends.length; i++ ) {
47                 check_style( check_vends[i] );
48         }
49         return !!ret;
50 }
51
52 // Thanks to Modernizr src for this test idea. `perspective` check is limited to Moz to prevent a false positive for 3D transforms on Android.
53 function transform3dTest() {
54         var prop = "transform-3d";
55         return validStyle( 'perspective', '10px', 'moz' ) || $.mobile.media( "(-" + vendors.join( "-" + prop + "),(-" ) + "-" + prop + "),(" + prop + ")" );
56 }
57
58 // Test for dynamic-updating base tag support ( allows us to avoid href,src attr rewriting )
59 function baseTagTest() {
60         var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/",
61                 base = $( "head base" ),
62                 fauxEle = null,
63                 href = "",
64                 link, rebase;
65
66         if ( !base.length ) {
67                 base = fauxEle = $( "<base>", { "href": fauxBase }).appendTo( "head" );
68         } else {
69                 href = base.attr( "href" );
70         }
71
72         link = $( "<a href='testurl' />" ).prependTo( fakeBody );
73         rebase = link[ 0 ].href;
74         base[ 0 ].href = href || location.pathname;
75
76         if ( fauxEle ) {
77                 fauxEle.remove();
78         }
79         return rebase.indexOf( fauxBase ) === 0;
80 }
81
82 // Thanks Modernizr
83 function cssPointerEventsTest() {
84         var element = document.createElement( 'x' ),
85                 documentElement = document.documentElement,
86                 getComputedStyle = window.getComputedStyle,
87                 supports;
88
89         if ( !( 'pointerEvents' in element.style ) ) {
90                 return false;
91         }
92
93         element.style.pointerEvents = 'auto';
94         element.style.pointerEvents = 'x';
95         documentElement.appendChild( element );
96         supports = getComputedStyle &&
97         getComputedStyle( element, '' ).pointerEvents === 'auto';
98         documentElement.removeChild( element );
99         return !!supports;
100 }
101
102 function boundingRect() {
103         var div = document.createElement( "div" );
104         return typeof div.getBoundingClientRect !== "undefined";
105 }
106
107 // non-UA-based IE version check by James Padolsey, modified by jdalton - from http://gist.github.com/527683
108 // allows for inclusion of IE 6+, including Windows Mobile 7
109 $.extend( $.mobile, { browser: {} } );
110 $.mobile.browser.ie = (function() {
111         var v = 3,
112                 div = document.createElement( "div" ),
113                 a = div.all || [];
114
115         do {
116                 div.innerHTML = "<!--[if gt IE " + ( ++v ) + "]><br><![endif]-->";
117         } while( a[0] );
118
119         return v > 4 ? v : !v;
120 })();
121
122
123 $.extend( $.support, {
124         cssTransitions: "WebKitTransitionEvent" in window || validStyle( 'transition', 'height 100ms linear' ) && !opera,
125         pushState: "pushState" in history && "replaceState" in history,
126         mediaquery: $.mobile.media( "only all" ),
127         cssPseudoElement: !!propExists( "content" ),
128         touchOverflow: !!propExists( "overflowScrolling" ),
129         cssTransform3d: transform3dTest(),
130         boxShadow: !!propExists( "boxShadow" ) && !bb,
131         scrollTop: ( "pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[ 0 ] ) && !webos && !operamini,
132         dynamicBaseTag: baseTagTest(),
133         cssPointerEvents: cssPointerEventsTest(),
134         boundingRect: boundingRect()
135 });
136
137 fakeBody.remove();
138
139
140 // $.mobile.ajaxBlacklist is used to override ajaxEnabled on platforms that have known conflicts with hash history updates (BB5, Symbian)
141 // or that generally work better browsing in regular http for full page refreshes (Opera Mini)
142 // Note: This detection below is used as a last resort.
143 // We recommend only using these detection methods when all other more reliable/forward-looking approaches are not possible
144 var nokiaLTE7_3 = (function() {
145
146         var ua = window.navigator.userAgent;
147
148         //The following is an attempt to match Nokia browsers that are running Symbian/s60, with webkit, version 7.3 or older
149         return ua.indexOf( "Nokia" ) > -1 &&
150                         ( ua.indexOf( "Symbian/3" ) > -1 || ua.indexOf( "Series60/5" ) > -1 ) &&
151                         ua.indexOf( "AppleWebKit" ) > -1 &&
152                         ua.match( /(BrowserNG|NokiaBrowser)\/7\.[0-3]/ );
153 })();
154
155 // Support conditions that must be met in order to proceed
156 // default enhanced qualifications are media query support OR IE 7+
157
158 $.mobile.gradeA = function() {
159         return ( $.support.mediaquery || $.mobile.browser.ie && $.mobile.browser.ie >= 7 ) && ( $.support.boundingRect || $.fn.jquery.match(/1\.[0-7+]\.[0-9+]?/) !== null );
160 };
161
162 $.mobile.ajaxBlacklist =
163                         // BlackBerry browsers, pre-webkit
164                         window.blackberry && !window.WebKitPoint ||
165                         // Opera Mini
166                         operamini ||
167                         // Symbian webkits pre 7.3
168                         nokiaLTE7_3;
169
170 // Lastly, this workaround is the only way we've found so far to get pre 7.3 Symbian webkit devices
171 // to render the stylesheets when they're referenced before this script, as we'd recommend doing.
172 // This simply reappends the CSS in place, which for some reason makes it apply
173 if ( nokiaLTE7_3 ) {
174         $(function() {
175                 $( "head link[rel='stylesheet']" ).attr( "rel", "alternate stylesheet" ).attr( "rel", "stylesheet" );
176         });
177 }
178
179 // For ruling out shadows via css
180 if ( !$.support.boxShadow ) {
181         $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" );
182 }
183
184 })( jQuery );