[305] | 1 | (function() |
---|
[287] | 2 | { |
---|
[318] | 3 | |
---|
| 4 | var _cookies = new IMCookies; |
---|
| 5 | var _running = _cookies.get('IM_running'); |
---|
| 6 | if ( !_running ) |
---|
[287] | 7 | { |
---|
[337] | 8 | _cookies.set('IM_running', 'true', 5); |
---|
[318] | 9 | |
---|
| 10 | function _config(pObj, pEvent, pHandler) |
---|
[305] | 11 | { |
---|
[318] | 12 | if ( typeof pObj == 'object' ) |
---|
| 13 | { |
---|
| 14 | if ( pEvent.substring(0, 2) == 'on' ) |
---|
| 15 | pEvent = pEvent.substring(2, pEvent.length); |
---|
[305] | 16 | |
---|
[318] | 17 | if ( pObj.addEventListener ) |
---|
| 18 | pObj.addEventListener(pEvent, pHandler, false); |
---|
| 19 | else if ( pObj.attachEvent ) |
---|
| 20 | pObj.attachEvent('on' + pEvent, pHandler); |
---|
| 21 | } |
---|
[305] | 22 | } |
---|
| 23 | |
---|
[318] | 24 | _config(window, 'onbeforeunload', |
---|
| 25 | function() |
---|
| 26 | { |
---|
| 27 | var _running = _cookies.get('IM_running'); |
---|
| 28 | _cookies.clear('IM_running'); |
---|
| 29 | } |
---|
| 30 | ); |
---|
[287] | 31 | |
---|
[318] | 32 | if ( !(top.document.getElementById('instant_messenger_content')) ) |
---|
| 33 | { |
---|
| 34 | var _im_content = top.document.createElement('div'); |
---|
| 35 | _im_content.setAttribute('id', 'instant_messenger_content'); |
---|
| 36 | _im_content = top.document.body.appendChild(_im_content); |
---|
| 37 | } |
---|
[287] | 38 | |
---|
[318] | 39 | var buffer = ''; |
---|
| 40 | var _disconnected = false; |
---|
[305] | 41 | |
---|
[318] | 42 | var _conn = new IMConnector(path_im); |
---|
| 43 | var _xtools = new XTools(path_im); |
---|
| 44 | var _window = new Windows(_xtools, _im_content); |
---|
| 45 | var _ldap = new InstantMessengerLDAP(_conn, _xtools, _window); |
---|
| 46 | var _showhidden = new ShowHidden(1500); |
---|
| 47 | var _jabber = new Jabber(_conn, _xtools, _window, _ldap, _showhidden, _cookies); |
---|
[305] | 48 | |
---|
[318] | 49 | // XSL preload |
---|
| 50 | var _xsl_preload = [ |
---|
| 51 | 'window.xsl', |
---|
| 52 | 'layer.xsl', |
---|
| 53 | 'contacts.xsl', |
---|
| 54 | 'chat.xsl', |
---|
| 55 | 'options.xsl' |
---|
| 56 | ]; |
---|
| 57 | var _xsl_preload_legth = _xsl_preload.length; |
---|
| 58 | for ( var i = 0; i < _xsl_preload_legth; i++ ) |
---|
| 59 | _xtools.load(_xsl_preload[i]); |
---|
[287] | 60 | |
---|
[318] | 61 | function _stream(data) |
---|
| 62 | { |
---|
| 63 | data = data.replace(/^ | $/, ''); |
---|
[311] | 64 | |
---|
[318] | 65 | if ( !(data.length) ) |
---|
| 66 | return false; |
---|
[287] | 67 | |
---|
[318] | 68 | if ( data.indexOf('disconnected') != -1 || data.indexOf('</stream:stream>') != -1 ) |
---|
| 69 | _disconnect(); |
---|
| 70 | else |
---|
[311] | 71 | { |
---|
[318] | 72 | if ( data.lastIndexOf('>') != data.length - 1) |
---|
| 73 | buffer += data + ' '; |
---|
| 74 | else |
---|
[311] | 75 | { |
---|
[318] | 76 | if ( buffer.length ) |
---|
| 77 | { |
---|
| 78 | data = buffer + data; |
---|
| 79 | buffer = ''; |
---|
| 80 | } |
---|
[311] | 81 | |
---|
[318] | 82 | // with xmlns, occurs problems during parse between |
---|
| 83 | // xml and xsl, and for that reason it was removed |
---|
| 84 | data = data.replace(/ xmlns='.*?'/g, ''); |
---|
| 85 | data = '<handler>' + data + '</handler>'; |
---|
[311] | 86 | |
---|
[318] | 87 | var _xml = _xtools.convert(data); |
---|
[311] | 88 | |
---|
[318] | 89 | if ( _xml ) |
---|
| 90 | { |
---|
| 91 | var _node = _xml.documentElement.firstChild; |
---|
[311] | 92 | |
---|
[318] | 93 | while ( _node ) |
---|
[311] | 94 | { |
---|
[318] | 95 | if ( _node.nodeType == 1 ) |
---|
| 96 | _jabber.action(_node); |
---|
| 97 | //else |
---|
| 98 | // alert('name : ' + _node.nodeName + |
---|
| 99 | // "\n\nhas children:" + _node.hasChildNodes() + |
---|
| 100 | // "\nvalue\n\n" + _node.nodeValue); |
---|
[311] | 101 | |
---|
[318] | 102 | _node = _node.nextSibling; |
---|
[311] | 103 | } |
---|
[318] | 104 | } |
---|
[311] | 105 | } |
---|
| 106 | } |
---|
[318] | 107 | } |
---|
[275] | 108 | |
---|
[318] | 109 | var _count_reconnect = 0; |
---|
| 110 | function _request() |
---|
| 111 | { |
---|
| 112 | if ( !_disconnected ) |
---|
| 113 | return _conn.go( |
---|
| 114 | '$this.Ujabber.listen', |
---|
| 115 | {'stream':_stream, 'request':_wait}, |
---|
| 116 | 'classCostructor=read' |
---|
| 117 | ); |
---|
| 118 | else |
---|
| 119 | setTimeout(_reconnect, (++_count_reconnect * 2000)); |
---|
| 120 | } |
---|
[287] | 121 | |
---|
[318] | 122 | function _wait() |
---|
| 123 | { |
---|
| 124 | setTimeout(_request, 3000); |
---|
| 125 | } |
---|
[305] | 126 | |
---|
[318] | 127 | function _reconnect() |
---|
[287] | 128 | { |
---|
[318] | 129 | _disconnected = false; |
---|
| 130 | _request(); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | function _disconnect() |
---|
| 134 | { |
---|
[305] | 135 | _disconnected = true; |
---|
[318] | 136 | _conn.abort(); |
---|
| 137 | _loading(); |
---|
| 138 | var _status = top.document.getElementById('im_status'); |
---|
| 139 | if ( _status ) |
---|
| 140 | _status.style.backgroundImage = 'url(' + im_unavailable.src + ')'; |
---|
| 141 | |
---|
| 142 | var _win_contacts = _window.get('contact_list'); |
---|
| 143 | if ( _win_contacts ) |
---|
| 144 | _win_contacts.icon(im_unavailable.src); |
---|
[287] | 145 | } |
---|
[318] | 146 | |
---|
| 147 | function _contacts() |
---|
[260] | 148 | { |
---|
[318] | 149 | if ( !_disconnected ) |
---|
[321] | 150 | { |
---|
[327] | 151 | _conn.go('t.update'); |
---|
| 152 | |
---|
[321] | 153 | setTimeout(function() |
---|
| 154 | { |
---|
| 155 | var _contact_list = top.document.getElementById('im_contact_list'); |
---|
| 156 | if ( !_contact_list ) |
---|
| 157 | _contacts(); |
---|
| 158 | }, 5000); |
---|
| 159 | } |
---|
[318] | 160 | } |
---|
| 161 | |
---|
| 162 | function _loading() |
---|
| 163 | { |
---|
| 164 | var _win_contact = _window.get('contact_list'); |
---|
| 165 | if ( !_win_contact ) |
---|
[260] | 166 | { |
---|
[318] | 167 | _win_contact = _window.load('contact_list'); |
---|
| 168 | _win_contact.hidden(); |
---|
| 169 | _win_contact.title('.::Expresso Messenger::.'); |
---|
| 170 | _win_contact.size(170, 350); |
---|
| 171 | _win_contact.position(30, 30, true); |
---|
| 172 | _win_contact.icon(im_unavailable.src); |
---|
| 173 | _win_contact.bc.style.display = 'none'; |
---|
| 174 | } |
---|
[260] | 175 | |
---|
[318] | 176 | _win_contact.loading(); |
---|
| 177 | } |
---|
[260] | 178 | |
---|
[318] | 179 | function _showContacts() |
---|
| 180 | { |
---|
| 181 | var _win = _window.get('contact_list'); |
---|
| 182 | if ( _win ) |
---|
| 183 | if ( _win.wm.style.display == 'none' ) |
---|
| 184 | _win.wm.style.display = 'block'; |
---|
| 185 | else |
---|
| 186 | _win.wm.style.display = 'none'; |
---|
| 187 | } |
---|
[260] | 188 | |
---|
[318] | 189 | _loading(); |
---|
| 190 | |
---|
| 191 | var local; |
---|
[327] | 192 | if ( (local = top.document.getElementById('divStatusBar')) ) |
---|
[318] | 193 | { |
---|
[327] | 194 | // tentando colocar os icones em local que não seja mexido. |
---|
| 195 | // VERIFICAR |
---|
| 196 | var _div = top.document.createElement('div'); |
---|
| 197 | _div.appendChild(local.parentNode.removeChild(local.previousSibling)); |
---|
| 198 | local.parentNode.insertBefore(_div, local); |
---|
| 199 | //_div.appendChild(local); |
---|
[318] | 200 | |
---|
[327] | 201 | //local = _div; |
---|
| 202 | |
---|
| 203 | local.style.paddingLeft = '30px'; |
---|
| 204 | |
---|
[318] | 205 | var _status = top.document.createElement('div'); |
---|
| 206 | _status.setAttribute('id', 'im_status'); |
---|
[327] | 207 | _status.style.background = 'no-repeat'; |
---|
| 208 | _status.style.backgroundImage = 'url(' + im_unavailable.src + ')'; |
---|
| 209 | _status.style.float = 'left'; |
---|
[318] | 210 | _status.style.height = '15px'; |
---|
[327] | 211 | _status.style.left = '20px'; |
---|
[318] | 212 | _status.style.margin = '0 0 0 10px'; |
---|
| 213 | _status.style.padding = '0px'; |
---|
[327] | 214 | _status.style.position = 'absolute'; |
---|
[318] | 215 | _status.style.width = '15px'; |
---|
| 216 | |
---|
| 217 | local.insertBefore(_status, local.firstChild); |
---|
| 218 | |
---|
| 219 | _config(_status, 'onclick', _showContacts); |
---|
| 220 | |
---|
| 221 | var _menu; |
---|
| 222 | _menu = top.document.createElement('span'); |
---|
| 223 | _menu.setAttribute('id','fast_menu_im'); |
---|
| 224 | _menu.style.backgroundColor = 'b4cfe5'; |
---|
| 225 | _menu.style.display = 'none'; |
---|
| 226 | _menu.style.margin = '15px 0 0 -15px'; |
---|
| 227 | _menu.style.position = 'absolute'; |
---|
| 228 | _menu.style.zIndex = '99999'; |
---|
| 229 | local.insertBefore(_menu, local.firstChild); |
---|
| 230 | |
---|
| 231 | var _menu_img = top.document.createElement('div'); |
---|
| 232 | _menu_img.style.background = 'no-repeat'; |
---|
| 233 | _menu_img.style.backgroundImage = 'url(' + im_fast_menu.src + ')'; |
---|
[327] | 234 | _menu_img.style.float = 'left'; |
---|
[318] | 235 | _menu_img.style.height = '10px'; |
---|
[327] | 236 | _menu_img.style.left = '23px'; |
---|
[318] | 237 | _menu_img.style.margin = '0px'; |
---|
| 238 | _menu_img.style.padding = '0px'; |
---|
| 239 | _menu_img.style.position = 'absolute'; |
---|
| 240 | _menu_img.style.width = '10px'; |
---|
| 241 | local.insertBefore(_menu_img, local.firstChild); |
---|
| 242 | |
---|
| 243 | _config( |
---|
| 244 | _menu_img, |
---|
| 245 | 'onclick', |
---|
| 246 | function() |
---|
[260] | 247 | { |
---|
[318] | 248 | var _options = [ |
---|
| 249 | 'available', |
---|
| 250 | 'away', |
---|
| 251 | 'dnd', |
---|
| 252 | 'unavailable' |
---|
| 253 | ]; |
---|
[305] | 254 | |
---|
[318] | 255 | var _style_text = 'cursor: pointer; padding:2px 4px 2px 20px; background: no-repeat '; |
---|
| 256 | |
---|
| 257 | var _xml = _xtools.xml('menu'); |
---|
| 258 | var _option; |
---|
| 259 | var _item; |
---|
| 260 | var _action; |
---|
| 261 | var _style; |
---|
| 262 | |
---|
| 263 | for ( var i in _options ) |
---|
[305] | 264 | { |
---|
[318] | 265 | _option = _xml.createElement('option'); |
---|
[305] | 266 | |
---|
[318] | 267 | _item = _xml.createElement('item'); |
---|
| 268 | _item.appendChild(_xml.createTextNode(imGetLang(_options[i]))); |
---|
| 269 | |
---|
| 270 | _style = _xml.createElement('style'); |
---|
| 271 | _style.appendChild(_xml.createTextNode(_style_text + 'url(' + eval('im_' + _options[i] + '.src') + ')')); |
---|
| 272 | |
---|
| 273 | _option.appendChild(_item); |
---|
| 274 | _option.appendChild(_style); |
---|
| 275 | |
---|
| 276 | _xml.documentElement.appendChild(_option); |
---|
[305] | 277 | } |
---|
[260] | 278 | |
---|
[318] | 279 | _menu.innerHTML = _xtools.parse(_xml, 'options.xsl'); |
---|
| 280 | _showhidden.action('onmouseover', 'onmouseout', _menu); |
---|
[260] | 281 | |
---|
[318] | 282 | _item = _menu.firstChild; |
---|
[260] | 283 | |
---|
[318] | 284 | for ( var i in _options ) |
---|
| 285 | { |
---|
| 286 | _item.childNodes[i].setAttribute('presence', _options[i]); |
---|
| 287 | _config( |
---|
| 288 | _item.childNodes[i], |
---|
| 289 | 'onclick', |
---|
| 290 | function(e) |
---|
| 291 | { |
---|
| 292 | var el = ( e.target ) ? e.target : e.srcElement; |
---|
| 293 | var _presence = el.getAttribute('presence'); |
---|
| 294 | _jabber.setPresence(_presence); |
---|
| 295 | } |
---|
| 296 | ); |
---|
| 297 | } |
---|
| 298 | } |
---|
| 299 | ); |
---|
| 300 | } |
---|
[260] | 301 | |
---|
[318] | 302 | function Client() |
---|
| 303 | { |
---|
| 304 | _request(); |
---|
| 305 | setTimeout(_contacts, 3000); |
---|
| 306 | } |
---|
[305] | 307 | |
---|
[318] | 308 | window.InstantMessengerClient = Client; |
---|
[305] | 309 | } |
---|
| 310 | } |
---|
| 311 | )(); |
---|