-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
78 lines (64 loc) · 2.13 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="paper.css" />
<title>My Web Page</title>
</head>
<body>
<!-- This is a comment -->
<div id="content">
<h2>Micro-Notes</h2>
<h3>OSD600 Lab 2</h3>
<div id="note_message">
<p id="save_message"></p>
</div>
<div id="notes" contenteditable></div>
<div id="note_buttons">
<button onClick="save()">Save Changes</button>
<button onClick="window.location.reload();">Cancel</button>
</div>
</div>
<!-- Scripts -->
<script src="https://unpkg.com/filer/dist/filer.min.js"></script>
<script>
const fs = new Filer.FileSystem();
var defaultString = "Welcome to my notepad!";
window.addEventListener("DOMContentLoaded", event => {
window.onload = function() {
document.getElementById("notes").focus();
console.log("DOM fully loaded and parsed");
fs.readFile("/note", "utf8", function(err, data) {
if (err) {
console.log("unable to load documents");
notesDiv.textContent = defaultString;
}
if (data) {
console.log("documents loaded");
document.querySelector("#notes").innerHTML = data;
}
});
};
});
function save() {
var msg1 = "Document saved successfully!";
var msg2 = "Failed to save document!";
var notes = document.querySelector("#notes").innerHTML;
fs.writeFile("/note", notes, function(err) {
if (err) {
console.log("error saving to document");
document.querySelector("#save_message").innerHTML = msg2;
} else {
console.log("document saved");
document.querySelector("#save_message").innerHTML = msg1;
}
setTimeout(clearMessage, 2000);
function clearMessage() {
document.querySelector("#save_message").innerHTML = "";
}
});
}
</script>
</body>
</html>