Skip to content
Merged
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
37 changes: 10 additions & 27 deletions public/js/modules/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const menuExitButton = document.getElementById('menu-exit-button');
const voiceSelector = document.getElementById('voice-selector');

function voiceMatcher(voice) {
if(!voice || !voice.lang) {
if (!voice || !voice.lang) {
return false;
}
return voice.lang.replace('_', '-').startsWith(targetLang.substring(0, 3));
Expand Down Expand Up @@ -187,15 +187,6 @@ let saveVoicePreference = function (voiceName) {
tts = getTts();
};

let tts = getTts();
//TTS voice option loading appears to differ in degree of asynchronicity by browser...being defensive
speechSynthesis.onvoiceschanged = function () {
if (!tts) {
tts = getTts();
}
populateVoiceSelector();
};

// --- Search suggestions (character-level trie) ---
// TODO: we may want to move this to a worker, and also out of this file, and also should we use a wordset to get more words in there
let searchTrieRoot = null;
Expand Down Expand Up @@ -1479,7 +1470,7 @@ let updateGraph = function (value) {
}
return result;
};

let tts = null;
let initialize = function () {
//TODO: make specialized tries
for (const [key, value] of Object.entries(languageOptions)) {
Expand All @@ -1488,22 +1479,14 @@ let initialize = function () {
break;
}
}

// Update walkthrough text for the current language
if (walkthroughText[targetLang]) {
const walkthrough = walkthroughText[targetLang];
const titleEl = document.querySelector('.walkthrough-title');
const headingEl = document.querySelector('.walkthrough-heading');
const paragraphs = document.querySelectorAll('.walkthrough p');

if (titleEl) titleEl.textContent = walkthrough.title;
if (headingEl) headingEl.textContent = walkthrough.heading;
if (paragraphs.length >= 3) {
paragraphs[0].innerHTML = walkthrough.intro;
paragraphs[1].innerHTML = walkthrough.study;
paragraphs[2].innerHTML = walkthrough.colors;
tts = getTts();
//TTS voice option loading appears to differ in degree of asynchronicity by browser...being defensive
speechSynthesis.onvoiceschanged = function () {
if (!tts) {
tts = getTts();
}
}
populateVoiceSelector();
};

// Build the character-level search trie from the top-level words in `trie`
try {
Expand Down Expand Up @@ -1930,4 +1913,4 @@ let switchLanguage = function () {
}
languageSelector.addEventListener('change', switchLanguage);

export { initialize, makeSentenceNavigable, getActiveGraph, joinTokens, setupExamples };
export { initialize, makeSentenceNavigable, getActiveGraph, joinTokens, setupExamples, walkthroughText, languageOptions as languageOptionsMap };
42 changes: 24 additions & 18 deletions public/js/modules/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { initialize as dataInit } from "./data-layer.js";
import { initialize as baseInit } from "./base.js";
import { initialize as baseInit, walkthroughText } from "./base.js";
import { initialize as faqInit } from "./faq.js";
import { initialize as studyModeInit } from "./study-mode.js";
import { initialize as statsInit } from "./stats.js";
Expand Down Expand Up @@ -56,6 +56,7 @@ let init = function () {
.then(data => window.invertedTrie = data)
]
).then(_ => {
updateWalkthroughText();
firebaseInit();
dataInit();
studyModeInit();
Expand All @@ -75,6 +76,23 @@ function setupWordlist(data) {
window.freqs = freqs;
}

function updateWalkthroughText() {
if (walkthroughText[targetLang]) {
const walkthrough = walkthroughText[targetLang];
const titleEl = document.querySelector('.walkthrough-title');
const headingEl = document.querySelector('.walkthrough-heading');
const paragraphs = document.querySelectorAll('.walkthrough p');

if (titleEl) titleEl.textContent = walkthrough.title;
if (headingEl) headingEl.textContent = walkthrough.heading;
if (paragraphs.length >= 3) {
paragraphs[0].innerHTML = walkthrough.intro;
paragraphs[1].innerHTML = walkthrough.study;
paragraphs[2].innerHTML = walkthrough.colors;
}
}
}

let initWithMinimumDelay = function (minDelay) {
const startTime = Date.now();
const promise = Promise.all(
Expand Down Expand Up @@ -103,6 +121,7 @@ let initWithMinimumDelay = function (minDelay) {
const delayTime = Math.max(0, remaining);

setTimeout(() => {
updateWalkthroughText();
revealApp(() => {
firebaseInit();
dataInit();
Expand All @@ -117,24 +136,11 @@ let initWithMinimumDelay = function (minDelay) {
};

function revealApp(callback) {
// hide landing immediately so it doesn't affect layout during animation
landingContainer.style.display = 'none';
// make sure main container is available for animation
mainContainer.style.display = '';
// force reflow so animations will run
void mainContainer.offsetWidth;
landingContainer.classList.add('fade-out');
mainContainer.classList.add('slide-in-right');

const onEnd = function (e) {
if (e.target !== mainContainer) return;
mainContainer.removeEventListener('animationend', onEnd);
landingContainer.classList.remove('fade-out');
mainContainer.classList.remove('slide-in-right');
// hide landing after animation
landingContainer.style.display = 'none';
if (typeof callback === 'function') callback();
};

mainContainer.addEventListener('animationend', onEnd);
mainContainer.removeAttribute('style');
if (typeof callback === 'function') callback();
}

if (targetLang) {
Expand Down