1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: A workaround for browsers without window.matchMedia
3 //>>label: matchMedia Polyfill
7 define( [ "jquery", "./jquery.mobile.core" ], function( $ ) {
8 //>>excludeEnd("jqmBuildExclude");
9 (function( $, undefined ) {
11 var $window = $( window ),
14 /* $.mobile.media method: pass a CSS media type or query and get a bool return
15 note: this feature relies on actual media query support for media queries, though types will work most anywhere
17 $.mobile.media('screen') // tests for screen media type
18 $.mobile.media('screen and (min-width: 480px)') // tests for screen media type with window width > 480px
19 $.mobile.media('@media screen and (-webkit-min-device-pixel-ratio: 2)') // tests for webkit 2x pixel ratio (iPhone 4)
21 $.mobile.media = (function() {
22 // TODO: use window.matchMedia once at least one UA implements it
24 testDiv = $( "<div id='jquery-mediatest'>" ),
25 fakeBody = $( "<body>" ).append( testDiv );
27 return function( query ) {
28 if ( !( query in cache ) ) {
29 var styleBlock = document.createElement( "style" ),
30 cssrule = "@media " + query + " { #jquery-mediatest { position:absolute; } }";
32 //must set type for IE!
33 styleBlock.type = "text/css";
35 if ( styleBlock.styleSheet ){
36 styleBlock.styleSheet.cssText = cssrule;
38 styleBlock.appendChild( document.createTextNode(cssrule) );
41 $html.prepend( fakeBody ).prepend( styleBlock );
42 cache[ query ] = testDiv.css( "position" ) === "absolute";
43 fakeBody.add( styleBlock ).remove();
45 return cache[ query ];
50 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
52 //>>excludeEnd("jqmBuildExclude");