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