-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom.js
125 lines (94 loc) · 4.38 KB
/
dom.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function init() {
element = document.getElementById("load-local");
element.addEventListener('click', function () {
display();
});
element = document.getElementById("load-remote");
element.addEventListener('click', function () {
loadRemote();
});
}
function loadRemote() {
const apiKey = '$2b$10$38qpvDi3GCylbyfMLOWRG.BlYhkS3q9Kh2zBSzCmtpo8D915VNcwO'; // Replace with your JSONBin secret key
//const binId = 'your_bin_id'; // Replace with the ID of your JSONBin bin
const url = 'https://api.jsonbin.io/v3/b/64d01cac9d312622a38cfada';
fetch(url, {
headers: {
'X-Access-Key': apiKey,
'Content-Type': 'application/json',
}
})
.then(response => {
return response.json();
})
.then(data => {
console.log('Data from JSONBin:', data.record);
class MyCustomElement extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: 'open' });
const storedCollegeCourse = data.record.projectCard;
console.log(storedCollegeCourse[0].cardNum);
const rootList = document.createElement('section');
const style = document.createElement('style');
style.textContent = `
img{
width: 450px;
height: auto;
}
p{
font-style: italic;
text-align: start;
}
h2{
font-size: medium;
}
`;
if (storedCollegeCourse) {
storedCollegeCourse.forEach(card => {
const h2content = document.createElement('h2');
h2content.textContent = `${card.d}`;
rootList.appendChild(h2content);
// p element
const pcontent = document.createElement('p');
pcontent.textContent = `${card.p}`;
rootList.appendChild(pcontent);
//Img
const imgcontent = document.createElement('img');
const imgsrc = `${card.img}`;
imgcontent.setAttribute("src", imgsrc);
rootList.appendChild(imgcontent);
// link from a tag
const acontent = document.createElement('a');
const link = `${card.link}`;
acontent.setAttribute('href', link);
acontent.innerHTML = "Read More";
rootList.appendChild(acontent);
});
}
shadowRoot.appendChild(style);
shadowRoot.appendChild(rootList);
}
}
customElements.define('my-custom-element', MyCustomElement);
})
}
function display() {
localStorage.setItem("h2-content", "My first project");
localStorage.setItem("p-content", "Building my own portfolio website using HTML, CSS, Java Script. With the purpose of representing who I am, and what I have become.To impress the recruiter!");
localStorage.setItem("img-path", "./Images/iewek-gnos-hhUx08PuYpc-unsplash.jpg");
localStorage.setItem("a-content", "hi");
localStorage.setItem("link1", "https://github.com/vqnguyenSD/CSE134_HW4_Part2");
const rh2 = document.querySelector("#h3");
const h2value = localStorage.getItem("h2-content");
rh2.innerHTML = h2value;
const rp = document.querySelector("#p");
const pvalue = localStorage.getItem("p-content");
const img1 = document.querySelector("#img1");
img1.src = localStorage.getItem("img-path");
const link1 = document.querySelector("#link1");
const reflink = localStorage.getItem("link1");
link1.setAttribute("href", reflink);
rp.innerHTML = pvalue;
}
window.addEventListener('DOMContentLoaded', init);