Refactor components to simplify them

This commit is contained in:
Andras Schmelczer 2022-09-21 14:40:44 +02:00
parent 3cf5b14913
commit 077ed9d3bf
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E
36 changed files with 202 additions and 216 deletions

View file

@ -0,0 +1,7 @@
export const addSupportForTabNavigation = () =>
document.addEventListener('keydown', (e) => {
if (e.key === ' ') {
(document.activeElement as HTMLElement)?.click();
e.preventDefault();
}
});

View file

@ -3,7 +3,9 @@ export class Random {
public get next(): number {
// result is in [0, 1)
return ((2 ** 31 - 1) & (this.seed = Math.imul(48271, this.seed))) / 2 ** 31;
this.seed = Math.imul(48271, this.seed);
return ((2 ** 31 - 1) & this.seed) / 2 ** 31;
}
public choose<T>(list: Array<T>): T {

View file

@ -0,0 +1,4 @@
export const removeUnnecessaryOutlines = () =>
document.addEventListener('click', () =>
(document.activeElement as HTMLElement).blur?.()
);

View file

@ -0,0 +1,6 @@
export const scrollToFragment = () => {
// it might be necessary when the page takes too long to load
if (location.hash) {
document.getElementById(location.hash.slice(1))?.scrollIntoView();
}
};