notes.kaplon.us/views/index.hbs

72 lines
2.1 KiB
Handlebars

<!DOCTYPE html>
<html lang="en">
<head>
<title>Jody's CodeMirror</title>
<link rel="stylesheet" href="lib/codemirror.css">
<link rel="stylesheet" href="addon/dialog/dialog.css">
<script src="lib/codemirror.js"></script>
<script src="addon/dialog/dialog.js"></script>
<script src="addon/search/searchcursor.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>
<div style="font-size: 13px; width: 300px; height: 30px;">Key buffer: <span id="command-display"></span></div>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
mode: "markdown",
lineNumbers: "true",
keyMap: "vim",
showCursorWhenSelecting: true,
viewportMargin: Infinity
});
// Add my .vimrc stuff.
CodeMirror.Vim.map('jj', '<Esc>', 'insert')
CodeMirror.Vim.map(';', ':')
CodeMirror.Vim.map(':', ';')
//CodeMirror.commands.save = function(){ alert("Saving"); }
var commandDisplay = document.getElementById('command-display');
var keys = ''
CodeMirror.on(editor, 'vim-keypress', function(key) {
keys = keys + key
commandDisplay.innerHTML = keys
})
CodeMirror.on(editor, 'vim-command-done', function(e) {
keys = ''
commandDisplay.innerHTML = keys
})
var typingTimer;
editor.on("changes", function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(
function() {
//console.log(editor.getValue());
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
var DONE = this.DONE || 4;
if (this.readyState === DONE){
console.log('ajax is done.');
}
};
request.open('POST', '/', true);
request.send(editor.getValue());
},
2000
);
});
</script>
</body>
</html>