forked from textpattern/textpattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
css3-mediaqueries.js
executable file
·27 lines (27 loc) · 12.8 KB
/
css3-mediaqueries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"function"!==typeof Object.create&&(Object.create=function(i){function l(){}l.prototype=i;return new l});var ua={toString:function(){return navigator.userAgent},test:function(i){return this.toString().toLowerCase().indexOf(i.toLowerCase())>-1}};ua.version=(ua.toString().toLowerCase().match(/[\s\S]+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1];ua.webkit=ua.test("webkit");ua.gecko=ua.test("gecko")&&!ua.webkit;ua.opera=ua.test("opera");ua.ie=ua.test("msie")&&!ua.opera;
ua.ie6=ua.ie&&document.compatMode&&"undefined"===typeof document.documentElement.style.maxHeight;ua.ie7=ua.ie&&document.documentElement&&"undefined"!==typeof document.documentElement.style.maxHeight&&"undefined"===typeof XDomainRequest;ua.ie8=ua.ie&&"undefined"!==typeof XDomainRequest;
var domReady=function(){var i=[],l=function(){if(!arguments.callee.done){arguments.callee.done=true;for(var l=0;l<i.length;l++)i[l]()}};document.addEventListener&&document.addEventListener("DOMContentLoaded",l,false);if(ua.ie){(function(){try{document.documentElement.doScroll("left")}catch(i){setTimeout(arguments.callee,50);return}l()})();document.onreadystatechange=function(){if(document.readyState==="complete"){document.onreadystatechange=null;l()}}}ua.webkit&&document.readyState&&function(){document.readyState!==
"loading"?l():setTimeout(arguments.callee,10)}();window.onload=l;return function(n){typeof n==="function"&&(l.done?n():i[i.length]=n);return n}}(),cssHelper=function(){var i=/[^\s{][^{]*\{(?:[^{}]*\{[^{}]*\}[^{}]*|[^{}]*)*\}/g,l=/[^\s{][^{]*\{[^{}]*\}/g,n=/url\(['"]?([^\/\)'"][^:\)'"]+)['"]?\)/g,y=/(?:\/\*([^*\\\\]|\*(?!\/))+\*\/|@import[^;]+;)/g,z=/\s*(,|:|;|\{|\})\s*/g,q=/\s{2,}/g,t=/;\}/g,u=/\S+/g,o,v=false,r=[],w=function(g){typeof g==="function"&&(r[r.length]=g)},m={},s=function(g,a){if(m[g]){var d=
m[g].listeners;if(d)for(var e=0;e<d.length;e++)d[e](a)}},p=function(g,a,d){if(ua.ie&&!window.XMLHttpRequest)window.XMLHttpRequest=function(){return new ActiveXObject("Microsoft.XMLHTTP")};if(!XMLHttpRequest)return"";var e=new XMLHttpRequest;try{e.open("get",g,true);e.setRequestHeader("X_REQUESTED_WITH","XMLHttpRequest")}catch(b){d();return}var f=false;setTimeout(function(){f=true},5E3);document.documentElement.style.cursor="progress";e.onreadystatechange=function(){if(e.readyState===4&&!f){!e.status&&
location.protocol==="file:"||e.status>=200&&e.status<300||e.status===304||navigator.userAgent.indexOf("Safari")>-1&&typeof e.status==="undefined"?a(e.responseText):d();document.documentElement.style.cursor="";e=null}};e.send("")},f=function(g){g=g.replace(y,"");g=g.replace(z,"$1");g=g.replace(q," ");return g=g.replace(t,"}")},h={mediaQueryList:function(g){for(var a={},d=g.indexOf("{"),e=g.substring(0,d),g=g.substring(d+1,g.length-1),b=[],f=[],c=e.toLowerCase().substring(7).split(","),d=0;d<c.length;d++)b[b.length]=
h.mediaQuery(c[d],a);c=g.match(l);if(c!==null)for(d=0;d<c.length;d++)f[f.length]=h.rule(c[d],a);a.getMediaQueries=function(){return b};a.getRules=function(){return f};a.getListText=function(){return e};a.getCssText=function(){return g};return a},mediaQuery:function(g,a){for(var d=false,e,b=[],f=(g||"").match(u),h=0;h<f.length;h++){var c=f[h];if(!e&&(c==="not"||c==="only"))c==="not"&&(d=true);else if(e){if(c.charAt(0)==="("){c=c.substring(1,c.length-1).split(":");b[b.length]={mediaFeature:c[0],value:c[1]||
null}}}else e=c}return{getList:function(){return a||null},getValid:function(){return true},getNot:function(){return d},getMediaType:function(){return e},getExpressions:function(){return b}}},rule:function(g,a){for(var d={},e=g.indexOf("{"),b=g.substring(0,e),f=b.split(","),c=[],e=g.substring(e+1,g.length-1).split(";"),j=0;j<e.length;j++)c[c.length]=h.declaration(e[j],d);d.getMediaQueryList=function(){return a||null};d.getSelectors=function(){return f};d.getSelectorText=function(){return b};d.getDeclarations=
function(){return c};d.getPropertyValue=function(g){for(var a=0;a<c.length;a++)if(c[a].getProperty()===g)return c[a].getValue();return null};return d},declaration:function(g,a){var d=g.indexOf(":"),e=g.substring(0,d),b=g.substring(d+1);return{getRule:function(){return a||null},getProperty:function(){return e},getValue:function(){return b}}}},a=function(g){if(typeof g.cssHelperText==="string"){var a={mediaQueryLists:[],rules:[],selectors:{},declarations:[],properties:{}},d=a.mediaQueryLists,e=a.rules,
b=g.cssHelperText.match(i);if(b!==null)for(var c=0;c<b.length;c++)if(b[c].substring(0,7)==="@media "){d[d.length]=h.mediaQueryList(b[c]);e=a.rules=e.concat(d[d.length-1].getRules())}else e[e.length]=h.rule(b[c]);d=a.selectors;for(c=0;c<e.length;c++)for(var b=e[c],f=b.getSelectors(),j=0;j<f.length;j++){var k=f[j];d[k]||(d[k]=[]);d[k][d[k].length]=b}d=a.declarations;for(c=0;c<e.length;c++)d=a.declarations=d.concat(e[c].getDeclarations());e=a.properties;for(c=0;c<d.length;c++){b=d[c].getProperty();e[b]||
(e[b]=[]);e[b][e[b].length]=d[c]}g.cssHelperParsed=a;o[o.length]=g;return a}},c=function(g,b){g.cssHelperText=f(b||g.innerHTML);return a(g)},k=function(){v=true;o=[];for(var g=[],b=function(){for(var b=0;b<g.length;b++)a(g[b]);for(var d=document.getElementsByTagName("style"),b=0;b<d.length;b++)c(d[b]);v=false;for(b=0;b<r.length;b++)r[b](o)},d=document.getElementsByTagName("link"),e=0;e<d.length;e++){var h=d[e];h.getAttribute("rel").indexOf("style")>-1&&h.href&&h.href.length!==0&&!h.disabled&&(g[g.length]=
h)}if(g.length>0)for(var j=0,k=function(){j++;j===g.length&&b()},d=function(a){var g=a.href;p(g,function(b){b=f(b).replace(n,"url("+g.substring(0,g.lastIndexOf("/"))+"/$1)");a.cssHelperText=b;k()},k)},e=0;e<g.length;e++)d(g[e]);else b()},j={mediaQueryLists:"array",rules:"array",selectors:"object",declarations:"array",properties:"object"},b={mediaQueryLists:null,rules:null,selectors:null,declarations:null,properties:null},A=function(a,c){if(b[a]!==null){if(j[a]==="array")return b[a]=b[a].concat(c);
var d=b[a],e;for(e in c)c.hasOwnProperty(e)&&(d[e]=d[e]?d[e].concat(c[e]):c[e]);return d}},x=function(a){b[a]=j[a]==="array"?[]:{};for(var c=0;c<o.length;c++)A(a,o[c].cssHelperParsed[a]);return b[a]};domReady(function(){for(var a=document.body.getElementsByTagName("*"),b=0;b<a.length;b++)a[b].checkedByCssHelper=true;document.implementation.hasFeature("MutationEvents","2.0")||window.MutationEvent?document.body.addEventListener("DOMNodeInserted",function(a){a=a.target;if(a.nodeType===1){s("DOMElementInserted",
a);a.checkedByCssHelper=true}},false):setInterval(function(){for(var a=document.body.getElementsByTagName("*"),b=0;b<a.length;b++)if(!a[b].checkedByCssHelper){s("DOMElementInserted",a[b]);a[b].checkedByCssHelper=true}},1E3)});var B=function(a){if(typeof window.innerWidth!="undefined")return window["inner"+a];if(typeof document.documentElement!="undefined"&&typeof document.documentElement.clientWidth!="undefined"&&document.documentElement.clientWidth!=0)return document.documentElement["client"+a]};
return{addStyle:function(a,b){var d=document.createElement("style");d.setAttribute("type","text/css");document.getElementsByTagName("head")[0].appendChild(d);d.styleSheet?d.styleSheet.cssText=a:d.appendChild(document.createTextNode(a));d.addedWithCssHelper=true;typeof b==="undefined"||b===true?cssHelper.parsed(function(){var b=c(d,a),f;for(f in b)b.hasOwnProperty(f)&&A(f,b[f]);s("newStyleParsed",d)}):d.parsingDisallowed=true;return d},removeStyle:function(a){return a.parentNode.removeChild(a)},parsed:function(a){if(v)w(a);
else if(typeof o!=="undefined")typeof a==="function"&&a(o);else{w(a);k()}},mediaQueryLists:function(a){cssHelper.parsed(function(){a(b.mediaQueryLists||x("mediaQueryLists"))})},rules:function(a){cssHelper.parsed(function(){a(b.rules||x("rules"))})},selectors:function(a){cssHelper.parsed(function(){a(b.selectors||x("selectors"))})},declarations:function(a){cssHelper.parsed(function(){a(b.declarations||x("declarations"))})},properties:function(a){cssHelper.parsed(function(){a(b.properties||x("properties"))})},
broadcast:s,addListener:function(a,b){if(typeof b==="function"){m[a]||(m[a]={listeners:[]});m[a].listeners[m[a].listeners.length]=b}},removeListener:function(a,b){if(typeof b==="function"&&m[a])for(var c=m[a].listeners,e=0;e<c.length;e++)if(c[e]===b){c.splice(e,1);e=e-1}},getViewportWidth:function(){return B("Width")},getViewportHeight:function(){return B("Height")}}}();
domReady(function(){var i,l=/[0-9]+(em|ex|px|in|cm|mm|pt|pc)$/,n=/[0-9]+(dpi|dpcm)$/,y=/^[0-9]+\/[0-9]+$/,z=/^[0-9]*(\.[0-9]+)*$/,q=[],t=function(){var f=document.createElement("div");f.id="css3-mediaqueries-test";var h=cssHelper.addStyle("@media all and (width) { #css3-mediaqueries-test { width: 1px !important; } }",false);document.body.appendChild(f);var a=f.offsetWidth===1;h.parentNode.removeChild(h);f.parentNode.removeChild(f);t=function(){return a};return a},u=function(f){i.style.width=f;f=i.offsetWidth;
i.style.width="";return f},o=function(f,h){var a=f.length,c=f.substring(0,4)==="min-",k=!c&&f.substring(0,4)==="max-";if(h!==null){var j,b;if(l.exec(h)){j="length";b=u(h)}else if(n.exec(h)){j="resolution";b=parseInt(h,10);var i=h.substring((b+"").length)}else if(y.exec(h)){j="aspect-ratio";b=h.split("/")}else if(z){j="absolute";b=h}else j="unknown"}if("device-width"===f.substring(a-12,a)){a=screen.width;return h!==null?j==="length"?c&&a>=b||k&&a<b||!c&&!k&&a===b:false:a>0}if("device-height"===f.substring(a-
13,a)){i=screen.height;return h!==null?j==="length"?c&&i>=b||k&&i<b||!c&&!k&&i===b:false:i>0}if("width"===f.substring(a-5,a)){a=document.documentElement.clientWidth||document.body.clientWidth;return h!==null?j==="length"?c&&a>=b||k&&a<b||!c&&!k&&a===b:false:a>0}if("height"===f.substring(a-6,a)){i=document.documentElement.clientHeight||document.body.clientHeight;return h!==null?j==="length"?c&&i>=b||k&&i<b||!c&&!k&&i===b:false:i>0}if("orientation"===f.substring(a-11,a)){a=document.documentElement.clientWidth||
document.body.clientWidth;i=document.documentElement.clientHeight||document.body.clientHeight;return j==="absolute"?b==="portrait"?a<=i:a>i:false}if("aspect-ratio"===f.substring(a-12,a)){a=document.documentElement.clientWidth||document.body.clientWidth;i=document.documentElement.clientHeight||document.body.clientHeight;a=a/i;b=b[1]/b[0];return j==="aspect-ratio"?c&&a>=b||k&&a<b||!c&&!k&&a===b:false}if("device-aspect-ratio"===f.substring(a-19,a))return j==="aspect-ratio"&&screen.width*b[1]===screen.height*
b[0];if("color-index"===f.substring(a-11,a)){a=Math.pow(2,screen.colorDepth);return h!==null?j==="absolute"?c&&a>=b||k&&a<b||!c&&!k&&a===b:false:a>0}if("color"===f.substring(a-5,a)){a=screen.colorDepth;return h!==null?j==="absolute"?c&&a>=b||k&&a<b||!c&&!k&&a===b:false:a>0}if("resolution"===f.substring(a-10,a)){a=i==="dpcm"?u("1cm"):u("1in");return h!==null?j==="resolution"?c&&a>=b||k&&a<b||!c&&!k&&a===b:false:a>0}return false},v=function(f){for(var h=f.getMediaQueries(),a={},c=0;c<h.length;c++){var i;
var j=h[c];i=j.getValid();var b=j.getExpressions(),l=b.length;if(l>0){for(var m=0;m<l&&i;m++)i=o(b[m].mediaFeature,b[m].value);j=j.getNot();i=i&&!j||j&&!i}else i=void 0;i&&(a[h[c].getMediaType()]=true)}var h=[],c=0,n;for(n in a)if(a.hasOwnProperty(n)){c>0&&(h[c++]=",");h[c++]=n}h.length>0&&(q[q.length]=cssHelper.addStyle("@media "+h.join("")+"{"+f.getCssText()+"}",false))},r=function(f){for(var h=0;h<f.length;h++)v(f[h]);if(ua.ie){document.documentElement.style.display="block";setTimeout(function(){document.documentElement.style.display=
""},0);setTimeout(function(){cssHelper.broadcast("cssMediaQueriesTested")},100)}else cssHelper.broadcast("cssMediaQueriesTested")},w=function(){for(var f=0;f<q.length;f++)cssHelper.removeStyle(q[f]);q=[];cssHelper.mediaQueryLists(r)},m=0,s=function(){var f=cssHelper.getViewportWidth(),h=cssHelper.getViewportHeight();if(ua.ie){var a=document.createElement("div");a.style.position="absolute";a.style.top="-9999em";a.style.overflow="scroll";document.body.appendChild(a);m=a.offsetWidth-a.clientWidth;document.body.removeChild(a)}var c,
i=function(){var a=cssHelper.getViewportWidth(),b=cssHelper.getViewportHeight();if(Math.abs(a-f)>m||Math.abs(b-h)>m){f=a;h=b;clearTimeout(c);c=setTimeout(function(){t()?cssHelper.broadcast("cssMediaQueriesTested"):w()},500)}};window.onresize=function(){var a=window.onresize||function(){};return function(){a();i()}}()},p=document.documentElement;p.style.marginLeft="-32767px";setTimeout(function(){p.style.marginTop=""},2E4);return function(){if(t())p.style.marginLeft="";else{cssHelper.addListener("newStyleParsed",
function(f){r(f.cssHelperParsed.mediaQueryLists)});cssHelper.addListener("cssMediaQueriesTested",function(){if(ua.ie)p.style.width="1px";setTimeout(function(){p.style.width="";p.style.marginLeft=""},0);cssHelper.removeListener("cssMediaQueriesTested",arguments.callee)});i=document.createElement("div");i.style.cssText="position:absolute;top:-9999em;left:-9999em;margin:0;border:none;padding:0;width:1em;font-size:1em;";document.body.appendChild(i);if(i.offsetWidth!==16)i.style.fontSize=16/i.offsetWidth+
"em";i.style.width="";w()}s()}}());try{document.execCommand("BackgroundImageCache",!1,!0)}catch(e$$11){};