Revert "Export"
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / js / jquery.mobile.media.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: A workaround for browsers without window.matchMedia
3 //>>label: matchMedia Polyfill
4 //>>group: Utilities
5
6
7 define( [ "jquery", "./jquery.mobile.core" ], function( $ ) {
8 //>>excludeEnd("jqmBuildExclude");
9 (function( $, undefined ) {
10
11 var $window = $( window ),
12         $html = $( "html" );
13
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
16         examples:
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)
20 */
21 $.mobile.media = (function() {
22         // TODO: use window.matchMedia once at least one UA implements it
23         var cache = {},
24                 testDiv = $( "<div id='jquery-mediatest'>" ),
25                 fakeBody = $( "<body>" ).append( testDiv );
26
27         return function( query ) {
28                 if ( !( query in cache ) ) {
29                         var styleBlock = document.createElement( "style" ),
30                                 cssrule = "@media " + query + " { #jquery-mediatest { position:absolute; } }";
31
32                         //must set type for IE!
33                         styleBlock.type = "text/css";
34
35                         if ( styleBlock.styleSheet  ){
36                                 styleBlock.styleSheet.cssText = cssrule;
37                         } else {
38                                 styleBlock.appendChild( document.createTextNode(cssrule) );
39                         }
40
41                         $html.prepend( fakeBody ).prepend( styleBlock );
42                         cache[ query ] = testDiv.css( "position" ) === "absolute";
43                         fakeBody.add( styleBlock ).remove();
44                 }
45                 return cache[ query ];
46         };
47 })();
48
49 })(jQuery);
50 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
51 });
52 //>>excludeEnd("jqmBuildExclude");