//////////////////// //Chat Window Manager functions //////////////////// //////////////////// //ChatBoxes Creation //////////////////// var nBox = 0; var maxBox = 5; var chatBoxWidth = 230; var chatBoxHeight = 180; var videoBoxHeight = 145; var visibleChatBoxes = new Array(); var offsetForFlowBox = 0; var chatBoxSeparation = chatBoxWidth+12; //Create chatbox for new conversations //Open chatbox for old conversations function createChatBox(guest_slug,isGroup){ var guest_name = getNameFromSlug(guest_slug) if(isGroup){ var chatBoxTitle = I18n.t("chat.muc.group", {group: guest_name}) } else { var chatBoxTitle = guest_name; } //Box Variable name = getChatVariableFromSlug(guest_slug) if (typeof window[getChatVariableFromSlug(guest_slug)] == 'undefined') { //Add div with id = guest_slug $("#chat_divs").append("
") //Offset Management for new box boxParams = getBoxParams(); var offset = boxParams[0]; var position = boxParams[1]; window[getChatVariableFromSlug(guest_slug)] = $("#" + guest_slug).chatbox({id: user_name, user:{key : "value"}, hidden: false, offset: offset, // relative to right edge of the browser window width: chatBoxWidth, // width of the chatbox height: chatBoxHeight, // height of the chatbox video: 0, //height of the videoBox title : chatBoxTitle, position: position, priority: visibleChatBoxes.length+1, groupBox: isGroup, boxClosed: function(id) { closeChatBox(guest_slug) }, messageSent: function(id, user, msg){ sendChatMessage(guest_slug, msg) }}); visibleChatBoxes[position-1] = window[getChatVariableFromSlug(guest_slug)]; return true; } else { if (visibleChatBoxes.indexOf(window[getChatVariableFromSlug(guest_slug)]) == -1) { //Offset Management for old box boxParams = getBoxParams(); var offset = boxParams[0]; var position = boxParams[1]; window[getChatVariableFromSlug(guest_slug)].chatbox("option", "offset", offset); window[getChatVariableFromSlug(guest_slug)].chatbox("option", "position", position); visibleChatBoxes[position-1] = window[getChatVariableFromSlug(guest_slug)]; } window[getChatVariableFromSlug(guest_slug)].chatbox("option", "hidden", false); window[getChatVariableFromSlug(guest_slug)].parent().toggle(true) return false; } } function getBoxParams(){ var boxParams = new Array(2); if (nBox==maxBox){ //Select box to replaced replaced = visibleChatBoxes[getBoxIndexToReplace()]; replaced.chatbox("option", "hidden", true) index = visibleChatBoxes.indexOf(replaced); boxParams[0] = replaced.chatbox("option", "offset") boxParams[1] = replaced.chatbox("option", "position") } else { nBox++; boxParams[0] = (nBox-1)*(chatBoxSeparation); if((nBox!=1)&&(mainChatBox!=null)){ boxParams[0] = boxParams[0] - offsetForFlowBox; } boxParams[1] = nBox; } return boxParams } function closeChatBox(guest_slug){ var position = getChatBoxForSlug(guest_slug).chatbox("option", "position"); for (i=position+1;i mainChatBoxMaxHeight){ //overflow = true; height = mainChatBoxMaxHeight; $(mainChatBox).css('overflow-y','visible'); mainChatBox.chatbox("option", "offset","5px") mainChatBox.chatbox("option", "width", mainChatBoxWidth + 5) } else { $(mainChatBox).css('overflow-y','hidden'); mainChatBox.chatbox("option", "offset","0px") mainChatBox.chatbox("option", "width",mainChatBoxWidth) height = Math.max(height,mainChatBoxMinHeight) } window[getChatVariableFromSlug(chatSlugId)].css("height", height); } } function getChatBoxHeightRequiredForConnectionBoxes(){ if(mainChatBox!=null){ var desiredHeight = mainChatBoxaddonsHeight + Math.ceil(getAllConnectedSlugs().length/connectionBoxesForFile) * heightForConnectionBoxFile; return desiredHeight; } else { return null; } } //////////////////// //Box replacement //////////////////// function getBoxIndexToReplace(){ tmp = visibleChatBoxes[0]; for (i=0;i tmp.chatbox("option", "priority")) { tmp = visibleChatBoxes[i]; } } return visibleChatBoxes.indexOf(tmp); } function rotatePriority(guest_slug){ priority = $("#" + guest_slug).chatbox("option", "priority") if(priority>1){ for (i=0;i 0) { return pubDiv } else { return null; } } function setVideoBoxContent(slug,embed){ var videoBox = getVideoBoxForSlug(slug); if(videoBox!=null){ videoBox.html(embed); } } function addVideoBoxContent(slug,embed){ var videoBox = getVideoBoxForSlug(slug); if(videoBox!=null){ videoBox.append(embed); } } function showVideoBox(chatBox){ chatBox.chatbox("option", "video",videoBoxHeight); } function hideVideoBox(chatBox){ chatBox.chatbox("option", "video", 0); } //Function called from JQuery UI Plugin function toggleVideoBox(uiElement){ var slug = $(uiElement.element).attr("id"); clickVideoChatButton(slug); } //Function called from JQuery UI Plugin function toggleVideoBoxChange(uiElement){ var slug = $(uiElement.element).attr("id"); clickVideoChangeChatButton(slug); } function toggleVideoBoxForSlug(slug,force){ var aux; var chatBox = getChatBoxForSlug(slug); if(chatBox==null) { return null; } if(typeof force != 'undefined'){ aux = force; } else { if (chatBox.chatbox("option", "video")==0){ aux=true; } else { aux=false; } } if (aux){ //Show showVideoBox(chatBox); return true; } else { //Hide hideVideoBox(chatBox); return false; } } ///////// //Getters ///////// function getChatVariableFromSlug(slug){ return "Slug_" + slug; } function getSlugFromChatVariable(variable){ return variable.split("_")[1]; } function getVisibleChatBoxes(){ for(i=0; i