Created
May 22, 2014 20:04
-
-
Save Azeirah/6759ee635df3b113b0c1 to your computer and use it in GitHub Desktop.
Note taking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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