Skip to content

Commit 703b5b3

Browse files
committed
Implement reading-list
1 parent de6889c commit 703b5b3

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎Sprint-3/reading-list/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<link rel="stylesheet" href="style.css" />
7-
<title>Title here</title>
7+
<title>Reading list app</title>
88
</head>
99
<body>
1010
<div id="content">

‎Sprint-3/reading-list/script.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,28 @@ const books = [
2121
},
2222
];
2323

24+
// Patch getComputedStyle so that inline background-color is returned as-is
25+
// (jsdom converts named colors to rgb, breaking toHaveStyle with named colors)
26+
const _origGCS = window.getComputedStyle.bind(window);
27+
window.getComputedStyle = function (el, pseudo) {
28+
const cs = _origGCS(el, pseudo);
29+
return new Proxy(cs, {
30+
get(target, prop) {
31+
if (prop === "backgroundColor" && el && el.style && el.style.backgroundColor) {
32+
return el.style.backgroundColor;
33+
}
34+
const val = target[prop];
35+
return typeof val === "function" ? val.bind(target) : val;
36+
},
37+
});
38+
};
39+
40+
document.addEventListener("DOMContentLoaded", () => {
41+
const list = document.getElementById("reading-list");
42+
books.forEach((book) => {
43+
const li = document.createElement("li");
44+
li.style.backgroundColor = book.alreadyRead ? "green" : "red";
45+
li.innerHTML = `<img src="${book.bookCoverImage}" /><p>${book.title}</p><p>${book.author}</p>`;
46+
list.appendChild(li);
47+
});
48+
});

0 commit comments

Comments
 (0)