2013-08-04 13:01:01 -04:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>A smart, organizing text editor</title>
|
|
|
|
<link href="/static/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css">
|
|
|
|
<link href="/static/bootstrap/css/bootstrap-responsive.css" rel="stylesheet" type="text/css">
|
|
|
|
<link href="/static/shoofle.css" rel="stylesheet" type="text/css">
|
|
|
|
<script src="/static/jquery.min.js" type="text/javascript"></script>
|
|
|
|
<style type="text/css">
|
2013-08-09 08:30:46 -04:00
|
|
|
body {
|
|
|
|
background-color: gray;
|
|
|
|
margin: 1em;
|
|
|
|
}
|
|
|
|
#editor p {
|
2013-08-04 13:01:01 -04:00
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
.block {
|
|
|
|
font-family: monospace;
|
|
|
|
background-color: white;
|
|
|
|
padding: 4px;
|
2013-08-09 08:30:46 -04:00
|
|
|
display: block;
|
2013-08-04 13:01:01 -04:00
|
|
|
}
|
2013-08-09 08:30:46 -04:00
|
|
|
.if-elseif-else-wrapper {
|
2013-08-04 13:01:01 -04:00
|
|
|
white-space: normal;
|
|
|
|
background-color: rgb(200,200,255);
|
|
|
|
}
|
|
|
|
.branch {
|
2013-08-09 08:30:46 -04:00
|
|
|
margin-right: 4px;
|
2013-08-04 13:01:01 -04:00
|
|
|
background-color: rgb(200,255,200);
|
2013-08-09 08:30:46 -04:00
|
|
|
display: inline-block;
|
2013-08-04 13:01:01 -04:00
|
|
|
}
|
2013-08-09 08:30:46 -04:00
|
|
|
.while-wrapper {
|
2013-08-04 13:01:01 -04:00
|
|
|
background-color: rgb(255,200,200);
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body style="background-color: gray; margin: 1em;">
|
2013-08-09 08:30:46 -04:00
|
|
|
<div class="block" id="editor" contentEditable>
|
|
|
|
<p class="code">some kind of preparation code, I guess</p>
|
|
|
|
<p class="code">or something</p>
|
|
|
|
<div class="branch if">
|
|
|
|
<p class="condition">if (condition)</p>
|
|
|
|
<div class="block base">
|
|
|
|
<p>do something in response to a true condition</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="branch else-if">
|
|
|
|
<p class="condition">else if (some other condition)</p>
|
|
|
|
<div class="block base">
|
|
|
|
<p>then we should do something specific else</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="branch else">
|
|
|
|
<p class="condition">else</p>
|
|
|
|
<div class="block base">
|
|
|
|
<p>some fallback thing!</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<p>some code</p>
|
|
|
|
<p>do other thing</p>
|
|
|
|
<p>{} | : {} ();</p>
|
|
|
|
<div class="while-wrapper">
|
|
|
|
<p class="condition">while (something)</p>
|
|
|
|
<div class="block base">
|
|
|
|
<p>update the counters</p>
|
|
|
|
<p>hack the gibsons</p>
|
|
|
|
<p>do the stuff</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2013-08-04 13:01:01 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
2013-08-09 08:30:46 -04:00
|
|
|
var finds_if_regex = /(?:\s*)((?:else\s*)?if\s*\([^)]+\)\s*)\{([^}]*)\}/;
|
|
|
|
function respond_to_ifs() {
|
|
|
|
var editor = $('#editor');
|
2013-08-06 07:17:33 -04:00
|
|
|
|
2013-08-09 08:30:46 -04:00
|
|
|
var lines_of_code = editor.find('p');
|
|
|
|
lines_of_code.each(individual_line_if);
|
|
|
|
}
|
|
|
|
function individual_line_if() {
|
|
|
|
if (!finds_if_regex.exec($(this).text())) { return true; }
|
|
|
|
var split_up = $(this).text().split(finds_if_regex);
|
|
|
|
|
|
|
|
var branch = $('<div></div>').addClass('branch if');
|
|
|
|
$(this).before(branch);
|
|
|
|
|
|
|
|
if (split_up[0].length > 0) {
|
|
|
|
branch.before($('<p></p>').text(split_up[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
branch.append($('<p class="condition"></p>').text(split_up[1]));
|
|
|
|
branch.append($('<div></div>').addClass('block').append($(this)));
|
|
|
|
$(this).before('{');
|
|
|
|
$(this).text(split_up[2]);
|
|
|
|
$(this).after('}');
|
|
|
|
|
|
|
|
if (split_up[3].length > 0) {
|
|
|
|
branch.after($('<p></p>').text(split_up[2]));
|
2013-08-04 13:01:01 -04:00
|
|
|
}
|
|
|
|
}
|
2013-08-06 07:17:33 -04:00
|
|
|
var finds_else_regex = /(?:[^\S])\s*else\s*(\{[^}]*\})/;
|
|
|
|
function make_new_else(c1, c2) {
|
|
|
|
var target;
|
|
|
|
if (c1 == undefined) { target = $(this); }
|
|
|
|
if (c2 == undefined) { target = $(c1); }
|
|
|
|
else { target = $(c2); }
|
2013-08-04 13:01:01 -04:00
|
|
|
|
2013-08-06 07:17:33 -04:00
|
|
|
if (!target.is('.block.base')) {
|
|
|
|
target.find('.block.base')
|
|
|
|
}
|
2013-08-05 08:39:00 -04:00
|
|
|
}
|
2013-08-06 07:17:33 -04:00
|
|
|
|
2013-08-04 13:01:01 -04:00
|
|
|
$(document).ready(function () {
|
2013-08-09 08:30:46 -04:00
|
|
|
$('#editor').on('input', function() { respond_to_ifs(); });
|
2013-08-04 13:01:01 -04:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|