social_stream-presence 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
@@ -1,3 +1,5 @@
1
+ var global;
2
+
1
3
  ////////////////////
2
4
  //Reconnect button interface functions
3
5
  ////////////////////
@@ -30,8 +32,15 @@ function requestConnectToChat(){
30
32
  //Chat interface: Connection boxes
31
33
  ////////////////////
32
34
 
35
+ var focusSearchContactsFlag=false;
36
+
33
37
  function setUserFunctions(){
34
-
38
+
39
+ settingTooltips();
40
+
41
+ ///////////////////////
42
+ //Open chatbox function
43
+ ///////////////////////
35
44
  $("div.user_presence").click(function(event, ui){
36
45
  var guest_name = $(this).attr("name");
37
46
  var guest_slug = $(this).attr("slug");
@@ -43,10 +52,21 @@ function setUserFunctions(){
43
52
  };
44
53
  });
45
54
 
55
+
56
+ //Hide tooltips on mouseleave
57
+ $("div.user_presence").mouseleave(function(e){
58
+ var div = $(this);
59
+ $.each($(".tooltip:visible"), function(index, value) {
60
+ if ( $($(".tooltip:visible")[0]).html() == $(div).attr("name") ){
61
+ $($(".tooltip:visible")[index]).hide();
62
+ }
63
+ });
64
+ });
46
65
 
47
- ////////////////////
48
- //Chat interface: Status selector
49
- ////////////////////
66
+
67
+ ////////////////////
68
+ //Chat interface: Status selector
69
+ ////////////////////
50
70
 
51
71
  //JQuery DropdwanStatus
52
72
 
@@ -78,15 +98,105 @@ function setUserFunctions(){
78
98
 
79
99
  $(document).bind('click', function(e) {
80
100
  var $clicked = $(e.target);
101
+
81
102
  if (! $clicked.parents().hasClass("dropdown")){
82
103
  //Click outside the select...
83
104
  $(".dropdown dd ul").hide();
84
105
  setStatusWidgetTitle(userStatus);
85
106
  }
86
107
  });
108
+
109
+ ///////////////
110
+ //Search contacts enabling
111
+ ///////////////
112
+ $("select.flexselect").flexselect({
113
+ allowMismatch: true
114
+ });
115
+
116
+ //Select contact function
117
+ //callback in changeSelectContactValue()
118
+
119
+
120
+ $("#search_chat_contact_flexselect").focus(function(e) {
121
+ changeContactListVisibility(true);
122
+ });
123
+
124
+ $("#search_chat_contact_flexselect").blur(function(e) {
125
+ changeContactListVisibility(false);
126
+ });
127
+
128
+ }
129
+
130
+
131
+ function changeSelectContactValue(name,value){
132
+ $("#search_chat_contact_flexselect").blur();
133
+
134
+ if(value == "ZERO_CONTACTS"){
135
+ return;
136
+ }
137
+
138
+ var guest_slug = value;
139
+ var guest_name = name;
140
+ var guest_jid = guest_slug + "@" + domain;
141
+ if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
142
+ } else {
143
+ window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
144
+ };
145
+
146
+ //Check for online status and show notification
147
+ if (getAllConnectedSlugs().indexOf(guest_slug)==-1) {
148
+ showOfflineChatNotificationForSlug(guest_slug);
149
+ }
87
150
 
151
+ changeContactListVisibility(false);
88
152
  }
89
153
 
154
+
155
+ function settingTooltips(){
156
+ if (mainChatBox == null) {
157
+ //Enabling default tooltips
158
+ $(".user_presence a[title]").tooltip();
159
+ } else {
160
+ //Enabling tooltips with center left position
161
+
162
+ //Changing Tooltip CSS class by JQuery
163
+ var ss = document.styleSheets;
164
+ for (var i=0; i<ss.length; i++) {
165
+ var rules = ss[i].cssRules || ss[i].rules;
166
+ for (var j=0; j<rules.length; j++) {
167
+ if (rules[j].selectorText === ".tooltip") {
168
+ rules[j].style.background = 'url("black_arrow9.png") repeat scroll 0% 0% transparent'
169
+ }
170
+ }
171
+ }
172
+ $(".user_presence a[title]").tooltip({
173
+ opacity: 0.95,
174
+ relative: false,
175
+ position: 'top left',
176
+ offset: [0,37]
177
+ });
178
+ }
179
+ }
180
+
181
+
182
+ function changeContactListVisibility(visible){
183
+ var nItems = $("#search_chat_contact_flexselect_dropdown ul li").length-1;
184
+ if (visible){
185
+ focusSearchContactsFlag=true;
186
+ if(nItems > 9){
187
+ changeMainChatBoxHeight(mainChatBoxHeightWhileSearchContacts);
188
+ } else {
189
+ var mainChatBoxMinRequiredHeight= mainChatBoxaddonsHeight + 20 + nItems * 19;
190
+ changeMainChatBoxHeight(mainChatBoxMinRequiredHeight);
191
+ }
192
+ $(".users_connected").hide();
193
+ } else {
194
+ changeMainChatBoxHeight(getChatBoxHeightRequiredForConnectionBoxes());
195
+ $(".users_connected").show();
196
+ }
197
+ }
198
+
199
+
90
200
  function setStatusWidgetTitle(status){
91
201
 
92
202
  if((status in sstreamChatStatus)){
@@ -179,14 +289,18 @@ function updateChatWindow(){
179
289
  $.post("/chatWindow", { userConnected: stropheConnectedAndOnlineStatus }, function(data){
180
290
  $(".tooltip").hide() //Prevent tooltips
181
291
  $("#chat_partial").html(modifyChatPartialIfMainBox(data));
292
+ updateConnectedUsersOfMainChatBox();
182
293
  if (isStropheConnected()) {
183
294
  setStatusWidgetTitle(userStatus);
184
- $(".user_presence a[title]").tooltip();
185
- setUserFunctions();
186
- updateConnectedUsersOfMainChatBox();
295
+ setUserFunctions();
187
296
  if (afterNewConnectionFlag){
188
297
  afterNewConnectionFlag = false;
189
- restoreChatData();
298
+ if(afterFirstConnectionFlag){
299
+ restoreChatData();
300
+ afterFirstConnectionFlag = false;
301
+ } else {
302
+ updateAllNotifications();
303
+ }
190
304
  }
191
305
  }
192
306
  });
@@ -201,11 +315,23 @@ function getConnectionBoxFromSlug(slug){
201
315
  }
202
316
 
203
317
  var cacheConnectedUsers = [];
318
+
204
319
  function hideConnectionBoxFromSlug(slug){
205
320
  if ($('div.user_presence[slug=' + slug + ']').length > 0){
206
321
  $('div.user_presence[slug=' + slug + ']').hide();
207
322
  if(cacheConnectedUsers.indexOf(slug)==-1){
208
323
  cacheConnectedUsers.push(slug);
324
+ }
325
+ updateMainChatBoxAfterUserDisconnect();
326
+
327
+ //Last user disconnected?
328
+ if (getAllConnectedSlugs().length ==0){
329
+ if($(".users_connected p.zero_users_connected").length > 0){
330
+ $(".users_connected p.zero_users_connected").show();
331
+ } else {
332
+ var msg = '<%=I18n.t('chat.zerousers')%>';
333
+ $(".users_connected").append('<p class="zero_users_connected">' + msg + '</p>')
334
+ }
209
335
  }
210
336
  }
211
337
  }
@@ -214,6 +340,7 @@ function showConnectionBoxFromSlug(slug){
214
340
  if ($('div.user_presence[slug=' + slug + ']').length > 0){
215
341
  if (!($('div.user_presence[slug=' + slug + ']').is(":visible"))){
216
342
  $('div.user_presence[slug=' + slug + ']').show();
343
+ $(".users_connected p.zero_users_connected").hide();
217
344
  }
218
345
  }
219
346
  }
@@ -229,17 +356,29 @@ function setUserIconStatus(slug, status){
229
356
  }
230
357
 
231
358
  function getAllConnectedSlugs(){
232
- connectedSlugs=[];
359
+ return getAllSlugsByChatConnectedState()[0];
360
+ }
361
+
362
+ function getAllDisconnectedSlugs(){
363
+ return getAllSlugsByChatConnectedState()[1];
364
+ }
365
+
366
+ function getAllSlugsByChatConnectedState(){
367
+ var onlineSlugs=[];
368
+ var offlineSlugs=[];
369
+ var allSlugs=[];
233
370
  connectionBoxes = $('div.user_presence[slug]');
234
371
  $.each(connectionBoxes, function(index, value) {
235
- if($(value).css("display")!="none"){
236
- connectedSlugs.push($(value).attr("slug"))
237
- }
372
+ if($(value).css("display")!="none"){
373
+ onlineSlugs.push($(value).attr("slug"))
374
+ } else {
375
+ offlineSlugs.push($(value).attr("slug"))
376
+ }
377
+ allSlugs.push($(value).attr("slug"))
238
378
  });
239
- return connectedSlugs
379
+ return [onlineSlugs,offlineSlugs,allSlugs]
240
380
  }
241
381
 
242
-
243
382
  ////////////////////
244
383
  //Insert received message in chatbox
245
384
  ////////////////////
@@ -293,20 +432,24 @@ function putReceivedMessageOnChatWindow(from_jid,from_slug,body,msgID){
293
432
  //Notifications on chat Window
294
433
  ////////////////////
295
434
 
296
- function showChatNotificationForSlug(slug,msg){
297
- var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
298
- showChatNotification(notification,msg);
299
- }
300
-
301
435
  function showChatNotification(notification,msg){
302
436
  notification.html("<p class==\"ui-chatbox-notify-text\">" + msg + "</p>");
303
437
  notification.css("visibility","visible");
304
438
  notification.fadeIn();
305
439
  }
306
440
 
307
- function hideChatNotificationForSlug(slug){
441
+ function showChatNotificationForSlug(slug,msg){
308
442
  var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
309
- hideChatNotification(notification);
443
+ showChatNotification(notification,msg);
444
+ }
445
+
446
+ function showOfflineChatNotificationForSlug(slug){
447
+ var slug_chat_box = getChatBoxForSlug(slug);
448
+ if(slug_chat_box!=null){
449
+ var name = slug_chat_box.attr("name")
450
+ var msg = name + ' ' + '<%=I18n.t('chat.notify.guestOffline')%>';
451
+ showChatNotificationForSlug(slug,msg);
452
+ }
310
453
  }
311
454
 
312
455
  function hideChatNotification(notification){
@@ -314,6 +457,11 @@ function hideChatNotification(notification){
314
457
  notification.css("visibility","hidden");
315
458
  }
316
459
 
460
+ function hideChatNotificationForSlug(slug){
461
+ var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
462
+ hideChatNotification(notification);
463
+ }
464
+
317
465
  function notifyWhenUsersDisconnect(){
318
466
  var notification = $("div.ui-chatbox-notify");
319
467
  var msg = '<%=I18n.t('chat.notify.offline')%>';
@@ -325,6 +473,17 @@ function hideAllNotifications(){
325
473
  hideChatNotification(notification);
326
474
  }
327
475
 
476
+ function updateAllNotifications(){
477
+ hideAllNotifications();
478
+ if(disconnectionFlag){
479
+ notifyWhenUsersDisconnect();
480
+ } else {
481
+ //Notification for offline contacts
482
+ $.each(getAllDisconnectedSlugsWithChatBoxes(), function(index, value) {
483
+ showOfflineChatNotificationForSlug(value)
484
+ });
485
+ }
486
+ }
328
487
 
329
488
 
330
489
  ////////////////////
@@ -332,6 +491,15 @@ function hideAllNotifications(){
332
491
  ////////////////////
333
492
 
334
493
  function updateConnectedUsersOfMainChatBox(){
335
- var connectedUsers = getAllConnectedSlugs().length;
336
- changeMainChatBoxHeaderTitle( '<%=I18n.t('chat.title')%>' + " (" + connectedUsers + ")");
494
+ if(mainChatBox!=null){
495
+ var connectedUsers = getAllConnectedSlugs().length;
496
+ changeMainChatBoxHeaderTitle( '<%=I18n.t('chat.title')%>' + " (" + connectedUsers + ")");
497
+ changeMainChatBoxHeight(getChatBoxHeightRequiredForConnectionBoxes());
498
+ }
337
499
  }
500
+
501
+
502
+ function updateMainChatBoxAfterUserDisconnect(){
503
+ changeMainChatBoxHeight(getChatBoxHeightRequiredForConnectionBoxes());
504
+ updateConnectedUsersOfMainChatBox();
505
+ }
@@ -64,11 +64,19 @@ function storeConversations() {
64
64
 
65
65
 
66
66
  function storeChatConnectionParametres() {
67
- if (sessionStorage.getItem("cookie") == null){
68
- sessionStorage.setItem("cookie", cookie);
69
- sessionStorage.setItem("chat_user_name", user_name);
70
- sessionStorage.setItem("chat_user_slug", user_slug);
71
- sessionStorage.setItem("chat_user_jid", user_jid);
67
+ if ((sessionStorage.getItem("cookie") == null)||(sessionStorage.getItem("chat_user_name") == null)){
68
+ if ((typeof cookie != 'undefined')&&(cookie!=null)){
69
+ sessionStorage.setItem("cookie", cookie);
70
+ }
71
+ if ((typeof user_name != 'undefined') && (user_name != null)) {
72
+ sessionStorage.setItem("chat_user_name", user_name);
73
+ }
74
+ if ((typeof user_slug != 'undefined') && (user_slug != null)) {
75
+ sessionStorage.setItem("chat_user_slug", user_slug);
76
+ }
77
+ if ((typeof user_jid != 'undefined') && (user_jid != null)) {
78
+ sessionStorage.setItem("chat_user_jid", user_jid);
79
+ }
72
80
  }
73
81
  }
74
82
 
@@ -104,6 +112,7 @@ function getRestoreUserChatStatus(){
104
112
 
105
113
 
106
114
  function restoreChatData(){
115
+
107
116
  //Check for Session Storage support
108
117
  if (! window.sessionStorage){
109
118
  return
@@ -162,7 +171,7 @@ function restoreConversations() {
162
171
  window[getChatVariableFromSlug(guest_slug)].parent().toggle(false);
163
172
  }
164
173
  if ((visibleMaxSlugs.indexOf(guest_slug)==-1)&&(visibleMinSlugs.indexOf(guest_slug)==-1)){
165
- window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(false);
174
+ closeChatBox(guest_slug);
166
175
  }
167
176
  } else {
168
177
  //Always created.
@@ -6,6 +6,16 @@ function log(msg) {
6
6
  //console.log(msg)
7
7
  }
8
8
 
9
+ function simulate_new_user_connected(slug) {
10
+ var stanza_test = '<presence xmlns="jabber:client" from="' + slug + '@localhost/27825459741328802387991286" to="demo@localhost/2517285379132880233667729">'
11
+ onPresence(stanza_test);
12
+ }
13
+
14
+ function simulate_new_user_disconnected(slug) {
15
+ var stanza_test = '<presence xmlns="jabber:client" type="unavailable" from="' + slug + '@localhost/27825459741328802387991286" to="demo@localhost/2517285379132880233667729">'
16
+ onPresence(stanza_test);
17
+ }
18
+
9
19
 
10
20
  ////////////////////
11
21
  //Blink page title when focus lost on new messages
@@ -231,6 +241,9 @@ function getNameFromSlug(slug){
231
241
  }
232
242
 
233
243
 
244
+
245
+
246
+
234
247
  ////////////////////
235
248
  //Next features...
236
249
  ////////////////////
@@ -41,17 +41,7 @@ function createChatBox(guest_slug,guest_name,guest_jid,user_name,user_jid){
41
41
  position: position,
42
42
  priority: visibleChatBoxes.length+1,
43
43
  boxClosed: function(id) {
44
-
45
- position = $("#" + guest_slug).chatbox("option", "position");
46
-
47
- for (i=position+1;i<visibleChatBoxes.length+1;i++){
48
- visibleChatBoxes[i-1].chatbox("option", "offset", visibleChatBoxes[i-1].chatbox("option", "offset") - chatBoxSeparation);
49
- visibleChatBoxes[i-1].chatbox("option", "position", visibleChatBoxes[i-1].chatbox("option", "position") - 1 );
50
- }
51
-
52
- visibleChatBoxes.splice(position-1,1);
53
- $("#" + guest_slug).chatbox("option", "hidden", true);
54
- nBox--;
44
+ closeChatBox(guest_slug)
55
45
  },
56
46
 
57
47
  messageSent : function(id, user, msg) {
@@ -111,30 +101,73 @@ function getBoxParams(){
111
101
  }
112
102
 
113
103
 
104
+ function closeChatBox(guest_slug){
105
+ var position = $("#" + guest_slug).chatbox("option", "position");
106
+
107
+ for (i=position+1;i<visibleChatBoxes.length+1;i++){
108
+ visibleChatBoxes[i-1].chatbox("option", "offset", visibleChatBoxes[i-1].chatbox("option", "offset") - chatBoxSeparation);
109
+ visibleChatBoxes[i-1].chatbox("option", "position", visibleChatBoxes[i-1].chatbox("option", "position") - 1 );
110
+ }
111
+
112
+ visibleChatBoxes.splice(position-1,1);
113
+ $("#" + guest_slug).chatbox("option", "hidden", true);
114
+ nBox--;
115
+ }
116
+
117
+
114
118
  function getChatVariableFromSlug(slug){
115
119
  return "slug_" + slug;
116
120
  }
117
121
 
118
-
119
122
  function getSlugFromChatVariable(variable){
120
123
  return variable.split("_")[1];
121
124
  }
122
125
 
123
126
  function getVisibleChatBoxes(){
124
-
125
127
  for(i=0; i<visibleChatBoxes.length; i++){
126
128
  if (visibleChatBoxes[i][0].id==chatSlugId){
127
129
  visibleChatBoxes.splice(i,1)
128
130
  }
129
131
  }
130
-
131
132
  return visibleChatBoxes
132
133
  }
133
134
 
135
+
134
136
  function getAllChatBoxes(){
135
137
  return $(".chatbox").not(document.getElementById(chatSlugId))
136
138
  }
137
139
 
140
+ function getChatBoxForSlug(slug){
141
+ if (typeof window[getChatVariableFromSlug(slug)] == 'undefined') {
142
+ return null;
143
+ } else {
144
+ return window[getChatVariableFromSlug(slug)];
145
+ }
146
+ }
147
+
148
+
149
+ function getAllSlugsWithChatBoxes(){
150
+ var slugsWithChatBox = [];
151
+ $.each(getAllChatBoxes(), function(index, value) {
152
+ slugsWithChatBox.push($(value).attr("id"))
153
+ });
154
+ return slugsWithChatBox;
155
+ }
156
+
157
+ function getAllDisconnectedSlugsWithChatBoxes(){
158
+ var slugsWithChatBox = getAllSlugsWithChatBoxes();
159
+ var slugsConnected = getAllConnectedSlugs();
160
+ var allDisconnectedSlugsWithChatBox = [];
161
+
162
+ $.each(slugsWithChatBox, function(index, value) {
163
+ if (slugsConnected.indexOf(value)==-1){
164
+ allDisconnectedSlugsWithChatBox.push(value);
165
+ }
166
+ });
167
+ return allDisconnectedSlugsWithChatBox;
168
+ }
169
+
170
+
138
171
  ////////////////////
139
172
  //Box replacement
140
173
  ////////////////////
@@ -211,6 +244,14 @@ function getVideoEmbedForSlug(slug){
211
244
  ///////////////////////////
212
245
 
213
246
  var mainChatBox;
247
+ var connectionBoxesForFile=5;
248
+ var maxConnectionChatBoxesFilesWithoutOverflow = 11;
249
+ var mainChatBoxWidth=150;
250
+ var mainChatBoxaddonsHeight=50;
251
+ var heightForConnectionBoxFile=30;
252
+ var mainChatBoxHeightWhileSearchContacts=260;
253
+ var mainChatBoxMinHeight=136;
254
+ var mainChatBoxMaxHeight= mainChatBoxaddonsHeight + heightForConnectionBoxFile*maxConnectionChatBoxesFilesWithoutOverflow;
214
255
  var chatSlugId="SocialStream_MainChat";
215
256
 
216
257
  function createMainChatBox(){
@@ -233,22 +274,23 @@ function createMainChatBox(){
233
274
  $(mainChatBox.parent()).find(".ui-chatbox-input").remove();
234
275
 
235
276
  //Set height
236
- window[getChatVariableFromSlug(chatSlugId)].css( "height", "180" );
277
+ changeMainChatBoxHeight(getChatBoxHeightRequiredForConnectionBoxes());
237
278
 
238
279
  //Set width
239
- var windowWidth=150;
240
- window[getChatVariableFromSlug(chatSlugId)].parent().parent().css( "width", windowWidth );
241
- $(mainChatBox.parent().parent()).find(".ui-chatbox-titlebar").css( "width", windowWidth-6 );
242
- $(mainChatBox).css( "width", windowWidth-6 );
280
+ window[getChatVariableFromSlug(chatSlugId)].parent().parent().css( "width", mainChatBoxWidth );
281
+ $(mainChatBox.parent().parent()).find(".ui-chatbox-titlebar").css( "width", mainChatBoxWidth-6 );
282
+ $(mainChatBox).css( "width", mainChatBoxWidth-6 );
243
283
 
244
284
 
245
285
  //Adjust window offset
246
- offsetForFlowBox = 235-windowWidth;
286
+ offsetForFlowBox = 235-mainChatBoxWidth;
247
287
 
248
288
  //CSS Adjusts
249
289
  $("#chat_partial").css("margin-top",-3)
250
290
  $("#chat_partial").css("margin-left",-3)
251
291
  $(".dropdown dd ul").css("min-width",147)
292
+ $(mainChatBox).css('overflow-x','hidden')
293
+ $(mainChatBox).css('overflow-y','hidden')
252
294
 
253
295
  //Header title
254
296
  updateConnectedUsersOfMainChatBox();
@@ -280,3 +322,42 @@ function changeMainChatBoxHeaderTitle(title){
280
322
  $($(mainChatBox.parent().parent()).find(".ui-chatbox-titlebar").find("span")[0]).html(title);
281
323
  }
282
324
  }
325
+
326
+
327
+ function changeMainChatBoxHeight(height){
328
+ if (mainChatBox != null) {
329
+
330
+ if(($("#search_chat_contact_flexselect").is(":focus"))&&(! (focusSearchContactsFlag))){
331
+ return;
332
+ } else {
333
+ focusSearchContactsFlag=false;
334
+ }
335
+
336
+ if(height > mainChatBoxMaxHeight){
337
+ //overflow = true;
338
+ height = mainChatBoxMaxHeight;
339
+ $(mainChatBox).css('overflow-y','visible');
340
+ mainChatBox.chatbox("option", "offset","5px")
341
+ mainChatBox.chatbox("option", "width", mainChatBoxWidth + 5)
342
+ } else {
343
+ $(mainChatBox).css('overflow-y','hidden');
344
+ mainChatBox.chatbox("option", "offset","0px")
345
+ mainChatBox.chatbox("option", "width",mainChatBoxWidth)
346
+ height = Math.max(height,mainChatBoxMinHeight)
347
+ }
348
+
349
+ window[getChatVariableFromSlug(chatSlugId)].css("height", height);
350
+ }
351
+ }
352
+
353
+
354
+ function getChatBoxHeightRequiredForConnectionBoxes(){
355
+ if(mainChatBox!=null){
356
+ var desiredHeight = mainChatBoxaddonsHeight + Math.ceil(getAllConnectedSlugs().length/connectionBoxesForFile) * heightForConnectionBoxFile;
357
+ return desiredHeight;
358
+ } else {
359
+ return null;
360
+ }
361
+ }
362
+
363
+