@@ -42,15 +42,15 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4242- make Ace editor resizable width-wise using jQuery resizable
4343 (stackoverflow has some tips for how to do that)
4444
45- - add toggles for language choices
46-
4745- support pasting in code via URL, which will be important for
4846 transporting the user from regular OPT to live mode
4947
5048- make sure server logging works properly, esp. session and user IDs,
5149 and slider interactions
5250 - have separate web_exec_live executor scripts for logging live mode
5351
52+ - add "Generate permanent link" button, but no need for iframe embed btn
53+
5454- if these Ace enhancements look good, then I can also use them for
5555 Codeopticon as well!
5656
@@ -59,13 +59,44 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5959
6060*/
6161
62+
6263// Pre-reqs:
6364// - pytutor.js
6465// - jquery.ba-bbq.min.js
6566// - jquery.ba-dotimeout.min.js // for event debouncing: http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/
6667// - opt-frontend-common.js
6768// should all be imported BEFORE this file
6869
70+
71+ // these scripts override the versions defined in opt-frontend-common.js
72+
73+ // backend scripts to execute (Python 2 and 3 variants, if available)
74+ // make two copies of ../web_exec.py and give them the following names,
75+ // then change the first line (starting with #!) to the proper version
76+ // of the Python interpreter (i.e., Python 2 or Python 3).
77+ // Note that your hosting provider might have stringent rules for what
78+ // kind of scripts are allowed to execute. For instance, my provider
79+ // (Webfaction) seems to let scripts execute only if permissions are
80+ // something like:
81+ // -rwxr-xr-x 1 pgbovine pgbovine 2.5K Jul 5 22:46 web_exec_py2.py*
82+ // (most notably, only the owner of the file should have write
83+ // permissions)
84+ //var python2_backend_script = 'web_exec_LIVE_py2.py';
85+ //var python3_backend_script = 'web_exec_LIVE_py3.py';
86+
87+ // uncomment below if you're running on Google App Engine using the built-in app.yaml
88+ var python2_backend_script = 'exec' ;
89+ var python3_backend_script = 'exec' ;
90+
91+ // empty dummy just to do logging on the Apache's server
92+ var js_backend_script = 'web_exec_LIVE_js.py' ;
93+ var ts_backend_script = 'web_exec_LIVE_ts.py' ;
94+ var java_backend_script = 'web_exec_LIVE_java.py' ;
95+ var ruby_backend_script = 'web_exec_LIVE_ruby.py' ;
96+ var c_backend_script = 'web_exec_LIVE_c.py' ;
97+ var cpp_backend_script = 'web_exec_LIVE_cpp.py' ;
98+
99+
69100var originFrontendJsFile = 'opt-live.js' ;
70101
71102var prevVisualizer = null ; // the visualizer object from the previous execution
@@ -328,10 +359,32 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
328359 clearFrontendError ( ) ;
329360 startExecutingCode ( ) ;
330361
362+ jsonp_endpoint = null ;
363+
364+ // hacky!
331365 if ( backendScript === python2_backend_script ) {
332366 frontendOptionsObj . lang = 'py2' ;
333367 } else if ( backendScript === python3_backend_script ) {
334368 frontendOptionsObj . lang = 'py3' ;
369+ } else if ( backendScript === js_backend_script ) {
370+ frontendOptionsObj . lang = 'js' ;
371+ jsonp_endpoint = JS_JSONP_ENDPOINT ;
372+ } else if ( backendScript === ts_backend_script ) {
373+ frontendOptionsObj . lang = 'ts' ;
374+ jsonp_endpoint = TS_JSONP_ENDPOINT ;
375+ } else if ( backendScript === ruby_backend_script ) {
376+ frontendOptionsObj . lang = 'ruby' ;
377+ jsonp_endpoint = RUBY_JSONP_ENDPOINT ;
378+ } else if ( backendScript === java_backend_script ) {
379+ frontendOptionsObj . lang = 'java' ;
380+ frontendOptionsObj . disableHeapNesting = true ; // never nest Java objects, seems like a good default
381+ jsonp_endpoint = JAVA_JSONP_ENDPOINT ;
382+ } else if ( backendScript === c_backend_script ) {
383+ frontendOptionsObj . lang = 'c' ;
384+ jsonp_endpoint = C_JSONP_ENDPOINT ;
385+ } else if ( backendScript === cpp_backend_script ) {
386+ frontendOptionsObj . lang = 'cpp' ;
387+ jsonp_endpoint = CPP_JSONP_ENDPOINT ;
335388 } else {
336389 assert ( false ) ;
337390 }
@@ -350,7 +403,7 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
350403 rawInputLst = forceRawInputLst ; // UGLY global across modules, FIXME
351404 }
352405
353- backend_script = python2_backend_script ;
406+ var backend_script = langToBackendScript ( $ ( '#pythonVersionSelector' ) . val ( ) ) ;
354407
355408 var backendOptionsObj = { cumulative_mode : false ,
356409 heap_primitives : false ,
@@ -374,6 +427,12 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
374427}
375428
376429$ ( document ) . ready ( function ( ) {
377- genericOptFrontendReady ( ) ; // initialize at the very end
430+ genericOptFrontendReady ( ) ;
431+
432+ $ ( '#pythonVersionSelector' ) . change ( function ( ) {
433+ // force a recompile on a toggle switch
434+ executeCode ( ) ;
435+ } ) ;
436+
378437 $ ( "#pyOutputPane" ) . show ( ) ;
379438} ) ;
0 commit comments