Skip to content

Commit

Permalink
♻️ 🚮 [amp story interactives] [amp story dev tools] Refactor loadFont…
Browse files Browse the repository at this point in the history
…s_ (#36795)

* Refactor loadFonts

* lint

* add new
  • Loading branch information
processprocess committed Nov 5, 2021
1 parent defb288 commit e38c8d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
18 changes: 6 additions & 12 deletions extensions/amp-story-dev-tools/0.1/amp-story-dev-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,14 @@ export class AmpStoryDevTools extends AMP.BaseElement {
});
}

/**
* @private
*/
/** @private */
loadFonts_() {
if (this.win.document.fonts && FontFace) {
fontsToLoad.forEach((fontProperties) => {
const font = new FontFace(fontProperties.family, fontProperties.src, {
weight: fontProperties.weight,
style: 'normal',
});
font.load().then(() => {
this.win.document.fonts.add(font);
});
});
fontsToLoad.forEach(({family, src, style = 'normal', weight}) =>
new FontFace(family, src, {weight, style})
.load()
.then((font) => this.win.document.fonts.add(font))
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,24 +284,18 @@ export class AmpStoryInteractive extends AMP.BaseElement {
});
}

/**
* @private
*/
/** @private */
loadFonts_() {
if (
!AmpStoryInteractive.loadedFonts &&
this.win.document.fonts &&
FontFace
) {
fontsToLoad.forEach((fontProperties) => {
const font = new FontFace(fontProperties.family, fontProperties.src, {
weight: fontProperties.weight,
style: 'normal',
});
font.load().then(() => {
this.win.document.fonts.add(font);
});
});
fontsToLoad.forEach(({family, src, style = 'normal', weight}) =>
new FontFace(family, src, {weight, style})
.load()
.then((font) => this.win.document.fonts.add(font))
);
}
AmpStoryInteractive.loadedFonts = true;
}
Expand Down

0 comments on commit e38c8d9

Please sign in to comment.