/
respond.min.js
6 lines (5 loc) · 3.39 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.0.1: 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 t=e.document,q=t.documentElement,h=[],j=[],o=[],n={},g=30,f=t.getElementsByTagName("head")[0]||q,b=f.getElementsByTagName("link"),d=[],a=function(){var A=b,v=A.length,y=0,x,w,z,u;for(;y<v;y++){x=A[y],w=x.href,z=x.media,u=x.rel&&x.rel.toLowerCase()==="stylesheet";if(!!w&&u&&!n[w]){if(x.styleSheet&&x.styleSheet.rawCssText){l(x.styleSheet.rawCssText,w,z);n[w]=true}else{if(!/^([a-zA-Z]+?:(\/\/)?)/.test(w)||w.replace(RegExp.$1,"").split("/")[0]===e.location.host){d.push({href:w,media:z})}}}}s()},s=function(){if(d.length){var u=d.shift();m(u.href,function(v){l(v,u.href,u.media);n[u.href]=true;s()})}},l=function(F,u,w){var D=F.match(/@media[^\{]+\{([^\{\}]+\{[^\}\{]+\})+/gi),G=D&&D.length||0,u=u.substring(0,u.lastIndexOf("/")),v=function(H){return H.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+u+"$2$3")},x=!G&&w,A=0,z,B,C,y,E;if(u.length){u+="/"}if(x){G=1}for(;A<G;A++){z=0;if(x){B=w;j.push(v(F))}else{B=D[A].match(/@media *([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1;j.push(RegExp.$2&&v(RegExp.$2))}y=B.split(",");E=y.length;for(;z<E;z++){C=y[z];h.push({media:C.match(/(only\s+)?([a-zA-Z]+)(\sand)?/)&&RegExp.$2,rules:j.length-1,minw:C.match(/\(min\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/)&&parseFloat(RegExp.$1),maxw:C.match(/\(max\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/)&&parseFloat(RegExp.$1)})}}i()},k,p,i=function(C){var u="clientWidth",w=q[u],B=t.compatMode==="CSS1Compat"&&w||t.body[u]||w,x={},A=b[b.length-1],v=(new Date()).getTime();if(C&&k&&v-k<g){clearTimeout(p);p=setTimeout(i,g);return}else{k=v}for(var y in h){var D=h[y];if(!D.minw&&!D.maxw||(!D.minw||D.minw&&B>=D.minw)&&(!D.maxw||D.maxw&&B<=D.maxw)){if(!x[D.media]){x[D.media]=[]}x[D.media].push(j[D.rules])}}for(var y in o){if(o[y]&&o[y].parentNode===f){f.removeChild(o[y])}}for(var y in x){var E=t.createElement("style"),z=x[y].join("\n");E.type="text/css";E.media=y;f.insertBefore(E,A.nextSibling);if(E.styleSheet){E.styleSheet.cssText=z}else{E.appendChild(t.createTextNode(z))}o.push(E)}},m=function(u,w){var v=c();if(!v){return}v.open("GET",u,true);v.onreadystatechange=function(){if(v.readyState!=4||v.status!=200&&v.status!=304){return}w(v.responseText)};if(v.readyState==4){return}v.send(null)},c=(function(){var u=false;try{u=new XMLHttpRequest()}catch(v){u=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return u}})();a();respond.update=a;function r(){i(true)}if(e.addEventListener){e.addEventListener("resize",r,false)}else{if(e.attachEvent){e.attachEvent("onresize",r)}}})(this);