source: trunk/jabberit_messenger/js/load.js @ 551

Revision 551, 12.7 KB checked in by niltonneto, 15 years ago (diff)

resolve #358, #363, #365, #366

  • Property svn:executable set to *
Line 
1(function()
2{
3        var _conn   = new JITConnector(path_jabberit);
4        var _xtools = new JITXTools(path_jabberit);
5        var _showhidden = new ShowHidden(1500);
6        var myWindow      = '';
7        var flagMouseOver = '';
8        var flagOpenIM    = '';
9   
10        // Sniffer Browser
11        var agt=navigator.userAgent.toLowerCase();
12    var is_major = parseInt(navigator.appVersion);
13    var is_minor = parseFloat(navigator.appVersion);   
14    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
15                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
16                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
17    var is_gecko = (agt.indexOf('gecko') != -1);
18    var is_gecko1_5 = (agt.indexOf('firefox/1.5') != -1 || agt.indexOf('firefox/2') != -1 || agt.indexOf('iceweasel/2') != -1);
19    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
20    var is_ie3    = (is_ie && (is_major < 4));
21    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
22    var is_ie4up  = (is_ie && (is_major >= 4));
23    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
24    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
25    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
26    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
27    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
28    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);   
29    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
30
31        if ( !(document.getElementById('jabberit_messenger_content')) )
32        {
33                var _jabberit_content = document.createElement('div');
34                _jabberit_content.setAttribute('id', 'jabberit_messenger_content');
35                _jabberit_content = document.body.appendChild(_jabberit_content);
36        }
37
38        var _window = new JITWindows(_xtools, _jabberit_content);
39        var _ldap       = new JITLdap( _conn, _xtools, _window);
40
41        function addIcon()
42        {
43                /**
44                 * Criada o elemento(div) jabberWriteMsg, dentro da função write_msg do módulo expressoMail1_2,
45                 * quando estiver habilitada a opção fora de escritório nos filtros.
46                 */
47               
48                if(document.getElementById('jabberWriteMsg'))
49                        var StatusBar = document.getElementById('jabberWriteMsg');
50                else
51                        var StatusBar = document.getElementById('divStatusBar');
52               
53                if(StatusBar)
54                {
55                        if( StatusBar.id != 'jabberWriteMsg' )
56                        {
57                                var _div = document.createElement('div');
58                                _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
59                                StatusBar.parentNode.insertBefore(_div,StatusBar);
60                        }
61
62                        StatusBar.style.paddingLeft = '33px';
63                       
64                        var divJabber = document.createElement('div');
65                                divJabber.setAttribute('id', 'JabberMessenger');
66                       
67                        var _status = top.document.createElement('div');
68                                _status.setAttribute('id', 'jabberit_login');
69                                _status.style.background = 'no-repeat';
70                                _status.style.backgroundImage = 'url(' + jabberit_group_open.src + ')';
71                                _status.style.float = 'left';
72                                _status.style.height = '15px';
73                                _status.style.left = '7px';
74                                _status.style.margin = '8 0 0 10px';
75                                _status.style.padding = '0px';
76                                _status.style.position = 'absolute';
77                                _status.style.width = '15px';
78                                _status.style.cursor = 'pointer';
79
80                        divJabber.insertBefore(_status,divJabber.firstChild);
81
82                        var _menu;
83                                _menu = top.document.createElement('span');
84                                _menu.setAttribute('id','fast_menu_jabberit');
85                                _menu.style.backgroundColor = 'cecece';
86                                _menu.style.display = 'none';
87                                _menu.style.margin = '20px 5px 0px -15px';
88                                _menu.style.position = 'absolute';
89                                _menu.style.zIndex = '99999';
90                                _menu.style.border = '1px dashed #000';
91                               
92                        divJabber.insertBefore(_menu, divJabber.firstChild);
93
94                        var _menu_div = top.document.createElement('div');
95                                _menu_div.style.background = 'no-repeat';
96                                _menu_div.style.backgroundImage = 'url(' + jabberit_add_user.src + ')';
97                                _menu_div.style.float = 'left';
98                                _menu_div.style.height = '18px';
99                                _menu_div.style.left = '19px';
100                                _menu_div.style.margin = '0 0 0 10px';
101                                _menu_div.style.padding = '0px';
102                                _menu_div.style.position = 'absolute';
103                                _menu_div.style.width = '18px';
104                                _menu_div.style.cursor = 'pointer';
105                                _menu_div.style.zindex = '99999999';
106                       
107                        divJabber.insertBefore(_menu_div, divJabber.firstChild);
108                        StatusBar.insertBefore(divJabber, StatusBar.firstChild);                       
109                       
110                        configEvents(_menu_div,'onclick',showWindow);
111
112                        configEvents(
113                                _status,
114                                'onclick',
115                                function()
116                                {
117                                        var _options = [
118                                                ['Add Contacts',addContacts],
119                                                ['Help',helpJabberit],
120                                                ['Preferences', preferences]
121                                        ];
122
123                                        var _style_text = 'cursor: pointer; padding:2px 2px 2px 15px; background: no-repeat url(' + jabberit_group_close.src + ');';                                   
124
125                                        var _xml = _xtools.xml('menu');
126                                        var _option;
127                                        var _item;
128                                        var _action;
129                                        var _style;
130
131                                        for ( var i in _options )
132                                        {
133                                                _option = _xml.createElement('option');
134
135                                                _item = _xml.createElement('item');
136                                                _item.appendChild(_xml.createTextNode(jabberitGetLang(_options[i][0])));
137                                               
138                                                _style = _xml.createElement('style');
139                                                _style.appendChild(_xml.createTextNode(_style_text));
140
141                                                _option.appendChild(_item);
142                                                _option.appendChild(_style);
143
144                                                _xml.documentElement.appendChild(_option);
145                                        }
146
147                                        _menu.innerHTML = _xtools.parse(_xml, 'options.xsl');
148                                        _showhidden.action('onmouseover', 'onmouseout', _menu);
149
150                                        _item = _menu.firstChild;
151
152                                        for ( var i in _options )
153                                        {
154                                                _item.childNodes[i].setAttribute('presence', _options[i]);
155                                                configEvents(
156                                                        _item.childNodes[i],
157                                                        'onclick',
158                                                        _options[i][1]
159                                                );
160                                        }
161                                }
162                        );
163                }
164        }
165
166        function addContacts()
167        {
168                _ldap.add();
169        }
170
171        function changeLabel()
172        {
173                if( arguments.length > 0 )
174                {
175                        var element = arguments[0].parentNode.parentNode.firstChild;
176
177                        if(arguments[0].checked)
178                                element.innerHTML = "Digite o Email .:";
179                        else
180                                element.innerHTML = "Nome do Contato .:";
181                }
182        }
183
184        function configEvents(pObj, pEvent, pHandler)
185        {
186                if ( typeof pObj == 'object' )
187                {
188                        if ( pEvent.substring(0, 2) == 'on' )
189                                pEvent = pEvent.substring(2, pEvent.length);
190
191                        if ( pObj.addEventListener )
192                                pObj.addEventListener(pEvent, pHandler, false);
193                        else if ( pObj.attachEvent )
194                                pObj.attachEvent('on' + pEvent, pHandler);
195                }
196        }
197
198        function closeWindow()
199        {
200                myWindow = '';
201        }
202
203        function getFocus()
204        {
205                var pNewWindow = myWindow;
206                for( var i = 15 ; i > 0 ; i-- )
207                {
208                        pNewWindow.moveBy(i,0);
209                        pNewWindow.moveBy(-i,0);
210                }
211                pNewWindow.focus();
212        }
213
214        function helpJabberit()
215        {
216                var myWindowHelp = window.open( path_jabberit + 'help.php', 'HelpjabberIM', 'width=800,height=495,top=50,left=50,scrollbars=yes');
217        }
218
219        function keyPressSearch()
220        {
221                var ev = arguments[0];
222                var element = arguments[1];
223
224                if ( ev.keyCode == 13 )
225                        if( element.value.length >= 4 )
226                                _ldap.search( element.value ); 
227                        else
228                                alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
229        }
230
231        function openPopup()
232        {
233                try{
234                        if( ! myWindow )
235                        {       
236                                myWindow = window.open( path_jabberit + 'client.php', 'JabberIM', 'width=215,height=400,top=50,left=50,toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no');
237                                myWindow.blur();
238                                configEvents(myWindow,'onbeforeunload', closeWindow );
239                        }else
240                                myWindow.focus();
241                }
242                catch(e)
243                {
244                        delete myWindow;
245                        myWindow = window.open( path_jabberit + 'client.php', 'JabberIM', 'width=215,height=400,top=50,left=50,toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no');
246                        myWindow.blur();
247                        configEvents(myWindow,'onbeforeunload', closeWindow );
248                }
249        }
250
251        function openWindow()
252        {
253                var _win_contacts = _window.load('jabberit_contacts');
254                if( flagOpenIM == 'openWindowJabberit:false' )
255                {
256                        _win_contacts.size(215,400);
257                }                                       
258                else
259                {
260                        _win_contacts.size(1,1);
261                        _win_contacts.wm.style.visibility = 'hidden';
262                }
263
264                _win_contacts.position(50,50);
265                _win_contacts.bc.style.display = "none";
266                _win_contacts.bx.style.display = "none";
267
268                if( _win_contacts.bz.removeEventListener )
269                        _win_contacts.bz.removeEventListener('click',_win_contacts.button, false);
270                else
271                        _win_contacts.bz.detachEvent('onclick',_win_contacts.button);
272
273                configEvents(
274                        _win_contacts.bz,
275                        "onclick",
276                        function()
277                        {
278                                _win_contacts.size(1,1);
279                                _win_contacts.wm.style.visibility = 'hidden';
280                                _win_contacts.position(50,50);
281                                _win_contacts.title('');
282                        }
283                );
284
285                var _params = {'path' : path_jabberit};
286                _win_contacts.content(_xtools.parse(_xtools.xml('contacts_jabberit'), 'contacts_jabberit.xsl', _params));
287
288                if( flagOpenIM == 'openWindowJabberit:false' )
289                {
290                        _win_contacts.wm.style.visibility = "visible";
291                        _win_contacts.title('.:: Expresso - JMessenger ::.');
292                }
293                else _win_contacts.wm.style.visibility = "hidden";
294        }
295
296        function getPreferences()
297        {
298                if( flagOpenIM == '' )
299                {
300                        _conn.go("$this.db_im.getPreferences",
301                                         function(data)
302                                         {
303                                                        flagOpenIM = data;
304                                                        if(flagOpenIM == 'openWindowJabberit:true')
305                                                        {
306                                                                setTimeout('loadscript.showW();', 2000);
307                                                        }
308                                         });
309                }
310        }
311
312        function preferences()
313        {
314                if( !(_window.get('jabberit_preferences')) )
315                {
316                        var _win_preferences = _window.load('jabberit_preferences');
317                                _win_preferences.size(300,250);
318                                _win_preferences.position(150,100);
319                                _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
320                                _win_preferences.bc.style.display = "none";
321                                _win_preferences.bx.style.display = "none";
322                                _win_preferences.wc.style.padding = "5px";                                                             
323
324                        if( _win_preferences.bz.removeEventListener )
325                                _win_preferences.bz.removeEventListener('click',_win_preferences.button, false);
326                        else
327                                _win_preferences.bz.detachEvent('onclick',_win_preferences.button);
328                               
329                        configEvents(
330                                _win_preferences.bz,
331                                "onclick",
332                                function()
333                                {
334                                        _win_preferences.size(1,1);
335                                        _win_preferences.wm.style.visibility = 'hidden';
336                                        _win_preferences.position(50,50);
337                                        _win_preferences.title('');
338                                });
339
340                        var _params = {'path'  : path_jabberit,
341                                                   'lang1' : jabberitGetLang('Your Preferences'),       
342                                                   'lang2' : 'Conectar o IM Automaticamente',
343                                                   'lang3' : jabberitGetLang('Save'),
344                                                   'lang4' : jabberitGetLang('Cancel')                                                                             
345                                                  };
346                        _win_preferences.content(_xtools.parse(_xtools.xml('preferences_jabberit'), 'preferences_jabberit.xsl', _params));
347                        _win_preferences.wc.lastChild.lastChild.onclick = _win_preferences.close;
348                }
349                else
350                {
351                        var _win_preferences = _window.get('jabberit_preferences');
352                        _win_preferences.wm.style.visibility = "visible";
353                        _win_preferences.position(150,100);                                                     
354                        _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
355                        _win_preferences.size(300,250);
356                }
357               
358                var value = flagOpenIM.split(':');
359                var elementSelect = document.getElementById(value[0]);
360                var valueSelect = value[1];
361
362
363                // Preenchendo a Select
364                for(var i = 0; i < elementSelect.options.length; i++)
365                        if( elementSelect.options[i].value == valueSelect )
366                                elementSelect.options[i].selected = true;
367        }
368
369        function searchUser()
370        {
371                var element = arguments[0].previousSibling;
372               
373                if( element.value.length >= 4 )
374                        _ldap.search( element.value ); 
375                else
376                        alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
377        }
378       
379        function setPreferences()
380        {
381                var element = document.getElementById('openWindowJabberit');
382               
383                for(var i = 0 ; i < element.options.length; i++)
384                        if( element.options[i].selected == true)
385                                var value = element.options[i].value;
386                               
387                _conn.go('$this.db_im.setPreferences',
388                                 function(data)
389                                 {
390                                        if(data == 'true')
391                                        {
392                                                flagOpenIM = 'openWindowJabberit:' + value;
393                                                alert(jabberitGetLang('Preferences saved with success!'));
394                                        }
395                                        else
396                                                alert(jabberitGetLang('Error saving your preferences!'));
397                                                                               
398                                        var _win_preferences = _window.get('jabberit_preferences');
399                                                _win_preferences.close();
400                                                                                       
401                                 },
402                                'preferences=openWindowJabberit:' + value);
403        }
404       
405        function showDiv()
406        {
407                var _element = ( myWindow ) ? myWindow.document.body.firstChild : null ;
408                if( _element != null )
409                        _element.style.visibility = 'visible';
410        }
411
412        function showWindow()
413        {
414                var _win_contacts = _window.get('jabberit_contacts');
415                if( !is_ie )
416                {
417                        if ( _win_contacts )
418                        {       
419                                _win_contacts.wm.style.visibility = "visible";
420                                _win_contacts.title('.:: Expresso - JMessenger ::.');
421                                _win_contacts.size(215,400);
422                        }
423                        else
424                                openWindow();
425                }
426                else
427                        openPopup();
428        }
429
430        function Load()
431        {
432                addIcon();
433                getPreferences();
434        }
435
436        Load.prototype.keyPress = keyPressSearch;
437        Load.prototype.search = searchUser;
438        Load.prototype.show = showDiv;
439        Load.prototype.showW = showWindow;
440        Load.prototype.setPrefe = setPreferences;
441        Load.prototype.closeW = closeWindow;
442        Load.prototype.cLabel = changeLabel;
443        Load.prototype.adIcon = addIcon;
444        window.loadscript = new Load;
445
446})();
Note: See TracBrowser for help on using the repository browser.