|
|
@@ -9,14 +9,17 @@ import UIEvents from '../../../../service/UI/UIEvents';
|
|
9
|
9
|
|
|
10
|
10
|
var smileys = require("./smileys.json").smileys;
|
|
11
|
11
|
|
|
12
|
|
-var notificationInterval = false;
|
|
13
|
12
|
var unreadMessages = 0;
|
|
14
|
13
|
|
|
|
14
|
+/**
|
|
|
15
|
+ * The container id, which is and the element id.
|
|
|
16
|
+ */
|
|
|
17
|
+var CHAT_CONTAINER_ID = "chat_container";
|
|
15
|
18
|
|
|
16
|
19
|
/**
|
|
17
|
|
- * Shows/hides a visual notification, indicating that a message has arrived.
|
|
|
20
|
+ * Updates visual notification, indicating that a message has arrived.
|
|
18
|
21
|
*/
|
|
19
|
|
-function setVisualNotification(show) {
|
|
|
22
|
+function updateVisualNotification() {
|
|
20
|
23
|
var unreadMsgElement = document.getElementById('unreadMessages');
|
|
21
|
24
|
|
|
22
|
25
|
var glower = $('#toolbar_button_chat');
|
|
|
@@ -37,27 +40,9 @@ function setVisualNotification(show) {
|
|
37
|
40
|
'style',
|
|
38
|
41
|
'top:' + topIndent +
|
|
39
|
42
|
'; left:' + leftIndent + ';');
|
|
40
|
|
-
|
|
41
|
|
- if (!glower.hasClass('icon-chat-simple')) {
|
|
42
|
|
- glower.removeClass('icon-chat');
|
|
43
|
|
- glower.addClass('icon-chat-simple');
|
|
44
|
|
- }
|
|
45
|
43
|
}
|
|
46
|
44
|
else {
|
|
47
|
45
|
unreadMsgElement.innerHTML = '';
|
|
48
|
|
- glower.removeClass('icon-chat-simple');
|
|
49
|
|
- glower.addClass('icon-chat');
|
|
50
|
|
- }
|
|
51
|
|
-
|
|
52
|
|
- if (show && !notificationInterval) {
|
|
53
|
|
- notificationInterval = window.setInterval(function () {
|
|
54
|
|
- glower.toggleClass('active');
|
|
55
|
|
- }, 800);
|
|
56
|
|
- }
|
|
57
|
|
- else if (!show && notificationInterval) {
|
|
58
|
|
- window.clearInterval(notificationInterval);
|
|
59
|
|
- notificationInterval = false;
|
|
60
|
|
- glower.removeClass('active');
|
|
61
|
46
|
}
|
|
62
|
47
|
}
|
|
63
|
48
|
|
|
|
@@ -131,7 +116,7 @@ function addSmileys() {
|
|
131
|
116
|
*/
|
|
132
|
117
|
function resizeChatConversation() {
|
|
133
|
118
|
var msgareaHeight = $('#usermsg').outerHeight();
|
|
134
|
|
- var chatspace = $('#chat_container');
|
|
|
119
|
+ var chatspace = $('#' + CHAT_CONTAINER_ID);
|
|
135
|
120
|
var width = chatspace.width();
|
|
136
|
121
|
var chat = $('#chatconversation');
|
|
137
|
122
|
var smileys = $('#smileysarea');
|
|
|
@@ -187,10 +172,20 @@ var Chat = {
|
|
187
|
172
|
};
|
|
188
|
173
|
usermsg.autosize({callback: onTextAreaResize});
|
|
189
|
174
|
|
|
190
|
|
- $("#chat_container").bind("shown",
|
|
191
|
|
- function () {
|
|
|
175
|
+ eventEmitter.on(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
|
|
|
176
|
+ function(containerId, isVisible) {
|
|
|
177
|
+ if (containerId !== CHAT_CONTAINER_ID || !isVisible)
|
|
|
178
|
+ return;
|
|
|
179
|
+
|
|
192
|
180
|
unreadMessages = 0;
|
|
193
|
|
- setVisualNotification(false);
|
|
|
181
|
+ updateVisualNotification();
|
|
|
182
|
+
|
|
|
183
|
+ // if we are in conversation mode focus on the text input
|
|
|
184
|
+ // if we are not, focus on the display name input
|
|
|
185
|
+ if (APP.settings.getDisplayName())
|
|
|
186
|
+ $('#usermsg').focus();
|
|
|
187
|
+ else
|
|
|
188
|
+ $('#nickinput').focus();
|
|
194
|
189
|
});
|
|
195
|
190
|
|
|
196
|
191
|
addSmileys();
|
|
|
@@ -210,7 +205,7 @@ var Chat = {
|
|
210
|
205
|
if (!Chat.isVisible()) {
|
|
211
|
206
|
unreadMessages++;
|
|
212
|
207
|
UIUtil.playSoundNotification('chatNotification');
|
|
213
|
|
- setVisualNotification(true);
|
|
|
208
|
+ updateVisualNotification();
|
|
214
|
209
|
}
|
|
215
|
210
|
}
|
|
216
|
211
|
|
|
|
@@ -271,12 +266,18 @@ var Chat = {
|
|
271
|
266
|
|
|
272
|
267
|
/**
|
|
273
|
268
|
* Sets the chat conversation mode.
|
|
|
269
|
+ * Conversation mode is the normal chat mode, non conversation mode is
|
|
|
270
|
+ * where we ask user to input its display name.
|
|
274
|
271
|
* @param {boolean} isConversationMode if chat should be in
|
|
275
|
272
|
* conversation mode or not.
|
|
276
|
273
|
*/
|
|
277
|
274
|
setChatConversationMode (isConversationMode) {
|
|
278
|
|
- $('#chat_container')
|
|
|
275
|
+ $('#' + CHAT_CONTAINER_ID)
|
|
279
|
276
|
.toggleClass('is-conversation-mode', isConversationMode);
|
|
|
277
|
+
|
|
|
278
|
+ // this is needed when we transition from no conversation mode to
|
|
|
279
|
+ // conversation mode. When user enters his nickname and hits enter,
|
|
|
280
|
+ // to focus on the write area.
|
|
280
|
281
|
if (isConversationMode) {
|
|
281
|
282
|
$('#usermsg').focus();
|
|
282
|
283
|
}
|
|
|
@@ -286,7 +287,7 @@ var Chat = {
|
|
286
|
287
|
* Resizes the chat area.
|
|
287
|
288
|
*/
|
|
288
|
289
|
resizeChat (width, height) {
|
|
289
|
|
- $('#chat_container').width(width).height(height);
|
|
|
290
|
+ $('#' + CHAT_CONTAINER_ID).width(width).height(height);
|
|
290
|
291
|
|
|
291
|
292
|
resizeChatConversation();
|
|
292
|
293
|
},
|
|
|
@@ -296,7 +297,7 @@ var Chat = {
|
|
296
|
297
|
*/
|
|
297
|
298
|
isVisible () {
|
|
298
|
299
|
return UIUtil.isVisible(
|
|
299
|
|
- document.getElementById("chat_container"));
|
|
|
300
|
+ document.getElementById(CHAT_CONTAINER_ID));
|
|
300
|
301
|
},
|
|
301
|
302
|
/**
|
|
302
|
303
|
* Shows and hides the window with the smileys
|