//= require jquery.watermark // //////////////////// //Reconnect button interface functions //////////////////// var connectButtonTimer; var periodBetweenAttempts=15; //(seg) var connectButtonTimerCounter=periodBetweenAttempts+1; function connectButtonTimerFunction(){ connectButtonTimerCounter++; if (connectButtonTimerCounter > (periodBetweenAttempts-1)) { clearTimeout(connectButtonTimer); changeChatHeaderTitle(I18n.t('chat.disconnected')) } } function requestConnectToChat(){ if (connectButtonTimerCounter > (periodBetweenAttempts-1)) { connectButtonTimerCounter=0; connectButtonTimer = setInterval("connectButtonTimerFunction()", 1000) changeChatHeaderTitle(I18n.t('chat.connecting')) return true } else { return false } } function changeChatHeaderTitle(msg){ if(mainChatBox==null){ $("#chat_header_title").html(msg) } else { changeMainChatBoxHeaderTitle(msg); } } //////////////////// //Chat interface: Setting Functions //////////////////// var focusSearchContactsFlag=false; var changeSelectContactValueFlag = false; function settingStatusSelector(){ //JQuery DropdwanStatus $(".dropdown dt a").click(function(event) { event.preventDefault(); $(".dropdown dd ul").toggle(); if($(".dropdown dd ul").is(":visible")){ setStatusWidgetTitle("default"); } else { setStatusWidgetTitle(userStatus); } restartAwayTimer(); }); $(".dropdown dd ul li a.option").click(function(event) { event.preventDefault(); userStatus = $(this).find("span.value").html(); if(userStatus == "offline"){ disconnectStrophe(); } else { sendStatus(userStatus); } $(".dropdown dd ul").hide(); }); $(document).bind('click', function(e) { var $clicked = $(e.target); if (! $clicked.parents().hasClass("dropdown")){ //Click outside the select... $(".dropdown dd ul").hide(); setStatusWidgetTitle(userStatus); } }); } function settingChatBoxFunctions(){ $("div.user_presence").click(function(event, ui){ var guest_slug = $(this).attr("slug"); createBuddyChatBox(guest_slug) }); //Hide tooltips on mouseleave $("div.user_presence").mouseleave(function(e){ var div = $(this); $.each($(".tooltip:visible"), function(index, value) { if ( $($(".tooltip:visible")[0]).html() == $(div).attr("name") ){ $($(".tooltip:visible")[index]).hide(); } }); }); } function settingTooltips(){ if (mainChatBox == null) { //Enabling default tooltips $(".user_presence a[title]").tooltip(); } else { //Enabling tooltips with center left position //Changing Tooltip CSS class by JQuery var ss = document.styleSheets; for (var i=0; i 9){ changeMainChatBoxHeight(mainChatBoxHeightWhileSearchContacts); } else { var mainChatBoxMinRequiredHeight= mainChatBoxaddonsHeight + 20 + nItems * 19; changeMainChatBoxHeight(mainChatBoxMinRequiredHeight); } $(".users_connected").hide(); } else { changeMainChatBoxHeight(getChatBoxHeightRequiredForConnectionBoxes()); $(".users_connected").show(); } } function setStatusWidgetTitle(status){ if((status in sstreamChatStatus)){ status = sstreamChatStatus[status]; } if ($(".dropdown dt a span").length == 0){ return; } if(status=="default"){ var defaultTitle = I18n.t('chat.status.choose') $(".dropdown dt a span").html(defaultTitle); return; } if(status=="offline"){ var text = $("#" + status).html(); $(".dropdown dt a span").html(text); return; } if ((status in statusIcons)&&($("#" + statusIcons[status]).length > 0)) { var text = $("#" + statusIcons[status]).html(); $(".dropdown dt a span").html(text); } } //////////////////// //Away Timer Management //////////////////// function awayTimerFunction(){ awayCounter++; if (awayCounter > (awayTime/awayTimerPeriod)){ if ((userStatus != "dnd")&&(userStatus != "away")) { userStatus = "autoaway"; sendStatus(userStatus); } clearTimeout(awayTimer); } } function autochangeStatusIfAutoAway(){ if (userStatus == "autoaway"){ userStatus = "available"; sendStatus(userStatus); } } function restartAwayTimer(){ if (awayCounter > (awayTime/awayTimerPeriod)){ awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod); autochangeStatusIfAutoAway(); } awayCounter = 0; } //////////////////// //Update chatWindow Management //////////////////// function updateChatWindow(){ timerCounter=0; log("updateChatWindow()"); log("Connected " + isUserConnected()); if(! isUserConnected()){ loadDisconnectionDiv(); updateConnectedUsersOfMainChatBox(); return; } $.post("/chatWindow", { }, function(data){ //Prevent tooltips $(".tooltip").hide() loadWidgetsDiv(data); hideConnectionBoxesFromDisconnectedSlugs(); setAllUserFunctions(); updateConnectedUsersOfMainChatBox(); checkForZeroUsersConnected(); if (isStropheConnected()) { if (afterNewConnectionFlag){ afterNewConnectionFlag = false; if(afterFirstConnectionFlag){ restoreChatData(); if(typeof current_group_slug != 'undefined') { accessRoom(current_group_slug,false); } afterFirstConnectionFlag = false; } else { updateAllNotifications(); //Rejoin rooms $.each(getAllSlugsWithVisibleGroupBoxes(), function(index, value) { accessRoom(value,$(value).is(":visible")) }); } } } },'html'); } ////////////// //Divs Load ////////////// function loadConnectingDiv(){ $("#chat_partial").html($("#chat_connecting").html()); } function loadDisconnectionDiv(){ $("#chat_partial").html(modifyChatPartialIfMainBox($("#chat_connection_off").html())); $('.connectChatButton').bind('click', function () { if (requestConnectToChat()){ if (authByCookie()) { connectToChat(user_jid,cookie,null); } else { connectToChat(user_jid,null,$('#user_password').val()); } } }); if (authByCookie()){ $("#chat_partial #passwordFormChat").hide(); } else { //Authentication by password $('.storePass').bind('click', function () { storePassword(); }); if ((window.sessionStorage) && (sessionStorage.getItem("ss_user_pass") != null)) { $("#chat_partial #passwordFormChat").hide() } else { $("#chat_partial #passwordFormChat").show(); } } } function loadWidgetsDiv(data){ $("#chat_partial").html(modifyChatPartialIfMainBox($("#chat_widgets").html())); $("#chat_partial").append(data); fillSearchContactSelect(); settingSearchContactFunctions(); } function fillSearchContactSelect(){ $("#chat_partial #search_chat_contact").children().remove() $("#chat_partial #search_chat_contact").append('') $.each(getAllSlugs(), function(index, value) { $("#chat_partial #search_chat_contact").append('') }); } function updateInterfaceAfterUserDisconnect(){ updateNotificationsAfterUserDisconnect(); $.each(getAllSlugsWithVisibleVideoBoxes(), function(index, value) { closeVideoSession(value); }); } ///////////////////// // Connection Box Management ///////////////////// function hideConnectionBoxesFromDisconnectedSlugs(){ $('div.user_presence[slug][connected="false"]').hide(); } function hideConnectionBoxFromSlug(slug){ $('div.user_presence[slug=' + slug + ']').attr("connected","false"); $('div.user_presence[slug=' + slug + ']').hide(); } function showConnectionBoxFromSlug(slug){ $('div.user_presence[slug=' + slug + ']').attr("connected","true"); $('div.user_presence[slug=' + slug + ']').show(); } function updateInterfaceAfterPresenceStanza(slug,available){ if(available){ showConnectionBoxFromSlug(slug); hideChatNotificationForSlug(slug); } else { hideConnectionBoxFromSlug(slug); showOfflineChatNotificationForSlug(slug); closeVideoSession(slug); } updateMainChatBoxAfterConnectionBoxChanges(); checkForZeroUsersConnected(); } function checkForZeroUsersConnected(){ if (getConnectedSlugsLength() == 0){ if($(".users_connected p.zero_users_connected").length > 0){ $(".users_connected p.zero_users_connected").show(); } else { var msg = I18n.t('chat.zerousers'); $(".users_connected").append('

' + msg + '

') } } else { $(".users_connected p.zero_users_connected").hide(); } } //////////////////// // Set Status Interface //////////////////// function setUserIconStatus(slug, status){ if (status in statusIcons) { var iconName = statusIcons[status]; var $img_status = $('img.presence_status'); var path = '<%=image_path("status")%>'; var connectionBox = getConnectionBoxFromSlug(slug); $(connectionBox).find($img_status).attr("src", path + "/" + iconName + ".png") } } ////////////////////// //Getters and Setters ////////////////////// function getConnectionBoxFromSlug(slug){ if ($('div.user_presence[slug=' + slug + ']').length > 0){ return ($('div.user_presence[slug=' + slug + ']'))[0]; } else { return null; } } function isSlugChatConnected(slug){ return $('div.user_presence[slug=' + slug + ']').attr("connected")=="true"; } function existsSlugChatBox(slug){ return getChatBoxForSlug(slug)!=null; } function getConnectedSlugsLength(){ return $('div.user_presence[slug][connected="true"]').length; } function getAllSlugsLength(){ return $('div.user_presence[slug]').length; } function getDisconnectedSlugsLength(){ return $('div.user_presence[slug][connected="false"]').length; } function getAllSlugs(){ return getAllSlugsByChatConnectedState()[2]; } function getAllConnectedSlugs(){ return getAllSlugsByChatConnectedState()[0]; } function getAllDisconnectedSlugs(){ return getAllSlugsByChatConnectedState()[1]; } function getAllSlugsByChatConnectedState(){ var onlineSlugs=[]; var offlineSlugs=[]; var allSlugs=[]; var connectionBoxes = $('div.user_presence[slug]'); $.each(connectionBoxes, function(index, value) { if($(value).attr("connected")=="true"){ onlineSlugs.push($(value).attr("slug")) } else { offlineSlugs.push($(value).attr("slug")) } allSlugs.push($(value).attr("slug")) }); return [onlineSlugs,offlineSlugs,allSlugs] } //////////////////// //Insert received message in chatbox //////////////////// function afterReceivedChatMessage(from_slug,msg,msgID){ //Antiflood control if (antifloodControl(from_slug,msg,msgID)){ return; } var from_name = getNameFromSlug(from_slug) createBuddyChatBox(from_slug) writeReceivedMessageOnChatWindow(from_name,from_slug,msg) } function afterReceivedGroupChatMessage(room_nick_jid,msg){ var from_slug = getSlugFromJid(room_nick_jid) var from_name = getNickFromChatRoomJid(room_nick_jid) if(!(existsSlugChatBox(from_slug))){ createGroupChatBox(from_slug,true) } writeReceivedMessageOnChatWindow(from_name,from_slug,msg) } function writeReceivedMessageOnChatWindow(from_name,from_slug,msg){ //Parse content before show it. var content = getParsedContent(msg, false) var headerMessage = getParsedName(from_name,false); //Write message in chatBox. getChatBoxForSlug(from_slug).chatbox("option", "boxManager").addMsg(headerMessage, content); //Rotate chatBoxes priority. rotatePriority(from_slug); //Check for start blinkTitle. blinkTitleOnMessage(from_name); //Check for play sound if (mustPlaySoundForChatWindow(getChatBoxForSlug(from_slug))) { playSound("onMessageAudio"); } } //////////////////// //Update connected users of MainChatBox //////////////////// function updateConnectedUsersOfMainChatBox(){ if(mainChatBox!=null){ if(isUserConnected()){ var connectedUsers = getConnectedSlugsLength(); changeMainChatBoxHeaderTitle( I18n.t('chat.title') + " (" + connectedUsers + ")"); changeMainChatBoxHeight(getChatBoxHeightRequiredForConnectionBoxes()); } else { if(afterFirstConnectionFlag){ changeChatHeaderTitle(I18n.t('chat.connecting')) } else { changeChatHeaderTitle(I18n.t('chat.disconnected')) } } } } function updateMainChatBoxAfterConnectionBoxChanges(){ changeMainChatBoxHeight(getChatBoxHeightRequiredForConnectionBoxes()); updateConnectedUsersOfMainChatBox(); }