Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1 --add default message #2

Merged
merged 1 commit into from Sep 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
114 changes: 63 additions & 51 deletions index.html
@@ -1,68 +1,80 @@
<!doctype html>
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<head>
<meta charset="utf-8" />
<title>My Web Note</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://fonts.google.com/specimen/Josefin+Sans">
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://fonts.google.com/specimen/Josefin+Sans"
/>
<style>
body {
background-image: url("https://ak0.picdn.net/shutterstock/videos/935170/thumb/1.jpg");
}
body {
background-image: url("https://ak0.picdn.net/shutterstock/videos/935170/thumb/1.jpg");
}
</style>
</head>
</head>

<body>
<body>
<div class=" container">
<div class="raw" style="font-family: Josefin Sans, serif">
<h1 class="font-weight-bold text-center mt-5 mb-4">Take Notes Here!!!</h1>
<div class="border rounded" id="note" style="overflow-y: scroll; height: 200px; background-color: white" contenteditable></div>
</div>
<div class="raw">
<div class="text-right my-3">
<button id="clear" class="btn btn-primary px-4">Clear</button>
<button id="save" class="btn btn-primary px-4">Save</button>
</div>
<div class="raw" style="font-family: Josefin Sans, serif">
<h1 class="font-weight-bold text-center mt-5 mb-4">
Take Notes Here!!!
</h1>
<div
class="border rounded"
id="note"
style="overflow-y: scroll; height: 200px; background-color: white"
contenteditable
></div>
</div>
<div class="raw">
<div class="text-right my-3">
<button id="clear" class="btn btn-primary px-4">Clear</button>
<button id="save" class="btn btn-primary px-4">Save</button>
</div>
</div>
</div>

<script src="https://unpkg.com/filer/dist/filer.min.js"></script>
<script>
const fs = new Filer.FileSystem();
var note = document.querySelector('#note');
const fs = new Filer.FileSystem();
var note = document.querySelector("#note");

window.addEventListener('DOMContentLoaded', (event) => {
note.focus();
fs.readFile('/note', 'utf8', function (err, data) {
if (err) {
console.log("Welcome to my notepad!");
throw err;
}
if (data) note.innerHTML = data;
});

document.querySelector('#clear').addEventListener("click", clearContent);
document.querySelector('#save').addEventListener("click", saveContent);
window.addEventListener("DOMContentLoaded", event => {
fs.readFile("/note", "utf8", function(err, data) {
if (err) {
throw err;
}
if (data) note.innerHTML = data;
else note.innerHTML = "Welcome to my notepad!";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Very simple way to display a default message if there is no data.

});

function saveContent() {
fs.writeFile('/note', note.innerHTML, function (err) {
if (err) throw err;
document
.querySelector("#clear")
.addEventListener("click", clearContent);
document.querySelector("#save").addEventListener("click", saveContent);
});

if (note.innerHTML)
alert("Contents saved!");
});
}
function saveContent() {
fs.writeFile("/note", note.innerHTML, function(err) {
if (err) throw err;

function clearContent() {
fs.writeFile('/note', "", function (err) {
if (err) throw err;
note.innerHTML = "";
});
}
</script>
</body>
if (note.innerHTML) alert("Contents saved!");
});
}

</html>
function clearContent() {
fs.writeFile("/note", "", function(err) {
if (err) throw err;
note.innerHTML = "";
});
}
</script>
</body>
</html>