-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.js
48 lines (37 loc) · 1.28 KB
/
main.js
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
42
43
44
45
46
47
48
class List extends HTMLElement{
constructor(){
super();
let shadow = this.attachShadow({mode: 'open'});
this.divHeader = document.createElement("div");
this.divContent = document.createElement("div");
this.modePicture = false;
shadow.appendChild(this.divHeader);
shadow.appendChild(this.divContent);
}
connectedCallback(){
this.divHeader.innerHTML= `<strong>
${this.getAttribute("data-title")}
</strong>`
let url = this.getAttribute("data-url");
let field = this.getAttribute("data-field");
if(this.getAttribute("modePicture")){
this.modePicture=this.getAttribute("modePicture");
}
console.log(this.modePicture)
this.divContent.innerHTML = "";
fetch(url)
.then(response=>response.json())
.then(json=>json.forEach(element=>{
if(this.modePicture === 'true'){
this.divContent.innerHTML += `<img
src='${element[field]}'>
</img>`
}else{
this.divContent.innerHTML += `<div>
${element[field]}
</div>`
}
}));
}
}
customElements.define("app-list", List);