locomotivemtl / locomotive-boilerplate

🚂 Front-end boilerplate for projects by Locomotive.
https://locomotivemtl-boilerplate.vercel.app/
MIT License
458 stars 71 forks source link

Add font faces watcher #128

Closed arnvvd closed 1 year ago

arnvvd commented 1 year ago

Add the function fontFacesWatcher to watch font faces used in our website and trigger a global custom event fontsLoaded when all font faces are loaded. This function returns a promise that can be used to execute a script when the fonts are loaded (E.g. add a class on the body; lock/unlock the website loader...). It's a watcher not a loader, the loading process is made by the browser.

To use the function correctly you need to :

The function fontFacesWatcher trigger a global custom event fontsLoaded. So you can use it in your modules; it's very useful for a scrolling update or a split text, for example. The function also updates the font loaded status on the window object as window.isFontsLoaded, useful with Ajax and the init method of our modules. You can find the implementation in Example.js.

cloudflare-pages[bot] commented 1 year ago

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: f35a16f
Status: ✅  Deploy successful!
Preview URL: https://caf75e10.locomotive-boilerplate.pages.dev
Branch Preview URL: https://feature-fonts-check.locomotive-boilerplate.pages.dev

View logs

mcaskill commented 1 year ago

Superseded by #129