Skip to content

Commit

Permalink
Add in a restart button for restarting the execution of the code, fro…
Browse files Browse the repository at this point in the history
…m the beginning. Fixes #98.
  • Loading branch information
jeresig committed Mar 23, 2012
1 parent 8efd2e8 commit 3bfa149
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
22 changes: 13 additions & 9 deletions css/style.css
Expand Up @@ -98,19 +98,19 @@ body {
position: relative;
}

#output form {
#output-text form {
display: inline-block;
margin: 0;
}

#output div {
#output-text div {
line-height: 28px;
margin: 2px 5px;
font-family: Monaco, Courier New;
font-size: 12px;
}

#output div input.text {
#output-text div input.text {
font-family: Monaco, Courier New;
font-size: 12px;
width: 125px;
Expand Down Expand Up @@ -723,23 +723,27 @@ div.container-fluid > div.content {
}

#output.side {
/*
position: absolute;
width: 360px;
*/
height: 360px;
height: 393px;
border: 1px solid #D4CCB0;
}

#output.side .toolbar {
margin: 0;
top: 360px;
position: absolute;
width: 100%;
}

#output-text-test {
display: none;
}

#output-canvas {
#output-text, #output-canvas {
position: absolute;
top: 0px;
left: 0px;
width: 400px;
height: 360px;
display: none;
overflow: auto;
}
30 changes: 25 additions & 5 deletions js/output.js
Expand Up @@ -276,6 +276,12 @@ var Output = {
}
},

restart: function() {
if ( Output.output && Output.output.restart ) {
Output.output.restart();
}
},

clear: function() {
if ( Output.output && Output.output.clear ) {
Output.output.clear();
Expand Down Expand Up @@ -480,8 +486,10 @@ var TextOutput = {
if ( last != val ) {
var pos = root.find( "input" ).index( this );

curProblem.inputs[ pos ] = val;
TextOutput.focusLine = root.children().index( this.parentNode );
if ( !TextOutput.restarting ) {
curProblem.inputs[ pos ] = val;
TextOutput.focusLine = root.children().index( this.parentNode );
}

$(this).data( "last", val );
}
Expand All @@ -492,7 +500,7 @@ var TextOutput = {
TextOutput.runCode( Output.getUserCode() );
TextOutput.focusLine = null;
}
}, 13 )
}, 13 );

this.bound = true;
},
Expand Down Expand Up @@ -621,6 +629,17 @@ var TextOutput = {
kill: function() {
TextOutput.$elem.empty();
TextOutput.$elem.hide();
},

restart: function() {
curProblem.inputs = [];
TextOutput.focusLine = null;
TextOutput.inputNum = 0;
TextOutput.curLine = -1;

TextOutput.restarting = true;
Output.runCode( Output.getUserCode() );
TextOutput.restarting = false;
}
};

Expand Down Expand Up @@ -724,8 +743,9 @@ var CanvasOutput = {
CanvasOutput.lastGrab = grabAll;
},

reset: function() {

restart: function() {
CanvasOutput.lastGrab = null;
CanvasOutput.runCode( Output.getUserCode() );
},

testContext: {
Expand Down
4 changes: 4 additions & 0 deletions js/play-ui.js
Expand Up @@ -91,6 +91,10 @@ $(function(){
insertExerciseForm( testObj );
});

$("#restart-code").bind( "buttonClick", function() {
Output.restart();
});

$("#get-hint").bind( "buttonClick", function() {
$("#editor-box").toggleTip( "Hint", curProblem.hints, function() {
$("#get-hint .ui-button-text").text( testAnswers.length > 0 ? "Answer" : "Hints" );
Expand Down

0 comments on commit 3bfa149

Please sign in to comment.