Skip to content

Commit 5f66d40

Browse files
committed
added chatbox support!
1 parent 672bd26 commit 5f66d40

3 files changed

Lines changed: 50 additions & 17 deletions

File tree

‎v3/css/jquery.ui.chatbox.css‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
height: 250px;
2626
overflow-y: auto;
2727
overflow-x: hidden;
28-
background: #FFFFFF;
28+
background: #FFFFFF !important;
2929
}
3030

3131
.ui-chatbox-input {
@@ -39,6 +39,7 @@
3939
border: 2px solid lightgrey;/* #6699FF */
4040
padding: 2px;
4141
height: 50px;
42+
background: #FFFFFF !important;
4243
}
4344

4445
.ui-chatbox-icon {

‎v3/js/jquery.ui.chatbox.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* customized by Philip Guo */
2+
13
/*
24
* Copyright 2010, Wen Pu (dexterpu at gmail dot com)
35
* Dual licensed under the MIT or GPL Version 2 licenses.
@@ -26,6 +28,9 @@
2628
// override this
2729
this.boxManager.addMsg(user.first_name, msg);
2830
},
31+
chatboxToggled: function(isVisible) {
32+
// called when box's contents are toggled opened or closed
33+
},
2934
boxClosed: function(id) {
3035
}, // called when the close icon is clicked
3136
boxManager: {
@@ -60,11 +65,14 @@
6065
$(e).fadeIn();
6166
self._scrollToBottom();
6267

68+
// pgbovine - don't do this for simplicity
69+
/*
6370
if (!self.elem.uiChatboxTitlebar.hasClass("ui-state-focus")
6471
&& !self.highlightLock) {
6572
self.highlightLock = true;
6673
self.highlightBox();
6774
}
75+
*/
6876
},
6977
highlightBox: function() {
7078
var self = this;
@@ -87,8 +95,15 @@
8795
this.uiChatboxContent.toggle();
8896
if (this.uiChatboxContent.is(":visible")) {
8997
this.uiChatboxInputBox.focus();
98+
this.options.chatboxToggled(true);
99+
} else {
100+
this.options.chatboxToggled(false);
90101
}
91102
},
103+
// pgbovine
104+
showContent: function(event) {
105+
this.uiChatboxContent.show();
106+
},
92107
widget: function() {
93108
return this.uiChatbox
94109
},

‎v3/js/opt-frontend.js‎

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,30 +291,36 @@ var PY3_EXAMPLES = {
291291
}
292292

293293
var 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

310307
function 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
316313
function 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

Comments
 (0)