Skip to content

Commit

Permalink
Restrict size of Explanation on WebIDE (closes #58) and fix numbers
Browse files Browse the repository at this point in the history
The max size of the Explanation div is set to 25% of the window.

The number parser for the Explanation didn't include 0. The regex
has been updated.

Signed-off-by: Jadon Fowler <jadonflower@gmail.com>
  • Loading branch information
phase committed May 2, 2016
1 parent 51a94ef commit ef3b06e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -13,4 +13,5 @@ __pycache__/
heroku*
log*
docs/_*
*.stackdump
*.stackdump
oide
16 changes: 14 additions & 2 deletions static/o.js
Expand Up @@ -33,7 +33,19 @@ function getExplanantion() {
var e = parse(code);
$("#explanation").html(e);
var width = getMaxWidth() * 8;
$("#explanation").width(width);
$("#explanation").width(width > window.innerWidth * 0.25 ? window.innerWidth * 0.25 : width);
if ($("#explanation").height() > window.innerHeight * 0.25) $("#explanation").height(window.innerHeight * 0.25);
}

function selectText(container) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(container));
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(container));
window.getSelection().addRange(range);
}
}

function updateUtils() {
Expand All @@ -53,4 +65,4 @@ $(document).ready(function() {
$('#code').on('input propertychange paste', function() {
updateUtils();
});
});
});
6 changes: 3 additions & 3 deletions static/parser.coffee
Expand Up @@ -16,7 +16,7 @@ stringExplanation = (string) -> new Explanation("\""+string+"\"", "Push string t
charExplanation = (c) -> new Explanation("'"+c, " Push " + c + " to the stack\n")

getExplanation = (c) ->
if c.match /[1-9A-F]/
if c.match /[0-9A-F]/
numberExplanation c
else if explanations[c] != undefined
new Explanation c, explanations[c] + "\n"
Expand Down Expand Up @@ -101,7 +101,7 @@ parse = (code) ->
buffer = ""
continue
buffer += c
else if c.match /[1-9A-F]/
else if c.match /[0-9A-F]/
events.push eventObj newNumber c
else if c is "{"
fcb = true
Expand Down Expand Up @@ -204,4 +204,4 @@ explain = (events) ->
maxWidth = g
beforeSpaces += 1
e += s + "\n"
e
e
4 changes: 2 additions & 2 deletions static/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/primary.html
Expand Up @@ -42,7 +42,7 @@ <h3>Utilities</h3>
<br/>
<h4>General Explanation <small>(not always correct)</small>:</h4>
<div class="container" style="margin-top: 5%;margin-right: 5%;">
<pre id="explanation"></pre>
<pre id="explanation" onclick="selectText('explanation')"></pre>
</div>
</div>
</div>
Expand Down

0 comments on commit ef3b06e

Please sign in to comment.