99 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			99 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!DOCTYPE html>
 | 
						|
<html lang="en">
 | 
						|
<head>
 | 
						|
<title>Jody's Notes</title>
 | 
						|
<meta http-equiv="cache-control" content="max-age=0" />
 | 
						|
<meta http-equiv="cache-control" content="no-cache" />
 | 
						|
<meta http-equiv="expires" content="0" />
 | 
						|
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
 | 
						|
<meta http-equiv="pragma" content="no-cache" />
 | 
						|
<link rel="stylesheet" href="lib/codemirror.css">
 | 
						|
<link rel="stylesheet" href="addon/dialog/dialog.css">
 | 
						|
<script src="lib/codemirror.js"></script>
 | 
						|
<script src="addon/selection/active-line.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="addon/edit/matchbrackets.js"></script>
 | 
						|
<script src="keymap/vim.js"></script>
 | 
						|
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
 | 
						|
<style type="text/css">
 | 
						|
    html, body { height: 100%; margin: 0; padding: 0; }
 | 
						|
    .wrap {
 | 
						|
        position: relative;
 | 
						|
        height: 100%;
 | 
						|
        background: #eee;
 | 
						|
        padding: 15px;
 | 
						|
        box-sizing: border-box;
 | 
						|
    }
 | 
						|
    .border {
 | 
						|
        -webkit-border-radius: 5px;
 | 
						|
        -moz-border-radius: 5px;
 | 
						|
        border-radius: 5px;
 | 
						|
        border: 1px solid #999;
 | 
						|
        position: relative;
 | 
						|
        height: 100%;
 | 
						|
        padding: 1px;
 | 
						|
    }
 | 
						|
    .CodeMirror {
 | 
						|
        height: 96%;
 | 
						|
    }
 | 
						|
</style>
 | 
						|
<!-- favicon design by Rockicon of thenounproject.com -->
 | 
						|
</head>
 | 
						|
<body>
 | 
						|
 | 
						|
<div class=wrap>
 | 
						|
    <div class=border>
 | 
						|
        <!-- <textarea id="editor" name="editor">{{{notetxt}}}</textarea> -->
 | 
						|
        <textarea id="editor" name="editor"></textarea>
 | 
						|
    </div>
 | 
						|
</div>
 | 
						|
 | 
						|
<script>
 | 
						|
    var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
 | 
						|
        mode:  "markdown",
 | 
						|
        lineNumbers: "true",
 | 
						|
        keyMap: "vim",
 | 
						|
        matchBrackets: true,
 | 
						|
        showCursorWhenSelecting: true,
 | 
						|
        viewportMargin: Infinity,
 | 
						|
        indentUnit: 4,
 | 
						|
        styleActiveLine: true,
 | 
						|
        autofocus: true
 | 
						|
    });
 | 
						|
    // Add my .vimrc stuff.
 | 
						|
    CodeMirror.Vim.map('jj', '<Esc>', 'insert')
 | 
						|
    // Hacked semi-colon/colon swap remap into /assets/keymap/vim.js...kind of a heavy hammer might bite me later.
 | 
						|
    // ...and it's already confused me later the same day. I deleted ~/notes.kaplon.us/CodeMirror w/out realizing I'd symlinked it into /assets!
 | 
						|
    // This no worky, there's no concept of <leader> in CodeMirror, but i was hoping this would work-around it.
 | 
						|
    //CodeMirror.Vim.map(' c', '<Esc>o- [ ] ', 'normal')
 | 
						|
    //CodeMirror.Vim.map(' x', '<ESC>;s/\[\s\]/[x]/g<CR>;noh<CR>', 'normal')
 | 
						|
    CodeMirror.commands.save = function(){
 | 
						|
        socket.emit('cm-save', 'codemirror save event');
 | 
						|
    }
 | 
						|
 | 
						|
    var socket = io();
 | 
						|
    socket.on('download allNotes', function(msg){
 | 
						|
        //console.log(msg);
 | 
						|
        editor.getDoc().setValue(msg);
 | 
						|
    });
 | 
						|
 | 
						|
    var userKeypress = false;
 | 
						|
    document.onkeydown = function(){ userKeypress = true; };
 | 
						|
    var typingTimer;
 | 
						|
    editor.on("changes", function() {
 | 
						|
        if (!userKeypress) { return; };  // Do nothing if no keys hit yet, avoids infinite loop since 'changes' event fires after initial websocket content loading.
 | 
						|
        userKeypress = false;   // Set this back to false, still getting infinite loop.
 | 
						|
        clearTimeout(typingTimer);
 | 
						|
        typingTimer = setTimeout(
 | 
						|
        function() {
 | 
						|
            socket.emit('upload allNotes', editor.getValue());
 | 
						|
        },
 | 
						|
        2000
 | 
						|
      );
 | 
						|
    });
 | 
						|
</script>
 | 
						|
</body>
 | 
						|
</html>
 |