1010 that can be exported wholesale to other modules
1111
1212 - look for initializeFrontendParams as a potential abstraction point
13-
1413 - e.g., getAppState and appStateEq, etc., can be in an AppState class
1514
15+ - figure out how to avoid unnecessary duplication with opt-live.js
16+
1617*/
1718
1819require ( './lib/diff_match_patch.js' ) ;
@@ -65,6 +66,11 @@ const CPP_BLANK_TEMPLATE = 'int main() {\n\
6566 return 0;\n\
6667}'
6768
69+ const CODE_SNAPSHOT_DEBOUNCE_MS = 1000 ;
70+ const SUBMIT_UPDATE_HISTORY_INTERVAL_MS = 1000 * 60 ;
71+
72+
73+ // TODO: encapsulate tons of globals into a class of some sort:
6874
6975var myVisualizer = null ; // singleton ExecutionVisualizer instance
7076function getVisualizer ( ) { return myVisualizer ; }
@@ -74,12 +80,35 @@ var rawInputLst = []; // a list of strings inputted by the user in response to r
7480function getRawInputLst ( ) { return rawInputLst ; }
7581function setRawInputLst ( lst ) { rawInputLst = lst ; }
7682
83+ var isExecutingCode = false ; // nasty, nasty global
84+
85+ var appMode = 'edit' ; // 'edit' or 'display'. also support
86+ // 'visualize' for backward compatibility (same as 'display')
87+ function getAppMode ( ) {
88+ return appMode ;
89+ }
90+
91+ var sessionUUID = generateUUID ( ) ; // remains constant throughout one page load ("session")
92+ function getSessionUUID ( ) { return sessionUUID ; }
7793
7894var originFrontendJsFile : string = undefined ;
7995
8096var appStateAugmenter : any = undefined ; // super hacky! fixme
8197var loadTestCases : any = undefined ; // super hacky! fixme
8298
99+ var pyInputAceEditor ; // Ace editor object that contains the input code
100+ function getAceEditor ( ) { return pyInputAceEditor ; }
101+ function setAceEditor ( e ) { pyInputAceEditor = e ; }
102+
103+ var dmp = new diff_match_patch ( ) ;
104+ var curCode = '' ;
105+ var deltaObj : { start : string , deltas : any [ ] , v : number , startTime : number , executeTime ?: number } = undefined ;
106+
107+ var num414Tries = 0 ; // SUPER hacky global, ergh
108+
109+ // each frontend must implement its own executeCode function
110+ var executeCode = undefined ;
111+
83112
84113// these settings are all customized for my own server setup,
85114// so you will need to customize for your server:
@@ -127,22 +156,6 @@ var langSettingToJsonpEndpoint = {
127156} ;
128157
129158
130- var isExecutingCode = false ; // nasty, nasty global
131-
132- var appMode = 'edit' ; // 'edit' or 'display'. also support
133- // 'visualize' for backward compatibility (same as 'display')
134-
135- function getAppMode ( ) {
136- return appMode ;
137- }
138-
139- var pyInputAceEditor ; // Ace editor object that contains the input code
140- function getAceEditor ( ) { return pyInputAceEditor ; }
141- function setAceEditor ( e ) { pyInputAceEditor = e ; }
142-
143- var CODE_SNAPSHOT_DEBOUNCE_MS = 1000 ;
144-
145-
146159// From http://stackoverflow.com/a/8809472
147160function generateUUID ( ) {
148161 var d = new Date ( ) . getTime ( ) ;
@@ -154,9 +167,6 @@ function generateUUID(){
154167 return uuid ;
155168} ;
156169
157- var sessionUUID = generateUUID ( ) ; // remains constant throughout one page load ("session")
158- function getSessionUUID ( ) { return sessionUUID ; }
159-
160170
161171// OMG nasty wtf?!?
162172
@@ -176,11 +186,6 @@ if (typeof localStorage === 'object') {
176186 }
177187}
178188
179-
180- var dmp = new diff_match_patch ( ) ;
181- var curCode = '' ;
182- var deltaObj = undefined ;
183-
184189function initDeltaObj ( ) {
185190 // make sure the editor already exists
186191 // (editor doesn't exist when you're, say, doing an iframe embed)
@@ -710,9 +715,6 @@ function populateTogetherJsShareUrl() {
710715// END - shared session stuff
711716
712717
713- // each frontend must implement its own executeCode function
714- var executeCode = undefined ;
715-
716718function redrawConnectors ( ) {
717719 if ( appMode == 'display' || appMode == 'visualize' /* deprecated */ ) {
718720 if ( myVisualizer ) {
@@ -764,6 +766,8 @@ function pyInputSetScrollTop(st) {
764766
765767
766768// TODO: fixme, this is all very hacky and inelegant
769+ // this is a good candidate for a constructor, and these fields are ones
770+ // that can be overriden or something :)
767771function initializeFrontendParams ( params ) {
768772 originFrontendJsFile = params . originFrontendJsFile ; // nasty global
769773 executeCode = params . executeCode ; // nasty global
@@ -791,18 +795,12 @@ function initializeFrontendParams(params) {
791795 }
792796}
793797
794-
795- var num414Tries = 0 ; // hacky global
796-
797798// run at the END so that everything else can be initialized first
798799function genericOptFrontendReady ( params ) {
799800 assert ( params ) ;
800801 initializeFrontendParams ( params ) ;
801802 initTogetherJS ( ) ; // initialize early but after initializeFrontendParams
802803
803-
804- // be friendly to the browser's forward and back buttons
805- // thanks to http://benalman.com/projects/jquery-bbq-plugin/
806804 $ ( window ) . bind ( "hashchange" , function ( e ) {
807805 // if you've got some preseeded code, then parse the entire query
808806 // string from scratch just like a page reload
@@ -834,7 +832,6 @@ function genericOptFrontendReady(params) {
834832 }
835833 } ) ;
836834
837-
838835 // don't sync for Ace since I can't get it working properly yet
839836 /*
840837 pyInputAceEditor.getSession().on('changeScrollTop', function() {
@@ -853,7 +850,7 @@ function genericOptFrontendReady(params) {
853850
854851
855852 // first initialize options from HTML LocalStorage. very important
856- // that this code runs first so that options get overridden by query
853+ // that this code runs FIRST so that options get overridden by query
857854 // string options and anything else the user wants to override with.
858855 if ( supports_html5_storage ( ) ) {
859856 var lsKeys = [ 'cumulative' ,
@@ -907,20 +904,15 @@ function genericOptFrontendReady(params) {
907904 return ; // get out early
908905 }
909906
910- // ugh other idiosyncratic stuff
911- if ( settings . url . indexOf ( 'name_lookup.py' ) > - 1 ) {
907+ // ugh other idiosyncratic errors to ignore
908+ if ( ( settings . url . indexOf ( 'name_lookup.py' ) > - 1 ) ||
909+ ( settings . url . indexOf ( 'syntax_err_survey.py' ) > - 1 ) ||
910+ ( settings . url . indexOf ( 'viz_interaction.py' ) > - 1 ) {
912911 return ; // get out early
913912 }
914913
915- if ( settings . url . indexOf ( 'syntax_err_survey.py' ) > - 1 ) {
916- return ; // get out early
917- }
918-
919- if ( settings . url . indexOf ( 'viz_interaction.py' ) > - 1 ) {
920- return ; // get out early
921- }
914+ /* On my server ...
922915
923- /*
924916 This jqxhr.responseText might be indicative of the URL being too
925917 long, since the error message returned by the server is something
926918 like this in nginx:
@@ -958,7 +950,6 @@ function genericOptFrontendReady(params) {
958950 "Report a bug to philip@pgbovine.net by clicking the 'Generate permanent link' button" ,
959951 "at the bottom of this page and including a URL in your email." ] ) ;
960952 }
961-
962953 doneExecutingCode ( ) ;
963954 } ) ;
964955
@@ -996,10 +987,9 @@ function genericOptFrontendReady(params) {
996987 submitUpdateHistory ( 'periodic' ) ;
997988 }
998989 }
999- } , 1000 * 60 ) ;
990+ } , SUBMIT_UPDATE_HISTORY_INTERVAL_MS ) ;
1000991}
1001992
1002-
1003993// sets globals such as rawInputLst, code input box, and toggle options
1004994function parseQueryString ( ) {
1005995 var queryStrOptions = getQueryStringOptions ( ) ;
@@ -1629,71 +1619,10 @@ function getBaseFrontendOptionsObj() {
16291619}
16301620
16311621
1632- /* For survey questions:
1633-
1634- Versions of survey wording:
1635-
1636- v1: (deployed around 2014-04-09, revoked on 2014-06-20)
1622+ /* For survey questions. Versions of survey wording:
16371623
1638- var survey_v1 = '\n\
1639- <p style="margin-top: 10px; line-height: 175%;">\n\
1640- [Optional] Please answer these questions to support our research and to help improve this tool.<br/>\n\
1641- Where is your code from? <input type="text" id="code-origin-Q" class="surveyQ" size=60 maxlength=140/><br/>\n\
1642- What do you hope to learn by visualizing it? <input type="text" id="what-learn-Q" class="surveyQ" size=55 maxlength=140/><br/>\n\
1643- How did you find this web site? <input type="text" id="how-find-Q" class="surveyQ" size=60 maxlength=140/>\n\
1644- <input type="hidden" id="Q-version" value="v1"/> <!-- for versioning -->\n\
1645- </p>'
1646-
1647- v2: (deployed on 2014-06-20, revoked on 2014-06-28)
1624+ [see ../../v3/js/opt-frontend-common.js for older versions of survey wording - v1 to v7]
16481625
1649- var survey_v2 = '\n\
1650- <p style="margin-top: 10px; line-height: 175%;">\n\
1651- [Optional] Please answer these questions to support our research and to help improve this tool.<br/>\n\
1652- What do you hope to learn by visualizing this code? <input type="text" id="what-learn-Q" class="surveyQ" size=60 maxlength=200/><br/>\n\
1653- Paste a website link to a course that uses Python: <input type="text" id="course-website-Q" class="surveyQ" size=55 maxlength=300/><br/>\n\
1654- <span style="font-size: 8pt; color: #666;">(This could be a course that you\'re taking or teaching in school, or that you\'ve taken or taught in the past.)</span>\n\
1655- <input type="hidden" id="Q-version" value="v2"/> <!-- for versioning -->\n\
1656- </p>'
1657-
1658- v3: (deployed on 2014-06-28, revoked on 2014-07-13) [it's a simplified version of v1]
1659- var survey_v3 = '\n\
1660- <p style="margin-top: 10px; line-height: 175%;">\n\
1661- [Optional] Please answer these questions to support our research and to help improve this tool.<br/>\n\
1662- Where is your code from? <input type="text" id="code-origin-Q" class="surveyQ" size=60 maxlength=140/><br/>\n\
1663- What do you hope to learn by visualizing it? <input type="text" id="what-learn-Q" class="surveyQ" size=55 maxlength=140/><br/>\n\
1664- <input type="hidden" id="Q-version" value="v3"/> <!-- for versioning -->\n\
1665- </p>'
1666-
1667- v4: (deployed on 2014-07-13, revoked on 2015-03-01)
1668- [an even more simplified version of v1 just to focus on ONE important question]
1669- var survey_v4 = '\n\
1670- <p style="margin-top: 10px; line-height: 175%;">\n\
1671- [Optional] What do you hope to learn by visualizing this code?<br/>\n\
1672- <input type="text" id="what-learn-Q" class="surveyQ" size=80 maxlength=300/><br/>\n\
1673- <input type="hidden" id="Q-version" value="v4"/> <!-- for versioning -->\n\
1674- </p>'
1675-
1676- v5: (deployed on 2015-03-01, retired on 2015-08-31) - target older population
1677- var survey_v5 = '\n\
1678- <p style="margin-top: 10px; line-height: 175%;">\n\
1679- If you are <span style="color: #333; font-weight: bold;">at least 60 years old</span> and would like to help our research on how older people learn programming, please enter your email address here:\n\
1680- <input type="text" id="email-addr-Q" class="surveyQ" size=30 maxlength=300/><br/>\n\
1681- <input type="hidden" id="Q-version" value="v5"/> <!-- for versioning -->\n\
1682- </p>'
1683-
1684- v6: (deployed on 2015-08-31) - use Google Forms links
1685- var survey_v6 = '\n\
1686- <p style="font-size: 9pt; margin-top: 10px; line-height: 175%;">\n\
1687- Please support our research and keep this tool free by <b><a href="https://docs.google.com/forms/d/1-aKilu0PECHZVRSIXHv8vJpEuKUO9uG3MrH864uX56U/viewform" target="_blank">filling out this short survey</a></b>.<br/>\n\
1688- If you are at least 60 years old, please also <a href="https://docs.google.com/forms/d/1lrXsE04ghfX9wNzTVwm1Wc6gQ5I-B4uw91ACrbDhJs8/viewform" target="_blank">fill out this survey</a>.</p>'
1689-
1690- v7: (deployed on 2016-05-22) - use Google Forms links - emphasize the over-60 survey more, but same links
1691- var survey_v7 = '\n\
1692- <p style="font-size: 10pt; margin-top: 10px; line-height: 175%;">\n\
1693- If you are <b>at least 60 years old</b>, please support our research by <a href="https://docs.google.com/forms/d/1lrXsE04ghfX9wNzTVwm1Wc6gQ5I-B4uw91ACrbDhJs8/viewform" target="_blank">filling out this short survey</a>.\n\
1694- <br/>\n\
1695- <span style="font-size: 9pt;">Everyone else can help keep this tool free by <a href="https://docs.google.com/forms/d/1-aKilu0PECHZVRSIXHv8vJpEuKUO9uG3MrH864uX56U/viewform" target="_blank">filling out this usage survey</a>.</span>\n\
1696- </p>'
16971626v8: (deployed on 2016-06-20) - like v7 except emphasize the main usage survey more, and have the over-60 survey as auxiliary
16981627*/
16991628var survey_v8 = '\n\
@@ -1703,10 +1632,8 @@ var survey_v8 = '\n\
17031632<span style="font-size: 9pt;">If you are <b>at least 60 years old</b>, please also fill out <a href="https://docs.google.com/forms/d/1lrXsE04ghfX9wNzTVwm1Wc6gQ5I-B4uw91ACrbDhJs8/viewform" target="_blank">our survey about learning programming</a>.</span>\n\
17041633</p>'
17051634
1706- var survey_html = survey_v8 ;
1707-
17081635function setSurveyHTML ( ) {
1709- $ ( '#surveyPane' ) . html ( survey_html ) ;
1636+ $ ( '#surveyPane' ) . html ( survey_v8 ) ;
17101637}
17111638
17121639// empty stub so that our code doesn't crash.
0 commit comments