///////////////////////////////////
// ajax im 3.41 //
// AJAX Instant Messenger //
// Copyright (c) 2006-2008 //
// http://www.ajaxim.com/ //
// Do not remove this notice //
///////////////////////////////////
/**
* Class to handle buddylist events
*
* @author Joshua Gross
**/
var Buddylist = {
buddyListWin: null, // buddy list window
/**
* Process the creation of the buddy list window
*
* @author Joshua Gross
**/
create: function() {
Event.observe(window, 'resize', Buddylist.fixBuddyList);
if(!$('bl')) {
this.buddyListWin = new Window({id: 'bl', className: "dialog", width: 210, height: (Browser.height() - 60), zIndex: 100, resizable: true, title: Languages.get('buddyList'), draggable: true, closable: false, maximizable: false, detachable: false, minWidth: 205, minHeight: 150, showEffectOptions: {duration: 0}, hideEffectOptions: {duration: 0}});
this.buddyListWin.setConstraint(true, {left: 0, right: 0, top: 0, bottom: 0});
}
this.buddyListWin.getContent().innerHTML = '
';
Event.observe(this.buddyListWin.getContent(), 'contextmenu', function() { return false; });
$('bl_minimize').setStyle({left: (this.buddyListWin.getSize()['width'] - 21) + 'px'});
this.sizeBuddyList();
this.buddyListWin.showCenter(false, (((Browser.height()-40) / 2) - (this.buddyListWin.getSize()['height'] / 2)), (buddyListLoc == 0 ? 10 : (Browser.width() - this.buddyListWin.getSize()['width'] - 10)));
this.buddyListWin.toFront();
this.list = {};
this.listObjects = {};
this.blocked = {};
},
/**
* Destroy the buddy list window
*
* @author Joshua Gross
**/
destroy: function() {
this.buddyListWin.destroy();
},
/**
* Reposition buddylist
*
* @author Joshua Gross
**/
fixBuddyList: function() {
if(Buddylist.buddyListWin.isVisible()) {
Buddylist.buddyListWin.setSize(210, (Browser.height() - 60));
Buddylist.buddyListWin.setLocation((((Browser.height()-40) / 2) - (Buddylist.buddyListWin.getSize()['height'] / 2)), (buddyListLoc == 0 ? 10 : (Browser.width() - Buddylist.buddyListWin.getSize()['width'] - 10)));
Buddylist.sizeBuddyList();
}
},
/**
* Resize buddylist
*
* @author Joshua Gross
**/
sizeBuddyList: function() {
$('blContainer').setStyle({width: (this.buddyListWin.getSize()['width'] - 8) + 'px',
height: (this.buddyListWin.getSize()['height'] - 95) + 'px'});
$('blBottomToolbar').setStyle({width: (this.buddyListWin.getSize()['width'] - 8) + 'px',
top: (this.buddyListWin.getSize()['height'] - 7) + 'px'});
$('bl_minimize').setStyle({left: (this.buddyListWin.getSize()['width'] - 21) + 'px'});
},
/**
* Add new buddy to the list
*
* @arguments
* username - user's username
* groupname - group the user is in
*
* @author Joshua Gross
**/
addNewBuddy: function(username, groupname) {
username = username.toLowerCase();
if(!inArray(Buddylist.list, username) && (!Buddylist.listObjects[username] || !$(Buddylist.listObjects[username].obj))) {
var xhConn = new XHConn();
xhConn.connect(pingTo, "POST", "call=isuser&username="+username, function(xh) {
if(xh.responseText == 'not_exists') {
$('newbuddy_error_msg').innerHTML = Languages.get('noSuchUser');
} else {
if(!$(groupname.replace(/\s/, '_') + '_group')) {
Buddylist.addGroup(groupname);
Buddylist.list[groupname] = [];
}
Buddylist.addBuddy(username, 'Offline', 'none');
if(parseInt(xh.responseText) == 0) {
Buddylist.moveBuddy(username, 'Offline');
$(Buddylist.listObjects[username].img).src = 'themes/' + theme + '/offline.png';
} else if(parseInt(xh.responseText) == 2) {
Buddylist.moveBuddy(username, groupname);
$(Buddylist.listObjects[username].img).src = 'themes/' + theme + '/away.png';
} else {
Buddylist.moveBuddy(username, groupname);
$(Buddylist.listObjects[username].img).src = 'themes/' + theme + '/online.png';
}
Buddylist.list[groupname][username] = {'username': username, 'blocked': false, 'status': parseInt(xh.responseText)};
var xhConn = new XHConn();
xhConn.connect(pingTo, "POST", "call=addbuddy&username="+username+'&group='+groupname, null);
Windows.close('newBuddy');
}
});
} else {
$('newbuddy_error_msg').innerHTML = Languages.get('alreadyOnBuddylist');
}
},
/**
* Add buddy to the list
*
* @arguments
* username - username of the buddy we're adding
* groupname - the group the buddy is in
* buddyicon - the buddy's buddyiocn
*
* @author Joshua Gross
* update Benjamin Hutchins
**/
addBuddy: function(username, groupname, buddyicon) {
if(!$(groupname.replace(/\s/, '_') + '_group')) this.addGroup(groupname);
var groupList = $(groupname.replace(/\s/, '_') + '_group');
var iconsrc = (buddyicon=='none'?defaultIcon:pathToIcons+username+'.'+buddyicon);
var randId = Math.floor(Math.random()*1000000000);
while($(randId + '_blItem'))
randId = Math.floor(Math.random()*1000000000);
groupList.innerHTML += '' + (useIcons&&showInList?(defaultIcon==""&&buddyicon=='none'?'':'
'):'') + '
'+username+'';
Buddylist.listObjects[username] = {};
Buddylist.listObjects[username].obj = randId + '_blItem';
Buddylist.listObjects[username].img = randId + '_blImg';
Buddylist.listObjects[username].icon = buddyicon;
Buddylist.listObjects[username].group = groupname;
$(Buddylist.listObjects[username].obj).setStyle({listStyleType: 'none'});
},
/**
* Move a buddy from one group to another
*
* @arguments
* username - username of the buddy we're moving
* groupname - new group name
*
* @author Joshua Gross
**/
moveBuddy: function(username, groupname) {
if(groupname == null) return;
if($(Buddylist.listObjects[username].obj).parentNode == $(groupname.replace(/\s/, '_') + '_group')) return;
if(!$(groupname.replace(/\s/, '_') + '_group')) this.addGroup(groupname);
var group = $(groupname.replace(/\s/, '_') + '_group')
group.insertBefore($(Buddylist.listObjects[username].obj), null);
},
/**
* Add a new group the buddylist window
*
* @arguments
* groupname - group to add
*
* @author Joshua Gross
**/
addGroup: function(groupname) {
var bList = $('buddylist');
bList.innerHTML = (groupname=='Offline' ? bList.innerHTML : '') + '
' + groupname +
(groupname!='Offline' ? '
' : '') + '' + "\n" + '' + (groupname!='Offline' ? bList.innerHTML : '');
},
/**
* Remove buddy from the buddylist permanently
*
* @arguments
* username - buddy we're removin
*
* @author Joshua Gross
**/
deleteBuddy: function(username) {
if(username.indexOf('_group') != -1) {
this.deleteGroup(username.substring(0, username.length - 6));
return;
}
var usernam = username;
var ingroup = null;
for (var group in this.list) {
if(typeof(this.list[group][username]) !== 'undefined' && this.list[group][username].username == username) {
ingroup = group;
break;
}
}
var buddyToRmv = $(Buddylist.listObjects[username].obj);
if(typeof(buddyToRmv) !== 'undefined') {
buddyToRmv.parentNode.removeChild(buddyToRmv);
if(this.list[ingroup]) {
this.list[ingroup][username] = null;
var xhConn = new XHConn();
xhConn.connect(pingTo, "POST", "call=removebuddy&username="+username, null);
}
Dialog.closeInfo();
}
},
/**
* Process the blocking of a buddy
*
* @arguments
* username - the buddy to be blocked
*
* @author Joshua Gross
* @update Benjamin Hutchins
**/
blockBuddy: function(username) {
var isBlocked = this.blocked.inArray(username);
if(isBlocked) {
for(var i=0; i= 2 ? 'themes/' + theme + '/away.png' : 'themes/' + theme + '/offline.png')));
if(!blockedBuddyStatus && isBlocked) {
Buddylist.moveBuddy(username, Languages.get('offline'));
}
break;
}
}
},
/**
* Remove a group from the buddylist permanently
*
* @arguments
* groupname - group to be removes
*
* @author Joshua Gross
**/
deleteGroup: function(groupname) {
var groupNoSpaces = groupname.replace(/\s/, '_');
var groupToRmv = $(groupNoSpaces+"_group");
var groupTop = $(groupNoSpaces+"_groupTop");
if(typeof(groupToRmv) !== 'undefined') {
groupToRmv.parentNode.removeChild(groupToRmv);
groupTop.parentNode.removeChild(groupTop);
for(var i=0;i 0) {
try {
var el = $(Buddylist.listObjects[curSelected].obj);
Element.addClassName(el, 'listNotSelected');
Element.removeClassName(el, 'listSelected');
Element.removeClassName(el, 'listHover');
} catch(e) { }
}
curSelected = username;
var oel = $(Buddylist.listObjects[curSelected].obj);
Element.addClassName(oel, 'listSelected');
Element.removeClassName(oel, 'listNotSelected');
Element.removeClassName(oel, 'listHover');
}
return false;
},
/**
* Process double clicks, open the IM window
*
* @author Joshua Gross
**/
onBuddyDblClick: function() {
if(curSelected.length > 0) {
if(typeof(IM.windows[curSelected]) == 'undefined') {
IM.create(curSelected, curSelected);
} else {
if(IM.windows[curSelected].detached) {
if(IM.windows[curSelected].popup.closed) {
IM.windows[curSelected] = IM.windows[curSelected].old;
IM.windows[curSelected].show();
} else {
IM.windows[curSelected].popup.focus();
}
} else if(!IM.windows[curSelected].isVisible()) {
IM.windows[curSelected].show();
IM.windows[curSelected].toFront();
setTimeout("scrollToBottom('" + IM.windows[curSelected].getId() + "_rcvd')", 125);
setTimeout("$('" + IM.windows[curSelected].getId() + "_sendBox').focus();", 250);
} else {
IM.windows[curSelected].toFront();
setTimeout("$('" + IM.windows[curSelected].getId() + "_sendBox').focus();", 250);
}
}
}
}
};