-
Notifications
You must be signed in to change notification settings - Fork 0
/
implications.html
206 lines (173 loc) · 5.36 KB
/
implications.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
<!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>Implications</h1>
<p>
Websites are one of the most commonly used forms of application. They
are designed to work across a very wide range of devices, from mobile
phones to desktop computers, which is why they are so widely used.
</p>
<p>
However, compatibility across devices is limited due to different
browsers not supporting the same features or latest specifications for
HTML and CSS.
</p>
<aside>
<h2>Downsides of web development</h2>
<ul>
<li>
Processing power is limited, as most computation must be performed
through a Javascript engine
</li>
<li>
Features are often limited, however modern web standards such as the
Geolocation and Sensors API are making this less of an issue
</li>
</ul>
</aside>
<figure>
<img
src="https://c.tenor.com/9rlry5qfipAAAAAC/boris-johnson-thumbs-up.gif"
/>
<figcaption>Boris Johnson approves of web development.</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--implications_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>