forked from tombigel/detect-zoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect-zoom.min.js
1 lines (1 loc) · 2.86 KB
/
detect-zoom.min.js
1
(function(e,t,n){"use strict";if(typeof module!=="undefined"&&module.exports){module.exports=n(t,e)}else if(typeof define==="function"&&define.amd){define(function(){return n(t,e)})}else{e[t]=n(t,e)}})(window,"detectZoom",function(){var e=function(){return window.devicePixelRatio||1};var t=function(){return{zoom:1,devicePxPerCssPx:1}};var n=function(){var t=Math.round(screen.deviceXDPI/screen.logicalXDPI*100)/100;return{zoom:t,devicePxPerCssPx:t*e()}};var i=function(){var t=Math.round(document.documentElement.offsetHeight/window.innerHeight*100)/100;return{zoom:t,devicePxPerCssPx:t*e()}};var r=function(){var t=Math.abs(window.orientation)==90?screen.height:screen.width;var n=t/window.innerWidth;return{zoom:n,devicePxPerCssPx:n*e()}};var o=function(){var t=function(e){return e.replace(/;/g," !important;")};var n=document.createElement("div");n.innerHTML="1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>0";n.setAttribute("style",t("font: 100px/1em sans-serif; -webkit-text-size-adjust: none; height: auto; width: 1em; padding: 0; overflow: visible;"));var i=document.createElement("div");i.setAttribute("style",t("width:0; height:0; overflow:hidden; visibility:hidden; position: absolute;"));i.appendChild(n);document.body.appendChild(i);var r=1e3/n.clientHeight;r=Math.round(r*100)/100;document.body.removeChild(i);return{zoom:r,devicePxPerCssPx:r*e()}};var d=function(){var e=s("min--moz-device-pixel-ratio","",0,10,20,1e-4);e=Math.round(e*100)/100;return{zoom:e,devicePxPerCssPx:e}};var a=function(){return{zoom:d().zoom,devicePxPerCssPx:e()}};var u=function(){var t=window.outerWidth/window.innerWidth;t=Math.round(t*100)/100;return{zoom:t,devicePxPerCssPx:t*e()}};var s=function(e,t,n,i,r,o){var d;var a,u,s;if(window.matchMedia){d=window.matchMedia}else{a=document.getElementsByTagName("head")[0];u=document.createElement("style");a.appendChild(u);s=document.createElement("div");s.className="mediaQueryBinarySearch";s.style.display="none";document.body.appendChild(s);d=function(e){u.sheet.insertRule("@media "+e+"{.mediaQueryBinarySearch "+"{text-decoration: underline} }",0);var t=getComputedStyle(s,null).textDecoration=="underline";u.sheet.deleteRule(0);return{matches:t}}}var c=m(n,i,r);if(s){a.removeChild(u);document.body.removeChild(s)}return c;function m(n,i,r){var a=(n+i)/2;if(r<=0||i-n<o){return a}var u="("+e+":"+a+t+")";if(d(u).matches){return m(a,i,r-1)}else{return m(n,a,r-1)}}};var c=function(){var e=t;if(!isNaN(screen.logicalXDPI)&&!isNaN(screen.systemXDPI)){e=n}else if(window.navigator.msMaxTouchPoints){e=i}else if("ontouchstart"in window&&typeof document.body.style.webkitTextSizeAdjust==="string"){e=r}else if(typeof document.body.style.webkitTextSizeAdjust==="string"){e=o}else if(navigator.userAgent.indexOf("Opera")>=0){e=u}else if(window.devicePixelRatio){e=a}else if(d().zoom>.001){e=d}return e}();return{zoom:function(){return c().zoom},device:function(){return c().devicePxPerCssPx}}});