Skip to content

Commit 96cac25

Browse files
committed
more refactoring action
1 parent 75decf9 commit 96cac25

4 files changed

Lines changed: 44 additions & 151 deletions

File tree

‎v3/js/composingprograms.js‎

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3737
// should all be imported BEFORE this file
3838

3939

40-
var appMode = 'edit'; // 'edit', 'display', or 'display_no_frills'
41-
42-
var preseededCurInstr = null; // if you passed in a 'curInstr=<number>' in the URL, then set this var
43-
44-
var myVisualizer = null; // singleton ExecutionVisualizer instance
45-
46-
47-
var pyInputCodeMirror; // CodeMirror object that contains the input text
48-
49-
function setCodeMirrorVal(dat) {
50-
pyInputCodeMirror.setValue(dat.rtrim() /* kill trailing spaces */);
51-
$('#urlOutput,#embedCodeOutput').val('');
52-
53-
// also scroll to top to make the UI more usable on smaller monitors
54-
$(document).scrollTop(0);
55-
}
56-
57-
5840
$(document).ready(function() {
5941
setSurveyHTML();
6042

@@ -77,49 +59,7 @@ $(document).ready(function() {
7759
// thanks to http://benalman.com/projects/jquery-bbq-plugin/
7860
$(window).bind("hashchange", function(e) {
7961
appMode = $.bbq.getState('mode'); // assign this to the GLOBAL appMode
80-
81-
if (appMode === undefined || appMode == 'edit') {
82-
$("#pyInputPane").show();
83-
$("#pyOutputPane").hide();
84-
$("#embedLinkDiv").hide();
85-
86-
$(".surveyQ").val(''); // clear all survey results when user hits forward/back
87-
88-
// destroy all annotation bubbles (NB: kludgy)
89-
if (myVisualizer) {
90-
myVisualizer.destroyAllAnnotationBubbles();
91-
}
92-
}
93-
else if (appMode == 'display') {
94-
$("#pyInputPane").hide();
95-
$("#pyOutputPane").show();
96-
97-
$("#embedLinkDiv").show();
98-
99-
$('#executeBtn').html("Visualize Execution");
100-
$('#executeBtn').attr('disabled', false);
101-
102-
103-
// do this AFTER making #pyOutputPane visible, or else
104-
// jsPlumb connectors won't render properly
105-
myVisualizer.updateOutput();
106-
107-
// customize edit button click functionality AFTER rendering (NB: awkward!)
108-
$('#pyOutputPane #editCodeLinkDiv').show();
109-
$('#pyOutputPane #editBtn').click(function() {
110-
enterEditMode();
111-
});
112-
}
113-
else if (appMode == 'display_no_frills') {
114-
$("#pyInputPane").hide();
115-
$("#pyOutputPane").show();
116-
$("#embedLinkDiv").show();
117-
}
118-
else {
119-
assert(false);
120-
}
121-
122-
$('#urlOutput,#embedCodeOutput').val(''); // clear to avoid stale values
62+
updateAppDisplay();
12363
});
12464

12565

‎v3/js/csc108h.js‎

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3838
// should all be imported BEFORE this file
3939

4040

41-
var appMode = 'edit'; // 'edit', 'display', or 'display_no_frills'
42-
43-
var preseededCurInstr = null; // if you passed in a 'curInstr=<number>' in the URL, then set this var
44-
45-
var myVisualizer = null; // singleton ExecutionVisualizer instance
46-
47-
48-
var pyInputCodeMirror; // CodeMirror object that contains the input text
49-
50-
function setCodeMirrorVal(dat) {
51-
pyInputCodeMirror.setValue(dat.rtrim() /* kill trailing spaces */);
52-
$('#urlOutput,#embedCodeOutput').val('');
53-
54-
// also scroll to top to make the UI more usable on smaller monitors
55-
$(document).scrollTop(0);
56-
}
57-
58-
5941
$(document).ready(function() {
6042
setSurveyHTML();
6143

@@ -78,49 +60,7 @@ $(document).ready(function() {
7860
// thanks to http://benalman.com/projects/jquery-bbq-plugin/
7961
$(window).bind("hashchange", function(e) {
8062
appMode = $.bbq.getState('mode'); // assign this to the GLOBAL appMode
81-
82-
if (appMode === undefined || appMode == 'edit') {
83-
$("#pyInputPane").show();
84-
$("#pyOutputPane").hide();
85-
$("#embedLinkDiv").hide();
86-
87-
$(".surveyQ").val(''); // clear all survey results when user hits forward/back
88-
89-
// destroy all annotation bubbles (NB: kludgy)
90-
if (myVisualizer) {
91-
myVisualizer.destroyAllAnnotationBubbles();
92-
}
93-
}
94-
else if (appMode == 'display') {
95-
$("#pyInputPane").hide();
96-
$("#pyOutputPane").show();
97-
98-
$("#embedLinkDiv").show();
99-
100-
$('#executeBtn').html("Visualize Execution");
101-
$('#executeBtn').attr('disabled', false);
102-
103-
104-
// do this AFTER making #pyOutputPane visible, or else
105-
// jsPlumb connectors won't render properly
106-
myVisualizer.updateOutput();
107-
108-
// customize edit button click functionality AFTER rendering (NB: awkward!)
109-
$('#pyOutputPane #editCodeLinkDiv').show();
110-
$('#pyOutputPane #editBtn').click(function() {
111-
enterEditMode();
112-
});
113-
}
114-
else if (appMode == 'display_no_frills') {
115-
$("#pyInputPane").hide();
116-
$("#pyOutputPane").show();
117-
$("#embedLinkDiv").show();
118-
}
119-
else {
120-
assert(false);
121-
}
122-
123-
$('#urlOutput,#embedCodeOutput').val(''); // clear to avoid stale values
63+
updateAppDisplay();
12464
});
12565

12666

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ var domain = "http://pythontutor.com/"; // for deployment
5656
//var domain = "http://localhost:8080/"; // for Google App Engine local testing
5757

5858

59+
var appMode = 'edit'; // 'edit', 'display', or 'display_no_frills' also support
60+
// 'visualize' for backward compatibility (same as 'display')
61+
62+
var preseededCurInstr = null; // if you passed in a 'curInstr=<number>' in the URL, then set this var
63+
64+
var pyInputCodeMirror; // CodeMirror object that contains the input text
65+
66+
function setCodeMirrorVal(dat) {
67+
pyInputCodeMirror.setValue(dat.rtrim() /* kill trailing spaces */);
68+
$('#urlOutput,#embedCodeOutput').val('');
69+
70+
// also scroll to top to make the UI more usable on smaller monitors
71+
$(document).scrollTop(0);
72+
}
73+
74+
75+
var myVisualizer = null; // singleton ExecutionVisualizer instance
76+
var myVisualizerState = null; // contains the parameters necessary to generate myVisualizer
77+
78+
5979
var rawInputLst = []; // a list of strings inputted by the user in response to raw_input or mouse_input events
6080

6181

@@ -169,6 +189,8 @@ function executePythonCode(pythonSourceCode,
169189
return;
170190
}
171191

192+
myVisualizerState = null; // clear this before attempting to execute
193+
172194
$.get(backendScript,
173195
{user_script : pythonSourceCode,
174196
raw_input_json: rawInputLst.length > 0 ? JSON.stringify(rawInputLst) : '',
@@ -225,6 +247,14 @@ function executePythonCode(pythonSourceCode,
225247
});
226248
}
227249

250+
// set some nasty global state that represents the current
251+
// code that's being visualized at the moment
252+
myVisualizerState = {visualizedCode: pythonSourceCode,
253+
backendScript: backendScript,
254+
backendOptionsObj: backendOptionsObj,
255+
frontendOptionsObj: frontendOptionsObj};
256+
// TODO: insert UUID
257+
228258
handleSuccessFunc();
229259
}
230260
},

‎v3/js/opt-frontend.js‎

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3939
// should all be imported BEFORE this file
4040

4141

42-
var appMode = 'edit'; // 'edit', 'display', or 'display_no_frills'
43-
// also support 'visualize' for backward
44-
// compatibility (it's the same as 'display')
45-
46-
var preseededCurInstr = null; // if you passed in a 'curInstr=<number>' in the URL, then set this var
47-
48-
var myVisualizer = null; // singleton ExecutionVisualizer instance
49-
50-
51-
var pyInputCodeMirror; // CodeMirror object that contains the input text
52-
53-
function setCodeMirrorVal(dat) {
54-
pyInputCodeMirror.setValue(dat.rtrim() /* kill trailing spaces */);
55-
$('#urlOutput,#embedCodeOutput').val('');
56-
57-
// also scroll to top to make the UI more usable on smaller monitors
58-
$(document).scrollTop(0);
42+
function redrawConnectors() {
43+
if (appMode == 'display' || appMode == 'visualize' /* 'visualize' is deprecated */) {
44+
if (myVisualizer) {
45+
myVisualizer.redrawConnectors();
46+
}
47+
}
5948
}
6049

6150

@@ -100,6 +89,7 @@ var try_hook = function(hook_name, args) {
10089
}
10190

10291

92+
// get the ENTIRE current state of the app
10393
function getAppState() {
10494
return {code: pyInputCodeMirror.getValue(),
10595
mode: appMode,
@@ -108,7 +98,8 @@ function getAppState() {
10898
drawParentPointers: $('#drawParentPointerSelector').val(),
10999
textReferences: $('#textualMemoryLabelsSelector').val(),
110100
showOnlyOutputs: $('#showOnlyOutputsSelector').val(),
111-
py: $('#pythonVersionSelector').val()};
101+
py: $('#pythonVersionSelector').val(),
102+
myVisualizerState: myVisualizerState};
112103
}
113104

114105

@@ -208,14 +199,14 @@ $(document).ready(function() {
208199
}
209200

210201
if (dat.helpAvailable) {
211-
$("#togetherJSHeader").fadeIn(750);
202+
$("#togetherJSHeader").fadeIn(750, redrawConnectors);
212203
}
213204
else {
214205
if (TogetherJS.running) {
215206
alert("No more live tutors are available now.\nPlease check back later.");
216207
TogetherJS(); // toggle off
217208
}
218-
$("#togetherJSHeader").fadeOut(750);
209+
$("#togetherJSHeader").fadeOut(750, redrawConnectors);
219210
}
220211
};
221212
}
@@ -332,9 +323,6 @@ $(document).ready(function() {
332323
// undocumented experimental modes:
333324
pyCrazyMode: ($('#pythonVersionSelector').val() == '2crazy'),
334325
holisticMode: ($('#cumulativeModeSelector').val() == 'holistic')
335-
//allowEditAnnotations: true,
336-
337-
//, hideCode: true,
338326
}
339327

340328
function handleUncaughtExceptionFunc(trace) {
@@ -704,12 +692,7 @@ $(document).ready(function() {
704692
});
705693

706694

707-
// redraw connector arrows on window resize
708-
$(window).resize(function() {
709-
if (appMode == 'display' || appMode == 'visualize' /* 'visualize' is deprecated */) {
710-
myVisualizer.redrawConnectors();
711-
}
712-
});
695+
$(window).resize(redrawConnectors);
713696

714697
$('#genUrlBtn').bind('click', function() {
715698
var myArgs = getAppState();

0 commit comments

Comments
 (0)