forked from JenniferSimonds/FontDetect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfontdetect.2.min.js
More file actions
1 lines (1 loc) · 1.23 KB
/
fontdetect.2.min.js
File metadata and controls
1 lines (1 loc) · 1.23 KB
1
fontdetect=function(){var a=false;var b=["serif","sans-serif","monospace","cursive","fantasy"];function c(){if(a){return;}a=true;$("body > :first-child").before('<div id="fontdetectHelper"><span>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</span></div>');$("#fontdetectHelper").css({"position":"absolute","visibility":"hidden","top":"-200px","width":"100000px","height":"200px","font-size":"100px"});}return{onFontLoaded:function(j,e,i,h){if(!j){return;}var g=(h&&h.msInterval)?h.msInterval:100;var k=(h&&h.msTimeout)?h.msTimeout:2000;if(!e&&!i){return;}if(!a){c();}if(this.isFontLoaded(j&&i)){e(j);return;}var d=this;var l=new Date().getTime();var f=setInterval(function(){if(d.isFontLoaded(j)){clearInterval(f);e(j);return;}else{var m=new Date().getTime();if((m-l)>k){clearInterval(f);if(i){i(j);}}}},g);},isFontLoaded:function(d){var g=0;var f=0;if(!a){c();}for(var e=0;e<b.length;++e){$("#fontdetectHelper > SPAN").css("font-family",d+","+b[e]);g=$("#fontdetectHelper > SPAN").width();if(e>0&&g!=f){return false;}f=g;}return true;},whichFont:function(d){var e=$(d).css("font-family");var g=e.split(",");var f=g.shift();while(f){f=f.replace(/^\s*['"]?\s*([^'"]*)\s*['"]?\s*$/,"$1");if(this.isFontLoaded(f)){return f;}f=g.shift();}return null;}};}();