Skip to content

Commit bb91bb0

Browse files
committed
bam
1 parent 989a868 commit bb91bb0

3 files changed

Lines changed: 47 additions & 75 deletions

File tree

v5-unity/iframe-embed.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
4+
<head>
5+
<title>Online Python Tutor - iframe embed page</title>
6+
7+
<!-- let Webpack take care of everything. Use the [hash] feature to
8+
create unique filenames for releases:
9+
https://webpack.github.io/docs/long-term-caching.html -->
10+
<script type="text/javascript" src="iframe-embed.bundle.js" charset="utf-8"></script>
11+
12+
</head>
13+
14+
<body>
15+
16+
<div id="vizDiv"></div>
17+
18+
</body>
19+
</html>

v5-unity/js/iframe-embed.js

Lines changed: 20 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,28 @@
1-
/*
1+
// Python Tutor: https://github.com/pgbovine/OnlinePythonTutor/
2+
// Copyright (C) Philip Guo (philip@pgbovine.net)
3+
// LICENSE: https://github.com/pgbovine/OnlinePythonTutor/blob/master/LICENSE.txt
24

3-
Online Python Tutor
4-
https://github.com/pgbovine/OnlinePythonTutor/
5+
// use Webpack to automatically package up these dependencies
6+
require('./jquery-3.0.0.min.js');
7+
require('./jquery.ba-bbq.js'); // contains slight pgbovine modifications
58

6-
Copyright (C) Philip J. Guo (philip@pgbovine.net)
9+
var optCommon = require('./opt-frontend-common.js');
10+
var pytutor = require('./pytutor.js');
11+
var assert = pytutor.assert;
712

8-
Permission is hereby granted, free of charge, to any person obtaining a
9-
copy of this software and associated documentation files (the
10-
"Software"), to deal in the Software without restriction, including
11-
without limitation the rights to use, copy, modify, merge, publish,
12-
distribute, sublicense, and/or sell copies of the Software, and to
13-
permit persons to whom the Software is furnished to do so, subject to
14-
the following conditions:
13+
require('../css/opt-frontend.css');
1514

16-
The above copyright notice and this permission notice shall be included
17-
in all copies or substantial portions of the Software.
18-
19-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26-
27-
*/
28-
29-
30-
// Pre-reqs:
31-
// - pytutor.js
32-
// - jquery.ba-bbq.min.js
33-
// - jquery.ba-dotimeout.min.js // for event debouncing: http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/
34-
// - opt-frontend-common.js
35-
// should all be imported BEFORE this file
3615

3716
var originFrontendJsFile = 'iframe-embed.js';
3817

3918
function NOP() {};
4019

4120

4221
$(document).ready(function() {
43-
var queryStrOptions = getQueryStringOptions();
22+
optCommon.initializeFrontendParams({originFrontendJsFile: originFrontendJsFile,
23+
executeCode: executeCode});
24+
25+
var queryStrOptions = optCommon.getQueryStringOptions();
4426

4527
var preseededCode = queryStrOptions.preseededCode;
4628
var pyState = queryStrOptions.py;
@@ -71,32 +53,7 @@ $(document).ready(function() {
7153
startingInstruction = 0;
7254
}
7355

74-
var backend_script = null;
75-
if (pyState == '2') {
76-
backend_script = python2_backend_script;
77-
}
78-
else if (pyState == '3') {
79-
backend_script = python3_backend_script;
80-
}
81-
else if (pyState == '2crazy') {
82-
backend_script = python2crazy_backend_script;
83-
}
84-
else if (pyState == 'js') {
85-
backend_script = js_backend_script;
86-
}
87-
else if (pyState == 'ts') {
88-
backend_script = ts_backend_script;
89-
}
90-
else if (pyState == 'ruby') {
91-
backend_script = ruby_backend_script;
92-
}
93-
else if (pyState == 'java') {
94-
backend_script = java_backend_script;
95-
} else if (pyState == 'c') {
96-
backend_script = c_backend_script;
97-
} else if (pyState == 'cpp') {
98-
backend_script = cpp_backend_script;
99-
}
56+
var backend_script = optCommon.langToBackendScript(pyState);
10057
assert(backend_script);
10158

10259
// David Pritchard's code for resizeContainer option ...
@@ -136,7 +93,7 @@ $(document).ready(function() {
13693
drawParentPointers: drawParentPointerBool,
13794
textualMemoryLabels: textRefsBool,
13895
showOnlyOutputs: showOnlyOutputsBool,
139-
executeCodeWithRawInputFunc: executeCodeWithRawInput,
96+
executeCodeWithRawInputFunc: optCommon.executeCodeWithRawInput,
14097
heightChangeCallback: (resizeContainer ? resizeContainerNow : NOP),
14198

14299
// undocumented experimental modes:
@@ -150,32 +107,20 @@ $(document).ready(function() {
150107
if (forceStartingInstr) {
151108
frontendOptionsObj.startingInstruction = forceStartingInstr;
152109
}
153-
executeCodeAndCreateViz(preseededCode,
110+
optCommon.executeCodeAndCreateViz(preseededCode,
154111
backend_script, backendOptionsObj,
155112
frontendOptionsObj,
156113
'vizDiv',
157114
function() { // success
158115
if (resizeContainer)
159116
resizeContainerNow();
117+
var myVisualizer = optCommon.getVisualizer();
160118
myVisualizer.redrawConnectors();
161119
},
162120
NOP);
163121
}
164122

165123

166-
function executeCodeFromScratch() {
167-
// reset these globals
168-
rawInputLst = [];
169-
executeCode();
170-
}
171-
172-
function executeCodeWithRawInput(rawInputStr, curInstr) {
173-
// set some globals
174-
rawInputLst.push(rawInputStr);
175-
executeCode(curInstr);
176-
}
177-
178-
179124
// log a generic AJAX error handler
180125
$(document).ajaxError(function() {
181126
alert("Ugh, Online Python Tutor server error :( Email philip@pgbovine.net");
@@ -184,9 +129,10 @@ $(document).ready(function() {
184129

185130
// redraw connector arrows on window resize
186131
$(window).resize(function() {
132+
var myVisualizer = optCommon.getVisualizer();
187133
myVisualizer.redrawConnectors();
188134
});
189135

190136

191-
executeCodeFromScratch(); // finally, execute code and display visualization
137+
optCommon.executeCodeFromScratch(); // finally, execute code and display visualization
192138
});

v5-unity/js/opt-live.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
// very dicey and dangerous due to scoping issues!
77

88
// TODO: overriding backend_script from opt-frontend-common.js is also dicey, ergh
9-
// so it currently doesn't work for JavaScript
9+
// so it currently doesn't work for JavaScript. also it logs the WRONG
10+
// SCRIPT for Python since it uses the script names from
11+
// opt-frontend-common.js
1012

1113

1214
// use Webpack to automatically package up these dependencies
@@ -59,6 +61,11 @@ require('script!./ace/src-min-noconflict/mode-ruby.js');
5961
*/
6062

6163

64+
// TODO: overriding backend_script from opt-frontend-common.js is also dicey, ergh
65+
// so it currently doesn't work for JavaScript. also it logs the WRONG
66+
// SCRIPT for Python since it uses the script names from
67+
// opt-frontend-common.js
68+
6269
// these scripts override the versions defined in opt-frontend-common.js
6370

6471
// backend scripts to execute (Python 2 and 3 variants, if available)

0 commit comments

Comments
 (0)