@@ -9,10 +9,12 @@ var qtipShared = {
99 ready : true , // show on document.ready instead of on mouseenter
1010 delay : 0 ,
1111 event : null ,
12+ effect : function ( ) { $ ( this ) . show ( ) ; } , // don't do any fancy fading because it screws up with scrolling
1213 } ,
1314 hide : {
1415 fixed : true ,
1516 event : null ,
17+ effect : function ( ) { $ ( this ) . hide ( ) ; } , // don't do any fancy fading because it screws up with scrolling
1618 } ,
1719 style : {
1820 classes : 'ui-tooltip-pgbootstrap' , // my own customized version of the bootstrap style
@@ -88,18 +90,20 @@ function AnnotationBubble(type, domID) {
8890 }
8991
9092 // possible states:
91- // 'hidden '
93+ // 'invisible '
9294 // 'edit'
9395 // 'view'
9496 // 'minimized'
9597 // 'stub'
96- this . state = 'hidden ' ;
98+ this . state = 'invisible ' ;
9799
98100 this . text = '' ; // the actual contents of the annotation bubble
101+
102+ this . qtipHidden = false ; // is there a qtip object present but hidden? (TODO: kinda confusing)
99103}
100104
101105AnnotationBubble . prototype . showStub = function ( ) {
102- assert ( this . state == 'hidden ' || this . state == 'edit' ) ;
106+ assert ( this . state == 'invisible ' || this . state == 'edit' ) ;
103107 assert ( this . text == '' ) ;
104108
105109 var myBubble = this ; // to avoid name clashes with 'this' in inner scopes
@@ -237,10 +241,11 @@ AnnotationBubble.prototype.restoreViewer = function() {
237241 this . state = 'view' ;
238242}
239243
240- AnnotationBubble . prototype . hide = function ( ) {
244+ // NB: actually DESTROYS the QTip object
245+ AnnotationBubble . prototype . makeInvisible = function ( ) {
241246 assert ( this . state == 'stub' || this . state == 'edit' ) ;
242247 this . destroyQTip ( ) ;
243- this . state = 'hidden ' ;
248+ this . state = 'invisible ' ;
244249}
245250
246251
@@ -258,44 +263,58 @@ AnnotationBubble.prototype.qTipID = function() {
258263
259264
260265AnnotationBubble . prototype . enterEditMode = function ( ) {
261- // punt if you're a codeline annotation and your line of code is hidden
262- if ( this . type == 'codeline' && ! isOutputLineVisible ( this . domID ) ) {
263- return ;
264- }
265-
266266 assert ( globalAnnotationMode == 'edit' ) ;
267- if ( this . state == 'hidden ' ) {
267+ if ( this . state == 'invisible ' ) {
268268 this . showStub ( ) ;
269+
270+ if ( this . type == 'codeline' ) {
271+ this . redrawCodelineBubble ( ) ;
272+ }
269273 }
270274}
271275
272276AnnotationBubble . prototype . enterViewMode = function ( ) {
273- // punt if you're a codeline annotation and your line of code is hidden
274- if ( this . type == 'codeline' && ! isOutputLineVisible ( this . domID ) ) {
275- return ;
276- }
277-
278277 assert ( globalAnnotationMode == 'view' ) ;
279278 if ( this . state == 'stub' ) {
280- this . hide ( ) ;
279+ this . makeInvisible ( ) ;
281280 }
282281 else if ( this . state == 'edit' ) {
283282 this . text = $ ( this . qTipContentID ( ) ) . find ( 'textarea.bubbleInputText' ) . val ( ) . trim ( ) ; // strip all leading and trailing spaces
284283
285284 if ( this . text ) {
286285 this . showViewer ( ) ;
286+
287+ if ( this . type == 'codeline' ) {
288+ this . redrawCodelineBubble ( ) ;
289+ }
287290 }
288291 else {
289- this . hide ( ) ;
292+ this . makeInvisible ( ) ;
290293 }
291294 }
292295}
293296
297+ AnnotationBubble . prototype . redrawCodelineBubble = function ( ) {
298+ assert ( this . type == 'codeline' ) ;
294299
295- inputTextarea = '<textarea class="bubbleInputText"></textarea>'
300+ if ( isOutputLineVisible ( this . domID ) ) {
301+ if ( this . qtipHidden ) {
302+ $ ( this . hashID ) . qtip ( 'show' ) ;
303+ }
304+ else {
305+ $ ( this . hashID ) . qtip ( 'reposition' ) ;
306+ }
296307
297- globalAnnotationMode = 'view' ;
308+ this . qtipHidden = false ;
309+ }
310+ else {
311+ $ ( this . hashID ) . qtip ( 'hide' ) ;
312+ this . qtipHidden = true ;
313+ }
314+ }
298315
316+
317+ globalAnnotationMode = 'view' ;
299318allBubbles = [ ] ;
300319
301320
@@ -312,54 +331,14 @@ function isOutputLineVisible(lineDivID) {
312331 var H = pcod . height ( ) ;
313332
314333 // add a few pixels of fudge factor on the bottom end due to bottom scrollbar
315- return ( PO <= LO ) && ( LO < ( PO + H - 30 ) ) ;
334+ return ( PO <= LO ) && ( LO < ( PO + H - 25 ) ) ;
316335}
317336
318337
319338$ ( document ) . ready ( function ( ) {
320339 // force vertical code scrolling
321340 $ ( '#pyCodeOutputDiv' ) . css ( 'max-height' , '120px' ) ;
322341
323- /*
324- var listSumVisualizer = new ExecutionVisualizer('listSumDiv', listSumTrace,
325- {embeddedMode: false,
326- editCodeBaseURL: 'http://pythontutor.com/visualize.html'});
327- */
328-
329- /*
330- createSpeechBubble('v1__heap_object_1', 'bottom left', 'top center',
331- "Here's a function!");
332-
333- createSpeechBubble('v1__heap_object_2', 'bottom left', 'top center',
334- 'This is the head of our linked list.');
335-
336- createSpeechBubble('v1__heap_object_4', 'bottom left', 'top center',
337- 'This is the final element of our linked list. Its car is 3 and cdr is <tt>None</tt>');
338-
339-
340- createSpeechBubble('v1__stack0', 'right center', 'left center',
341- "The first of several recursive calls.");
342-
343- createSpeechBubble('v1__cod4', 'left center', 'right center',
344- "line four, booooooooooooo ...");
345-
346- createSpeechBubble('v1__cod5', 'left center', 'right center',
347- "line five, yay!!!");
348-
349- createSpeechBubble('v1__cod9', 'left center', 'right center',
350- "line nine, yay!!!");
351-
352- createSpeechBubble('v1__listSum_f2__numbers', 'right center', 'left center',
353- "this is a variable, of course!");
354-
355- createSpeechBubble('v1__listSum_f2__rest', 'right center', 'left center',
356- "this is another variable, of course; what else would it be?!?");
357-
358- createSpeechBubble('v1__stack2', 'right center', 'left center',
359- inputTextarea, true);
360- */
361-
362-
363342 allBubbles . push ( new AnnotationBubble ( 'frame' , 'v1__globals' ) ) ;
364343 allBubbles . push ( new AnnotationBubble ( 'frame' , 'v1__stack0' ) ) ;
365344 allBubbles . push ( new AnnotationBubble ( 'frame' , 'v1__stack1' ) ) ;
@@ -401,7 +380,11 @@ $(document).ready(function() {
401380
402381
403382 $ ( '#pyCodeOutputDiv' ) . scroll ( function ( ) {
404- console . log ( 'scrolled!!!' ) ;
383+ $ . each ( allBubbles , function ( i , e ) {
384+ if ( e . type == 'codeline' ) {
385+ e . redrawCodelineBubble ( ) ;
386+ }
387+ } ) ;
405388 } ) ;
406389
407390
0 commit comments