/////////////////////////////////// // 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" + '
' + "\n" + '
' + Languages.get('bold') + ' ' + '' + Languages.get('italic') + ' '+ '' + Languages.get('underline') + '
' + ' Tahoma' + ' 12' + '
' + ' ' + "\n" + '
'; this.windows[name].setRoom(name); $(winId + '_userlist').setStyle({left: (this.windows[name].getSize().width - 155) + 'px', height: (this.windows[name].getSize().height - 12) + 'px'}); $(winId + '_rcvd').setStyle({marginTop: '5px', height: (this.windows[name].getSize().height - 103) + 'px', width: (this.windows[name].getSize().width - 170) + 'px'}); $(winId + '_toolbar').setStyle({top: (this.windows[name].getSize().height - 73) + 'px', width: (this.windows[name].getSize().width - 170) + 'px'}); $(winId + '_setFont').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'}); $(winId + '_setFontSize').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'}); $(winId + '_setFontColor').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'}); $(winId + '_setFontColorColor').setStyle({backgroundColor: '#000'}); $(winId + '_insertEmoticon').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'}); var sendBox = $(winId + '_sendBox'); sendBox.setStyle({top: (this.windows[name].getSize().height - 45) + 'px', left: '2px', width: (this.windows[name].getSize().width - 175) + 'px', fontWeight: '400', fontStyle: 'normal', textDecoration: 'none'}); this.windows[name].show(); this.windows[name].toFront(); Windows.focusedWindow = this.windows[name]; setTimeout("$('"+winId+"_sendBox').focus();", 250); }, /** * Process chatroom window resize * * @arguments * name - chatroom name * * @author Joshua Gross **/ handleResize: function(name) { var winId = this.windows[name].getId(); $(winId + '_userlist').setStyle({left: (this.windows[name].getSize().width - 155) + 'px', height: (this.windows[name].getSize().height - 12) + 'px'}); $(winId + '_rcvd').setStyle({height: (this.windows[name].getSize().height - 103) + 'px', width: (this.windows[name].getSize().width - 170) + 'px'}); $(winId + '_toolbar').setStyle({top: (this.windows[name].getSize().height - 73) + 'px', width: (this.windows[name].getSize().width - 170) + 'px'}); $(winId + '_setFont').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'}); $(winId + '_setFontSize').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'}); $(winId + '_setFontColor').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'}); $(winId + '_setFontColorColor').setStyle({backgroundColor: '#000'}); $(winId + '_insertEmoticon').setStyle({top: (this.windows[name].getSize().height - 65) + 'px'}); $(winId + '_sendBox').setStyle({top: (this.windows[name].getSize().height - 45) + 'px', left: '2px', width: (this.windows[name].getSize().width - 175) + 'px'}); }, /** * Send request to server to enter a chatroom * * @argument * room - room name user is entering * * @author Joshua Gross **/ join: function(room) { room = room.toLowerCase(); var xhConn = new XHConn(); xhConn.connect(pingTo, "POST", "call=joinroom&room="+room, function(xh) { if(xh.responseText.indexOf('"') == -1) { switch(xh.responseText) { case 'already_joined': $('newroom_error_msg').innerHTML = Languages.get('alreadyInRoom').replace('%1', room); break; case 'room_is_user': $('newroom_error_msg').innerHTML = Languages.get('invalidRoom'); break; case 'invalid_chars': $('newroom_error_msg').innerHTML = Languages.get('invalidRoomChars'); break; } } else { if(!$(room + '_im')) { Chatroom.create(room, room); } else { if(!Chatroom.windows[room].isVisible()) { Chatroom.windows[room].show(); setTimeout("scrollToBottom('" + room + "_rcvd')", 125); } } var users = xh.responseText.parseJSON().users; for(var i=0; i '+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 = ''; }); }, /** * Proccess mouseover and mouseout of list items * * @arguments * sel - list element * roomname - chatroom name * selected - did mouse go over or out * * @author Joshua Gross **/ selectRoom: function(sel, roomname, selected) { if(selected === false) { if(this.curSelected != roomname) { try { Element.addClassName(sel, 'listNotSelected').removeClassName('listSelected').removeClassName('listHover'); } catch(e) { } } else { Element.addClassName(sel, 'listSelected').removeClassName('listNotSelected').removeClassName('listHover'); } } else { Element.addClassName(sel, 'listHover').removeClassName('listSelected').removeClassName('listNotSelected'); } }, /** * Process the clicking of a room * * @arguments * roomname - room that was clicked * * @author Joshua Gross **/ clickRoom: function(roomname) { if(this.curSelected.length > 0) { try { Element.addClassName($('chatroom_list_' + hex_md5(this.curSelected)), 'listNotSelected').removeClassName('listSelected').removeClassName('listHover'); } catch(e) { } } this.curSelected = roomname; $('roomname').value = roomname; Element.addClassName($('chatroom_list_' + hex_md5(roomname)), 'listSelected').removeClassName('listNotSelected').removeClassName('listHover'); } };