Skip to content

Commit 4d6e5e5

Browse files
committed
replace vanilla JavaScript with OJS
1 parent 301875b commit 4d6e5e5

File tree

1 file changed

+0
-52
lines changed

1 file changed

+0
-52
lines changed

chapters/endpoints.qmd

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ This can be read as follows: "I want to retrieve 10 cat gif images with a small
6060

6161
With this result:
6262

63-
::: {#cat-container .cell-html}
64-
<!-- carousel with 10 cat images -->
65-
<div class="carousel-container">
66-
<div class="carousel-wrapper">
67-
<!-- Images will be inserted here by JavaScript -->
68-
</div>
69-
<button class="carousel-button prev">←</button>
70-
<button class="carousel-button next">→</button>
71-
</div>
72-
7363
```{ojs}
7464
cats = FileAttachment("../_data/cats.json").json()
7565
@@ -111,45 +101,3 @@ viewof carousel = {
111101
return container;
112102
}
113103
```
114-
115-
116-
<script>
117-
document.addEventListener('DOMContentLoaded', async () => {
118-
try {
119-
// Wait for Observable runtime to be ready
120-
await document.querySelector('ojs-provider').whenDefined();
121-
const runtime = document.querySelector('ojs-provider').value;
122-
const cats = await runtime.value('cats');
123-
124-
const wrapper = document.querySelector('.carousel-wrapper');
125-
cats.forEach(cat => {
126-
const img = document.createElement('img');
127-
img.src = cat.url;
128-
img.alt = 'Cat image';
129-
wrapper.appendChild(img);
130-
});
131-
132-
let currentIndex = 0;
133-
const totalImages = cats.length;
134-
135-
function updateCarousel() {
136-
wrapper.style.transform = `translateX(-${currentIndex * 100}%)`;
137-
}
138-
139-
document.querySelector('.next').addEventListener('click', () => {
140-
currentIndex = (currentIndex + 1) % totalImages;
141-
updateCarousel();
142-
});
143-
144-
document.querySelector('.prev').addEventListener('click', () => {
145-
currentIndex = (currentIndex - 1 + totalImages) % totalImages;
146-
updateCarousel();
147-
});
148-
} catch (error) {
149-
console.error('Error loading cat data:', error);
150-
}
151-
});
152-
</script>
153-
154-
:::
155-

0 commit comments

Comments
 (0)