notes.kaplon.us/views/index.hbs

55 lines
1.4 KiB
Handlebars

<!DOCTYPE html>
<html lang="en">
<head>
<title>Jody's CodeMirror</title>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="lib/codemirror.js"></script>
<script src="mode/markdown/markdown.js"></script>
<script src="keymap/vim.js"></script>
<style type="text/css">
.CodeMirror {
border: 1px solid #eee;
height: auto;
}
</style>
</head>
<body>
<form><textarea id="editor" name="editor">
{{{notetxt}}}
</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
mode: "markdown",
lineNumbers: "true",
keyMap: "vim",
viewportMargin: Infinity
});
var typingTimer;
editor.on("changes", function() {
//console.log("changes fired");
clearTimeout(typingTimer);
typingTimer = setTimeout(
function() {
//alert("saved now!");
//post('/', editor.getValue());
console.log(editor.getValue());
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
var DONE = this.DONE || 4;
if (this.readyState === DONE){
alert(request.responseText);
}
};
request.open('POST', '/', true);
request.send(editor.getValue());
},
2000
);
});
</script>
</body>
</html>