social_stream-presence 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  var global;
2
-
3
2
  ////////////////////
4
3
  //Reconnect button interface functions
5
4
  ////////////////////
@@ -27,49 +26,25 @@ function requestConnectToChat(){
27
26
  }
28
27
  }
29
28
 
29
+ function changeChatHeaderTitle(msg){
30
+ if(mainChatBox==null){
31
+ $("#chat_header_title").html(msg)
32
+ } else {
33
+ changeMainChatBoxHeaderTitle(msg);
34
+ }
35
+ }
36
+
30
37
 
31
38
  ////////////////////
32
- //Chat interface: Connection boxes
39
+ //Chat interface: Setting Functions
33
40
  ////////////////////
34
41
 
35
42
  var focusSearchContactsFlag=false;
43
+ var changeSelectContactValueFlag = false;
36
44
 
37
- function setUserFunctions(){
38
-
39
- settingTooltips();
40
-
41
- ///////////////////////
42
- //Open chatbox function
43
- ///////////////////////
44
- $("div.user_presence").click(function(event, ui){
45
- var guest_name = $(this).attr("name");
46
- var guest_slug = $(this).attr("slug");
47
- var guest_jid = guest_slug + "@" + domain;
48
-
49
- if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
50
- } else {
51
- window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
52
- };
53
- });
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
- });
65
-
66
-
67
- ////////////////////
68
- //Chat interface: Status selector
69
- ////////////////////
70
45
 
71
- //JQuery DropdwanStatus
72
-
46
+ function settingStatusSelector(){
47
+ //JQuery DropdwanStatus
73
48
  $(".dropdown dt a").click(function(event) {
74
49
  event.preventDefault();
75
50
  $(".dropdown dd ul").toggle();
@@ -81,7 +56,6 @@ function setUserFunctions(){
81
56
  }
82
57
 
83
58
  restartAwayTimer();
84
-
85
59
  });
86
60
 
87
61
  $(".dropdown dd ul li a.option").click(function(event) {
@@ -98,64 +72,41 @@ function setUserFunctions(){
98
72
 
99
73
  $(document).bind('click', function(e) {
100
74
  var $clicked = $(e.target);
101
-
75
+
102
76
  if (! $clicked.parents().hasClass("dropdown")){
103
77
  //Click outside the select...
104
78
  $(".dropdown dd ul").hide();
105
79
  setStatusWidgetTitle(userStatus);
106
80
  }
107
81
  });
108
-
109
- ///////////////
110
- //Search contacts enabling
111
- ///////////////
112
- $("select.flexselect").flexselect({
113
- allowMismatch: true,
114
- defaultmessage: I18n.t('chat.zerocontacts')
115
- });
116
-
117
- $("#search_chat_contact_flexselect").Watermark(I18n.t('chat.search'),"#666");
118
-
119
- //Select contact function
120
- //callback in changeSelectContactValue()
121
-
122
-
123
- $("#search_chat_contact_flexselect").focus(function(e) {
124
- changeContactListVisibility(true);
125
- });
126
-
127
- $("#search_chat_contact_flexselect").blur(function(e) {
128
- changeContactListVisibility(false);
129
- });
130
-
131
82
  }
132
83
 
133
84
 
134
- function changeSelectContactValue(name,value){
135
-
136
- $("#search_chat_contact_flexselect").blur();
137
-
138
- if(value == "ZERO_CONTACTS"){
139
- return;
140
- }
85
+ function settingChatBoxFunctions(){
141
86
 
142
- var guest_slug = value;
143
- var guest_name = name;
144
- var guest_jid = guest_slug + "@" + domain;
145
- if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
146
- } else {
147
- window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
148
- };
149
-
150
- //Check for online status and show notification
151
- if (getAllConnectedSlugs().indexOf(guest_slug)==-1) {
152
- showOfflineChatNotificationForSlug(guest_slug);
153
- }
87
+ $("div.user_presence").click(function(event, ui){
88
+ var guest_name = $(this).attr("name");
89
+ var guest_slug = $(this).attr("slug");
90
+ var guest_jid = guest_slug + "@" + domain;
91
+
92
+ if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
93
+ } else {
94
+ window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
95
+ };
96
+ });
154
97
 
155
- changeContactListVisibility(false);
98
+ //Hide tooltips on mouseleave
99
+ $("div.user_presence").mouseleave(function(e){
100
+ var div = $(this);
101
+ $.each($(".tooltip:visible"), function(index, value) {
102
+ if ( $($(".tooltip:visible")[0]).html() == $(div).attr("name") ){
103
+ $($(".tooltip:visible")[index]).hide();
104
+ }
105
+ });
106
+ });
107
+
156
108
  }
157
109
 
158
-
159
110
  function settingTooltips(){
160
111
  if (mainChatBox == null) {
161
112
  //Enabling default tooltips
@@ -177,14 +128,65 @@ function settingTooltips(){
177
128
  opacity: 0.95,
178
129
  relative: false,
179
130
  position: 'top left',
180
- offset: [0,37]
131
+ offset: [0,31]
181
132
  });
182
133
  }
183
134
  }
184
135
 
136
+ function settingSearchContactFunctions(){
137
+
138
+ $("#chat_partial select.flexselect").flexselect({
139
+ allowMismatch: true,
140
+ defaultmessage: I18n.t('chat.zerocontacts')
141
+ });
142
+
143
+ $("#chat_partial #search_chat_contact_flexselect").Watermark(I18n.t('chat.search'),"#666");
144
+
145
+ //Select contact function
146
+ //callback in changeSelectContactValue()
147
+
148
+
149
+ $("#chat_partial #search_chat_contact_flexselect").focus(function(e) {
150
+ changeContactListVisibility(true);
151
+ });
152
+
153
+ $("#chat_partial #search_chat_contact_flexselect").blur(function(e) {
154
+ changeContactListVisibility(false);
155
+ });
156
+ }
157
+
158
+ function setAllUserFunctions(){
159
+ settingStatusSelector();
160
+ settingChatBoxFunctions();
161
+ settingTooltips();
162
+ }
163
+
164
+
165
+ function changeSelectContactValue(name,valueSelectedInSearchContacts){
166
+
167
+ if((valueSelectedInSearchContacts != "ZERO_CONTACTS")&&(valueSelectedInSearchContacts != "")){
168
+ var guest_slug = valueSelectedInSearchContacts;
169
+ var guest_name = getNameFromSlug(guest_slug);
170
+ var guest_jid = guest_slug + "@" + domain;
171
+
172
+ if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
173
+ } else {
174
+ window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
175
+ };
176
+
177
+ //Check for online status and show notification
178
+ if (! isSlugChatConnected(guest_slug)) {
179
+ showOfflineChatNotificationForSlug(guest_slug);
180
+ }
181
+ }
182
+
183
+ $("#chat_partial #search_chat_contact_flexselect").blur();
184
+ changeContactListVisibility(false);
185
+ }
186
+
185
187
 
186
188
  function changeContactListVisibility(visible){
187
- var nItems = $("#search_chat_contact_flexselect_dropdown ul li").length-1;
189
+ var nItems = getAllSlugsLength();
188
190
  if (visible){
189
191
  focusSearchContactsFlag=true;
190
192
  if(nItems > 9){
@@ -207,7 +209,6 @@ function setStatusWidgetTitle(status){
207
209
  status = sstreamChatStatus[status];
208
210
  }
209
211
 
210
-
211
212
  if ($(".dropdown dt a span").length == 0){
212
213
  return;
213
214
  }
@@ -286,17 +287,27 @@ function refreshChatWindow(){
286
287
  }
287
288
 
288
289
 
289
- function updateChatWindow(){
290
- timerCounter=0;
291
- log("updateChatWindow()");
292
- var stropheConnectedAndOnlineStatus = ((isStropheConnected()) && (userStatus!="offline") && (!disconnectionFlag));
293
- $.post("/chatWindow", { userConnected: stropheConnectedAndOnlineStatus }, function(data){
294
- $(".tooltip").hide() //Prevent tooltips
295
- $("#chat_partial").html(modifyChatPartialIfMainBox(data));
290
+ function updateChatWindow(){
291
+ var stropheConnectedAndOnlineStatus = ((isStropheConnected()) && (userStatus!="offline") && (!disconnectionFlag));
292
+ timerCounter=0;
293
+
294
+ log("updateChatWindow()");
295
+ log("Connected " + stropheConnectedAndOnlineStatus);
296
+
297
+ if(! stropheConnectedAndOnlineStatus){
298
+ loadDisconnectionDiv();
299
+ updateConnectedUsersOfMainChatBox();
300
+ return;
301
+ }
302
+
303
+ $.post("/chatWindow", { }, function(data){
304
+ //Prevent tooltips
305
+ $(".tooltip").hide()
306
+ loadWidgetsDiv(data);
307
+ hideConnectionBoxesFromDisconnectedSlugs();
308
+ setAllUserFunctions();
296
309
  updateConnectedUsersOfMainChatBox();
297
310
  if (isStropheConnected()) {
298
- setStatusWidgetTitle(userStatus);
299
- setUserFunctions();
300
311
  if (afterNewConnectionFlag){
301
312
  afterNewConnectionFlag = false;
302
313
  if(afterFirstConnectionFlag){
@@ -310,55 +321,158 @@ function updateChatWindow(){
310
321
  });
311
322
  }
312
323
 
313
- function getConnectionBoxFromSlug(slug){
314
- if ($('div.user_presence[slug=' + slug + ']').length > 0){
315
- return ($('div.user_presence[slug=' + slug + ']'))[0];
316
- } else {
317
- return null;
318
- }
319
- }
320
324
 
321
- var cacheConnectedUsers = [];
325
+ //////////////
326
+ //Divs Load
327
+ //////////////
322
328
 
323
- function hideConnectionBoxFromSlug(slug){
324
- if ($('div.user_presence[slug=' + slug + ']').length > 0){
325
- $('div.user_presence[slug=' + slug + ']').hide();
326
- if(cacheConnectedUsers.indexOf(slug)==-1){
327
- cacheConnectedUsers.push(slug);
329
+ function loadConnectingDiv(){
330
+ $("#chat_partial").html($("#chat_connecting").html());
331
+ }
332
+
333
+ function loadDisconnectionDiv(){
334
+ $("#chat_partial").html(modifyChatPartialIfMainBox($("#chat_connection_off").html()));
335
+
336
+ $('.connectChatButton').bind('click', function () {
337
+ if (requestConnectToChat()){
338
+ if (authByCookie()) {
339
+ connectToChat(user_jid,cookie,null);
340
+ } else {
341
+ connectToChat(user_jid,null,$('#user_password').val());
342
+ }
328
343
  }
329
- updateMainChatBoxAfterUserDisconnect();
344
+ });
345
+
346
+ if (authByCookie()){
347
+ $("#chat_partial #passwordFormChat").hide();
348
+ } else {
349
+ //Authentication by password
330
350
 
331
- //Last user disconnected?
332
- if (getAllConnectedSlugs().length ==0){
333
- if($(".users_connected p.zero_users_connected").length > 0){
334
- $(".users_connected p.zero_users_connected").show();
335
- } else {
336
- var msg = I18n.t('chat.zerousers');
337
- $(".users_connected").append('<p class="zero_users_connected">' + msg + '</p>')
338
- }
351
+ $('.storePass').bind('click', function () {
352
+ storePassword();
353
+ });
354
+
355
+ if ((window.sessionStorage) && (sessionStorage.getItem("ss_user_pass") != null)) {
356
+ $("#chat_partial #passwordFormChat").hide()
357
+ } else {
358
+ $("#chat_partial #passwordFormChat").show();
339
359
  }
340
360
  }
341
361
  }
342
362
 
363
+
364
+ function loadWidgetsDiv(data){
365
+ $("#chat_partial").html(modifyChatPartialIfMainBox($("#chat_widgets").html()));
366
+ $("#chat_partial").append(data);
367
+ fillSearchContactSelect();
368
+ settingSearchContactFunctions();
369
+ }
370
+
371
+ function fillSearchContactSelect(){
372
+ $("#chat_partial #search_chat_contact").children().remove()
373
+ $("#chat_partial #search_chat_contact").append('<option value=""></option>')
374
+ $.each(getAllSlugs(), function(index, value) {
375
+ $("#chat_partial #search_chat_contact").append('<option value=' + value + '>' + getNameFromSlug(value) + '</option>')
376
+ });
377
+ }
378
+
379
+
380
+
381
+ /////////////////////
382
+ // Connection Box Management
383
+ /////////////////////
384
+
385
+ function hideConnectionBoxesFromDisconnectedSlugs(){
386
+ $('div.user_presence[slug][connected="false"]').hide();
387
+ }
388
+
389
+ function hideConnectionBoxFromSlug(slug){
390
+ $('div.user_presence[slug=' + slug + ']').attr("connected","false");
391
+ $('div.user_presence[slug=' + slug + ']').hide();
392
+ }
393
+
343
394
  function showConnectionBoxFromSlug(slug){
344
- if ($('div.user_presence[slug=' + slug + ']').length > 0){
345
- if (!($('div.user_presence[slug=' + slug + ']').is(":visible"))){
346
- $('div.user_presence[slug=' + slug + ']').show();
347
- $(".users_connected p.zero_users_connected").hide();
395
+ $('div.user_presence[slug=' + slug + ']').attr("connected","true");
396
+ $('div.user_presence[slug=' + slug + ']').show();
397
+ }
398
+
399
+ function updateInterfaceAfterPresenceStanza(slug,available){
400
+ if(available){
401
+ showConnectionBoxFromSlug(slug);
402
+ hideChatNotificationForSlug(slug);
403
+ } else {
404
+ hideConnectionBoxFromSlug(slug);
405
+ showOfflineChatNotificationForSlug(slug);
406
+ }
407
+ updateMainChatBoxAfterConnectionBoxChanges();
408
+ checkForZeroUsersConnected();
409
+ }
410
+
411
+ function checkForZeroUsersConnected(){
412
+ if (getConnectedSlugsLength() == 0){
413
+ if($(".users_connected p.zero_users_connected").length > 0){
414
+ $(".users_connected p.zero_users_connected").show();
415
+ } else {
416
+ var msg = I18n.t('chat.zerousers');
417
+ $(".users_connected").append('<p class="zero_users_connected">' + msg + '</p>')
348
418
  }
349
- }
419
+ } else {
420
+ $(".users_connected p.zero_users_connected").hide();
421
+ }
350
422
  }
351
423
 
424
+
425
+ ////////////////////
426
+ // Set Status Interface
427
+ ////////////////////
428
+
352
429
  function setUserIconStatus(slug, status){
353
430
  if (status in statusIcons) {
354
431
  var iconName = statusIcons[status];
355
432
  var $img_status = $('img.presence_status');
356
433
  var path = '<%=image_path("status")%>';
357
- connectionBox = getConnectionBoxFromSlug(slug);
434
+ var connectionBox = getConnectionBoxFromSlug(slug);
358
435
  $(connectionBox).find($img_status).attr("src", path + "/" + iconName + ".png")
359
436
  }
360
437
  }
361
438
 
439
+
440
+ //////////////////////
441
+ //Getters and Setters
442
+ //////////////////////
443
+
444
+ function getConnectionBoxFromSlug(slug){
445
+ if ($('div.user_presence[slug=' + slug + ']').length > 0){
446
+ return ($('div.user_presence[slug=' + slug + ']'))[0];
447
+ } else {
448
+ return null;
449
+ }
450
+ }
451
+
452
+ function isSlugChatConnected(slug){
453
+ return $('div.user_presence[slug=' + slug + ']').attr("connected")=="true";
454
+ }
455
+
456
+ function existsSlugChatBox(slug){
457
+ return getConnectionBoxFromSlug(slug)!=null;
458
+ }
459
+
460
+ function getConnectedSlugsLength(){
461
+ return $('div.user_presence[slug][connected="true"]').length;
462
+ }
463
+
464
+ function getAllSlugsLength(){
465
+ return $('div.user_presence[slug]').length;
466
+ }
467
+
468
+ function getDisconnectedSlugsLength(){
469
+ return $('div.user_presence[slug][connected="false"]').length;
470
+ }
471
+
472
+ function getAllSlugs(){
473
+ return getAllSlugsByChatConnectedState()[2];
474
+ }
475
+
362
476
  function getAllConnectedSlugs(){
363
477
  return getAllSlugsByChatConnectedState()[0];
364
478
  }
@@ -371,9 +485,9 @@ function getAllSlugsByChatConnectedState(){
371
485
  var onlineSlugs=[];
372
486
  var offlineSlugs=[];
373
487
  var allSlugs=[];
374
- connectionBoxes = $('div.user_presence[slug]');
488
+ var connectionBoxes = $('div.user_presence[slug]');
375
489
  $.each(connectionBoxes, function(index, value) {
376
- if($(value).css("display")!="none"){
490
+ if($(value).attr("connected")=="true"){
377
491
  onlineSlugs.push($(value).attr("slug"))
378
492
  } else {
379
493
  offlineSlugs.push($(value).attr("slug"))
@@ -383,6 +497,8 @@ function getAllSlugsByChatConnectedState(){
383
497
  return [onlineSlugs,offlineSlugs,allSlugs]
384
498
  }
385
499
 
500
+
501
+
386
502
  ////////////////////
387
503
  //Insert received message in chatbox
388
504
  ////////////////////
@@ -394,17 +510,20 @@ function putReceivedMessageOnChatWindow(from_jid,from_slug,body,msgID){
394
510
  return;
395
511
  }
396
512
 
397
- //Check for from_slug name and connectionBox visibility
398
- if (typeof($('div.user_presence[slug=' + from_slug + ']').attr('name')) == 'undefined') {
513
+ //Check slug connection and slugs connectionBox
514
+ if (existsSlugChatBox(from_slug)) {
399
515
  //No connectionBox for this user!
400
- var from_name = from_slug;
401
- refreshChatWindow();
516
+ var from_name = getNameFromSlug(from_slug);
517
+ if(! isAdminSlug(from_slug)){
518
+ refreshChatWindow();
519
+ }
402
520
  } else {
403
- showConnectionBoxFromSlug(from_slug);
521
+ if(! isSlugChatConnected(from_slug)){
522
+ updateInterfaceAfterPresenceStanza(from_slug,"true");
523
+ }
404
524
  var from_name = $('div.user_presence[slug=' + from_slug + ']').attr('name');
405
525
  }
406
526
 
407
-
408
527
  //Create or toggle from_slug's chatBox.
409
528
  if (createChatBox(from_slug, from_name, from_jid, user_name, user_jid)) {
410
529
  } else {
@@ -436,15 +555,16 @@ function putReceivedMessageOnChatWindow(from_jid,from_slug,body,msgID){
436
555
  //Notifications on chat Window
437
556
  ////////////////////
438
557
 
439
- function showChatNotification(notification,msg){
440
- notification.html("<p class==\"ui-chatbox-notify-text\">" + msg + "</p>");
441
- notification.css("visibility","visible");
558
+ function showChatNotification(notification,type,msg){
559
+ notification.html("<p notification_type=\"" + type + "\" class=\"ui-chatbox-notify-text\">" + msg + "</p>");
560
+ notification.css("display","block");
561
+ notification.css("visibility","visible");
442
562
  notification.fadeIn();
443
563
  }
444
564
 
445
- function showChatNotificationForSlug(slug,msg){
565
+ function showChatNotificationForSlug(slug,type,msg){
446
566
  var notification = $("#" + slug).parent().find("div.ui-chatbox-notify");
447
- showChatNotification(notification,msg);
567
+ showChatNotification(notification,type,msg);
448
568
  }
449
569
 
450
570
  function showOfflineChatNotificationForSlug(slug){
@@ -452,13 +572,14 @@ function showOfflineChatNotificationForSlug(slug){
452
572
  if(slug_chat_box!=null){
453
573
  var name = slug_chat_box.attr("name")
454
574
  var msg = name + ' ' + I18n.t('chat.notify.guestOffline');
455
- showChatNotificationForSlug(slug,msg);
575
+ showChatNotificationForSlug(slug,"guestOffline",msg);
456
576
  }
457
577
  }
458
578
 
459
579
  function hideChatNotification(notification){
460
580
  notification.fadeOut();
461
- notification.css("visibility","hidden");
581
+ notification.css("display","none");
582
+ notification.css("visibility","hidden");
462
583
  }
463
584
 
464
585
  function hideChatNotificationForSlug(slug){
@@ -469,7 +590,7 @@ function hideChatNotificationForSlug(slug){
469
590
  function notifyWhenUsersDisconnect(){
470
591
  var notification = $("div.ui-chatbox-notify");
471
592
  var msg = I18n.t('chat.notify.offline');
472
- showChatNotification(notification,msg);
593
+ showChatNotification(notification,"userOffline",msg);
473
594
  }
474
595
 
475
596
  function hideAllNotifications(){
@@ -496,8 +617,9 @@ function updateAllNotifications(){
496
617
 
497
618
  function updateConnectedUsersOfMainChatBox(){
498
619
  if(mainChatBox!=null){
499
- if(isStropheConnected()){
500
- var connectedUsers = getAllConnectedSlugs().length;
620
+ var stropheConnectedAndOnlineStatus = ((isStropheConnected()) && (userStatus!="offline") && (!disconnectionFlag));
621
+ if(stropheConnectedAndOnlineStatus){
622
+ var connectedUsers = getConnectedSlugsLength();
501
623
  changeMainChatBoxHeaderTitle( I18n.t('chat.title') + " (" + connectedUsers + ")");
502
624
  changeMainChatBoxHeight(getChatBoxHeightRequiredForConnectionBoxes());
503
625
  } else {
@@ -510,8 +632,7 @@ function updateConnectedUsersOfMainChatBox(){
510
632
  }
511
633
  }
512
634
 
513
-
514
- function updateMainChatBoxAfterUserDisconnect(){
635
+ function updateMainChatBoxAfterConnectionBoxChanges(){
515
636
  changeMainChatBoxHeight(getChatBoxHeightRequiredForConnectionBoxes());
516
637
  updateConnectedUsersOfMainChatBox();
517
638
  }