-
Notifications
You must be signed in to change notification settings - Fork 19
/
fontloader.standalone.js
5 lines (3 loc) · 1.38 KB
/
fontloader.standalone.js
1
2
3
4
5
;(function() {
"use strict";var fontFaceSet=document.fonts,FONT_CLASS_NAME="font-marketsans",FONT_FACE_OBSERVER_LIB="https://ir.ebaystatic.com/cr/v/c1/vendor/fontfaceobserver.js";function lazyLoad(e,t){var a=document.createElement("script");a.type="application/javascript",a.async=!0,a.onload=t,a.src=e;e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(a,e)}function updateLocalStorage(){try{localStorage.setItem("ebay-font",FONT_CLASS_NAME)}catch(e){}}function isFontFaceSetCompatible(){var e,t=fontFaceSet&&fontFaceSet.load;return t&&/Apple/.test(window.navigator.vendor)&&(t=!((e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(window.navigator.userAgent))&&parseInt(e[1],10)<603)),t}function loadFont(){isFontFaceSetCompatible()?(fontFaceSet.load("1em Market Sans"),fontFaceSet.load("bold 1em Market Sans"),fontFaceSet.ready.then(updateLocalStorage)):lazyLoad(FONT_FACE_OBSERVER_LIB,function(){var e=new FontFaceObserver("Market Sans"),t=new FontFaceObserver("Market Sans",{weight:"bold"});Promise.all([e.load(),t.load()]).then(updateLocalStorage)})}function isFontLoaded(){return"fontDisplay"in document.documentElement.style||localStorage&&localStorage.getItem("ebay-font")===FONT_CLASS_NAME}function init(){isFontLoaded()||window.addEventListener("load",function(){requestAnimationFrame?requestAnimationFrame(loadFont):loadFont()})}init();
}());