fonts.js 645 B

1234567891011121314151617181920212223242526272829303132
  1. import Observer from 'fontfaceobserver';
  2. import promisesPolyfill from 'es6-promise';
  3. import config from '../config.js';
  4. // preload fonts
  5. export default () => {
  6. const fontObservers = [];
  7. Object.keys(config.fonts).forEach((f) => {
  8. const font = config.fonts[f];
  9. fontObservers.push(
  10. new Observer(
  11. font.family,
  12. {
  13. weight: font.weight,
  14. style: font.style
  15. }
  16. ).load()
  17. );
  18. });
  19. if (fontObservers.length >= 1) {
  20. promisesPolyfill.polyfill();
  21. Promise.all(fontObservers)
  22. .then(() => {
  23. document.documentElement.classList.add('fonts-loaded');
  24. });
  25. }
  26. };