aboutsummaryrefslogtreecommitdiffstats
path: root/html/rtb/public/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/rtb/public/app.js')
-rw-r--r--html/rtb/public/app.js85
1 files changed, 54 insertions, 31 deletions
diff --git a/html/rtb/public/app.js b/html/rtb/public/app.js
index db91289..8b0a100 100644
--- a/html/rtb/public/app.js
+++ b/html/rtb/public/app.js
@@ -304,7 +304,7 @@ function render(model) {
applyDarkMode(model);
if (model.view === 'loading') {
- app.innerHTML = '<div class="loading">Loading...</div>';
+ app.innerHTML = '<div class="loading" role="status" aria-live="polite">Loading books...</div>';
return;
}
@@ -323,31 +323,47 @@ function render(model) {
return `
<li class="book-item" data-book-id="${book.id}">
- <div class="book-title">${book.title}</div>
- <div class="book-author">by ${book.author}</div>
- ${progress ? `<div class="book-progress">${percentage}% complete</div>` : ''}
+ <button class="book-button" type="button">
+ <div class="book-title">${book.title}</div>
+ <div class="book-author">by ${book.author}</div>
+ ${progress ? `<div class="book-progress">${percentage}% complete</div>` : ''}
+ </button>
</li>
`;
}).join('');
app.innerHTML = `
- <div class="header">
+ <header class="header">
<h1>Read the Book</h1>
- <select id="dark-mode-select" class="dark-mode-select" title="Choose dark mode preference">
+ <label for="dark-mode-select" class="sr-only">Choose dark mode preference</label>
+ <select id="dark-mode-select" class="dark-mode-select">
<option value="auto" ${model.darkMode === null ? 'selected' : ''}>🌓 Auto</option>
<option value="light" ${model.darkMode === false ? 'selected' : ''}>☀️ Light</option>
<option value="dark" ${model.darkMode === true ? 'selected' : ''}>🌙 Dark</option>
</select>
- </div>
- ${model.error ? `<div class="error">${model.error}</div>` : ''}
- <ul class="book-list">${bookItems}</ul>
- <footer><p><a href="about.html">About</a></p></footer>
+ </header>
+ ${model.error ? `<div class="error" role="alert">${model.error}</div>` : ''}
+ <main>
+ <h2 class="sr-only">Available Books</h2>
+ <ul class="book-list">${bookItems}</ul>
+ </main>
+ <footer>
+ <p><a href="about.html">About Read the Book</a></p>
+ </footer>
`;
- document.querySelectorAll('.book-item').forEach(item => {
- item.addEventListener('click', () => {
- const bookId = item.getAttribute('data-book-id');
+ document.querySelectorAll('.book-button').forEach(button => {
+ const handleBookSelection = () => {
+ const bookId = button.closest('.book-item').getAttribute('data-book-id');
dispatch({ type: 'SelectBook', bookId });
+ };
+
+ button.addEventListener('click', handleBookSelection);
+ button.addEventListener('keydown', (e) => {
+ if (e.key === 'Enter' || e.key === ' ') {
+ e.preventDefault();
+ handleBookSelection();
+ }
});
});
@@ -371,22 +387,27 @@ function render(model) {
const canGoForward = model.currentSentence < book.totalSentences - SENTENCES_PER_PAGE;
app.innerHTML = `
- <div class="reading-view">
- ${model.error ? `<div class="error">${model.error}</div>` : ''}
- <div class="reading-text">
- ${model.currentSentences.join(' ')}
- </div>
- <div class="controls">
+ <main class="reading-view">
+ ${model.error ? `<div class="error" role="alert">${model.error}</div>` : ''}
+ <article class="reading-content">
+ <h1 class="sr-only">Reading: ${book.title}</h1>
+ <div class="reading-text">
+ ${model.currentSentences.join(' ')}
+ </div>
+ </article>
+ <nav class="controls">
<button class="secondary" id="back" ${!canGoBack ? 'disabled' : ''}>← Back</button>
<button id="next" ${!canGoForward ? 'disabled' : ''}>Next →</button>
- </div>
- <div class="progress-info">
+ </nav>
+ <div class="progress-info" role="status" aria-live="polite">
${book.title} — ${progress}% complete
</div>
- <button class="secondary" id="select-another" style="margin-top: 2rem;">
- Choose a Different Book
- </button>
- </div>
+ <nav class="book-selection">
+ <button class="secondary" id="select-another" style="margin-top: 2rem;">
+ Choose a Different Book
+ </button>
+ </nav>
+ </main>
`;
const backBtn = document.getElementById('back');
@@ -412,13 +433,15 @@ function render(model) {
const book = getBook(model, model.currentBookId);
app.innerHTML = `
- <div class="completed-view">
- <h2>The End!</h2>
+ <main class="completed-view">
+ <h1>The End!</h1>
<p>You've finished <em>${book ? book.title : 'this book'}</em></p>
- <button id="select-another" style="margin-top: 2rem;">
- Choose A New Book
- </button>
- </div>
+ <nav>
+ <button id="select-another" style="margin-top: 2rem;">
+ Choose A New Book
+ </button>
+ </nav>
+ </main>
`;
document.getElementById('select-another').addEventListener('click', () => {