Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions assets/js/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FontLoader } from './tools';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want to load the theme fonts into the editor/CMS - perhaps we can add a placeholder or just console log for the editor file to be generated for now?


const fonts = new FontLoader([
{ name: 'Scene', weight: 700 },
{ name: 'Scene', weight: 600 },
{ name: 'Scene', weight: 400 },
{ name: 'Scene', weight: 300 }
]);

fonts.load();
49 changes: 49 additions & 0 deletions assets/js/tools/fonts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import FontFaceObserver from 'fontfaceobserver';

export default class FontLoader {
fonts = [];

constructor(fontsArray) {
this.fonts = fontsArray;
}

load() {
const fontsToLoad = [];

this.fonts.map((font) => {
const fontObserver = font.weight !== undefined
? new FontFaceObserver(font.name, {weight: font.weight}).load(null, 400)
: new FontFaceObserver(font.name).load(null, 400);

fontsToLoad.push(fontObserver);
});

Promise.all(fontsToLoad)
.then(() => {
// eslint-disable-next-line no-console
console.log('All fonts have loaded via FontFaceObserver');
this.saveSession();
})
.catch(() => {
this.removeSession();
});

this.setLoadingClass();
}

saveSession() {
sessionStorage.fontsLoaded = true;

this.setLoadingClass();
}

removeSession() {
sessionStorage.fontsLoaded = false;
}

setLoadingClass() {
if (sessionStorage.fontsLoaded) {
document.documentElement.classList.add('fonts-loaded');
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a newline at the end of this file (keeps git happy) - Looks like you can enable this across all files in PHPStorm like so https://stackoverflow.com/a/36020003/2166894

1 change: 1 addition & 0 deletions assets/js/tools/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export FontLoader from './fonts';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here re: newline

2 changes: 1 addition & 1 deletion assets/scss/globals/_reset.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@import 'normalize.css';
@import '~normalize.css';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here re: newline

4 changes: 4 additions & 0 deletions assets/scss/tools/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,7 @@
}
}
}

@function fluid-unit($pixel_value) {
@return #{strip-unit($pixel_value) / strip-unit($max-font)}rem;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here re: newline

5 changes: 0 additions & 5 deletions views/base.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@
{% endblock %}
</main>
{% endblock %}
{% block livechat %}
<a class="live-chat" href="/contact/ask-an-expert/"
target="_blank">{{ source('svgs/live-chat-circle.svg') }}</a>
{% endblock %}
{% block footer %}
{% include 'views/partials/footer.twig' %}
{% endblock %}
</div>
{% include 'views/partials/components/modal.twig' %}

{{ function('wp_footer') }}
{% endblock %}
Expand Down