////////////////////
//WINDOW MANAGER MODULE
////////////////////
PRESENCE.WINDOW = (function(P,$,undefined){
var init = function(){ }
////////////////////
//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
var createChatBox = function(guest_slug,isGroup){
var guest_name = PRESENCE.XMPPClient.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) {
PRESENCE.WINDOW.closeChatBox(guest_slug)
},
messageSent: function(id, user, msg){
PRESENCE.XMPPClient.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;
}
}
var getBoxParams = function(){
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
}
var closeChatBox = function(guest_slug){
var position = getChatBoxForSlug(guest_slug).chatbox("option", "position");
for (i=position+1;i').append(chatPartial);
$(p).find(".header").remove();
$(p).find(".dropdown dd ul").css("min-width",147);
return $(p);
}
return chatPartial;
}
var changeMainChatBoxHeaderTitle = function(title){
if (mainChatBox != null) {
$($(mainChatBox.parent().parent()).find(".ui-chatbox-titlebar").find("span")[0]).html(title);
}
}
var changeMainChatBoxHeight = function(height){
if (mainChatBox != null) {
if(($("#chat_partial #search_chat_contact_flexselect").is(":focus"))&&(! (focusSearchContactsFlag))){
return;
} else {
focusSearchContactsFlag=false;
}
if(height > 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);
}
}
var getChatBoxHeightRequiredForConnectionBoxes = function(){
if(mainChatBox!=null){
var desiredHeight = mainChatBoxaddonsHeight + Math.ceil(PRESENCE.UIMANAGER.getAllConnectedSlugs().length/connectionBoxesForFile) * heightForConnectionBoxFile;
return desiredHeight;
} else {
return null;
}
}
////////////////////
//Box replacement
////////////////////
var getBoxIndexToReplace = function(){
tmp = visibleChatBoxes[0];
for (i=0;i tmp.chatbox("option", "priority")) {
tmp = visibleChatBoxes[i];
}
}
return visibleChatBoxes.indexOf(tmp);
}
var rotatePriority = function(guest_slug){
priority = $("#" + guest_slug).chatbox("option", "priority")
if(priority>1){
for (i=0;i 0) {
return pubDiv
} else {
return null;
}
}
var setVideoBoxContent = function(slug,embed){
var videoBox = getVideoBoxForSlug(slug);
if(videoBox!=null){
videoBox.html(embed);
}
}
var addVideoBoxContent = function(slug,embed){
var videoBox = getVideoBoxForSlug(slug);
if(videoBox!=null){
videoBox.append(embed);
}
}
var showVideoBox = function(chatBox){
chatBox.chatbox("option", "video",videoBoxHeight);
}
var hideVideoBox = function(chatBox){
chatBox.chatbox("option", "video", 0);
}
//Function called from JQuery UI Plugin
var toggleVideoBox = function(uiElement){
var slug = $(uiElement.element).attr("id");
PRESENCE.VIDEOCHAT.clickVideoChatButton(slug);
}
//Function called from JQuery UI Plugin
var toggleVideoBoxChange = function(uiElement){
var slug = $(uiElement.element).attr("id");
PRESENCE.VIDEOCHAT.clickVideoChangeChatButton(slug);
}
var toggleVideoBoxForSlug = function(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
/////////
var getChatVariableFromSlug = function(slug){
return "Slug_" + slug;
}
var getSlugFromChatVariable = function(variable){
return variable.split("_")[1];
}
var getVisibleChatBoxes = function(){
var tmp = new Array();
for(i=0; i