Skip to content

Instantly share code, notes, and snippets.

@Azeirah
Created May 22, 2014 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Azeirah/6759ee635df3b113b0c1 to your computer and use it in GitHub Desktop.
Save Azeirah/6759ee635df3b113b0c1 to your computer and use it in GitHub Desktop.
Note taking
<!DOCTYPE html>
<html>
<head>
<title>Text Editor</title>
<style>
body, document, html {
width: 100%;height: 100%;
}
div {
height: 60rem;
font-size:2rem;
font-family:Helvetica;
line-height:1.4;
max-width:60%;
margin:0 auto;
padding:4rem;
}
</style>
</head>
<body>
<div contenteditable></div>
<script>
var div = document.body.children[0];
var debounce = function(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function() {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
}, wait);
if (immediate && !timeout){
func.apply(context, args);
}
};
};
window.addEventListener("load", function () {
div.innerHTML = localStorage.getItem("note");
}, false);
document.body.addEventListener("keyup", debounce(function () {
localStorage.setItem("note", div.innerHTML);
}, 760));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment