Skip to content

Commit a50df37

Browse files
committed
got iframe embed working
1 parent 2011427 commit a50df37

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎v5-unity/README.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ and run the server with Bottle:
3333
python bottle_server.py
3434

3535

36+
# to start using npm:
37+
npm start
38+
npm run webpack
39+
3640
---
3741

3842
https://github.com/petehunt/webpack-howto

‎v5-unity/js/opt-frontend-common.js‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var pytutor = require('./pytutor.js');
1212
var assert = pytutor.assert;
1313

1414
// TODO: abstract this better
15+
// only export methods and NOT objects, since they're copied by value
1516
module.exports = {
1617
setSurveyHTML: setSurveyHTML,
1718
genericOptFrontendReady: genericOptFrontendReady,
@@ -30,9 +31,12 @@ module.exports = {
3031
handleUncaughtExceptionFunc: handleUncaughtExceptionFunc,
3132
populateTogetherJsShareUrl: populateTogetherJsShareUrl,
3233
getAppState: getAppState,
33-
appMode: appMode,
34+
getAppMode: getAppMode,
3435
getBaseBackendOptionsObj: getBaseBackendOptionsObj,
3536
getBaseFrontendOptionsObj: getBaseFrontendOptionsObj,
37+
getVisualizer: getVisualizer,
38+
getRawInputLst: getRawInputLst,
39+
setRawInputLst: setRawInputLst,
3640
}
3741

3842
var originFrontendJsFile = undefined; // init in initializeFrontend
@@ -127,14 +131,15 @@ function langToBackendScript(lang) {
127131
}
128132

129133

130-
var domain = "http://pythontutor.com/"; // for deployment
131-
132-
133134
var isExecutingCode = false; // nasty, nasty global
134135

135136
var appMode = 'edit'; // 'edit' or 'display'. also support
136137
// 'visualize' for backward compatibility (same as 'display')
137138

139+
function getAppMode() {
140+
return appMode;
141+
}
142+
138143
var pyInputCodeMirror; // CodeMirror object that contains the input code
139144
var pyInputAceEditor; // Ace editor object that contains the input code
140145

@@ -756,8 +761,11 @@ function populateTogetherJsShareUrl() {
756761

757762

758763
var myVisualizer = null; // singleton ExecutionVisualizer instance
764+
function getVisualizer() {return myVisualizer;}
759765

760766
var rawInputLst = []; // a list of strings inputted by the user in response to raw_input or mouse_input events
767+
function getRawInputLst() {return rawInputLst;}
768+
function setRawInputLst(lst) {rawInputLst = lst;}
761769

762770

763771
// each frontend must implement its own executeCode function

‎v5-unity/js/opt-frontend.js‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ function TogetherjsReadyHandler() {
4848
}
4949

5050
function TogetherjsCloseHandler() {
51-
if (optCommon.appMode == "display") {
51+
if (optCommon.getAppMode() == "display") {
5252
$("#surveyHeader").show();
5353
}
5454
}
5555

5656
function executeCode(forceStartingInstr, forceRawInputLst) {
5757
if (forceRawInputLst !== undefined) {
58-
rawInputLst = forceRawInputLst; // UGLY global across modules, FIXME
58+
optCommon.setRawInputLst(forceRawInputLst); // UGLY global across modules, FIXME
5959
}
6060

6161
var backend_script = optCommon.langToBackendScript($('#pythonVersionSelector').val());
@@ -139,6 +139,7 @@ function experimentalPopUpSyntaxErrorSurvey() {
139139
}
140140

141141
// make sure jquery.qtip has been imported
142+
var myVisualizer = optCommon.getVisualizer();
142143

143144
var codelineIDs = [];
144145
$.each(myVisualizer.domRoot.find('#pyCodeOutput .cod'), function(i, e) {
@@ -556,6 +557,7 @@ $(document).ready(function() {
556557

557558
$("#hideHeaderLink").click(function() {
558559
$("#experimentalHeader").hide();
560+
var myVisualizer = optCommon.getVisualizer();
559561
if (myVisualizer) {
560562
myVisualizer.updateOutput(); // redraw arrows
561563
}
@@ -613,6 +615,7 @@ $(document).ready(function() {
613615
// very subtle! for TogetherJS to sync #pythonVersionSelector
614616
// properly, we must manually send a sync request event:
615617
if (TogetherJS && TogetherJS.running) {
618+
var myVisualizer = optCommon.getVisualizer();
616619
TogetherJS.send({type: "syncAppState",
617620
myAppState: optCommon.getAppState(),
618621
codeInputScrollTop: optCommon.pyInputGetScrollTop(),
@@ -628,12 +631,14 @@ $(document).ready(function() {
628631

629632

630633
$('#genEmbedBtn').bind('click', function() {
631-
assert(optCommon.appMode == 'display' || optCommon.appMode == 'visualize' /* 'visualize' is deprecated */);
634+
assert(optCommon.getAppMode() == 'display' || optCommon.getAppMode() == 'visualize' /* 'visualize' is deprecated */);
632635
var myArgs = optCommon.getAppState();
633636
delete myArgs.mode;
637+
var myVisualizer = optCommon.getVisualizer();
634638
myArgs.codeDivWidth = myVisualizer.DEFAULT_EMBEDDED_CODE_DIV_WIDTH;
635639
myArgs.codeDivHeight = myVisualizer.DEFAULT_EMBEDDED_CODE_DIV_HEIGHT;
636640

641+
var domain = "http://pythontutor.com/"; // for deployment
637642
var embedUrlStr = $.param.fragment(domain + "iframe-embed.html", myArgs, 2 /* clobber all */);
638643
embedUrlStr = embedUrlStr.replace(/\)/g, '%29') // replace ) with %29 so that links embed well in Markdown
639644
var iframeStr = '<iframe width="800" height="500" frameborder="0" src="' + embedUrlStr + '"> </iframe>';

‎v5-unity/js/pytutor.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require('../css/jquery.qtip.css');
1515
require('../css/pytutor.css');
1616

1717
// TODO: abstract this better
18+
// only export methods and NOT objects, since they're copied by value
1819
module.exports = {
1920
assert: assert,
2021
htmlspecialchars: htmlspecialchars,

‎v5-unity/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"license": "BSD-3-Clause",
88

99
"scripts": {
10-
"start": "webpack-dev-server --hot --inline",
10+
"start": "python bottle_server.py",
1111
"webpack": "webpack --progress --colors --watch"
1212
},
1313

0 commit comments

Comments
 (0)