1
0
mirror of https://github.com/locomotivemtl/locomotive-boilerplate.git synced 2026-01-15 00:55:08 +08:00

Add constant to collect all eager fonts

This commit is contained in:
Chauncey McAskill
2022-10-04 16:56:31 -04:00
parent e7f0455ce4
commit 3272521dba
4 changed files with 18 additions and 25 deletions

View File

@@ -24,6 +24,11 @@ window.onload = (event) => {
}
};
export const EAGER_FONTS = [
{ family: 'Source Sans', style: 'normal', weight: 400 },
{ family: 'Source Sans', style: 'normal', weight: 700 },
];
function init() {
globals();
@@ -37,10 +42,7 @@ function init() {
* Eagerly load the following fonts.
*/
if (isFontLoadingAPIAvailable) {
loadFonts([
{ family: 'Source Sans', style: 'normal', weight: 400 },
{ family: 'Source Sans', style: 'normal', weight: 700 },
], true).then((eagerFonts) => {
loadFonts(EAGER_FONTS, true).then((eagerFonts) => {
html.classList.add('fonts-loaded');
console.group('Eager fonts loaded!', eagerFonts.length, '/', document.fonts.size);
console.group('State of eager fonts:')

View File

@@ -1,4 +1,5 @@
import { module } from 'modujs';
import { EAGER_FONTS } from '../app';
import { whenReady } from '../utils/fonts';
export default class extends module {
@@ -7,20 +8,10 @@ export default class extends module {
}
init() {
whenReady(
{ family: 'Source Sans', style: 'normal', weight: 700 }
).then((fonts) => this.onBoldFontLoaded(fonts));
whenReady([
{ family: 'Source Sans', style: 'italic', weight: 400 },
]).then((fonts) => this.onItalicFontLoaded(fonts));
whenReady(EAGER_FONTS).then((fonts) => this.onFontsLoaded(fonts));
}
onBoldFontLoaded(fonts) {
console.log('Example: Bold Normal Font Loaded!', fonts)
}
onItalicFontLoaded(fonts) {
console.log('Example: Regular Italic Font Loaded!', fonts)
onFontsLoaded(fonts) {
console.log('Example: Eager Fonts Loaded!', fonts)
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long