-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
211 lines (178 loc) · 5.6 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Best Website</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<nav>
<ul role="none">
<li>
<a href="index.html">Markup and web languages</a>
</li>
<li>
<a href="implications.html">Implications</a>
</li>
<li>
<a href="client-scripting.html">Client-side scripting</a>
</li>
<li>
<a href="server-scripting.html">Server-side scripting</a>
</li>
</ul>
</nav>
<article>
<h1>Markup and web languages</h1>
<p>
HTML is the standard markup language for creating web pages. It is used
to create web pages that are displayed in a web browser. HTML is the
most basic building block of a web page. It defines the content and
behavior of a web page. HTML elements are the building blocks of HTML
pages. HTML elements tell the browser how the content of the page should
be displayed.
</p>
<p>
JavaScript is a lightweight, interpreted programming language used to
make web pages interactive. It is also used to control the behavior and
appearance of a web page. It bears almost no similarities to Java, other
than similar syntax.
</p>
<aside>
<h2>A trip back to the past</h2>
<p>
The web has used tonnes of different languages for dynamic content
over the years, including:
</p>
<ul>
<li>WebAssembly</li>
<li>Javascript</li>
<li>Visual Basic Scripts (Microsoft ActiveX)</li>
</ul>
</aside>
<figure>
<img
src="https://image.cnbcfm.com/api/v1/image/106828879-1611351385639-bern.jpg?v=1611783695"
/>
<figcaption>
Bernie Sanders. He has nothing to do with this topic.
</figcaption>
</figure>
</article>
<div class="Comments">
<h2>Comments</h2>
<div class="Comments-newComment">
<div class="Comments-newCommentNames">
<label>
First name
<input type="text" id="firstName" required />
</label>
<label>
Last name
<input type="text" id="lastName" required />
</label>
</div>
<label>
Email
<input type="email" id="email" required />
</label>
<label>
Date
<input type="date" id="date" required />
</label>
<label>
Comment content
<textarea
minlength="10"
placeholder="Type a comment..."
required
></textarea>
</label>
<button id="submit-comment">Submit comment</button>
</div>
<div class="Comments-list"></div>
</div>
<script>
const LS_KEY = "btec--markup_comments";
/**
* @type {HTMLTextAreaElement}
*/
const textarea = document.querySelector(".Comments-newComment textarea");
const firstName = document.getElementById("firstName");
const lastName = document.getElementById("lastName");
const email = document.getElementById("email");
const date = document.getElementById("date");
function getComments() {
return JSON.parse(localStorage.getItem(LS_KEY)) || [];
}
function addComment(message) {
const comments = getComments();
comments.push(message);
localStorage.setItem(LS_KEY, JSON.stringify(comments));
updateCommentsInDom();
}
function validateNewComment() {
if (textarea.value.trim().length < 10) {
return false;
}
if (
Math.min(
firstName.value.trim().length,
lastName.value.trim().length,
email.value.trim().length,
date.value.length
) === 0
) {
return false;
}
if (!email.checkValidity()) {
return false;
}
return {
comment: textarea.value.trim(),
name: `${firstName.value.trim()} ${lastName.value.trim()}`,
email: email.value.trim(),
date: date.value,
};
}
function submitCommentHandler(e) {
const result = validateNewComment();
if (result === false) {
return;
}
addComment(result);
firstName.value = "";
lastName.value = "";
email.value = "";
date.value = "";
textarea.value = "";
}
function updateCommentsInDom() {
/**
* @type {{ comment: string, name: string, email: string, date: string }[]}
*/
const comments = getComments();
const commentsContainer = document.querySelector(
".Comments .Comments-list"
);
commentsContainer.innerHTML = "";
comments.forEach((comment) => {
const commentElement = document.createElement("div");
commentElement.classList.add("Comment");
commentElement.innerText = comment.comment;
commentElement.setAttribute(
"data-header",
`${comment.name} <${comment.email}> (${comment.date})`
);
commentsContainer.appendChild(commentElement);
});
}
document
.getElementById("submit-comment")
.addEventListener("click", submitCommentHandler);
updateCommentsInDom();
</script>
</body>
</html>