1 (function( $, undefined ) {
3 var $window = $.mobile.$window,
6 /* $.mobile.media method: pass a CSS media type or query and get a bool return
7 note: this feature relies on actual media query support for media queries, though types will work most anywhere
9 $.mobile.media('screen') // tests for screen media type
10 $.mobile.media('screen and (min-width: 480px)') // tests for screen media type with window width > 480px
11 $.mobile.media('@media screen and (-webkit-min-device-pixel-ratio: 2)') // tests for webkit 2x pixel ratio (iPhone 4)
13 $.mobile.media = (function() {
14 // TODO: use window.matchMedia once at least one UA implements it
16 testDiv = $( "<div id='jquery-mediatest'></div>" ),
17 fakeBody = $( "<body>" ).append( testDiv );
19 return function( query ) {
20 if ( !( query in cache ) ) {
21 var styleBlock = document.createElement( "style" ),
22 cssrule = "@media " + query + " { #jquery-mediatest { position:absolute; } }";
24 //must set type for IE!
25 styleBlock.type = "text/css";
27 if ( styleBlock.styleSheet ) {
28 styleBlock.styleSheet.cssText = cssrule;
30 styleBlock.appendChild( document.createTextNode(cssrule) );
33 $html.prepend( fakeBody ).prepend( styleBlock );
34 cache[ query ] = testDiv.css( "position" ) === "absolute";
35 fakeBody.add( styleBlock ).remove();
37 return cache[ query ];