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
3716var originFrontendJsFile = 'iframe-embed.js' ;
3817
3918function 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} ) ;
0 commit comments