@@ -291,30 +291,36 @@ var PY3_EXAMPLES = {
291291}
292292
293293var chatBox = undefined ;
294-
295- function toggleChatBox ( ) {
296- if ( chatBox ) {
297- chatBox . chatbox ( "option" , "boxManager" ) . toggleBox ( ) ;
298- } else {
299- chatBox = $ ( "#chat_div" ) . chatbox ( { id : "Me" ,
300- user : { key : "value" } ,
301- title : "Live Chat With Tutor" ,
302- width : 250 ,
303- offset : 2 , // offset from right edge
304- messageSent : chatMsgSent ,
305- boxClosed : chatBoxClosed ,
306- } ) ;
307- }
294+ function createChatBox ( ) {
295+ assert ( ! chatBox ) ;
296+ chatBox = $ ( "#chat_div" ) . chatbox ( { id : "Me" ,
297+ user : { key : "value" } ,
298+ title : "Live Chat With Tutor" ,
299+ width : 250 ,
300+ offset : 2 , // offset from right edge
301+ messageSent : chatMsgSent ,
302+ boxClosed : chatBoxClosed ,
303+ chatboxToggled : chatBoxToggled ,
304+ } ) ;
308305}
309306
310307function chatMsgSent ( id , user , msg ) {
311308 $ ( "#chat_div" ) . chatbox ( "option" , "boxManager" ) . addMsg ( id , msg ) ;
312- logEvent ( { type : 'opt-client-chat' , text : msg } ) ;
309+ logEvent ( { type : 'opt-client-chat' , text : msg , sid : loggingSocketIO ? loggingSocketIO . id : undefined } ) ;
313310}
314311
315312// only called when the user hits the X button to explicitly close the chat box
316313function chatBoxClosed ( id ) {
317- console . log ( 'chat box closed!' , id ) ;
314+ logEvent ( { type : 'opt-client-chat' , text : '[closed chat box]' , sid : loggingSocketIO ? loggingSocketIO . id : undefined } ) ;
315+ }
316+
317+ // called when the user toggles the chat box open or close
318+ function chatBoxToggled ( visible ) {
319+ var msg = '[minimized chat box]' ;
320+ if ( visible ) {
321+ msg = '[maximized chat box]' ;
322+ }
323+ logEvent ( { type : 'opt-client-chat' , text : msg , sid : loggingSocketIO ? loggingSocketIO . id : undefined } ) ;
318324}
319325
320326$ ( document ) . ready ( function ( ) {
@@ -457,5 +463,16 @@ $(document).ready(function() {
457463
458464 reconnectAttempts ++ ;
459465 } ) ;
466+
467+ loggingSocketIO . on ( 'opt-codeopticon-observer-chat' , function ( msg ) {
468+ if ( ! chatBox ) {
469+ createChatBox ( ) ;
470+ } else {
471+ $ ( "#chat_div" ) . chatbox ( "option" , "hidden" , false ) ;
472+ $ ( "#chat_div" ) . chatbox ( "showContent" ) ;
473+ }
474+
475+ $ ( "#chat_div" ) . chatbox ( "option" , "boxManager" ) . addMsg ( 'Tutor' , msg . text ) ;
476+ } ) ;
460477 }
461478} ) ;
0 commit comments