Skip to content

Commit

Permalink
Improve text discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
gparant committed May 2, 2024
1 parent 09c5fea commit 2be8d0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion views/discussions/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ document.addEventListener("DOMContentLoaded", () => {

// Discussion text
if (text) {
text.innerText = getText(urlParams.get('text'))
playText(text as HTMLParagraphElement, getText(urlParams.get('text')));
}

// Close button event
Expand All @@ -46,6 +46,19 @@ document.addEventListener("DOMContentLoaded", () => {
}).catch(e => console.error(e))
})

const playText = (textElement: HTMLParagraphElement, text: string) => {
const texts = text.split(" ");
playTexts(textElement, texts);
}
const playTexts = (textElement: HTMLParagraphElement, texts: string[], index = 0) => {
setTimeout(() => {
textElement.innerText += " " + texts[index];
if (index < texts.length - 1) {
playTexts(textElement, texts, index + 1);
}
}, 100);
}

export {
getTitle,
getText,
Expand Down
4 changes: 2 additions & 2 deletions views/discussionsv2/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ document.addEventListener("DOMContentLoaded", () => {
})

const playText = (textElement: HTMLParagraphElement, text: string) => {
const texts = text.split(" ")
const texts = text.split(" ");
playTexts(textElement, texts);
}
const playTexts = (textElement: HTMLParagraphElement, texts: string[], index = 0) => {
setTimeout(() => {
textElement.innerText += " " + texts[index]
textElement.innerText += " " + texts[index];
if (index < texts.length - 1) {
playTexts(textElement, texts, index + 1);
}
Expand Down

0 comments on commit 2be8d0a

Please sign in to comment.