Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
106 lines (86 sloc) 3.12 KB
<!DOCTYPE html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0; width=device-width; user-scalable=no;"/>
<title>idea-depo: (:channel-name ~ index:)</title>
<style>
html, body {
padding: 0px;
margin: 0px;;
}
textarea#text {
position: absolute;
min-height: 100%;
width: 100%;
border: none;
margin: 0px;
padding: 0px;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
font-family: monospace;
}
</style>
</head>
<body>
<textarea id="text">(:text:)</textarea>
<div id="diff-bin">
</div>
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js" type="text/javascript" defer async></script>
<script src="/client.js" type="text/javascript"></script>
<script src="/operational-transforms.js" type="text/javascript"></script>
<script>
(function() {
var ch = new Channel("(:channel-name ~ index:)", (:initial-info-id ~ 0:));
var text = document.getElementById("text");
var curText = text.value;
function sendChanges() {
var newText = text.value;
var op = ot.produceOp(curText, newText);
if(op.length <= 0) { return; }
ch.send(op);
curText = newText;
}
function adjustHeight() {
text.style.setProperty("height", text.scrollHeight + "px", null);
}
text.addEventListener('keyup', sendChanges, false);
text.addEventListener('mouseup', sendChanges, false);
text.addEventListener('input', sendChanges, false);
text.addEventListener('keyup', adjustHeight, false);
text.addEventListener('mouseup', adjustHeight, false);
text.addEventListener('input', adjustHeight, false);
text.addEventListener('keyup', function(e) { // Hanging tabs
if(e.which !== 13) { return; }
var curPos = text.selectionStart;
var spaces = curText.substring(curText.lastIndexOf("\n", curPos - 2), curPos - 1).match(/^\n*(\s*)/)[1];
if(spaces.length === 0) { return; }
var scroll = text.scrollTop;
text.value = curText.substr(0, curPos) + spaces + curText.substr(curPos);
sendChanges();
text.selectionStart = text.selectionEnd = curPos + spaces.length;
text.scrollTop = scroll;
}, false);
text.addEventListener('keydown', function(e) { // Making [tab] work
if(e.which !== 9) { return; }
var curPos = text.selectionStart;
text.value = curText.substr(0, curPos) + " " + curText.substr(curPos);
sendChanges();
text.selectionStart = text.selectionEnd = curPos + 2;
e.stopPropagation();
e.preventDefault();
return false;
}, false);
ch.onReceive(function(msg) {
curText = ot.applyOp(curText, msg.content);
text.value = curText;
adjustHeight();
});
window.addEventListener("load", function() { setTimeout(function() { ch.start(); }, 0) }, false);
adjustHeight();
})();
</script>
</body>
</html>