diff options
Diffstat (limited to 'js/polyfills')
-rw-r--r-- | js/polyfills/matchMedia.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/js/polyfills/matchMedia.js b/js/polyfills/matchMedia.js new file mode 100644 index 0000000..6d4d17c --- /dev/null +++ b/js/polyfills/matchMedia.js | |||
@@ -0,0 +1,30 @@ | |||
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 */ | ||
2 | |||
3 | window.matchMedia = window.matchMedia || (function(doc, undefined){ | ||
4 | |||
5 | var bool, | ||
6 | docElem = doc.documentElement, | ||
7 | refNode = docElem.firstElementChild || docElem.firstChild, | ||
8 | // fakeBody required for <FF4 when executed in <head> | ||
9 | fakeBody = doc.createElement('body'), | ||
10 | div = doc.createElement('div'); | ||
11 | |||
12 | div.id = 'mq-test-1'; | ||
13 | div.style.cssText = "position:absolute;top:-100em"; | ||
14 | fakeBody.style.background = "none"; | ||
15 | fakeBody.appendChild(div); | ||
16 | |||
17 | return function(q){ | ||
18 | |||
19 | div.innerHTML = '­<style media="'+q+'"> #mq-test-1 { width: 42px; }</style>'; | ||
20 | |||
21 | docElem.insertBefore(fakeBody, refNode); | ||
22 | bool = div.offsetWidth == 42; | ||
23 | docElem.removeChild(fakeBody); | ||
24 | |||
25 | return { matches: bool, media: q }; | ||
26 | }; | ||
27 | |||
28 | })(document); | ||
29 | |||
30 | |||