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