This repository was archived by the owner on Aug 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcore.js
More file actions
41 lines (35 loc) · 1.22 KB
/
core.js
File metadata and controls
41 lines (35 loc) · 1.22 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Define main container
const app = document.getElementById('app');
// Function for creating and appending elements
const addToElementbyId = (elementType, id, parent) => {
const element = document.createElement(elementType);
element.setAttribute('id', id);
parent.appendChild(element);
return element;
};
// Set up Kontent delivery
const Kk = window['kontentDelivery'];
const deliveryClient = new Kk.createDeliveryClient({
projectId: '975bf280-fd91-488c-994c-2f04416e5ee3'
});
// Function for adding elements to DOM with specific attributes
const createElement = (elementType, classToAdd, attribute, attributeValue) => {
const element = document.createElement(elementType);
element.setAttribute('class', classToAdd);
// Set attribute value based on the attribute required
attribute === 'href'
? (element.href = attributeValue)
: attribute === 'innerHTML'
? (element.innerHTML = attributeValue)
: attribute === 'innerText'
? (element.innerText = attributeValue)
: attribute === 'src'
? (element.src = attributeValue)
: undefined;
return element;
};
// Error messages
const reportErrors = err => {
console.error(err);
app.innerHTML = `<p>An error occured 😞:</p><p><i>${err}</i></p>`;
};