-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIForDictionary.js
More file actions
283 lines (234 loc) · 11.9 KB
/
UIForDictionary.js
File metadata and controls
283 lines (234 loc) · 11.9 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
class Dictionary{
static dictonaryData(response) {
const dictonary = document.querySelector("#dictionary");
if (response.title !== "No Definitions Found") {
// Changed property of "#dictionary" div if there is no error
dictonary.setAttribute("style", "display : inline-block");
/*
The " word.innerHTML = ""; " code between the codes to prevent the new incoming data from being added to the old data.
*/
const word = document.querySelector(".word");
word.innerHTML = "";
word.innerHTML = `
<h4> Word : ${response[0].word}</h4>
<h5> ${response[0].phonetic === undefined ? `` : `${response[0].phonetic}`}</h5>
`;
// For Phonetics
const cardphonetic = document.querySelector(".cardphonetic");
if (response[0].phonetics === undefined) {
// If there is no key named phonetics in the array
cardphonetic.setAttribute("style", "display : none");
}
else{
const phoneticList = document.querySelector(".tbodyPhonetic");
phoneticList.innerHTML = "";
response[0].phonetics.forEach(function (phonetics) {
phoneticList.innerHTML += `
<tr style="${phonetics.audio === '' ? `display:none` : ``}">
<th>
<img src="images/${phonetics.audio.includes("uk") === true ? `uk-flag.jpg` : `usa-flag.jpg`}" id="outputImage" height="30px" width="30px">
</th>
<td>
${phonetics.text === undefined ? `-` : `${phonetics.text}`}
</td>
<td>
<span class="btnContainer">
<input type="button" class='phoneticbutton'
onclick="playAudio.call(this,'${phonetics.audio}')"
id="btn_385">
</span>
</td>
<td>
${phonetics.audio.includes("noun") === true ? `Noun` : `Verb`}
</td>
</tr>
`;
if(phonetics.audio === ''){
cardphonetic.setAttribute("style", "display : none");
}
else{
cardphonetic.setAttribute("style", "");
}
});
}
//-----------------( partOfSpeech 1 (example noun) )------------------------
// Synonyms for partOfSpeech 1
if (response[0].meanings[0] === undefined) {
const speech1 = document.querySelector(".partOfSpeech1");
speech1.setAttribute("style", "display : none");
}
else {
// Speech1 Title
const speech1Title = document.querySelector(".speech1Title");
speech1Title.innerHTML = "";
speech1Title.innerHTML += `
<h4>--${response[0].meanings[0].partOfSpeech}</h4>`;
// Speech1 List
const speech1List = document.querySelector(".speech1");
speech1List.innerHTML = "";
response[0].meanings[0].definitions.forEach(function (speech) {
speech1List.innerHTML += `
<ul>
<li><a><strong>${speech.definition}</strong></a></li>
<li><a>${speech.example === undefined ? `` : `" ${speech.example} "`}</a></li>
</ul>
`;
})
// Speech1 For synonyms
const speech1synonymsList = document.querySelector(".speech1synonyms");
if (response[0].meanings[0].synonyms.length === 0) {
// If array named Synonyms is empty
speech1synonymsList.setAttribute("style", "display : none");
}
else{
speech1synonymsList.innerHTML = "";
response[0].meanings[0].synonyms.forEach(function (synonyms) {
if (synonyms.length !== 0) {
speech1synonymsList.innerHTML += `
<span class="badge bg-secondary">${synonyms}</span>
`;
}
});
const synonymsTitle1 = document.querySelector(".synonymsTitle1");
synonymsTitle1.innerHTML = "";
synonymsTitle1.innerHTML =`
<h5>SynymsList</h5>`;
}
}
//-----------------( partOfSpeech 2 (example verb) )------------------------
if (response[0].meanings[1] === undefined) {
const speech2 = document.querySelector(".partOfSpeech2");
speech2.setAttribute("style", "display : none");
}
else {
// Speech2 Title
const speech2Title = document.querySelector(".speech2Title");
speech2Title.innerHTML = "";
speech2Title.innerHTML += `<br/>
<h4>--${response[0].meanings[1].partOfSpeech}</h4>`;
// Speech 2 lists
const speech2List = document.querySelector(".speech2");
speech2List.innerHTML = "";
response[0].meanings[1].definitions.forEach(function (speech2) {
speech2List.innerHTML += `
<ul>
<li>
<a><strong>${speech2.definition}</strong></a>
</li>
<li><a>${speech2.example === undefined ? `` : `" ${speech2.example} "`}</a></li>
</ul>`;
});
// Speech 2 For Synonymos
const speech2synonymsList = document.querySelector(".speech2synonyms");
if (response[0].meanings[1].synonyms.length === 0) {
speech2synonymsList.setAttribute("style", "display : none");
}
else{
speech2synonymsList.innerHTML ="";
response[0].meanings[1].synonyms.forEach(function (synonyms) {
if (synonyms.length !== 0) {
speech2synonymsList.innerHTML += `
<span class="badge bg-secondary">${synonyms}</span>
`;
}
});
const synonymsTitle2 = document.querySelector(".synonymsTitle2");
synonymsTitle2.innerHTML = "";
synonymsTitle2.innerHTML =`
<h5>SynymsList</h5>`;
}
}
//-----------------( partOfSpeech 3 (example adverb) )------------------------
if (response[0].meanings[2] === undefined) {
const speech3 = document.querySelector(".partOfSpeech3");
speech3.setAttribute("style", "display : none");
}
else {
// Speech3 Title
const speech3Title = document.querySelector(".speech3Title");
speech3Title.innerHTML = "";
speech3Title.innerHTML += `<br/>
<h4>--${response[0].meanings[2].partOfSpeech}</h4>`;
// Speech 3 lists
const speech3List = document.querySelector(".speech3");
speech3List.innerHTML = "";
response[0].meanings[2].definitions.forEach(function (speech3) {
speech3List.innerHTML += `
<ul>
<li>
<a><strong>${speech3.definition}</strong></a>
</li>
<li><a>${speech3.example === undefined ? `` : `" ${speech3.example} "`}</a></li>
</ul>
`;
});
// Speech 3 For Synonymos
const speech3synonymsList = document.querySelector(".speech3synonyms");
if (response[0].meanings[2].synonyms.length === 0) {
speech3synonymsList.setAttribute("style", "display : none");
}
else{
response[0].meanings[2].synonyms.forEach(function (synonyms) {
if (synonyms.length !== 0) {
speech3synonymsList.innerHTML = "";
speech3synonymsList.innerHTML += `
<span class="badge bg-secondary">${synonyms}</span>`;
}
});
const synonymsTitle3 = document.querySelector(".synonymsTitle3");
speech3synonymsList.innerHTML = "";
synonymsTitle3.innerHTML =`
<h5>SynymsList</h5>`;
}
}
//-----------------( partOfSpeech 4 (example Conj) )------------------------
if (response[0].meanings[3] === undefined) {
const speech4 = document.querySelector(".partOfSpeech4");
speech4.setAttribute("style", "display : none");
}
else {
// Speech4 Title
const speech4Title = document.querySelector(".speech4Title");
speech4Title.innerHTML = "";
speech4Title.innerHTML += `<br/>
<h4>--${response[0].meanings[3].partOfSpeech}</h4>`;
// Speech 4 lists
const speech4List = document.querySelector(".speech4");
speech4List.innerHTML = "";
response[0].meanings[3].definitions.forEach(function (speech4) {
speech4List.innerHTML += `
<ul>
<li>
<a><strong>${speech4.definition}</strong></a>
</li>
<li><a> ${speech4.example === undefined ? `` : `" ${speech4.example} "`}</a></li>
</ul>
`;
});
// Speech 4 For Synonymos
const speech4synonymsList = document.querySelector(".speech4synonyms");
if (response[0].meanings[3].synonyms.length === 0) {
speech4synonymsList.setAttribute("style", "display : none");
}
else{
speech4synonymsList.innerHTML = "";
response[0].meanings[3].synonyms.forEach(function (synonyms) {
if (synonyms.length !== 0) {
speech4synonymsList.innerHTML += `
<span class="badge bg-secondary">${synonyms}</span>
`;
}
});
const synonymsTitle4 = document.querySelector(".synonymsTitle4");
speech4synonymsList.innerHTML = "";
synonymsTitle4.innerHTML =`
<h5>SynymsList</h5>`;
}
}
}
else{
const dictonary = document.querySelector("#dictionary");
dictonary.setAttribute("style", "display : none");
}
}
}