(function() { function _config(pObj, pEvent, pHandler) { if ( typeof pObj == 'object' ) { if ( pEvent.substring(0, 2) == 'on' ) pEvent = pEvent.substring(2, pEvent.length); if ( pObj.addEventListener ) pObj.addEventListener(pEvent, pHandler, false); else if ( pObj.attachEvent ) pObj.attachEvent('on' + pEvent, pHandler); } } if ( !(top.document.getElementById('instant_messenger_content')) ) { var _im_content = top.document.createElement('div'); _im_content.setAttribute('id', 'instant_messenger_content'); _im_content = top.document.body.appendChild(_im_content); } var buffer = ''; var _disconnected = false; var _conn = new IMConnector(path_im); var _xtools = new XTools(path_im); var _window = new Windows(_xtools, _im_content); var _ldap = new InstantMessengerLDAP(_conn, _xtools, _window); var _showhidden = new ShowHidden(1500); var _jabber = new Jabber(_conn, _xtools, _window, _ldap, _showhidden); // XSL preload var _xsl_preload = ['window.xsl','layer.xsl','contacts.xsl', 'chat.xsl']; var _xsl_preload_legth = _xsl_preload.length; for ( var i = 0; i < _xsl_preload_legth; i++ ) _xtools.load(_xsl_preload[i]); var local; if ( (local = top.document.getElementById('user_info')) ) { local.firstChild.style.marginLeft = '30px'; var _status = top.document.createElement('div'); _status.setAttribute('id', 'im_status'); _status.style.height = '15px'; _status.style.margin = '0 0 0 10px'; _status.style.padding = '0px'; _status.style.width = '15px'; _status.style.background = 'no-repeat'; _status.style.backgroundImage = 'url(' + im_unavailable.src + ')'; _status.style.float = 'left'; _status.style.position = 'absolute'; local.insertBefore(_status, local.firstChild); _config(_status, 'onclick', _contacts); var _menu; _menu = top.document.createElement('span'); _menu.setAttribute('id','fast_menu_im'); _menu.style.backgroundColor = 'b4cfe5'; _menu.style.display = 'none'; _menu.style.margin = '15px 0 0 -15px'; _menu.style.position = 'absolute'; _menu.style.zIndex = '99999'; local.insertBefore(_menu, local.firstChild); var _menu_img = top.document.createElement('div'); _menu_img.style.background = 'no-repeat'; _menu_img.style.backgroundImage = 'url(' + im_fast_menu.src + ')'; _menu_img.style.height = '10px'; _menu_img.style.margin = '0px'; _menu_img.style.padding = '0px'; _menu_img.style.position = 'absolute'; _menu_img.style.width = '10px'; _menu_img.style.float = 'left'; local.insertBefore(_menu_img, local.firstChild); _config( _menu_img, 'onclick', function() { var _options = [ 'available', 'away', 'dnd', 'unavailable' ]; var _style_text = 'cursor: pointer; padding:2px 4px 2px 20px; background: no-repeat '; var _xml = _xtools.xml('menu'); var _option; var _item; var _action; var _style; for ( var i in _options ) { _option = _xml.createElement('option'); _item = _xml.createElement('item'); _item.appendChild(_xml.createTextNode(imGetLang(_options[i]))); _style = _xml.createElement('style'); _style.appendChild(_xml.createTextNode(_style_text + 'url(' + eval('im_' + _options[i] + '.src') + ')')); _option.appendChild(_item); _option.appendChild(_style); _xml.documentElement.appendChild(_option); } _menu.innerHTML = _xtools.parse(_xml, 'options.xsl'); _showhidden.action('onmouseover', 'onmouseout', _menu); _item = _menu.firstChild; for ( var i in _options ) { _item.childNodes[i].setAttribute('presence', _options[i]); _config( _item.childNodes[i], 'onclick', function(e) { var el = ( e.target ) ? e.target : e.srcElement; _status.style.backgroundImage = el.style.backgroundImage; var _presence = el.getAttribute('presence'); _jabber.setPresence(_presence); var _win_contacts = _window.get('contact_list'); if ( _win_contacts ) _win_contacts.icon(eval('im_' + _presence + '.src')); } ); } } ); } function _stream(data) { data = data.replace(/^ | $/, ''); if ( !(data.length) ) return false; if ( data.indexOf('disconnected') != -1 || data.indexOf('') != -1 ) { _disconnected = true; //alert('disconnected'); } else { if ( data.lastIndexOf('>') != data.length - 1) buffer += data + ' '; else { if ( buffer.length ) { data = buffer + data; buffer = ''; } // com xmlns ocorre problemas durante o parse entre // xml e xsl e por esse motivo está sendo retirado data = data.replace(/ xmlns='.*?'/g, ''); data = '' + data + ''; var _xml = _xtools.convert(data); if ( _xml ) { var _node = _xml.documentElement.firstChild; while ( _node ) { if ( _node.nodeType == 1 ) _jabber.action(_node); //else // alert('name : ' + _node.nodeName + "\n\nhas children:" + _node.hasChildNodes() + "\nvalue\n\n" + _node.nodeValue); _node = _node.nextSibling; } } } } } var _count_reconnect = 0; function _request() { if ( !_disconnected ) return _conn.go( '$this.Ujabber.listen', {'stream':_stream, 'request':_wait}, 'classCostructor=read' ); else setTimeout(_reconnect, (++_count_reconnect * 2000)); } function _wait() { setTimeout(_request, 3000); } function _reconnect() { _disconnected = false; _request(); } function _disconnect() { _disconnected = true; } function _contacts() { var _win = _window.get('contact_list'); if ( _win ) if ( _win.wm.style.display != 'none' ) _win.wm.style.display = 'none'; else _win.wm.style.display = 'block'; else if ( !_disconnected ) _conn.go('$this.Ujabber.getContacts'); } function Client() { _request(); setTimeout('InstantMessengerContacts()', 3000); } window.InstantMessengerClient = Client; window.InstantMessengerReconnect = _reconnect; window.InstantMessengerDisconnect = _disconnect; window.InstantMessengerContacts = _contacts; } )();