Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 37 lines (24 sloc) 0.971 kb
4b31172 crunch-friendlier attribution. :)
scottjehl authored
1 /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
50c64c8 Paul Irish big refactor to incorporate nicholas's technique.
authored
2
35b041e just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl authored
3 window.matchMedia = window.matchMedia || (function( doc, undefined ) {
4
5 "use strict";
795df18 Paul Irish IE is the whiniest fixes #10
authored
6
50c64c8 Paul Irish big refactor to incorporate nicholas's technique.
authored
7 var bool,
35b041e just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl authored
8 docElem = doc.documentElement,
9 refNode = docElem.firstElementChild || docElem.firstChild,
50c64c8 Paul Irish big refactor to incorporate nicholas's technique.
authored
10 // fakeBody required for <FF4 when executed in <head>
35b041e just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl authored
11 fakeBody = doc.createElement( "body" ),
12 div = doc.createElement( "div" );
795df18 Paul Irish IE is the whiniest fixes #10
authored
13
35b041e just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl authored
14 div.id = "mq-test-1";
50c64c8 Paul Irish big refactor to incorporate nicholas's technique.
authored
15 div.style.cssText = "position:absolute;top:-100em";
795df18 Paul Irish IE is the whiniest fixes #10
authored
16 fakeBody.style.background = "none";
50c64c8 Paul Irish big refactor to incorporate nicholas's technique.
authored
17 fakeBody.appendChild(div);
795df18 Paul Irish IE is the whiniest fixes #10
authored
18
50c64c8 Paul Irish big refactor to incorporate nicholas's technique.
authored
19 return function(q){
795df18 Paul Irish IE is the whiniest fixes #10
authored
20
35b041e just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl authored
21 div.innerHTML = "&shy;<style media=\"" + q + "\"> #mq-test-1 { width: 42px; }</style>";
795df18 Paul Irish IE is the whiniest fixes #10
authored
22
35b041e just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl authored
23 docElem.insertBefore( fakeBody, refNode );
50fb527 strict compare
Scott Jehl authored
24 bool = div.offsetWidth === 42;
35b041e just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl authored
25 docElem.removeChild( fakeBody );
26
27 return {
28 matches: bool,
29 media: q
30 };
795df18 Paul Irish IE is the whiniest fixes #10
authored
31
50c64c8 Paul Irish big refactor to incorporate nicholas's technique.
authored
32 };
795df18 Paul Irish IE is the whiniest fixes #10
authored
33
35b041e just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl authored
34 }( document ));
154509a Paul Irish add back examples.
authored
35
36
Something went wrong with that request. Please try again.