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

Commit feito pelo desenvolvedor (rodrigosouza).

File:
1 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)(); 
Note: See TracChangeset for help on using the changeset viewer.