/////////////////////////////////// // ajax im 3.41 // // AJAX Instant Messenger // // Copyright (c) 2006-2008 // // http://www.ajaxim.com/ // // Do not remove this notice // /////////////////////////////////// /** * Chatroom Class **/ var Chatroom = { windows: {}, // JavaScript object to store all chatroom windows /** * Create a new chatroom * * @arguments * name - chatroom name * imTitle - window title, default is chatroom name * * @author Joshua Gross **/ create: function(name, imTitle) { var imLeft = Math.round(Math.random()*(Browser.width()-360))+'px'; var imTop = Math.round(Math.random()*(Browser.height()-400))+'px'; var winId = randomString(32) + '_chat'; this.windows[name] = new ChatWindow({id: winId, className: "dialog", width: 475, height: 340, top: imTop, left: imLeft, resizable: true, title: imTitle, draggable: true, detachable: false, minWidth: 475, minHeight: 150, showEffectOptions: {duration: 0}, hideEffectOptions: {duration: 0}}); this.windows[name].setConstraint(true, {left: 0, right: 0, top: 0, bottom: 0}); this.windows[name].getContent().innerHTML = '
' + "\n" + '
'+username+'';
$(username+'_'+this.room+'_chatUser').setStyle({listStyleType: 'none'});
},
/**
* Remove a user from the chatroom user list
*
* @arguments
* username - user to remove
*
* @author Joshua Gross
**/
deleteUser: function(username) {
var toDelete = $(username + '_' + this.room + '_chatUser');
if(typeof(toDelete) !== 'undefined')
toDelete.parentNode.removeChild(toDelete);
},
/**
* Process mouseover and mousout calls for the user list
*
* @arguments
* sel - element
* username - user's username
* selected - is mouse over or did it go out
*
* @author Joshua Gross
**/
selectUser: function(sel, username, selected) {
if(selected === false) {
if(this.curSelected != username) {
try {
Element.addClassName(sel, 'listNotSelected');
Element.removeClassName(sel, 'listSelected');
Element.removeClassName(sel, 'listHover');
} catch(e) { }
} else {
Element.addClassName(sel, 'listSelected');
Element.removeClassName(sel, 'listNotSelected');
Element.removeClassName(sel, 'listHover');
}
} else {
Element.addClassName(sel, 'listHover');
Element.removeClassName(sel, 'listSelected');
Element.removeClassName(sel, 'listNotSelected');
}
},
/**
* Process event when a user is clicked
*
* @arguments
* username - the username of the user clicked
*
* @author Josh Gross
**/
clickUser: function(username) {
if(this.curSelected.length > 0) {
try {
var el = $(this.curSelected + '_' + this.room + '_chatUser');
Element.addClassName(el, 'listNotSelected');
Element.removeClassName(el, 'listSelected');
Element.removeClassName(el, 'listHover');
} catch(e) { }
}
this.curSelected = username;
var oel = $(this.curSelected + '_' + this.room + '_chatUser');
Element.addClassName(oel, 'listSelected');
Element.removeClassName(oel, 'listNotSelected');
Element.removeClassName(oel, 'listHover');
},
/**
* On DoubleClick of a user from the chatroom user
* list, start a private IM with him/her.
*
* @author Joshua Gross
**/
onUserDblClick: function() {
if(this.curSelected.length > 0) {
if(typeof(IM.windows[this.curSelected]) == 'undefined') {
IM.create(this.curSelected, this.curSelected);
} else {
if(!IM.windows[this.curSelected].isVisible()) {
IM.windows[this.curSelected].show();
IM.windows[this.curSelected].toFront();
setTimeout("scrollToBottom('" + IM.windows[this.curSelected].getId() + "_rcvd')", 125);
setTimeout("$('" + IM.windows[this.curSelected].getId() + "_sendBox').focus();", 250);
} else {
IM.windows[this.curSelected].toFront();
setTimeout("$('" + IM.windows[this.curSelected].getId() + "_sendBox').focus();", 250);
}
}
}
}
});
/**
* Class to handle the window of the chat rooms
**/
var ChatroomList = {
curSelected: '', // current selected chat room
/**
* Get list of chat rooms that exist
*
* @author Joshua Gross
**/
get: function(applyTo) {
var xhConn = new XHConn();
xhConn.connect(pingTo, "POST", "call=roomlist", function(xh) {
var rooms = xh.responseText.parseJSON();
applyTo.innerHTML = '