function Jabber() { this.con = null; this.xtools = null; } Jabber.prototype = { 'doIt' : function(pAction, pParam) { var _this = this; function _connector() { if ( _this.con == null ) _this.con = new Connector; } function _xtools() { _this.xtools = new XTools; } _connector(); _xtools(); if ( typeof pAction != 'string' || typeof pParam != 'object' ) return false; switch ( pAction ) { case 'iq' : readIq(pParam); break; case 'message' : readMessage(pParam); break; case 'presence' : readPresence(pParam); break; case 'sendMessage': sendMessage(pParam.message,pParam.from); break; } function readContacts(pContacts) { var XmlDoc = "" + "" + im.get_lang("Nickname") + "" + "" + im.get_lang("Add Contact") + "" + "" + im.get_lang("Preferences") + "" + "" + im.get_lang("Username") + "" + "" + path_im + "" + ""; im_window.load('_contacts_im_','instant_messenger_content','.::Expresso Messenger::.','window.xsl','',true,true,false); im_window.elementC('_contacts_im_').innerHTML = _this.xtools.parse(XmlDoc,'layer.xsl'); im_window.elementC('_contacts_im_').innerHTML += _this.xtools.parse(pContacts, 'contacts.xsl'); var element = func.byId('im_contact_list').firstChild; while(element) { if( element.nodeType == 1 ) if(element.nodeName.toLowerCase() == "img") element.src = im_group_open.src else if(element.nodeName.toLowerCase() == "div" && element.hasChildNodes()) element.firstChild.src = im_unavailable.src; element = element.nextSibling; } if(func.byId('im_avatar').src === im_photo.src) { im.request_vcard('this',false); im.ldap_photo('im_avatar'); } } function readIq(pIq) { switch ( pIq.getAttribute('id') ) { case 'contacts' : readContacts(pIq); break; case 'vCard' : case 'vCard_user' : readVcard(pIq); break; } } function readMessage(pMessage) { if ( pMessage.getElementsByTagName('body').length > 0 ) { var msg = _this.xtools.parse(pMessage, 'message_new.xsl'); var from = pMessage.getAttribute('from'); from = from.substr(0,from.indexOf('/')); if(func.byId('iframe_' + from) != null) func.byId('iframe_' + from).parentNode.removeChild(func.byId('iframe_' + from)); var win; function include_iframe() { win = im_window.elementC(from); var iframe = document.createElement('iframe'); iframe.id = 'iframe_' + from; iframe.style.width = '290px'; iframe.style.height = '46px'; iframe.style.border = '0'; iframe.style.margin = '0'; iframe.style.padding = '0' var _messages_ = win.firstChild.firstChild.nextSibling.nextSibling; _messages_.appendChild(iframe); iframe.contentWindow.document.write(''); iframe.contentWindow.document.close(); iframe.contentWindow.document.designMode = "On"; iframe.contentWindow.focus(); function keypress_handler(e) { var evt = e.keyCode; var pId = ( e.srcElement ) ? e.srcElement.id : e.target.getElementsByTagName('body').item(0).id; switch ( evt ) { case 13 : if ( !e.shiftKey ) sendMessage(iframe.contentWindow.document.getElementsByTagName('body').item(0), from); return false; break; case 27 : im_window.window_close(pId); break; default : break; } } function keyup_handler(e) { var evt = e.keyCode; var _text = ( e.srcElement ) ? e.srcElement.id : e.target.getElementsByTagName('body').item(0); switch ( evt ) { case 13 : if ( !e.shiftKey ) _text.innerHTML = ''; return false; break; default : break; } } var obj = iframe.contentWindow.document; if ( obj.addEventListener ) { obj.addEventListener('keypress', keypress_handler, false); obj.addEventListener('keyup', keyup_handler, false); } else if ( obj.attachEvent ) { obj.attachEvent('onkeypress', keypress_handler); obj.attachEvent('onkeyup', keyup_handler); } } if ( !(win = im_window.elementC(from)) ) { im_window.load(from, 'instant_messenger_content', '.:: Expresso Messenger ::.', 'chat.xsl', '310', true, true, true); //im_window.visible(from,'block'); func.byId(from + '_avatar').src = path_im + "/templates/default/images/photo.png"; include_iframe(); } else { im_window.load(from, '', '', '', '', true, true, true); //im_window.visible(from,'block'); include_iframe(); } if ( win ) { if(!(im.nickname_contacts[from])) im.request_vcard(from, false); win = win.firstChild.firstChild; var nick = (im.nickname_contacts[from]) ? im.nickname_contacts[from] : from; win.innerHTML += "" + nick + "" + im.insertEmoticons(msg); win.scrollTop = win.scrollHeight; im.ldap_photo(from + "_avatar"); } im.newMessageNotification(); } } function readPresence(pPresence) { //@TODO: presenca antes da lista ocasiona erros //verificar e retirar o controle de erros abaixo try { var jidFrom = pPresence.getAttribute('from'); jidFrom = jidFrom.substr(0,jidFrom.indexOf('/')); if(pPresence.getAttribute('type')) { switch(pPresence.getAttribute('type')) { case 'subscribe' : if(func.byId(pPresence.getAttribute('from'))) { if(confirm('Autorizar o usuário ' + pPresence.getAttribute('from') + '?')) im.subscription(pPresence.getAttribute('from'),'subscribed'); else im.subscription(pPresence.getAttribute('from'),'unsubscribe'); } else { if(!func.byId(pPresence.getAttribute('from'))) { if(confirm('O usuário ' + pPresence.getAttribute('from') + ' quer adicioná-lo ?')) { im.addrequest(pPresence.getAttribute('from')); im.subscription(pPresence.getAttribute('from'),'subscribed'); } else im.subscription(pPresence.getAttribute('from'),'unsubscribe'); }else im.subscription(pPresence.getAttribute('from'),pPresence.getAttribute('type')); } break; case 'subscribed' : im.subscription(pPresence.getAttribute('from'),pPresence.getAttribute('type')); break; case 'unsubscribed' : //alert('O usuário ' + pPresence.getAttribute('from') + ' năo quer mais papo !'); break; case 'unsubscribe' : alert('O usuário ' + pPresence.getAttribute('from') + ' negou seu pedido !'); break; case 'unavailable' : func.byId('img_' + jidFrom).src = eval('im_' + pPresence.getAttribute('type') + '.src'); func.confEl(func.byId(jidFrom),"style","margin-left:15px;cursor:pointer;display:none;"); break; case 'available' : func.byId('img_' + jidFrom).src = eval('im_' + pPresence.getAttribute('type') + '.src'); func.confEl(func.byId(jidFrom),"style","margin-left:15px;cursor:pointer;display:block;"); break; } } else { var node = pPresence.firstChild; while( node ) { if(node.hasChildNodes()) { switch(node.nodeName) { case "show" : func.byId('img_' + jidFrom).src = eval('im_' + node.firstChild.nodeValue + '.src'); func.confEl(func.byId(jidFrom),"style","margin-left:15px;cursor:pointer;display:block;"); func.byId('status_' + jidFrom).innerHTML = " "; func.confEl(func.byId('status_' + jidFrom), "style", "font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif; font-style:italic; display:none;"); break; case "status" : func.byId('status_' + jidFrom).innerHTML = ( node.firstChild.nodeValue ) ? node.firstChild.nodeValue : "" ; func.confEl(func.byId('status_' + jidFrom), "style", "font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif; font-style:italic; display:block;"); break; default : func.byId('img_' + jidFrom).src = im_available.src; func.byId('status_' + jidFrom).innerHTML = " "; func.confEl(func.byId('status_' + jidFrom), "style", "font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif; font-style:italic; display:none;"); break; } } node = node.nextSibling; } if(!im.contacts_off_line) setTimeout("im.off_line()",3000); } } catch(e) { } } function readVcard(pVcard) { switch(pVcard.getAttribute('id')) { case "vCard_user" : var vcard = pVcard.firstChild; var cc = vcard.firstChild; while( cc ) { if(cc.nodeName == "NICKNAME" || cc.nodeName == "nickname") { if(cc.firstChild.nodeValue) func.byId('im_layer_nickname').innerHTML = cc.firstChild.nodeValue; } cc = cc.nextSibling; } if( im.vcard ) templates.vcard_user(pVcard); break; case "vCard" : var vcard = _this.xtools.parse(pVcard,'nickname.xsl'); im.nickname_contacts[vcard.substr(0,vcard.indexOf(','))] = ( vcard.substr(vcard.indexOf(',')+1) ) ? vcard.substr(vcard.indexOf(',')+1) : vcard.substr(0,vcard.indexOf(',')) ; if( im.vcard ) templates.vcard_contact(pVcard); break; } } function sendMessage(pMessage, pFrom) { var handler_sendMessage = function(data) { }; var sendMessage = pMessage.innerHTML; pMessage.innerHTML = pMessage.innerHTML.replace(/^( )*|( )*$/g, ''); var send = false; var node = pMessage.firstChild; while ( node && !send ) { if ( node.nodeName.toLowerCase() != 'br' ) send = true; node = node.nextSibling; } if ( send ) _this.con.go('$this.Ujabber.sendMessage', {'request':handler_sendMessage},"to="+pMessage.getAttribute('id')+"&body="+escape(pMessage.innerHTML)); pMessage.innerHTML = ''; var win = im_window.elementC(pFrom); if ( win ) { win = win.firstChild.firstChild; win.innerHTML += "" + im.get_lang("says") +":
" + sendMessage + "

"; win.scrollTop = win.scrollHeight; } } } };