-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_carousel.js
More file actions
27 lines (23 loc) · 891 Bytes
/
project_carousel.js
File metadata and controls
27 lines (23 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const CAROUSEL_SNIPPET_PATH = '/project_carousel.html';
export function doInjectCarousel(){
return true;
}
/**
* Injects pre-generated carousel HTML (from CAROUSEL_SNIPPET_PATH) after a target element.
* @param {HTMLElement|string} anchor - Element or selector after which to insert the carousel
*/
export function injectCarousel(anchor) {
const target = typeof anchor === 'string'
? document.querySelector(anchor)
: anchor;
if (!target) return;
fetch(CAROUSEL_SNIPPET_PATH)
.then(res => res.text())
.then(html => {
const template = document.createElement('template');
template.innerHTML = html.trim();
const carouselNode = template.content.firstElementChild;
target.insertAdjacentElement('afterend', carouselNode);
carouselNode.classList.add('carousel-loaded');
});
}