forked from sklochko-id/matchmedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatchmedia.min.js
3 lines (3 loc) · 1.2 KB
/
matchmedia.min.js
1
2
3
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
/*! matchMedia() polyfill addListener/removeListener extension. Author & copyright (c) 2012: Scott Jehl. Dual MIT/BSD license */
window.matchMedia=window.matchMedia||function(e,t){"use strict";var n,r=e.documentElement,i=r.firstElementChild||r.firstChild,s=e.createElement("body"),o=e.createElement("div");o.id="mq-test-1";o.style.cssText="position:absolute;top:-100em";s.style.background="none";s.appendChild(o);return function(e){o.innerHTML='<style media="'+e+'"> #mq-test-1 { width: 42px; }</style>';r.insertBefore(s,i);n=o.offsetWidth===42;r.removeChild(s);return{matches:n,media:e}}}(document);(function(){if(!window.matchMedia("all").addListener){var e=window.matchMedia;window.matchMedia=function(t){var n=e(t),r=[],i=n.matches,s,o=function(){var s=e(t),o=s.matches&&!i,u=!s.matches&&i;if(o||u){for(var a=0,f=r.length;a<f;a++){r[a].call(n,s)}}i=s.matches};n.addListener=function(e){r.push(e);if(!s){s=setInterval(o,1e3)}};n.removeListener=function(e){for(var t=0,n=r.length;t<n;t++){if(r[t]===e){r.splice(t,1)}}if(!r.length&&s){clearInterval(s)}};return n}}})()