-
Notifications
You must be signed in to change notification settings - Fork 0
/
textedit.html
57 lines (57 loc) · 1.97 KB
/
textedit.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
<!doctype html>
<html>
<head>
<meta charset=utf8>
<meta name=viewport content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<style>
* { box-sizing: border-box }
body { display: flex; flex-direction: column; height: 100vh; margin: 0 }
textarea, #t { width: 100% }
textarea { display: block; flex-grow: 1 }
#l { display: none }
.b { border: 1px solid #000; color: #000; text-decoration: none; cursor: default }
</style>
<script>
function main() {
var s = document.querySelector('#s'),
t = document.querySelector('#t'),
n = document.querySelector('#n'),
ed = document.querySelector('textarea');
function update() {
if (s.href) { URL.revokeObjectURL(s.href); }
s.href = URL.createObjectURL(new Blob([ed.value]));
s.download=t.value;
};
ed.oninput = update;
t.oninput=update;
l.onchange = function() {
if (l.files.length) {
var r = new FileReader();
r.onload = function() {
t.value = l.files[0].name;
ed.value = r.result;
update();
};
r.readAsText(l.files[0]);
}
}
function newFile() {
t.value = 'untitled.txt';
ed.value = '';
update();
}
n.onclick = newFile;
newFile();
}
</script>
</head>
<body onload="main()">
<input id=t value=untitled.txt>
<textarea></textarea>
<nav>
<a id=s class=b>Save</a>
<label class=b>Load<input id=l type=file></label>
<span id=n class=b>New</span>
</nav>
</body>
</html>