Permalink
Browse files

Initial commit

  • Loading branch information...
brymck committed Jun 24, 2011
0 parents commit 12ae9df1d114baeea1401d2639f2be92d2074636
Showing with 118 additions and 0 deletions.
  1. 0 README.md
  2. +8 −0 css/master.css
  3. +39 −0 index.html
  4. +18 −0 js/jquery-1.6.1.min.js
  5. +53 −0 js/sandbox.js
No changes.
@@ -0,0 +1,8 @@
ul {
list-style-type: none;
padding-left: 0;
}
.fixed_width {
display: inline-block;
width: 6em;
}
@@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Sandbox</title>
<link rel="stylesheet" href="css/master.css" type="text/css" media="screen" charset="utf-8">
</head>
<body>
<h1>Sandbox</h1>
<form id="sandbox_form" accept-charset="utf-8">
<ul>
<li>
<label for="code">Stuff to eval:</label><br>
<textarea id="code" rows="12" cols="80" autofocus></textarea>
</li>
<li>
<label for="iter" class="fixed_width">Iterations:</label>
<input type="number" id="iter" value="1" min="1">
</li>
<li>
<label for="keycode" class="fixed_width">Key pressed:</label>
<input type="text" id="keycode" value="" readonly>
</li>
<li>
<label for="error" class="fixed_width">Error message:</label>
<input type="text" id="error" value="" size="60" readonly>
</li>
<li>
<label for="timer" class="fixed_width">Time elapsed:</label>
<input type="text" id="timer" value="" readonly>
</li>
<li><input type="submit" value="Run (Ctrl+Shift+R)"></li>
</ul>
</form>
<script src="js/jquery-1.6.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/sandbox.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,53 @@
var Sandbox = (function() {
var KeyCodes = {
R: 82
};
var form = document.getElementById("sandbox_form");
var code = document.getElementById("code");
var iter = document.getElementById("iter");
var timer = document.getElementById("timer");
var keycode = document.getElementById("keycode");
var error = document.getElementById("error");
function addListeners() {
form.onsubmit = Sandbox.run;
form.onkeydown = keyHandler;
}
function keyHandler(e) {
if (e.which === KeyCodes.R) {
if (e.ctrlKey && e.shiftKey) {
Sandbox.run();
e.preventDefault();
}
}
keycode.value = e.which;
}
return {
init: function() {
addListeners();
},
run: function() {
try {
var count = parseInt(iter.value, 10),
codeText = code.value,
start = new Date(),
end;
for (var i = 0; i < count; i++) {
eval(codeText);
}
end = new Date();
error.value = "";
timer.value = end - start + " ms";
return false;
} catch(e) {
error.value = e.message;
}
}
}
})();
Sandbox.init();

0 comments on commit 12ae9df

Please sign in to comment.