Permalink
Browse files

adding isFontLoaded by harold kyle

  • Loading branch information...
1 parent 07acc23 commit 84fc954edb4f967ce4d894ca0b0a95426c0c1354 @paulirish committed Feb 12, 2010
Showing with 66 additions and 8 deletions.
  1. +0 −8 isFontFaceSupported.min.js
  2. +66 −0 isFontLoaded.js
View
8 isFontFaceSupported.min.js
@@ -1,8 +0,0 @@
-/*
- * isFontFaceSupported - v0.9 - 12/19/2009
- * http://paulirish.com/2009/font-face-feature-detection/
- *
- * Copyright (c) 2009 Paul Irish
- * MIT license
- */
-var isFontFaceSupported=(function(){var b,g=100;if(!(!/*@cc_on@if(@_jscript_version>=5)!@end@*/0)){b=true}else{var j=document,e=j.documentElement,l=j.createElement("style"),d=j.createElement("span"),m,f,h=j.body,k,c;l.textContent="@font-face{font-family:testfont;src:url(data:font/opentype;base64,T1RUTwALAIAAAwAwQ0ZGIMA92IQAAAVAAAAAyUZGVE1VeVesAAAGLAAAABxHREVGADAABAAABgwAAAAgT1MvMlBHT5sAAAEgAAAAYGNtYXAATQPNAAAD1AAAAUpoZWFk8QMKmwAAALwAAAA2aGhlYQS/BDgAAAD0AAAAJGhtdHgHKQAAAAAGSAAAAAxtYXhwAANQAAAAARgAAAAGbmFtZR8kCUMAAAGAAAACUnBvc3T/uAAyAAAFIAAAACAAAQAAAAEAQVTDUm9fDzz1AAsD6AAAAADHUuOGAAAAAMdS44YAAADzAz8BdgAAAAgAAgAAAAAAAAABAAABdgDzAAkDQQAAAAADPwABAAAAAAAAAAAAAAAAAAAAAwAAUAAAAwAAAAICmgGQAAUAAAK8AooAAACMArwCigAAAd0AMgD6AAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAEZIRAAAQAAgAC0C7v8GAAABdv8NAAAAAQAAAAAAAAAAACAAIAABAAAAFAD2AAEAAAAAAAAAPAB6AAEAAAAAAAEAAgC9AAEAAAAAAAIABwDQAAEAAAAAAAMAEQD8AAEAAAAAAAQAAwEWAAEAAAAAAAUABQEmAAEAAAAAAAYAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAA/7UAMgAAAAAAAAAAAAAAAAAAAAAAAAAAAQAEBAABAQEDUEkAAQIAAQAu+BAA+BsB+BwC+B0D+BgEWQwDi/eH+dP4CgUcAIwPHAAAEBwAkREcAB4cAKsSAAMCAAEAPQA/AEFHZW5lcmF0ZWQgaW4gMjAwOSBieSBGb250TGFiIFN0dWRpby4gQ29weXJpZ2h0IGluZm8gcGVuZGluZy5QSVBJAAAAAAEADgADAQECAxQODvb3h/cXAfeHBPnT9xf90wYO+IgU+WoVHgoDliX/DAmLDAr3Fwr3FwwMHgoG/wwSAAAAAAEAAAAOAAAAGAAAAAAAAgABAAEAAgABAAQAAAACAAAAAAABAAAAAMbULpkAAAAAx1KUiQAAAADHUpSJAfQAAAH0AAADQQAA)}";j.getElementsByTagName("head")[0].appendChild(l);d.setAttribute("style","font:99px _,serif;position:absolute;visibility:hidden");if(!h){h=e.appendChild(j.createElement("fontface"))}d.innerHTML="-------";d.id="fonttest";h.appendChild(d);m=d.offsetWidth;d.style.font="99px testfont,_,serif";b=m!==d.offsetWidth;var a=function(){if(c){return}b=m!==d.offsetWidth;k&&(c=true)&&k(b)};addEventListener("load",a,false);setTimeout(a,g)}function i(){return b||m!==d.offsetWidth}i.ready=function(n){(c||b)?n(b):(k=n)};return i})();
View
66 isFontLoaded.js
@@ -0,0 +1,66 @@
+
+// by harold kyle, based off of paul irish's work.
+
+//call the function to Firebug Console
+//isThisFontLoaded("Greta Text","Times New Roman",function(bool){console.debug('here');})
+
+
+
+var isThisFontLoaded = (function(font,fallback,fn){
+
+ var fontret,
+ fontfaceCheckDelay = 5000;
+
+ // IE supports EOT and has had EOT support since IE 5.
+ // This is a proprietary standard (ATOW) and thus this off-spec,
+ // proprietary test for it is acceptable.
+ if (!(!/*@cc_on@if(@_jscript_version>=5)!@end@*/0)) fontret = true;
+
+ else {
+ // Create variables for dedicated @font-face test
+ var doc = document, docElement = doc.documentElement,
+ st = doc.createElement('style'),
+ spn = doc.createElement('span'),
+ wid, nwid, body = doc.body,
+ callback, isCallbackCalled;
+
+ // The following is a font, only containing the - character. Thanks Ethan Dunham.
+ doc.getElementsByTagName('head')[0].appendChild(st);
+
+ spn.setAttribute('style','font:99px _,'+fallback+';position:absolute;visibility:hidden');
+ if (!body){
+ body = docElement.appendChild(doc.createElement('fontface'));
+ }
+
+ // the data-uri'd font only has the - character
+ spn.innerHTML = '-------';
+ spn.id = 'fonttest';
+
+ body.appendChild(spn);
+ wid = spn.offsetWidth*spn.offsetHeight;
+
+ spn.style.font = '99px '+font+',_,'+fallback;
+
+ // needed for the CSSFontFaceRule false positives (ff3, chrome, op9)
+ fontret = wid !== spn.offsetWidth*spn.offsetHeight;
+
+ var delayedCheck = function(){
+ if (isCallbackCalled) return;
+ fontret = wid !== spn.offsetWidth*spn.offsetHeight;
+ callback && (isCallbackCalled = true) && callback(fontret);
+ }
+
+ addEventListener('load',delayedCheck,false);
+ setTimeout(delayedCheck,fontfaceCheckDelay);
+ }
+ function ret(){ return fontret || wid !== spn.offsetWidth*spn.offsetHeight; };
+ // allow for a callback
+ if(ret()&&(typeof fn === 'function')){
+ (isCallbackCalled || fontret) ? fn(fontret) : (callback = fn);
+ }
+
+ return ret();
+});
+
+/* end font_face */
+

0 comments on commit 84fc954

Please sign in to comment.