forked from scottjehl/Respond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
respond.min.js
7 lines (5 loc) · 4.54 KB
/
respond.min.js
1
2
3
4
5
6
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
/*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */
window.matchMedia=window.matchMedia||(function(e,f){var c,a=e.documentElement,b=a.firstElementChild||a.firstChild,d=e.createElement("body"),g=e.createElement("div");g.id="mq-test-1";g.style.cssText="position:absolute;top:-100em";d.style.background="none";d.appendChild(g);return function(h){g.innerHTML='­<style media="'+h+'"> #mq-test-1 { width: 42px; }</style>';a.insertBefore(d,b);c=g.offsetWidth==42;a.removeChild(d);return{matches:c,media:h}}})(document);
/*! Respond.js v1.1.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
(function(f){f.respond={};respond.update=function(){};respond.throttle=100;respond.mediaQueriesSupported=f.matchMedia&&f.matchMedia("only all").matches;if(respond.mediaQueriesSupported){return}var v=f.document,s=v.documentElement,i=[],k=[],q=[],o={},g=v.getElementsByTagName("head")[0]||s,h=v.getElementsByTagName("base")[0],b=g.getElementsByTagName("link"),e=[],a=function(){var D=b,y=D.length,B=0,A,z,C,x;for(;B<y;B++){A=D[B],z=A.href,C=A.media,x=A.rel&&A.rel.toLowerCase()==="stylesheet";if(!!z&&x&&!o[z]){if(A.styleSheet&&A.styleSheet.rawCssText){m(A.styleSheet.rawCssText,z,C);o[z]=true}else{if((!/^([a-zA-Z:]*\/\/)/.test(z)&&!h)||z.replace(RegExp.$1,"").split("/")[0]===f.location.host){e.push({href:z,media:C})}}}}u()},u=function(){if(e.length){var x=e.shift();n(x.href,function(y){m(y,x.href,x.media);o[x.href]=true;setTimeout(function(){u()},0)})}},m=function(I,x,z){var G=I.match(/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi),J=G&&G.length||0,x=x.substring(0,x.lastIndexOf("/")),y=function(K){return K.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+x+"$2$3")},A=!J&&z,D=0,C,E,F,B,H;if(x.length){x+="/"}if(A){J=1}for(;D<J;D++){C=0;if(A){E=z;k.push(y(I))}else{E=G[D].match(/@media *([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1;k.push(RegExp.$2&&y(RegExp.$2))}B=E.split(",");H=B.length;for(;C<H;C++){F=B[C];i.push({media:F.split("(")[0].match(/(only\s+)?([a-zA-Z]+)\s?/)&&RegExp.$2||"all",rules:k.length-1,hasquery:F.indexOf("(")>-1,minw:F.match(/\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:F.match(/\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}}j()},l,r,w=function(){var z,A=v.createElement("div"),x=v.body,y=false;A.style.cssText="position:absolute;font-size:1em;width:1em";if(!x){x=y=v.createElement("body");x.style.background="none"}x.appendChild(A);s.insertBefore(x,s.firstChild);z=A.offsetWidth;if(y){s.removeChild(x)}else{x.removeChild(A)}z=p=parseFloat(z);return z},p,j=function(I){var x="clientWidth",B=s[x],H=v.compatMode==="CSS1Compat"&&B||v.body[x]||B,D={},G=b[b.length-1],z=(new Date()).getTime();for(var E in i){var K=i[E],C=K.minw,J=K.maxw,A=C===null,L=J===null,y="em";if(!!C){C=parseFloat(C)*(C.indexOf(y)>-1?(p||w()):1)}if(!!J){J=parseFloat(J)*(J.indexOf(y)>-1?(p||w()):1)}if(!K.hasquery||(!A||!L)&&(A||H>=C)&&(L||H<=J)){if(!D[K.media]){D[K.media]=[]}D[K.media].push(k[K.rules])}}for(var E in q){if(q[E]&&q[E].parentNode===g){g.removeChild(q[E])}}for(var E in D){var M=v.createElement("style"),F=D[E].join("\n");M.type="text/css";M.media=E;g.insertBefore(M,G.nextSibling);if(M.styleSheet){M.styleSheet.cssText=F}else{M.appendChild(v.createTextNode(F))}q.push(M)}},n=function(x,z){var y=d();if(!y){return}y.open("GET",x,true);y.onreadystatechange=function(){if(y.readyState!=4||y.status!=200&&y.status!=304){return}z(y.responseText)};if(y.readyState==4){return}y.send(null)},d=(function(){var x=false;try{x=new XMLHttpRequest()}catch(y){x=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return x}})();a();respond.update=a;function t(x){j(true);x.winResizing=false}respond.winSize=0;respond.resizeTimer=null;function c(y){var x=0;if(document.body&&document.body.offsetWidth){x=document.body.offsetWidth*document.body.offsetHeight}if(document.compatMode=="CSS1Compat"&&document.documentElement&&document.documentElement.offsetWidth){x=document.documentElement.offsetWidth*document.documentElement.offsetHeight}if(window.innerWidth&&window.innerHeight){x=window.innerWidth*window.innerHeight}if(!y.winResizing&&x!=y.winSize){y.winSize=x;y.winResizing=true;y.resizeTimer=setTimeout(function(){t(y)},y.throttle)}}if(f.addEventListener){f.addEventListener("resize",function(){c(respond)},false)}else{if(f.attachEvent){f.attachEvent("onresize",function(){c(respond)})}}})(this);