Skip to content

Commit fdc2b7f

Browse files
committed
a bit more gentle refactoring
1 parent f0d9cb1 commit fdc2b7f

4 files changed

Lines changed: 31 additions & 40 deletions

File tree

‎v3/js/composingprograms.js‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3838

3939

4040
$(document).ready(function() {
41+
genericOptFrontendReady();
4142
setSurveyHTML();
4243

4344
$("#embedLinkDiv").hide();
@@ -157,18 +158,6 @@ $(document).ready(function() {
157158
}
158159
}
159160

160-
161-
// log a generic AJAX error handler
162-
$(document).ajaxError(function() {
163-
alert("Server error (possibly due to memory/resource overload). " +
164-
"Report a bug to philip@pgbovine.net\n\n" +
165-
"(Click the 'Generate URL' button to include a unique URL in your email bug report.)");
166-
167-
$('#executeBtn').html("Visualize Execution");
168-
$('#executeBtn').attr('disabled', false);
169-
});
170-
171-
172161
// redraw connector arrows on window resize
173162
$(window).resize(function() {
174163
if (appMode == 'display') {

‎v3/js/csc108h.js‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3939

4040

4141
$(document).ready(function() {
42+
genericOptFrontendReady();
4243
setSurveyHTML();
4344

4445
$("#embedLinkDiv").hide();
@@ -158,18 +159,6 @@ $(document).ready(function() {
158159
}
159160
}
160161

161-
162-
// log a generic AJAX error handler
163-
$(document).ajaxError(function() {
164-
alert("Server error (possibly due to memory/resource overload). " +
165-
"Report a bug to philip@pgbovine.net\n\n" +
166-
"(Click the 'Generate URL' button to include a unique URL in your email bug report.)");
167-
168-
$('#executeBtn').html("Visualize Execution");
169-
$('#executeBtn').attr('disabled', false);
170-
});
171-
172-
173162
// redraw connector arrows on window resize
174163
$(window).resize(function() {
175164
if (appMode == 'display') {

‎v3/js/opt-frontend-common.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ var domain = "http://pythontutor.com/"; // for deployment
5858
//var domain = "http://localhost:8080/"; // for Google App Engine local testing
5959

6060

61+
var isExecutingCode = false; // nasty, nasty global
62+
63+
6164
var appMode = 'edit'; // 'edit', 'display', or 'display_no_frills' also support
6265
// 'visualize' for backward compatibility (same as 'display')
6366

@@ -91,6 +94,24 @@ var myVisualizer = null; // singleton ExecutionVisualizer instance
9194

9295
var rawInputLst = []; // a list of strings inputted by the user in response to raw_input or mouse_input events
9396

97+
function genericOptFrontendReady() {
98+
// log a generic AJAX error handler
99+
$(document).ajaxError(function(evt, jqxhr, settings, exception) {
100+
// ignore errors related to togetherjs stuff:
101+
if (settings.url.indexOf('togetherjs') > -1) {
102+
return; // get out early
103+
}
104+
105+
alert("Server error (possibly due to memory/resource overload). " +
106+
"Report a bug to philip@pgbovine.net\n\n" +
107+
"(Click the 'Generate URL' button to include a unique URL in your email bug report.)");
108+
109+
$('#executeBtn').html("Visualize Execution");
110+
$('#executeBtn').attr('disabled', false);
111+
112+
isExecutingCode = false; // ugh, nasty global
113+
});
114+
}
94115

95116
function getQueryStringOptions() {
96117
// note that any of these can be 'undefined'
@@ -273,6 +294,8 @@ function executePythonCode(pythonSourceCode,
273294
return;
274295
}
275296

297+
isExecutingCode = true; // nasty global
298+
276299
$.get(backendScript,
277300
{user_script : pythonSourceCode,
278301
raw_input_json: rawInputLst.length > 0 ? JSON.stringify(rawInputLst) : '',
@@ -335,6 +358,11 @@ function executePythonCode(pythonSourceCode,
335358

336359
handleSuccessFunc();
337360
}
361+
362+
// WARNING: this line may run before handleSuccessFunc or
363+
// handleUncaughtExceptionFunc fully finishes if they
364+
// contain asynchronous parts
365+
isExecutingCode = false;
338366
},
339367
"json");
340368
}

‎v3/js/opt-frontend.js‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ function executeCodeWithRawInput(rawInputStr, curInstr) {
370370

371371

372372
$(document).ready(function() {
373+
genericOptFrontendReady();
373374
setSurveyHTML();
374375

375376
$("#embedLinkDiv").hide();
@@ -706,22 +707,6 @@ $(document).ready(function() {
706707
}
707708

708709

709-
// log a generic AJAX error handler
710-
$(document).ajaxError(function(evt, jqxhr, settings, exception) {
711-
// ignore errors related to togetherjs stuff:
712-
if (settings.url.indexOf('togetherjs') > -1) {
713-
return; // get out early
714-
}
715-
716-
alert("Server error (possibly due to memory/resource overload). " +
717-
"Report a bug to philip@pgbovine.net\n\n" +
718-
"(Click the 'Generate URL' button to include a unique URL in your email bug report.)");
719-
720-
$('#executeBtn').html("Visualize Execution");
721-
$('#executeBtn').attr('disabled', false);
722-
});
723-
724-
725710
$(window).resize(redrawConnectors);
726711

727712
$('#genUrlBtn').bind('click', function() {

0 commit comments

Comments
 (0)