@@ -54,6 +54,8 @@ var helpQueueSize = 0;
5454var tutorAvailable = false ;
5555var tutorWaitText = 'Please wait for the next available tutor.' ;
5656
57+ var activateSyntaxErrorSurvey = false ; // true;
58+
5759function setHelpQueueSizeLabel ( ) {
5860 if ( helpQueueSize == 1 ) {
5961 $ ( "#helpQueueText" ) . html ( 'There is 1 person in line.' ) ;
@@ -175,6 +177,174 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
175177}
176178
177179
180+
181+ // domID is the ID of the element to attach to (without the leading '#' sign)
182+ function SyntaxErrorSurveyBubble ( parentViz , domID ) {
183+ this . parentViz = parentViz ;
184+
185+ this . domID = domID ;
186+ this . hashID = '#' + domID ;
187+
188+ this . my = 'left center' ;
189+ this . at = 'right center' ;
190+
191+ this . qtipHidden = false ; // is there a qtip object present but hidden? (TODO: kinda confusing)
192+ }
193+
194+ SyntaxErrorSurveyBubble . prototype . destroyQTip = function ( ) {
195+ $ ( this . hashID ) . qtip ( 'destroy' ) ;
196+ }
197+
198+ SyntaxErrorSurveyBubble . prototype . redrawCodelineBubble = function ( ) {
199+ if ( isOutputLineVisibleForBubbles ( this . domID ) ) {
200+ if ( this . qtipHidden ) {
201+ $ ( this . hashID ) . qtip ( 'show' ) ;
202+ }
203+ else {
204+ $ ( this . hashID ) . qtip ( 'reposition' ) ;
205+ }
206+
207+ this . qtipHidden = false ;
208+ }
209+ else {
210+ $ ( this . hashID ) . qtip ( 'hide' ) ;
211+ this . qtipHidden = true ;
212+ }
213+ }
214+
215+ SyntaxErrorSurveyBubble . prototype . qTipContentID = function ( ) {
216+ return '#ui-tooltip-' + this . domID + '-content' ;
217+ }
218+
219+ SyntaxErrorSurveyBubble . prototype . qTipID = function ( ) {
220+ return '#ui-tooltip-' + this . domID ;
221+ }
222+
223+
224+ // created on 2015-04-18
225+ function experimentalPopUpSyntaxErrorSurvey ( ) {
226+ if ( prevExecutionExceptionObj &&
227+ prevExecutionExceptionObj . killerException . line !== undefined ) {
228+ var offendingLine = prevExecutionExceptionObj . killerException . line ;
229+ // make sure jquery.qtip has been imported
230+
231+ var codelineIDs = [ ] ;
232+ $ . each ( myVisualizer . domRoot . find ( '#pyCodeOutput .cod' ) , function ( i , e ) {
233+ // hacky!
234+ var domID = $ ( e ) . attr ( 'id' ) ;
235+ var lineRE = new RegExp ( 'cod' + String ( offendingLine ) + '$' ) ; // $ for end-of-line match
236+ if ( lineRE . test ( domID ) ) {
237+ codelineIDs . push ( $ ( e ) . attr ( 'id' ) ) ;
238+ }
239+ } ) ;
240+
241+ // should find only 1 match, or else something is wonky, maybe
242+ // because the code changed so much that the line number in question
243+ // is no longer available
244+ if ( codelineIDs . length === 1 ) {
245+ console . log ( 'PREV' , prevExecutionExceptionObj ) ;
246+ var codLineId = codelineIDs [ 0 ] ;
247+
248+ var bub = new SyntaxErrorSurveyBubble ( myVisualizer , codLineId ) ;
249+
250+ // destroy then create a new tip:
251+ bub . destroyQTip ( ) ;
252+ $ ( bub . hashID ) . qtip ( $ . extend ( { } , qtipShared , {
253+ content : ' ' , // can't be empty!
254+ id : bub . domID ,
255+ position : {
256+ my : bub . my ,
257+ at : bub . at ,
258+ adjust : {
259+ x : - 10 ,
260+ } ,
261+ effect : null , // disable all cutesy animations
262+ } ,
263+ style : {
264+ classes : 'ui-tooltip-pgbootstrap ui-tooltip-pgbootstrap-RED'
265+ }
266+ } ) ) ;
267+
268+ // need to set both max-width and width() ...
269+ $ ( bub . qTipID ( ) ) . css ( 'max-width' , '350px' ) . width ( '350px' ) ;
270+
271+ $ ( bub . qTipContentID ( ) ) . html ( '<div id="syntaxErrBubbleContents"><div id="syntaxErrHeader">You just fixed the following error:</div>\
272+ <div id="syntaxErrMsg">[ERROR MSG]</div>\
273+ <div id="syntaxErrCodeDisplay"></div>\
274+ <div id="syntaxErrQuestion">\
275+ What would have been a better error message here?<br/>\
276+ <input type="text" id="syntaxErrTxtInput" size=60 maxlength=150/><br/>\
277+ <button class="syntaxErrSubmitBtn" type="button">Submit</button>\
278+ <button class="syntaxErrCloseBtn" type="button">Cancel</button>\
279+ </div></div>\
280+ ' ) ;
281+ // unbind first, then bind a new one
282+ myVisualizer . domRoot . find ( '#pyCodeOutputDiv' )
283+ . unbind ( 'scroll' )
284+ . scroll ( function ( ) {
285+ bub . redrawCodelineBubble ( ) ;
286+ } ) ;
287+
288+
289+ var bubbleAceEditor = ace . edit ( 'syntaxErrCodeDisplay' ) ;
290+
291+ var s = bubbleAceEditor . getSession ( ) ;
292+ // tab -> 4 spaces
293+ s . setTabSize ( 4 ) ;
294+ s . setUseSoftTabs ( true ) ;
295+ // disable extraneous indicators:
296+ s . setFoldStyle ( 'manual' ) ; // no code folding indicators
297+ bubbleAceEditor . setHighlightActiveLine ( false ) ;
298+ bubbleAceEditor . setShowPrintMargin ( false ) ;
299+ bubbleAceEditor . setBehavioursEnabled ( false ) ;
300+
301+ bubbleAceEditor . setFontSize ( 10 ) ;
302+
303+ bubbleAceEditor . setOptions ( { minLines : 5 , maxLines : 5 } ) ; // keep this SMALL
304+
305+ $ ( '#syntaxErrCodeDisplay' ) . css ( 'width' , '320px' ) ;
306+ $ ( '#syntaxErrCodeDisplay' ) . css ( 'height' , '200px' ) ; // VERY IMPORTANT so that it works on I.E., ugh!
307+
308+ // don't do real-time syntax checks:
309+ // https://github.com/ajaxorg/ace/wiki/Syntax-validation
310+ s . setOption ( "useWorker" , false ) ;
311+
312+ var lang = prevExecutionExceptionObj . myAppState . py ;
313+ var mod = 'python' ;
314+ if ( lang === 'java' ) {
315+ mod = 'java' ;
316+ } else if ( lang === 'js' ) {
317+ mod = 'javascript' ;
318+ } else if ( lang === 'ts' ) {
319+ mod = 'typescript' ;
320+ }
321+ s . setMode ( "ace/mode/" + mod ) ;
322+
323+ bubbleAceEditor . setValue ( prevExecutionExceptionObj . myAppState . code . rtrim ( ) /* kill trailing spaces */ ,
324+ - 1 /* do NOT select after setting text */ ) ;
325+ bubbleAceEditor . setReadOnly ( true ) ;
326+
327+ s . setAnnotations ( [ { row : offendingLine - 1 /* zero-indexed */ ,
328+ type : 'error' ,
329+ text : prevExecutionExceptionObj . killerException . exception_msg } ] ) ;
330+
331+ // scroll down to the line where the error occurred, trying to center it
332+ // by subtracing 3 from it (which should center it, assuming we're
333+ // displaying 5 lines of context)
334+ if ( ( offendingLine - 3 ) > 0 ) {
335+ bubbleAceEditor . scrollToLine ( offendingLine - 3 ) ;
336+ }
337+
338+ // don't forget htmlspecialchars
339+ $ ( "#syntaxErrMsg" ) . html ( htmlspecialchars ( prevExecutionExceptionObj . killerException . exception_msg ) ) ;
340+
341+ // TODO: why is this positioning so wonky in the beginning?!?
342+ bub . redrawCodelineBubble ( ) ; // do an initial redraw to align everything
343+ }
344+ }
345+ }
346+
347+
178348function initAceAndOptions ( ) {
179349 if ( $ ( '#pythonVersionSelector' ) . val ( ) === 'java' ) {
180350 $ ( "#javaOptionsPane" ) . show ( ) ;
0 commit comments