Skip to content

Commit

Permalink
Merge pull request #333 from statikbe/KarelJanVanHaute/issue301
Browse files Browse the repository at this point in the history
Block initial transitions
  • Loading branch information
Numkil authored May 16, 2024
2 parents d23f459 + 9e8860a commit e23564c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions tailoff/css/site/base/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
}
}

.preload-transitions * {
transition: none !important;
}

/* .lazyload,
.lazyloading {
opacity: 0;
Expand Down
23 changes: 18 additions & 5 deletions tailoff/js/components/general.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
export class GeneralComponent {
constructor() {
const bodyElement = document.getElementsByTagName('BODY')[0] as HTMLBodyElement;
bodyElement.classList.add('js-enabled');
const bodyElement = document.getElementsByTagName(
"BODY"
)[0] as HTMLBodyElement;
bodyElement.classList.add("js-enabled");
this.addOutlineForTabbers();

const node = document.querySelector(".preload-transitions");
document.addEventListener("DOMContentLoaded", function () {
node.classList.remove("preload-transitions");
});
if (
document.readyState === "interactive" ||
document.readyState === "complete"
) {
node.classList.remove("preload-transitions");
}
}

// This adds a class if the user is tabbing and thus using the keyboard, so the focus style will be visible. Otherwise if it's a clicker the focus is removed.
private addOutlineForTabbers() {
function handleFirstTab(e) {
if (e.keyCode === 9) {
// the "I am a keyboard user" key
document.body.classList.add('user-is-tabbing');
window.removeEventListener('keydown', handleFirstTab);
document.body.classList.add("user-is-tabbing");
window.removeEventListener("keydown", handleFirstTab);
}
}
window.addEventListener('keydown', handleFirstTab);
window.addEventListener("keydown", handleFirstTab);
}
}
5 changes: 2 additions & 3 deletions templates/_site/_layout.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
{% endif %}
</head>

<body class="page-{{ craft.app.request.getSegment(1) ?: 'home' }} {% block bodyClasses %}{% endblock %}">
{% apply enkode_emails %}

<body class="page-{{ craft.app.request.getSegment(1) ?: 'home' }} {% block bodyClasses %}{% endblock %} preload-transitions">
{% apply enkode_emails %}
{% if not craft.app.request.isPreview() %}
{# put GTM here #}
{% endif %}
Expand Down

0 comments on commit e23564c

Please sign in to comment.