Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e2bf444
Fix syntax error in for-loop (line 57) that blocked book list from re…
Iswanna Dec 9, 2025
c39e375
Fix: rename delButton to delBut and correct event to 'click' to enabl…
Iswanna Dec 9, 2025
c794174
Rename library to myLibrary in submit() so new books are added to the…
Iswanna Dec 9, 2025
436136b
fix: use author.value for author field when creating a new Book (line…
Iswanna Dec 9, 2025
dccb8a5
fix(render): correct read status display so checked=true shows “Yes” …
Iswanna Dec 9, 2025
07c6620
Remove redundant render() call in populateStorage (line 19) to avoid …
Iswanna Dec 9, 2025
085a373
Remove placeholder table row <tr> from <tbody> to allow render() to m…
Iswanna Dec 10, 2025
4bf7b31
Fix invalid HTML input types by changing <input type="title"/> and <i…
Iswanna Dec 10, 2025
d9870cf
Switch script.js to type="module", remove inline onclick="submit()", …
Iswanna Dec 10, 2025
3acd315
Add id="submitBtn" to the submit button to enable attaching an event …
Iswanna Dec 10, 2025
dae6c85
Refactor code to remove redundant null checks on input values, ensure…
Iswanna Dec 10, 2025
a6619ba
Refactor variable names for clarity: DOM inputs now use descriptive n…
Iswanna Dec 10, 2025
d413566
fix(js): add full input validation for author and page count
Iswanna Dec 10, 2025
c784153
refactor(js): optimize table clearing using tbody.innerHTML
Iswanna Dec 10, 2025
4757d2f
Clear rows via tbody.innerHTML to preserve header and speed up re-render
Iswanna Dec 10, 2025
0a4c4ae
ux(delete): confirm before deletion and show non-blocking success alert
Iswanna Dec 10, 2025
757fcd3
Correct book title spelling from “Robison Crusoe” to “Robinson Crusoe…
Iswanna Dec 10, 2025
2b98534
Fix(form): prevent default submit to avoid page reload on Submit butt…
Iswanna Dec 10, 2025
63652a8
Chore(html): add lang, split meta tags, set meaningful title, and mak…
Iswanna Dec 10, 2025
7c28cc2
Add #alerts container and move the dependency scripts to end of the body
Iswanna Dec 11, 2025
9526485
Fix indentation inconsistency in index.html
Iswanna Dec 11, 2025
9c3c39f
refactor(notices): use #alerts container with CSS-only auto-hide; rem…
Iswanna Dec 11, 2025
2417ca4
fix(validation): require pages to be a positive integer
Iswanna Dec 11, 2025
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
38 changes: 23 additions & 15 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta charset="utf-8" />
<title>Library — Add books to your virtual library</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />

<!-- Styles -->
<link
Expand All @@ -24,7 +19,12 @@ <h1>Library</h1>
<p>Add books to your virtual library</p>
</div>

<button data-toggle="collapse" data-target="#demo" class="btn btn-info" type="button">
<button
data-toggle="collapse"
data-target="#demo"
class="btn btn-info"
type="button"
>
Add new book
</button>

Expand Down Expand Up @@ -70,11 +70,7 @@ <h1>Library</h1>
</div>

<!-- Explicit type="button" to avoid default form submission -->
<button
type="button"
class="btn btn-primary mt-3"
id="submitBtn"
>
<button type="button" class="btn btn-primary mt-3" id="submitBtn">
Submit
</button>
</div>
Expand All @@ -93,7 +89,19 @@ <h1>Library</h1>
<tbody></tbody>
</table>

<!-- Load script at end of body; modules are deferred automatically -->
<!-- Designated notice container controlled via style.css -->
<div
id="alerts"
class="notice-root"
role="status"
aria-live="polite"
aria-atomic="true"
></div>

<!-- Scripts loaded at end of body -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="script.js" type="module"></script>
</body>
</html>
</html>
58 changes: 37 additions & 21 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ window.addEventListener("load", function (e) {
});

function populateStorage() {
if (myLibrary.length == 0) {
if (myLibrary.length === 0) {
let book1 = new Book("Robinson Crusoe", "Daniel Defoe", 252, true);
let book2 = new Book(
"The Old Man and the Sea",
Expand All @@ -33,40 +33,56 @@ const authorInput = document.getElementById("author");
const pagesInput = document.getElementById("pages");
const readCheckbox = document.getElementById("check");

// Non-blocking success message (appears briefly and fades out)
// Non-blocking success message using CSS animation; JS only toggles classes
function showSuccess(message) {
const root = document.getElementById("alerts");
if (!root) return;

const alertEl = document.createElement("div");
alertEl.className = "alert alert-success";
// Use Bootstrap alert styling + our notice classes
alertEl.className = "alert alert-success notice notice--auto-hide";
alertEl.setAttribute("role", "status");
alertEl.textContent = message;
alertEl.style.position = "fixed";
alertEl.style.top = "1rem";
alertEl.style.right = "1rem";
alertEl.style.zIndex = "1050";
document.body.appendChild(alertEl);

setTimeout(() => {
alertEl.style.transition = "opacity 0.3s";
alertEl.style.opacity = "0";
setTimeout(() => alertEl.remove(), 300);
}, 2500);

// Remove the element after the CSS animation completes (no setTimeout)
alertEl.addEventListener(
"animationend",
() => {
alertEl.remove();
},
{ once: true }
);

root.appendChild(alertEl);
}

//check the right input from forms and if its ok -> add the new book (object in array)
//via Book function and start render function
// Check the right input from forms and if it's ok -> add the new book (object in array)
// via Book function and start render function
function submit() {
const title = titleInput.value.trim();
const author = authorInput.value.trim();
const pages = Number(pagesInput.value);

// Validate title and author
if (title === "" || author === "") {
alert("Title and author cannot be empty.");
return;
}

// Validate pages
if (Number.isNaN(pages) || pages <= 0) {
alert("Pages must be a positive number.");
// Read and validate pages as a positive integer
const pages = pagesInput.valueAsNumber;
const v = pagesInput.validity;

if (v.valueMissing || !Number.isFinite(pages)) {
alert("Pages is required and must be a number.");
return;
}
if (v.rangeUnderflow || pages < 1) {
alert("Pages must be at least 1.");
return;
}
// Enforce whole numbers only (reject decimals like 3.5)
if (v.stepMismatch || !Number.isInteger(pages)) {
alert("Pages must be a whole number.");
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking !Number.isInteger(pages) || pages < 1 would be enough.


Expand Down Expand Up @@ -103,7 +119,7 @@ function render() {

titleCell.textContent = book.title;
authorCell.textContent = book.author;
pagesCell.textContent = book.pages;
pagesCell.textContent = String(book.pages);

// Read/unread toggle button
const changeBut = document.createElement("button");
Expand Down
44 changes: 44 additions & 0 deletions debugging/book-library/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,47 @@
button.btn-info {
margin: 20px;
}

/* --- Notices (toast) styles --- */

/* Container to control placement of notices */
.notice-root {
position: fixed;
top: 1rem;
right: 1rem;
z-index: 1050;
display: flex;
flex-direction: column;
gap: 0.5rem;
pointer-events: none; /* allow clicks to pass through container */
}

/* Each notice uses Bootstrap alert styles, plus these */
.notice {
pointer-events: auto; /* allow focus/click on the notice itself if needed */
}

/* Pure-CSS lifecycle: fade in, hold, fade out */
@keyframes notice-life {
0% {
opacity: 0;
transform: translateY(-6px);
}
10% {
opacity: 1;
transform: translateY(0);
}
85% {
opacity: 1;
transform: translateY(0);
}
100% {
opacity: 0;
transform: translateY(-6px);
}
}

/* Apply the animation */
.notice--auto-hide {
animation: notice-life 2500ms ease-in-out forwards;
}