forked from scottjehl/Respond
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrespond.min.js
7 lines (7 loc) · 3.19 KB
/
respond.min.js
1
2
3
4
5
6
7
/*
* respond.js - A small and fast polyfill for min/max-width CSS3 Media Queries
* Copyright 2011, Scott Jehl, scottjehl.com
* Dual licensed under the MIT or GPL Version 2 licenses.
* Usage: Check out the readme file or github.com/scottjehl/respond
*/
(function(f,d){if(d){return}var m=f.document,c=m.documentElement,a=[],g=50,j=m.getElementsByTagName("head")[0]||c,n=j.getElementsByTagName("link"),i=function(){var s=m.styleSheets,p=s.length;for(var r=0;r<p;r++){var q=s[r].href;k(q,function(t){h(t,q)})}},h=function(z,p){var v=z.match(/@media (only )?[a-z]+\sand(.*)\{([\S\s]+?)(?=\}\/\*\/mediaquery\*\/)/gmi),B=v&&v.length||0,p=p.substring(0,p.lastIndexOf("/"))+"/";for(var s=0;s<B;s++){var t=v[s].match(/@media (.*)\{([\S\s]+?)$/)&&RegExp.$1,x=RegExp.$2,u=t.match(/(only )?([a-z]+)\sand/)&&RegExp.$2,y=t.match(/\(min\-width:\s?(\s?[0-9]+)px\s?\)/)&&RegExp.$1,w=t.match(/\(max\-width:\s?(\s?[0-9]+)px\s?\)/)&&RegExp.$1;if(u&&y||w){var A=m.createElement("style"),q=m.createTextNode(""),y=parseFloat(y),w=parseFloat(w),x=x.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+p+"$2$3");A.type="text/css";A.media=u;if(A.styleSheet){A.styleSheet.cssText=x}else{A.appendChild(m.createTextNode(x))}var r=a.length&&a[a.length-1].ss||n[n.length-1];if(j.lastchild==r){j.appendChild(A)}else{j.insertBefore(A,r.nextSibling)}a.push({ss:A,minw:y,maxw:w,placehold:q})}o()}},l,o=function(w){var r=(new Date()).getTime();if(w&&l&&r-l<g){return}else{l=r}var q="clientWidth",v=c[q],p=m.compatMode==="CSS1Compat"&&v||m.body[q]||v,u=w?a:[a[a.length-1]];for(var t in u){var s=u[t];if((!s.minw||s.minw&&p>=s.minw)&&(!s.maxw||s.maxw&&p<=s.maxw)){if(s.placehold.parentNode===j){j.insertBefore(s.ss,s.placehold);j.removeChild(s.placehold)}}else{if(s.ss.parentNode===j){j.insertBefore(s.placehold,s.ss);j.removeChild(s.ss)}}}},k=function(p,r){var q=e();if(!q){return}q.open("GET",p,true);q.onreadystatechange=function(){if(q.readyState!=4||q.status!=200&&q.status!=304){return}r(q.responseText)};if(q.readyState==4){return}q.send()},e=(function(){var p=false,q=[function(){return new ActiveXObject("Microsoft.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new XMLHttpRequest()}],s=q.length;while(s--){try{p=q[s]()}catch(r){continue}break}return function(){return p}})();i();function b(){o(true)}if(f.addEventListener){f.addEventListener("resize",b,false)}else{if(f.attachEvent){f.attachEvent("onresize",b)}}})(this,(function(f){var g=(function(k){var i=3,l=document.createElement("div"),j=l.getElementsByTagName("i");while(l.innerHTML="<!--[if gt IE "+(++i)+"]><i></i><![endif]-->",j[0]){}return i>4?i:k}());if(f.matchMedia||g&&g>=9){return true}if(g&&g<=8){return false}var e=f.document,a=e.documentElement,b=e.createElement("body"),h=e.createElement("div"),d=e.createElement("style"),c="@media only all { #qtest { position: absolute; } }";h.setAttribute("id","qtest");d.type="text/css";b.appendChild(h);if(d.styleSheet){d.styleSheet.cssText=c}else{d.appendChild(e.createTextNode(c))}a.insertBefore(b,a.firstChild);a.insertBefore(d,b);support=(f.getComputedStyle?f.getComputedStyle(h,null):h.currentStyle)["position"]=="absolute";a.removeChild(b);a.removeChild(d);return support})(this));