Ignore:
Timestamp:
06/17/08 14:44:24 (16 years ago)
Author:
niltonneto
Message:

Commit feito pelo desenvolvedor (rodrigosouza).

Location:
trunk/instant_messenger/js
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/instant_messenger/js/client.js

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

    r311 r318  
    33        var _THREADS = []; 
    44        var _ie; 
     5 
     6        function _config(pObj, pEvent, pHandler) 
     7        { 
     8                if ( typeof pObj == 'object' ) 
     9                { 
     10                        if ( pEvent.substring(0, 2) == 'on' ) 
     11                                pEvent = pEvent.substring(2, pEvent.length); 
     12 
     13                        if ( pObj.addEventListener ) 
     14                                pObj.addEventListener(pEvent, pHandler, false); 
     15                        else if ( pObj.attachEvent ) 
     16                                pObj.attachEvent('on' + pEvent, pHandler); 
     17                } 
     18        } 
    519 
    620        // xhr = XMLHttpRequest 
     
    3650                var _ID = arguments[0]; 
    3751 
    38                 if ( _ie && _THREADS[_ID]._XHR.readyState != 4 ) 
    39                         return false; 
    40  
    41                 switch ( _THREADS[_ID]._XHR.readyState ) 
    42                 { 
    43                         case 3 : 
    44                                 if ( _THREADS[_ID]._HANDLER.stream ) 
    45                                 { 
    46                                         var _data = _THREADS[_ID]._XHR.responseText.substr(_THREADS[_ID]._index).replace(/^ +| +$/g, ''); 
    47                                         //alert(_data); 
    48                                         _THREADS[_ID]._rtlen = _THREADS[_ID]._XHR.responseText.length; 
    49  
    50                                         if ( _THREADS[_ID]._index < _THREADS[_ID]._rtlen && _data.length ) 
    51                                                 try 
    52                                                 { 
    53                                                         _THREADS[_ID]._HANDLER.stream(_data); 
    54                                                 } 
    55                                                 catch(_e) 
    56                                                 { 
    57                                                         alert("#stream\n\n" + _e + "\n\n" + _e.description); 
    58                                                 } 
    59  
    60                                         _THREADS[_ID]._index = _THREADS[_ID]._rtlen; 
    61                                 } 
    62                         break; 
    63                         case 4 : 
    64                                 switch ( _THREADS[_ID]._XHR.status ) 
    65                                 { 
    66                                         case 200: 
    67                                                 var _data = ( _THREADS[_ID]._MODE == 'XML' ) ? 
    68                                                         _THREADS[_ID]._XHR.responseXML : 
    69                                                         _THREADS[_ID]._XHR.responseText; 
    70  
    71                                                 if ( _ie && _THREADS[_ID]._HANDLER.stream ) 
    72                                                         _THREADS[_ID]._HANDLER.stream(_data); 
    73  
    74                                                 var _request = ( _THREADS[_ID]._HANDLER.request ) ? 
    75                                                         _THREADS[_ID]._HANDLER.request : false; 
    76  
    77                                                 delete _THREADS[_ID]; 
    78  
    79                                                 if ( _request ) 
     52                if  ( _THREADS[_ID] ) 
     53                { 
     54                        if ( _ie && _THREADS[_ID]._XHR.readyState != 4 ) 
     55                                return false; 
     56 
     57                        switch ( _THREADS[_ID]._XHR.readyState ) 
     58                        { 
     59                                case 3 : 
     60                                        if ( _THREADS[_ID]._HANDLER.stream ) 
     61                                        { 
     62                                                var _data = _THREADS[_ID]._XHR.responseText.substr(_THREADS[_ID]._index).replace(/^ +| +$/g, ''); 
     63                                                //alert(_data); 
     64                                                _THREADS[_ID]._rtlen = _THREADS[_ID]._XHR.responseText.length; 
     65 
     66                                                if ( _THREADS[_ID]._index < _THREADS[_ID]._rtlen && _data.length ) 
    8067                                                        try 
    8168                                                        { 
    82                                                                 _request(_data); 
     69                                                                _THREADS[_ID]._HANDLER.stream(_data); 
    8370                                                        } 
    8471                                                        catch(_e) 
    8572                                                        { 
    86                                                                 alert("#request\n\n" + _e + "\n\n" + _e.description); 
     73                                                                alert("#stream\n\n" + _e + "\n\n" + _e.description); 
    8774                                                        } 
    8875 
    89                                         break; // [case : status 200] 
    90                                         case 404: 
    91                                                 delete _THREADS[_ID]; 
    92                                                 alert('Page Not Found!'); 
    93                                         break; // [case : status 404] 
    94                                         default: 
    95                                                 delete _THREADS[_ID]; 
    96                                 } 
    97                         break; 
    98                         default : 
     76                                                if ( _THREADS[_ID] ) 
     77                                                        _THREADS[_ID]._index = _THREADS[_ID]._rtlen; 
     78                                        } 
     79                                break; 
     80                                case 4 : 
     81                                        try 
     82                                        { 
     83                                                switch ( _THREADS[_ID]._XHR.status ) 
     84                                                { 
     85                                                        case 200: 
     86                                                                var _data = ( _THREADS[_ID]._MODE == 'XML' ) ? 
     87                                                                        _THREADS[_ID]._XHR.responseXML : 
     88                                                                        _THREADS[_ID]._XHR.responseText; 
     89 
     90                                                                if ( _ie && _THREADS[_ID]._HANDLER.stream ) 
     91                                                                        _THREADS[_ID]._HANDLER.stream(_data); 
     92 
     93                                                                var _request = ( _THREADS[_ID]._HANDLER.request ) ? 
     94                                                                        _THREADS[_ID]._HANDLER.request : false; 
     95 
     96                                                                delete _THREADS[_ID]; 
     97 
     98                                                                if ( _request ) 
     99                                                                        try 
     100                                                                        { 
     101                                                                                _request(_data); 
     102                                                                        } 
     103                                                                        catch(_e) 
     104                                                                        { 
     105                                                                                alert("#request\n\n" + _e + "\n\n" + _e.description); 
     106                                                                        } 
     107 
     108                                                        break; // [case : status 200] 
     109                                                        case 404: 
     110                                                                delete _THREADS[_ID]; 
     111                                                                alert('Page Not Found!'); 
     112                                                        break; // [case : status 404] 
     113                                                        default: 
     114                                                                delete _THREADS[_ID]; 
     115                                                } 
     116                                        } 
     117                                        catch(e) 
     118                                        { 
     119                                        } 
     120                                break; 
     121                                default : 
     122                        } 
    99123                } 
    100124        } 
     
    236260        } 
    237261 
     262        function _abort() 
     263        { 
     264                for ( var _ID in _THREADS ) 
     265                { 
     266                        // @TODO 
     267                        // try/catch for unknown error of IE. 
     268                        // Check, store and retrieve the try/catch. 
     269                        try 
     270                        { 
     271                                if ( _THREADS[_ID] && _THREADS[_ID]._XHR && _THREADS[_ID]._XHR.abort ) 
     272                                        _THREADS[_ID]._XHR.abort(); 
     273 
     274                                delete _THREADS[_ID]; 
     275                        } 
     276                        catch(e){} 
     277                } 
     278        } 
     279 
    238280        function Connector() 
    239281        { 
     
    246288 
    247289        Connector.prototype.go = go; 
     290        Connector.prototype.abort = _abort; 
    248291        window.IMConnector = Connector; 
    249292 
    250         var _unload_event = window.onbeforeunload; 
    251         window.onbeforeunload = function() 
    252         { 
    253                 for ( var _ID in _THREADS ) 
    254                 { 
    255                         //if ( _THREADS[_ID]._XHR.abort ) 
    256                         try 
    257                         { 
    258                                 if ( _THREADS[_ID]._XHR && _THREADS[_ID]._XHR.abort ) 
    259                                         _THREADS[_ID]._XHR.abort(); 
    260                                 delete _THREADS[_ID]; 
    261                         } 
    262                         catch(e) 
    263                         { 
    264                         } 
    265                 } 
    266  
    267                 if ( typeof _unload_event == 'function' ) 
    268                         return _unload_event(); 
    269         }; 
     293        _config(window, 'onbeforeunload', _abort); 
    270294} 
    271295)(); 
  • trunk/instant_messenger/js/dragdrop.js

    r305 r318  
    129129                        e.preventDefault(); 
    130130                else 
    131                         el.onselectstart = new Function("return false;"); 
     131                        e.onselectstart = new Function("return false;"); 
    132132 
    133133                var el = ( e.target ) ? e.target : e.srcElement; 
  • trunk/instant_messenger/js/images.js

    r311 r318  
    3232        var im_group_close = new Image(); 
    3333        im_group_close.src = path_im + 'templates/default/images/group_close.gif'; 
     34 
     35        var im_console_prefs = new Image(); 
     36        im_console_prefs.src = path_im + 'templates/default/images/console_prefs2.png'; 
     37 
     38        var im_composing = new Image(); 
     39        im_composing.src = path_im + 'templates/default/images/typing.gif'; 
    3440 
    3541// Smiles 
  • trunk/instant_messenger/js/jabber.js

    r311 r318  
    66        var _ldap; 
    77        var _menu; 
     8        var _cookies; 
    89 
    910        var _vcards = []; 
    1011        var _info = []; 
    11  
    12         var _win_position = 30; 
     12        var _chats = []; 
     13 
     14        var _win_position = 0; 
    1315 
    1416        function _next_position() 
    1517        { 
     18                if ( _win_position > 200 ) 
     19                        _win_position = 0; 
    1620                return (_win_position += 30); 
    1721        } 
     
    1923        function _chat(_pJid) 
    2024        { 
     25                if ( !_chats[_pJid] ) 
     26                        _chats[_pJid] = []; 
     27 
    2128                var _win_pos = _next_position(); 
    2229                var _win_chat = _window.load('chat' + _pJid); 
     
    7683                ); 
    7784 
     85                var _composing_paused = null; 
    7886                function _execKeyAction(e) 
    7987                { 
     88                        if ( e.type.indexOf('keydown') != -1 ) 
     89                        { 
     90                                if ( (e.keyCode > 48 && e.keyCode < 112) || e.keyCode > 186 ) 
     91                                { 
     92                                        if ( _chats[_pJid]['composing_paused'] ) 
     93                                        { 
     94                                                clearTimeout(_chats[_pJid]['composing_paused']); 
     95                                                _chats[_pJid]['composing_paused'] = null; 
     96                                        } 
     97                                        else 
     98                                                _conn.go('t.composing','jid='+_pJid); 
     99 
     100                                        _chats[_pJid]['composing_paused'] = setTimeout( 
     101                                        function() 
     102                                        { 
     103                                                if ( _chats[_pJid]['composing_paused'] ) 
     104                                                { 
     105                                                        clearTimeout(_chats[_pJid]['composing_paused']); 
     106                                                        _chats[_pJid]['composing_paused'] = null; 
     107                                                } 
     108                                                _conn.go('t.paused','jid='+_pJid); 
     109                                        }, 5000); 
     110                                } 
     111                        } 
    80112                        switch ( e.keyCode ) 
    81113                        { 
     
    84116                                        { 
    85117                                                if ( e.type.indexOf('keydown') != -1 ) 
     118                                                { 
     119                                                        if ( _chats[_pJid]['composing_paused'] ) 
     120                                                        { 
     121                                                                clearTimeout(_chats[_pJid]['composing_paused']); 
     122                                                                _chats[_pJid]['composing_paused'] = null; 
     123                                                        } 
     124 
    86125                                                        _sendMessage( 
    87126                                                                _pJid, 
     
    89128                                                                _win_chat.wc.firstChild 
    90129                                                        ); 
     130                                                } 
    91131                                                else 
    92132                                                        _iframe.body.innerHTML = ''; 
     
    97137                                case 27 : 
    98138                                        if ( e.type.indexOf('keyup') != -1 ) 
     139                                        { 
     140                                                if ( _chats[_pJid]['composing_paused'] ) 
     141                                                { 
     142                                                        clearTimeout(_chats[_pJid]['composing_paused']); 
     143                                                        _chats[_pJid]['composing_paused'] = null; 
     144                                                } 
    99145                                                _win_chat.button(_win_chat.bc); 
     146                                        } 
    100147                                break; 
    101148                        } 
    102149                } 
     150                _config(_contentWindow.document, 'onkeyup', _execKeyAction); 
    103151                _config(_contentWindow.document, 'onkeydown', _execKeyAction); 
    104                 _config(_contentWindow.document, 'onkeyup', _execKeyAction); 
    105152 
    106153                if ( !(_vcards[_pJid]) ) 
     
    128175        function _openChat(el) 
    129176        { 
    130                 var id = el.id; 
    131  
    132                 id = id.substr(id.indexOf('_') + 1); 
     177                var id = el.getAttribute('jid'); 
    133178 
    134179                if ( id.indexOf('/') > -1 ) 
     
    139184                { 
    140185                        _win = _chat(id); 
    141                         var _st = el.style.backgroundImage; 
    142                         _win.icon(_st.substr(4, (_st.length - 5))); 
     186                        _win.title(el.getAttribute('idname')); 
     187                        _win.icon(eval('im_' + el.getAttribute('status') + '.src')); 
    143188                } 
    144189                else 
     
    152197        function _readContacts(_pContacts) 
    153198        { 
    154                 var _win_contact = _window.load('contact_list'); 
     199                var _win_contact = _window.get('contact_list'); 
     200                if ( !_win_contact ) 
     201                { 
     202                        _win_contact = _window.load('contact_list'); 
     203                        _win_contact.hidden(); 
    155204                        _win_contact.title('.::Expresso Messenger::.'); 
    156205                        _win_contact.size(170, 350); 
    157206                        _win_contact.position(30, 30, true); 
     207                        _win_contact.icon(im_unavailable.src); 
    158208                        _win_contact.bc.style.display = 'none'; 
    159                         _win_contact.wm.style.display = 'none'; 
    160                         _win_contact.icon(im_available.src); 
     209                } 
    161210 
    162211                var _params = { 
     
    176225                if ( _contact_list ) 
    177226                { 
    178                         _setPresence('unavailable'); 
     227                        _conn.go('$this.Ujabber.setPresence', 'type=unavailable'); 
    179228                        _setPresence(); 
    180229                        _ldap.photo( 
     
    241290                                                        var el = ( e.target ) ? e.target : e.srcElement; 
    242291                                                        var jid = el.parentNode.parentNode.id.substr(4); 
     292                                                        var _contact = el.parentNode.parentNode.previousSibling; 
     293                                                        _contact.parentNode.removeChild(_contact.nextSibling); 
     294                                                        _contact.parentNode.removeChild(_contact); 
    243295                                                        _conn.go('$this.Ujabber.removeContact','jid='+jid); 
    244296                                                } 
     
    264316                        } 
    265317                        var _contact = _contact_list.firstChild; 
     318                        var _show_all = _cookies.get('IM_unavailable'); 
    266319                        while ( _contact ) 
    267320                        { 
    268                                 _config(_contact, 'onmouseover', _hover); 
    269                                 _config(_contact, 'onmouseout', _hover); 
    270                                 if ( _contact.getAttribute('jid') ) 
     321                                if ( _contact.nodeName.toLowerCase() == 'div' ) 
    271322                                { 
    272                                         //_config(_contact, 'onmousedown', _click); 
    273                                         _config(_contact, 'onmouseup', _click); 
    274                                 } 
    275                                 else 
    276                                 { 
    277                                         _config(_contact, 'onclick', 
    278                                         function(e) 
    279                                         { 
    280                                                 var el = ( e.target ) ? e.target : e.srcElement; 
    281  
    282                                                 if ( el.style.backgroundImage.indexOf('group_open') < 0 ) 
    283                                                         el.style.backgroundImage = 'url(' + im_group_open.src + ')'; 
    284                                                 else 
    285                                                         el.style.backgroundImage = 'url(' + im_group_close.src + ')'; 
    286  
    287                                                 el = el.nextSibling; 
    288                                                 while ( el.getAttribute('jid') ) 
     323                                        _config(_contact, 'onmouseover', _hover); 
     324                                        _config(_contact, 'onmouseout', _hover); 
     325                                        if ( _contact.getAttribute('jid') ) 
     326                                        { 
     327                                                if ( _show_all == 'hidden' ) 
     328                                                        _contact.style.display = 'none'; 
     329                                                //_config(_contact, 'onmousedown', _click); 
     330                                                _config(_contact, 'onmouseup', _click); 
     331                                        } 
     332                                        else 
     333                                        { 
     334                                                _config(_contact, 'onclick', 
     335                                                function(e) 
    289336                                                { 
    290                                                         el.style.display = ( el.style.display != 'none' ) ? 
    291                                                                 'none' : 'block'; 
     337                                                        var el = ( e.target ) ? e.target : e.srcElement; 
     338                                                        var _display = "none"; 
     339                                                        var _image = im_group_close.src; 
     340 
     341                                                        if ( el.style.backgroundImage.indexOf('group_open') < 0 ) 
     342                                                        { 
     343                                                                _display = "block"; 
     344                                                                _image = im_group_open.src; 
     345                                                        } 
     346 
     347                                                        el.style.backgroundImage = 'url(' + _image + ')'; 
     348 
    292349                                                        el = el.nextSibling; 
    293                                                         if ( el && el.nextSibling ) 
     350                                                        while ( el.getAttribute('jid') ) 
     351                                                        { 
     352                                                                if ( el.style.backgroundImage.indexOf('unavailable') < 0 ) 
     353                                                                        el.style.display = _display; 
    294354                                                                el = el.nextSibling; 
    295                                                 } 
    296                                         }); 
     355                                                                if ( el && el.nextSibling ) 
     356                                                                        el = el.nextSibling; 
     357                                                        } 
     358                                                }); 
     359                                        } 
    297360                                } 
    298361                                _contact = _contact.nextSibling; 
     
    306369                var _pPresence; 
    307370                if ( arguments.length == 0 ) 
    308                         _pPresence = 'available'; 
     371                { 
     372                        if ( !(_pPresence = _cookies.get('IM_presence')) ) 
     373                                _pPresence = 'available'; 
     374                } 
    309375                else 
    310376                        _pPresence = arguments[0]; 
     377 
     378                _cookies.set('IM_presence', _pPresence); 
     379 
    311380                switch ( _pPresence ) 
    312381                { 
     
    324393                if ( _presence ) 
    325394                { 
     395                        var _img_status = eval('im_' + _pPresence + '.src'); 
     396 
    326397                        var _status = top.document.getElementById('im_status'); 
    327398                        if ( _status ) 
    328                                 _status.style.backgroundImage = 'url(' + eval('im_' + _pPresence + '.src') + ')'; 
     399                                _status.style.backgroundImage = 'url(' + _img_status + ')'; 
     400 
     401                        var _win_contacts = _window.get('contact_list'); 
     402                        if ( _win_contacts ) 
     403                                _win_contacts.icon(_img_status); 
     404 
    329405                        _conn.go('$this.Ujabber.setPresence', _presence); 
    330406                } 
     
    333409        function _vcard(_pJid) 
    334410        { 
     411                var _win_vcard; 
     412                if ( !(_win_vcard = _window.get('vcard_' + _pJid)) ) 
     413                { 
     414                        var _win_pos = _next_position(); 
     415 
     416                        _win_vcard = _window.load('vcard_' + _pJid); 
     417                        _win_vcard.title('.:: ' + imGetLang('Information Contacts') + ' ::.'); 
     418                        _win_vcard.size(300); 
     419                        _win_vcard.position(_win_pos, _win_pos); 
     420 
     421                        _win_vcard.wc.style.padding = "3px"; 
     422                        _win_vcard.bx.style.display = "none"; 
     423                } 
     424                else 
     425                        _win_vcard.focus(); 
     426 
    335427                if ( _vcards[_pJid] ) 
    336428                { 
    337429                        if ( _info[_pJid] ) 
    338430                                delete _info[_pJid]; 
    339  
    340                         var _win_vcard; 
    341                         if ( !(_win_vcard = _window.get('vcard_' + _pJid)) ) 
    342                         { 
    343                                 var _win_pos = _next_position(); 
    344  
    345                                 _win_vcard = _window.load('vcard_' + _pJid); 
    346                                 _win_vcard.title('.:: Informações do Contato ::.'); 
    347                                 _win_vcard.size(300); 
    348                                 _win_vcard.position(_win_pos, _win_pos); 
    349  
    350                                 _win_vcard.wc.style.padding = "3px"; 
    351                                 _win_vcard.bx.style.display = "none"; 
    352431 
    353432                                var _params = { 
     
    367446                                        ) 
    368447                                ); 
    369                         } 
    370                         else 
    371                                 _win_vcard.focus(); 
    372448                } 
    373449                else 
     450                { 
     451                        _win_vcard.loading(); 
    374452                        _conn.go('$this.Ujabber.getVcard', 'jid='+_pJid); 
     453                } 
    375454        } 
    376455 
     
    416495        { 
    417496                if ( pIq.firstChild.getAttribute("seconds") != 0 ) 
    418                         _setPresence(); 
     497                        _conn.go('$this.Ujabber.getContacts'); 
    419498        } 
    420499 
     
    426505                        _from = _from.substr(0, _from.indexOf('/')); 
    427506 
     507                var _contact_list = top.document.getElementById('contact_' + _from); 
     508 
    428509                var _win = _window.get('chat' + _from); 
    429510 
     511                if ( _contact_list && _pMessage.getElementsByTagName('composing').length > 0 ) 
     512                { 
     513                        _contact_list.style.backgroundImage = 'url(' + im_composing.src + ')'; 
     514                        setTimeout(function(){_contact_list.style.backgroundImage = 'url(' + eval('im_' + _contact_list.getAttribute('status') + '.src') + ')';}, 10000); 
     515                } 
     516 
    430517                if ( _win && _pMessage.getElementsByTagName('composing').length > 0 ) 
     518                { 
    431519                        _win.wc.childNodes[1].lastChild.style.display = 'block'; 
     520                        setTimeout(function(){_win.wc.childNodes[1].lastChild.style.display = 'none';}, 10000); 
     521                } 
    432522 
    433523                if ( _pMessage.getElementsByTagName('body').length > 0 ) 
     
    439529                                if ( _st ) 
    440530                                { 
    441                                         _st = _st.style.backgroundImage; 
    442                                         _win.icon(_st.substr(4, (_st.length - 5))); 
     531                                        _st = eval('im_' + _st.getAttribute('status') + '.src'); 
     532                                        _win.icon(_st); 
    443533                                } 
    444534                        } 
    445  
    446                         var _history = _win.wc.firstChild; 
     535                        _win.show(); 
    447536 
    448537                        var _nickname; 
     
    458547                                _nickname = _from; 
    459548 
    460                         var _msg = _xtools.parse(_pMessage, 'message_new.xsl', {'nickname':_nickname}); 
    461  
     549                        var _msg = _xtools.parse(_pMessage, 'message_new.xsl', {'nickname':_nickname,'time':Date().substr(16,5)}); 
     550 
     551                        var _history = _win.wc.firstChild; 
    462552                        if ( _history.scrollHeight == (_history.scrollTop + _history.clientHeight) ) 
    463553                        { 
     
    470560 
    471561                        _win.wc.childNodes[1].lastChild.style.display = 'none'; 
    472                 } 
     562                        if ( _contact_list ) 
     563                                _contact_list.style.backgroundImage = 'url(' + eval('im_' + _contact_list.getAttribute('status') + '.src') + ')'; 
     564                } 
     565 
     566                if ( _contact_list && _pMessage.getElementsByTagName('paused').length > 0 ) 
     567                        _contact_list.style.backgroundImage = 'url(' + eval('im_' + _contact_list.getAttribute('status') + '.src') + ')'; 
    473568 
    474569                if ( _win && _pMessage.getElementsByTagName('paused').length > 0 ) 
     
    486581                var _mensagem_status_contact = top.document.getElementById('status_' + _from); 
    487582                var _win_chat = _window.get('chat' + _from); 
     583 
     584                _img_status_contact.setAttribute('status', _presence_type); 
    488585 
    489586                if ( _mensagem_status_contact ) 
     
    503600                                        if ( _win_chat ) 
    504601                                                _win_chat.icon(eval('im_' + _presence_type + '.src')); 
     602                                        if ( _presence_type == 'unavailable' ) 
     603                                        { 
     604                                                var _show_all = _cookies.get('IM_unavailable'); 
     605                                                if ( _show_all == 'hidden' ) 
     606                                                        _img_status_contact.style.display = 'none'; 
     607                                        } 
     608                                        else 
     609                                                _img_status_contact.style.display = 'block'; 
    505610                                break; 
    506611                                case 'subscribe' : 
     
    613718                                if ( _node.hasChildNodes() ) 
    614719                                { 
     720                                        _img_status_contact.style.display = 'block'; 
    615721                                        switch ( _node.nodeName ) 
    616722                                        { 
     
    695801                _ldap = arguments[3]; 
    696802                _menu = arguments[4]; 
     803                _cookies = arguments[5]; 
    697804        } 
    698805 
  • trunk/instant_messenger/js/windows.js

    r311 r318  
    5656                                'button' : _button, 
    5757                                'content' : _content, 
     58                                'close' : function() 
     59                                { 
     60                                        _button(_window.childNodes[1].childNodes[2].childNodes[0]); 
     61                                }, 
    5862                                'focus' : _focus, 
     63                                'hidden' : function() 
     64                                { 
     65                                        _button(_window.childNodes[1].childNodes[2].childNodes[2]); 
     66                                }, 
    5967                                'icon' : _icon, 
     68                                'loading' : function() 
     69                                { 
     70                                        var _information = top.document.createElement('span'); 
     71                                                _information.appendChild( 
     72                                                        top.document.createTextNode(imGetLang('Loading')) 
     73                                                ); 
     74 
     75                                        var _loading = top.document.createElement('div'); 
     76                                                _loading.className = 'loading'; 
     77                                                _loading.appendChild(_information); 
     78 
     79                                        _content.call(this, _loading); 
     80                                }, 
    6081                                'position' : _position, 
     82                                'show' : function() 
     83                                { 
     84                                        _window.style.display = 'block'; 
     85                                }, 
    6186                                'size' : _size, 
    6287                                'title' : _title 
     
    106131                                delete _all_windows[w.id]; 
    107132                        break; 
     133                        case 'minimize' : 
     134                                w.style.display = 'none'; 
     135                        break; 
    108136                        case 'maximize' : 
    109137                                if ( !w.getAttribute('wParams') ) 
    110138                                { 
    111139                                        var _wParams  = (parseFloat(w.style.width) - 13); 
    112                                                 _wParams += ':' + parseFloat(w.childNodes[2].firstChild.style.height); 
     140                                                _wParams += ':' + parseFloat(w.childNodes[2].firstChild.style.maxHeight); 
    113141                                                _wParams += ':' + parseFloat(w.style.left); 
    114142                                                _wParams += ':' + parseFloat(w.style.right); 
     
    122150                                        w.style.height = "100%"; 
    123151                                        w.style.width = "100%"; 
     152 
     153                                        var _style = w.childNodes[2].firstChild.getAttribute('style'); 
     154                                        if ( typeof _style == 'object' && _style.cssText ) 
     155                                                _style = _style.cssText; 
     156 
     157                                        if ( w.childNodes[2].firstChild.style.cssText ) 
     158                                                w.childNodes[2].firstChild.style.cssText = ''; 
     159 
     160                                        _style = _style.replace(/max-height: ?\d+;?/i, ''); 
     161 
     162                                        w.childNodes[2].firstChild.setAttribute('style', _style); 
    124163 
    125164                                        w.childNodes[2].firstChild.style.height = (_bwr.height - 41) + "px"; 
     
    182221                                } 
    183222                        break; 
    184                         case 'minimize' : 
    185                                 w.style.display = 'none'; 
    186                         break; 
    187223                } 
    188224        } 
     
    271307 
    272308                if ( typeof pHeight == 'number' && !isNaN(pHeight) ) 
    273                         this.wc.style.height = pHeight + 'px'; 
     309                        this.wc.style.maxHeight = pHeight + 'px'; 
    274310        } 
    275311 
     
    285321        { 
    286322                var _argv = arguments; 
    287                 this._TARGET = ( _argv[_argv.length - 1].id ) ? 
    288                         _argv[_argv.length - 1] : document.body; 
     323                var _argc = _argv.length; 
     324                if ( (_argv[_argc - 1] != null) && (_argv[_argc - 1]).id ) 
     325                                this._TARGET = _argv[_argc - 1]; 
     326                else 
     327                        this._TARGET = top.document.body; 
    289328 
    290329                _xtools = arguments[0]; 
Note: See TracChangeset for help on using the changeset viewer.