forked from bloominstituteoftechnology/DOM-I
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
191 lines (164 loc) · 6.97 KB
/
index.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const siteContent = {
"nav": {
"nav-item-1": "Services",
"nav-item-2": "Product",
"nav-item-3": "Vision",
"nav-item-4": "Features",
"nav-item-5": "About",
"nav-item-6": "Contact",
"img-src": "img/logo.png"
},
"cta": {
"h1": "DOM Is Awesome",
"button": "Get Started",
"img-src": "img/header-img.png"
},
"main-content": {
"features-h4":"Features",
"features-content": "Features content elementum magna eros, ac posuere elvit tempus et. Suspendisse vel tempus odio, in interdutm nisi. Suspendisse eu ornare nisl. Nullam convallis augue justo, at imperdiet metus scelerisque quis.",
"about-h4":"About",
"about-content": "About content elementum magna eros, ac posuere elvit tempus et. Suspendisse vel tempus odio, in interdutm nisi. Suspendisse eu ornare nisl. Nullam convallis augue justo, at imperdiet metus scelerisque quis.",
"middle-img-src": "img/mid-page-accent.jpg",
"services-h4":"Services",
"services-content": "Services content elementum magna eros, ac posuere elvit tempus et. Suspendisse vel tempus odio, in interdutm nisi. Suspendisse eu ornare nisl. Nullam convallis augue justo, at imperdiet metus scelerisque quis.",
"product-h4":"Product",
"product-content": "Product content elementum magna eros, ac posuere elvit tempus et. Suspendisse vel tempus odio, in interdutm nisi. Suspendisse eu ornare nisl. Nullam convallis augue justo, at imperdiet metus scelerisque quis.",
"vision-h4":"Vision",
"vision-content": "Vision content elementum magna eros, ac posuere elvit tempus et. Suspendisse vel tempus odio, in interdutm nisi. Suspendisse eu ornare nisl. Nullam convallis augue justo, at imperdiet metus scelerisque quis.",
},
"contact": {
"contact-h4" : "Contact",
"address" : "123 Way 456 Street Somewhere, USA",
"phone" : "1 (888) 888-8888",
"email" : "[email protected]",
},
"footer": {
"copyright" : "Copyright Great Idea! 2018"
},
};
// Nav Bar
const navBarKeys = Object.keys(siteContent.nav).filter(key => {
if (key.includes('nav')) {
return key;
}
});
console.log(navBarKeys);
const navBar = document.querySelectorAll('nav a');
navBar.forEach((element,index) => {
element.textContent = siteContent.nav[navBarKeys[index]];
});
// CTA
const ctaText = document.querySelector(".cta-text h1");
ctaText.innerHTML = "DOM<br />is</br />Awesome"
const ctaBtn = document.querySelector(".cta-text button");
ctaBtn.textContent = siteContent.cta.button;
// Main Content
const h4list = document.querySelectorAll(".main-content h4");
// const topContentP = document.querySelectorAll(".main-content .top-content .text-content p");
// console.log(topContentH4);
const h4Keys = Object.keys(siteContent["main-content"]).filter(key => {
if (key.includes('h4')) {
return key;
}
});
h4list.forEach((element,index) => {
element.textContent = siteContent["main-content"][h4Keys[index]];});
console.log(h4Keys);
const mainPlist = document.querySelectorAll(".main-content p");
const mainPKeys = Object.keys(siteContent["main-content"]).filter(key => {
if (key.includes('content')) {
return key;
}
});
mainPlist.forEach((element,index) => {
element.textContent = siteContent["main-content"][mainPKeys[index]];});
// const contact = document.querySelectorAll(".contact");
// const contactChildren = contact.childNodes;
// console.log(contactChildren);
// const contactKeys = Object.keys(siteContent.contact);
// contact.children.ForEach((element,index) => {
// element.textContent = siteContent.contact[contactKeys[index]];
// });
const contacth4 = document.querySelector(".contact h4");
contacth4.textContent = siteContent["contact"]["contact-h4"];
const contactP = document.querySelectorAll(".contact p");
contactP[0].textContent = siteContent["contact"]["address"];
contactP[1].textContent = siteContent["contact"]["phone"];
contactP[2].textContent = siteContent["contact"]["email"];
// console.log(contactItems[0]);
// contactItems.forEach((element,i) => {
// const contactJSON = Array.from(siteContent["contact"]);
// const contactJSONEntries = Object.entries(siteContent["contact"]);
// console.log(contactJSON);
// element.textContent = siteContent["contact"][i];
// console.log(element);
// });
// function contactPLoop() {
// for (let i = 0; i < contactP.children.length; i++);
// }
// console.log(contactItems);
// contactP.textContent = siteContent["contact"]["contact-h4"];
// siteContent["contact"].forEach((currentValue) => {
// contactItems = document.querySelectorAll(".contact");
// console.log(contactItems);
// document.querySelectorAll(".contact").children.ForEach(()
// textContent = siteContent["contact"][currentValue];
// });
// document.
// contactStuff = document.querySelectorAll("contact");
// contactStuff = document.getElementsByClassName("contact");
// console.log(contactStuff.children);
// console.log(contactStuff.childNodes);
// contactStuff.children.forEach(() => {
// const currentItem = contactStuff[i];
// console.log(currentItem);
// // textContent = Object.entries(
// });
// function contactChildSet() {
// for (let i = 0; i < contactStuff[0].children.length; i++) {
// contactStuff[0].children[i].textContent = Object.entries(siteContent["contact"][i]);
// }
// console.log('Ran?')
// }
// console.log(contactStuff[0].children.length);
// console.log(contactStuff[0].children[0]);
// contactChildSet();
// siteContent["contact"].forEach( => {
// contactStuff[0].children[i].textContent = siteContent
// }
// console.log(siteContent["contact"]);
// console.log(Object.entries(siteContent["contact"]));
// Object.entries(siteContent["contact"].forEach(
// console.log(siteContent["contact"]);
// contactChildSet();
// console.log(contactStuff);
// console.log(contactStuff[0].children);
// contactStuff.textContent = siteContent["contact"];
// Footer
copywrong = document.querySelector("footer p");
copywrong.textContent = siteContent["footer"]["copyright"];
// [""0""].children
// Images
let logo = document.getElementById("logo-img");
logo.setAttribute('src', siteContent["nav"]["img-src"])
let ctaImg = document.getElementById("cta-img");
ctaImg.setAttribute('src', siteContent["cta"]["img-src"])
let middleImg = document.getElementById("middle-img");
middleImg.setAttribute('src', siteContent["main-content"]["middle-img-src"])
// * [ ] Remember, NO direct updating of the HTML source is allowed.
// * [ ] Using your selectors, update the content to match the example file.
// * [ ] Remember to update the src attributes on images
// * [ ] Change the color of the navigation text to be green.
// use .appendChild()` and `.prepend()
// add two new items to the navigation system. You can call them whatever you want.
navBar.forEach(element => {
element.style.color ="green"
});
let navtarget = document.querySelector('nav');
let JSMischief = document.createElement("a")
let JSMischief2 = document.createElement("a")
navtarget.appendChild(JSMischief);
JSMischief.textContent = "Doom!"
// textContent = "JS Mischief!");
navtarget.prepend(JSMischief2);
JSMischief2.textContent = "Boo!"