forked from scottjehl/Respond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrespond.min.js
6 lines (5 loc) · 3.82 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.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.0rc1: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
(function(e){e.respond={};respond.update=function(){};respond.mediaQueriesSupported=e.matchMedia&&e.matchMedia("only all").matches;if(respond.mediaQueriesSupported){return}var u=e.document,r=u.documentElement,h=[],j=[],p=[],n={},g=30,f=u.getElementsByTagName("head")[0]||r,b=f.getElementsByTagName("link"),d=[],a=function(){var C=b,x=C.length,A=0,z,y,B,w;for(;A<x;A++){z=C[A],y=z.href,B=z.media,w=z.rel&&z.rel.toLowerCase()==="stylesheet";if(!!y&&w&&!n[y]){if(z.styleSheet&&z.styleSheet.rawCssText){l(z.styleSheet.rawCssText,y,B);n[y]=true}else{if(!/^([a-zA-Z]+?:(\/\/)?)/.test(y)||y.replace(RegExp.$1,"").split("/")[0]===e.location.host){d.push({href:y,media:B})}}}}t()},t=function(){if(d.length){var w=d.shift();m(w.href,function(x){l(x,w.href,w.media);n[w.href]=true;t()})}},l=function(H,w,y){var F=H.match(/@media[^\{]+\{([^\{\}]+\{[^\}\{]+\})+/gi),I=F&&F.length||0,w=w.substring(0,w.lastIndexOf("/")),x=function(J){return J.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+w+"$2$3")},z=!I&&y,C=0,B,D,E,A,G;if(w.length){w+="/"}if(z){I=1}for(;C<I;C++){B=0;if(z){D=y;j.push(x(H))}else{D=F[C].match(/@media *([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1;j.push(RegExp.$2&&x(RegExp.$2))}A=D.split(",");G=A.length;for(;B<G;B++){E=A[B];h.push({media:E.match(/(only\s+)?([a-zA-Z]+)(\sand)?/)&&RegExp.$2,rules:j.length-1,minw:E.match(/\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:E.match(/\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}}i()},k,q,v=function(){var y,z=u.createElement("div"),w=u.body,x=false;z.style.cssText="position:absolute;font-size:1em;width:1em";if(!w){w=x=u.createElement("body")}w.appendChild(z);r.insertBefore(w,r.firstChild);y=z.offsetWidth;if(x){r.removeChild(w)}else{w.removeChild(z)}y=o=parseFloat(y);return y},o,i=function(G){var w="clientWidth",z=r[w],F=u.compatMode==="CSS1Compat"&&z||u.body[w]||z,B={},E=b[b.length-1],y=(new Date()).getTime();if(G&&k&&y-k<g){clearTimeout(q);q=setTimeout(i,g);return}else{k=y}for(var C in h){var I=h[C],A=I.minw,H=I.maxw,x="em";if(!!A){A=parseFloat(A)*(A.indexOf(x)>-1?(o||v()):1)}if(!!H){H=parseFloat(H)*(H.indexOf(x)>-1?(o||v()):1)}if(!A&&!H||(!A||A&&F>=A)&&(!H||H&&F<=H)){if(!B[I.media]){B[I.media]=[]}B[I.media].push(j[I.rules])}}for(var C in p){if(p[C]&&p[C].parentNode===f){f.removeChild(p[C])}}for(var C in B){var J=u.createElement("style"),D=B[C].join("\n");J.type="text/css";J.media=C;f.insertBefore(J,E.nextSibling);if(J.styleSheet){J.styleSheet.cssText=D}else{J.appendChild(u.createTextNode(D))}p.push(J)}},m=function(w,y){var x=c();if(!x){return}x.open("GET",w,true);x.onreadystatechange=function(){if(x.readyState!=4||x.status!=200&&x.status!=304){return}y(x.responseText)};if(x.readyState==4){return}x.send(null)},c=(function(){var w=false;try{w=new XMLHttpRequest()}catch(x){w=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return w}})();a();respond.update=a;function s(){i(true)}if(e.addEventListener){e.addEventListener("resize",s,false)}else{if(e.attachEvent){e.attachEvent("onresize",s)}}})(this);