Skip to content
Sign up
Sign in
This repository
Explore
Features
Enterprise
Blog
Star
1,445
Fork
222
paulirish
/
matchMedia.js
Code
Issues
Pull Requests
Pulse
Graphs
HTTPS
clone URL
Subversion
checkout URL
You can clone with
HTTPS
or
Subversion
.
Download ZIP
Permalink
matchMedia.js
/
matchMedia.js
Newer
Older
100644
37 lines (24 sloc)
0.971 kb
Raw
Normal view
History
4b31172
crunch-friendlier attribution. :)
scottjehl
authored
Jan 16, 2012
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
big refactor to incorporate nicholas's technique.
paulirish
authored
Mar 31, 2011
2
35b041e
just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl
authored
Sep 13, 2012
3
window
.matchMedia
=
window
.matchMedia
||
(
function
(
doc
,
undefined
) {
4
5
"
use strict
"
;
795df18
IE is the whiniest fixes #10
paulirish
authored
Apr 5, 2012
6
50c64c8
big refactor to incorporate nicholas's technique.
paulirish
authored
Apr 1, 2011
7
var
bool,
35b041e
just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl
authored
Sep 13, 2012
8
docElem
=
doc.
documentElement
,
9
refNode
=
docElem.firstElementChild
||
docElem.
firstChild
,
50c64c8
big refactor to incorporate nicholas's technique.
paulirish
authored
Apr 1, 2011
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
Sep 13, 2012
11
fakeBody
=
doc.
createElement
(
"
body
"
),
12
div
=
doc.
createElement
(
"
div
"
);
795df18
IE is the whiniest fixes #10
paulirish
authored
Apr 5, 2012
13
35b041e
just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl
authored
Sep 13, 2012
14
div.
id
=
"
mq-test-1
"
;
50c64c8
big refactor to incorporate nicholas's technique.
paulirish
authored
Apr 1, 2011
15
div.
style
.cssText
=
"
position:absolute;top:-100em
"
;
795df18
IE is the whiniest fixes #10
paulirish
authored
Apr 5, 2012
16
fakeBody.
style
.
background
=
"
none
"
;
50c64c8
big refactor to incorporate nicholas's technique.
paulirish
authored
Apr 1, 2011
17
fakeBody.
appendChild
(div);
795df18
IE is the whiniest fixes #10
paulirish
authored
Apr 5, 2012
18
50c64c8
big refactor to incorporate nicholas's technique.
paulirish
authored
Apr 1, 2011
19
return
function
(
q
){
795df18
IE is the whiniest fixes #10
paulirish
authored
Apr 5, 2012
20
35b041e
just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl
authored
Sep 13, 2012
21
div.innerHTML
=
"
­<style media=
\"
"
+
q
+
"
\"
> #mq-test-1 { width: 42px; }</style>
"
;
795df18
IE is the whiniest fixes #10
paulirish
authored
Apr 5, 2012
22
35b041e
just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl
authored
Sep 13, 2012
23
docElem.
insertBefore
( fakeBody, refNode );
50fb527
strict compare
Scott Jehl
authored
Jun 7, 2012
24
bool
=
div.offsetWidth
===
42
;
35b041e
just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl
authored
Sep 13, 2012
25
docElem.
removeChild
( fakeBody );
26
27
return
{
28
matches
:
bool,
29
media
:
q
30
};
795df18
IE is the whiniest fixes #10
paulirish
authored
Apr 5, 2012
31
50c64c8
big refactor to incorporate nicholas's technique.
paulirish
authored
Apr 1, 2011
32
};
795df18
IE is the whiniest fixes #10
paulirish
authored
Apr 5, 2012
33
35b041e
just some edits to coding style, and added "use strict" for linty freshn...
Scott Jehl
authored
Sep 13, 2012
34
}(
document
));
154509a
add back examples.
paulirish
authored
Mar 31, 2011
35
36
Something went wrong with that request. Please try again.