Skip to content

Commit 4eb3d68

Browse files
committed
Chapter 20 - A public space on the web
1 parent d7039bd commit 4eb3d68

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

chapter-20/test-files/www/eloquentjs.html

Whitespace-only changes.

chapter-20/test-files/www/index.css

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
input,
2+
textarea {
3+
padding: 9px;
4+
border: solid 1px #e5e5e5;
5+
outline: 0;
6+
font: normal 13px/100% Verdana, Tahoma, sans-serif;
7+
width: 100%;
8+
background: #ffffff;
9+
-moz-box-sizing: border-box;
10+
-webkit-box-sizing: border-box;
11+
box-sizing: border-box;
12+
}
13+
14+
textarea {
15+
width: 100%;
16+
min-height: 500px;
17+
line-height: 150%;
18+
}
19+
20+
input:hover,
21+
textarea:hover,
22+
input:focus,
23+
textarea:focus {
24+
border-color: #c9c9c9;
25+
}
26+
27+
label {
28+
margin-left: 0px;
29+
color: #999999;
30+
}
31+
32+
button,
33+
input[type='submit'] {
34+
width: auto;
35+
padding: 9px 15px;
36+
background: lightseagreen;
37+
border: 0;
38+
font-size: 14px;
39+
color: #ffffff;
40+
cursor: pointer;
41+
}

chapter-20/test-files/www/index.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>A public space on the web</title>
8+
<link rel="stylesheet" href="./index.css" />
9+
<script src="./index.js"></script>
10+
</head>
11+
<body>
12+
<form id="web-editor">
13+
<label for="files">File: </label>
14+
<select name="files" id="files">
15+
<option value="index.html">index.html</option>
16+
<option value="eloquentjs.html">eloquentjs.html</option>
17+
<option value="index.js">index.js</option>
18+
<option value="index.css">index.css</option>
19+
</select>
20+
<textarea name="file-contents" id="file-contents"></textarea>
21+
<button type="submit">Save</button>
22+
</form>
23+
</body>
24+
</html>

chapter-20/test-files/www/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
window.addEventListener('load', () => {
2+
const select = document.querySelector('#files');
3+
const textarea = document.querySelector('#file-contents');
4+
select.addEventListener('change', async (event) => {
5+
const response = await fetch(event.target.value);
6+
const fileContents = await response.text();
7+
textarea.value = fileContents;
8+
});
9+
select.dispatchEvent(new Event('change'));
10+
11+
const form = document.querySelector('#web-editor');
12+
form.addEventListener('submit', async (event) => {
13+
event.preventDefault();
14+
console.log(textarea.value);
15+
await fetch(select.value, {
16+
method: 'PUT',
17+
body: textarea.value,
18+
});
19+
select.dispatchEvent(new Event('change'));
20+
});
21+
});

0 commit comments

Comments
 (0)