Skip to content

Commit 67c0e88

Browse files
committed
more frontend code refactoring
1 parent 98eb2a6 commit 67c0e88

5 files changed

Lines changed: 21 additions & 58 deletions

File tree

‎v3/js/composingprograms.js‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ var preseededCurInstr = null; // if you passed in a 'curInstr=<number>' in the U
4444
var myVisualizer = null; // singleton ExecutionVisualizer instance
4545

4646

47-
function enterEditMode() {
48-
$.bbq.pushState({ mode: 'edit' }, 2 /* completely override other hash strings to keep URL clean */);
49-
}
50-
51-
function enterDisplayNoFrillsMode() {
52-
$.bbq.pushState({ mode: 'display_no_frills' }, 2 /* completely override other hash strings to keep URL clean */);
53-
}
54-
5547
var pyInputCodeMirror; // CodeMirror object that contains the input text
5648

5749
function setCodeMirrorVal(dat) {
@@ -170,13 +162,6 @@ $(document).ready(function() {
170162
compactFuncLabels: true,
171163
}
172164

173-
function handleSuccessFunc() {
174-
// also scroll to top to make the UI more usable on smaller monitors
175-
$(document).scrollTop(0);
176-
177-
$.bbq.pushState({ mode: 'display' }, 2 /* completely override other hash strings to keep URL clean */);
178-
}
179-
180165
function handleUncaughtExceptionFunc(trace) {
181166
if (trace.length == 1) {
182167
var errorLineNo = trace[0].line - 1; /* CodeMirror lines are zero-indexed */
@@ -201,7 +186,7 @@ $(document).ready(function() {
201186
backend_script, backendOptionsObj,
202187
frontendOptionsObj,
203188
'pyOutputPane',
204-
handleSuccessFunc, handleUncaughtExceptionFunc);
189+
enterDisplayMode, handleUncaughtExceptionFunc);
205190
}
206191

207192
function executeCodeFromScratch() {
@@ -285,4 +270,3 @@ $(document).ready(function() {
285270
$('#urlOutput').val(urlStr);
286271
});
287272
});
288-

‎v3/js/csc108h.js‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ var preseededCurInstr = null; // if you passed in a 'curInstr=<number>' in the U
4545
var myVisualizer = null; // singleton ExecutionVisualizer instance
4646

4747

48-
function enterEditMode() {
49-
$.bbq.pushState({ mode: 'edit' }, 2 /* completely override other hash strings to keep URL clean */);
50-
}
51-
52-
function enterDisplayNoFrillsMode() {
53-
$.bbq.pushState({ mode: 'display_no_frills' }, 2 /* completely override other hash strings to keep URL clean */);
54-
}
55-
5648
var pyInputCodeMirror; // CodeMirror object that contains the input text
5749

5850
function setCodeMirrorVal(dat) {
@@ -173,13 +165,6 @@ $(document).ready(function() {
173165
updateOutputCallback: function() {$('#urlOutput,#embedCodeOutput').val('');},
174166
}
175167

176-
function handleSuccessFunc() {
177-
// also scroll to top to make the UI more usable on smaller monitors
178-
$(document).scrollTop(0);
179-
180-
$.bbq.pushState({ mode: 'display' }, 2 /* completely override other hash strings to keep URL clean */);
181-
}
182-
183168
function handleUncaughtExceptionFunc(trace) {
184169
if (trace.length == 1) {
185170
var errorLineNo = trace[0].line - 1; /* CodeMirror lines are zero-indexed */
@@ -204,7 +189,7 @@ $(document).ready(function() {
204189
backend_script, backendOptionsObj,
205190
frontendOptionsObj,
206191
'pyOutputPane',
207-
handleSuccessFunc, handleUncaughtExceptionFunc);
192+
enterDisplayMode, handleUncaughtExceptionFunc);
208193
}
209194

210195
function executeCodeFromScratch() {
@@ -286,4 +271,3 @@ $(document).ready(function() {
286271
$('#urlOutput').val(urlStr);
287272
});
288273
});
289-

‎v3/js/matrixtutor.js‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ var myVisualizer = null; // singleton ExecutionVisualizer instance
4747
var VIZ_LABEL = "Run and Visualize Code";
4848

4949

50-
function enterEditMode() {
51-
$.bbq.pushState({ mode: 'edit' }, 2 /* completely override other hash strings to keep URL clean */);
52-
}
53-
54-
function enterDisplayNoFrillsMode() {
55-
$.bbq.pushState({ mode: 'display_no_frills' }, 2 /* completely override other hash strings to keep URL clean */);
56-
}
57-
5850
var pyInputCodeMirror; // CodeMirror object that contains the solution code
5951
var pyTestInputCodeMirror; // CodeMirror object that contains the test code
6052

@@ -166,13 +158,6 @@ $(document).ready(function() {
166158
jumpToEnd: true,
167159
}
168160

169-
function handleSuccessFunc() {
170-
// also scroll to top to make the UI more usable on smaller monitors
171-
$(document).scrollTop(0);
172-
173-
$.bbq.pushState({ mode: 'display' }, 2 /* completely override other hash strings to keep URL clean */);
174-
}
175-
176161
function handleUncaughtExceptionFunc(trace) {
177162
if (trace.length == 1) {
178163
var errorLineNo = trace[0].line - 1; /* CodeMirror lines are zero-indexed */
@@ -213,7 +198,7 @@ $(document).ready(function() {
213198
backend_script, backendOptionsObj,
214199
frontendOptionsObj,
215200
'pyOutputPane',
216-
handleSuccessFunc, handleUncaughtExceptionFunc);
201+
enterDisplayMode, handleUncaughtExceptionFunc);
217202
}
218203

219204
function executeCodeFromScratch() {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ function setToggleOptions(dat) {
9797
}
9898

9999

100+
function enterDisplayMode() {
101+
// also scroll to top to make the UI more usable on smaller monitors
102+
$(document).scrollTop(0);
103+
104+
$.bbq.pushState({ mode: 'display' }, 2 /* completely override other hash strings to keep URL clean */);
105+
}
106+
107+
function enterEditMode() {
108+
$.bbq.pushState({ mode: 'edit' }, 2 /* completely override other hash strings to keep URL clean */);
109+
}
110+
111+
function enterDisplayNoFrillsMode() {
112+
$.bbq.pushState({ mode: 'display_no_frills' }, 2 /* completely override other hash strings to keep URL clean */);
113+
}
114+
115+
100116
function executePythonCode(pythonSourceCode,
101117
backendScript, backendOptionsObj,
102118
frontendOptionsObj,

‎v3/js/opt-frontend.js‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ $(document).ready(function() {
9696
// thanks to http://benalman.com/projects/jquery-bbq-plugin/
9797
$(window).bind("hashchange", function(e) {
9898
appMode = $.bbq.getState('mode'); // assign this to the GLOBAL appMode
99+
//console.log("hashchange", appMode);
99100

100101
if (appMode === undefined || appMode == 'edit') {
101102
$("#pyInputPane").show();
@@ -201,13 +202,6 @@ $(document).ready(function() {
201202
//, hideCode: true,
202203
}
203204

204-
function handleSuccessFunc() {
205-
// also scroll to top to make the UI more usable on smaller monitors
206-
$(document).scrollTop(0);
207-
208-
$.bbq.pushState({ mode: 'display' }, 2 /* completely override other hash strings to keep URL clean */);
209-
}
210-
211205
function handleUncaughtExceptionFunc(trace) {
212206
if (trace.length == 1 && trace[0].line) {
213207
var errorLineNo = trace[0].line - 1; /* CodeMirror lines are zero-indexed */
@@ -232,7 +226,7 @@ $(document).ready(function() {
232226
backend_script, backendOptionsObj,
233227
frontendOptionsObj,
234228
'pyOutputPane',
235-
handleSuccessFunc, handleUncaughtExceptionFunc);
229+
enterDisplayMode, handleUncaughtExceptionFunc);
236230
}
237231

238232
function executeCodeFromScratch() {

0 commit comments

Comments
 (0)