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

Revision 560, 15.7 KB checked in by niltonneto, 15 years ago (diff)

resolve #376

  • 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                if( !is_ie )
36                        _jabberit_content = document.body.appendChild(_jabberit_content);
37        }
38
39        var _window = new JITWindows(_xtools, _jabberit_content);
40        var _ldap       = new JITLdap( _conn, _xtools, _window);
41
42        function addIcon()
43        {
44                /**
45                 * Criado o elemento(div) jabberWriteMsg, dentro da função write_msg do módulo expressoMail1_2,
46                 * quando estiver habilitada a opção fora de escritório nos filtros.
47                 */
48               
49                if(document.getElementById('jabberWriteMsg'))
50                        var StatusBar = document.getElementById('jabberWriteMsg');
51                else
52                        var StatusBar = document.getElementById('divStatusBar');
53               
54                if(StatusBar)
55                {
56                        if( StatusBar.id != 'jabberWriteMsg' )
57                        {
58                                var _div = document.createElement('div');
59                                _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
60                                StatusBar.parentNode.insertBefore(_div,StatusBar);
61                        }
62
63                        StatusBar.style.paddingLeft = '33px';
64                       
65                        var divJabber = document.createElement('div');
66                                divJabber.setAttribute('id', 'JabberMessenger');
67                       
68                        var _status = top.document.createElement('div');
69                                _status.setAttribute('id', 'jabberit_login');
70                                _status.style.background = 'no-repeat';
71                                _status.style.backgroundImage = 'url(' + jabberit_group_open.src + ')';
72                                _status.style.float = 'left';
73                                _status.style.height = '15px';
74                                _status.style.left = '7px';
75                                _status.style.margin = '8 0 0 10px';
76                                _status.style.padding = '0px';
77                                _status.style.position = 'absolute';
78                                _status.style.width = '15px';
79                                _status.style.cursor = 'pointer';
80
81                        divJabber.insertBefore(_status,divJabber.firstChild);
82
83                        var _menu;
84                                _menu = top.document.createElement('span');
85                                _menu.setAttribute('id','fast_menu_jabberit');
86                                _menu.style.backgroundColor = 'cecece';
87                                _menu.style.display = 'none';
88                                _menu.style.margin = '20px 5px 0px -15px';
89                                _menu.style.position = 'absolute';
90                                _menu.style.zIndex = '99999';
91                                _menu.style.border = '1px dashed #000';
92                               
93                        divJabber.insertBefore(_menu, divJabber.firstChild);
94
95                        var _menu_div = top.document.createElement('div');
96                                _menu_div.style.background = 'no-repeat';
97                                _menu_div.style.backgroundImage = 'url(' + jabberit_add_user.src + ')';
98                                _menu_div.style.float = 'left';
99                                _menu_div.style.height = '18px';
100                                _menu_div.style.left = '19px';
101                                _menu_div.style.margin = '0 0 0 10px';
102                                _menu_div.style.padding = '0px';
103                                _menu_div.style.position = 'absolute';
104                                _menu_div.style.width = '18px';
105                                _menu_div.style.cursor = 'pointer';
106                                _menu_div.style.zindex = '99999999';
107                       
108                        divJabber.insertBefore(_menu_div, divJabber.firstChild);
109                        StatusBar.insertBefore(divJabber, StatusBar.firstChild);                       
110                       
111                        configEvents(_menu_div,'onclick',showWindow);
112
113                        configEvents(
114                                _status,
115                                'onclick',
116                                function()
117                                {
118                                        var _options = [
119                                                ['Add Contacts',addContacts],
120                                                ['Help',helpJabberit],
121                                                ['Preferences', preferences]
122                                        ];
123
124                                        var _style_text = 'cursor: pointer; padding:2px 2px 2px 15px; background: no-repeat url(' + jabberit_group_close.src + ');';                                   
125
126                                        var _xml = _xtools.xml('menu');
127                                        var _option;
128                                        var _item;
129                                        var _action;
130                                        var _style;
131
132                                        for ( var i in _options )
133                                        {
134                                                _option = _xml.createElement('option');
135
136                                                _item = _xml.createElement('item');
137                                                _item.appendChild(_xml.createTextNode(jabberitGetLang(_options[i][0])));
138                                               
139                                                _style = _xml.createElement('style');
140                                                _style.appendChild(_xml.createTextNode(_style_text));
141
142                                                _option.appendChild(_item);
143                                                _option.appendChild(_style);
144
145                                                _xml.documentElement.appendChild(_option);
146                                        }
147
148                                        _menu.innerHTML = _xtools.parse(_xml, 'options.xsl');
149                                        _showhidden.action('onmouseover', 'onmouseout', _menu);
150
151                                        _item = _menu.firstChild;
152
153                                        for ( var i in _options )
154                                        {
155                                                _item.childNodes[i].setAttribute('presence', _options[i]);
156                                                configEvents(
157                                                        _item.childNodes[i],
158                                                        'onclick',
159                                                        _options[i][1]
160                                                );
161                                        }
162                                }
163                        );
164                }
165        }
166
167        function addContacts()
168        {
169                _ldap.add();
170        }
171
172        function changeLabel()
173        {
174                if( arguments.length > 0 )
175                {
176                        var element = arguments[0].parentNode.parentNode.firstChild;
177
178                        if(arguments[0].checked)
179                                element.innerHTML = "<span style='color:red;'>Digite o Email .: </span>";
180                        else
181                                element.innerHTML = "Nome do Contato .: ";
182                }
183        }
184
185        function configEvents(pObj, pEvent, pHandler)
186        {
187                if ( typeof pObj == 'object' )
188                {
189                        if ( pEvent.substring(0, 2) == 'on' )
190                                pEvent = pEvent.substring(2, pEvent.length);
191
192                        if ( pObj.addEventListener )
193                                pObj.addEventListener(pEvent, pHandler, false);
194                        else if ( pObj.attachEvent )
195                                pObj.attachEvent('on' + pEvent, pHandler);
196                }
197        }
198
199        function closeWindow()
200        {
201                myWindow = '';
202        }
203
204        function getFocus()
205        {
206                var pNewWindow = myWindow;
207                for( var i = 15 ; i > 0 ; i-- )
208                {
209                        pNewWindow.moveBy(i,0);
210                        pNewWindow.moveBy(-i,0);
211                }
212                pNewWindow.focus();
213        }
214
215        function helpJabberit()
216        {
217                var myWindowHelp = window.open( path_jabberit + 'help.php', 'HelpjabberIM', 'width=800,height=495,top=50,left=50,scrollbars=yes');
218        }
219
220        function keyPressSearch()
221        {
222                var ev = arguments[0];
223                var element = arguments[1];
224
225                if ( ev.keyCode == 13 )
226                        if( element.value.length >= 4 )
227                                _ldap.search( element.value ); 
228                        else
229                                alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
230        }
231
232        function openPopup()
233        {
234                try{
235                        if( ! myWindow )
236                        {       
237                                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');
238                                myWindow.blur();
239                                configEvents(myWindow,'onbeforeunload', closeWindow );
240                        }else
241                                myWindow.focus();
242                }
243                catch(e)
244                {
245                        delete myWindow;
246                        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');
247                        myWindow.blur();
248                        configEvents(myWindow,'onbeforeunload', closeWindow );
249                }
250        }
251
252        function openWindow()
253        {
254                var _win_contacts = _window.load('jabberit_contacts');
255                var flagOpenAux = '';
256               
257                if( flagOpenIM.indexOf(';') != -1 )
258                {
259                        var aux = flagOpenIM.split(';');
260                        flagOpenAux = aux[0];
261                }
262                else
263                        flagOpenAux = flagOpenIM;
264               
265                if( flagOpenAux == 'openWindowJabberit:false' )
266                {
267                        _win_contacts.size(215,400);
268                }                                       
269                else
270                {
271                        _win_contacts.size(1,1);
272                        _win_contacts.wm.style.visibility = 'hidden';
273                }
274
275                _win_contacts.position(50,50);
276                _win_contacts.bc.style.display = "none";
277                _win_contacts.bx.style.display = "none";
278
279                if( _win_contacts.bz.removeEventListener )
280                        _win_contacts.bz.removeEventListener('click',_win_contacts.button, false);
281                else
282                        _win_contacts.bz.detachEvent('onclick',_win_contacts.button);
283
284                configEvents(
285                        _win_contacts.bz,
286                        "onclick",
287                        function()
288                        {
289                                _win_contacts.size(1,1);
290                                _win_contacts.wm.style.visibility = 'hidden';
291                                _win_contacts.position(50,50);
292                                _win_contacts.title('');
293                        }
294                );
295
296                var _params = {'path' : path_jabberit};
297                _win_contacts.content(_xtools.parse(_xtools.xml('contacts_jabberit'), 'contacts_jabberit.xsl', _params));
298
299                if( flagOpenAux == 'openWindowJabberit:false' )
300                {
301                        _win_contacts.wm.style.visibility = "visible";
302                        _win_contacts.title('.:: Expresso - JMessenger ::.');
303                }
304                else _win_contacts.wm.style.visibility = "hidden";
305        }
306
307        function getPreferences()
308        {
309                if( flagOpenIM == '' )
310                {
311                        _conn.go("$this.db_im.getPreferences",
312                                         function(data)
313                                         {
314                                                        var autoConnect = '';
315                                                        flagOpenIM = data;
316                                                       
317                                                        if( flagOpenIM.indexOf(';') != -1)
318                                                        {
319                                                                var temp = flagOpenIM.split(';');
320                                                                autoConnect = temp[0];
321                                                        }
322                                                        else
323                                                                autoConnect = flagOpenIM;
324
325                                                        if( autoConnect == 'openWindowJabberit:true' )
326                                                        {
327                                                                setTimeout('loadscript.showW();', 2500);
328                                                        }
329                                         });
330                }
331        }
332
333        function openWindowParticipantsExternal()
334        {
335                if( arguments.length > 0)
336                {
337                        var element = arguments[0];
338                        var orgPartExternal = externalParticipantsJabberit.split(",");
339                       
340                        var _splash = top.document.createElement('span');
341                                _splash.setAttribute('id','fast_splash_jabberit');
342                                _splash.style.backgroundColor = 'dedede';
343                                _splash.style.position = 'absolute';
344                                _splash.style.display = 'block';
345                                _splash.style.width = '200px';
346                                _splash.style.height = 'auto';
347                                _splash.style.margin = ( !is_ie ) ? '0px 5px 0px 130px' : '20px 0px 0px 0px';
348                                _splash.style.zIndex = '99999';
349                                _splash.style.border = '2px outset #000';
350                       
351                                for(var i = 0; i < orgPartExternal.length; i++)
352                                        _splash.innerHTML += '<div style="margin:5px;border-bottom:1px dashed #000;cursor:default !important;">' + (i + 1) + " - " + orgPartExternal[i] + '</div>';     
353                               
354                        _showhidden.action('onmouseover', 'onmouseout', _splash);
355                        element.appendChild(_splash);
356                }
357        }
358
359        function preferences()
360        {
361                if( !(_window.get('jabberit_preferences')) )
362                {
363                        var _win_preferences = _window.load('jabberit_preferences');
364                                _win_preferences.size(300,250);
365                                _win_preferences.position(150,100);
366                                _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
367                                _win_preferences.bc.style.display = "none";
368                                _win_preferences.bx.style.display = "none";
369                                _win_preferences.wc.style.padding = "5px";                                                             
370
371                        if( _win_preferences.bz.removeEventListener )
372                                _win_preferences.bz.removeEventListener('click',_win_preferences.button, false);
373                        else
374                                _win_preferences.bz.detachEvent('onclick',_win_preferences.button);
375                               
376                        configEvents(
377                                _win_preferences.bz,
378                                "onclick",
379                                function()
380                                {
381                                        _win_preferences.size(1,1);
382                                        _win_preferences.wm.style.visibility = 'hidden';
383                                        _win_preferences.position(50,50);
384                                        _win_preferences.title('');
385                                });
386
387                        var _params = {'path'  : path_jabberit,
388                                                   'lang1' : jabberitGetLang('Your Preferences'),
389                                                   'lang2' : jabberitGetLang('Auto Connection'),       
390                                                   'lang3' : jabberitGetLang('Enable Auto Login IM'),
391                                                   'lang4' : jabberitGetLang('Users OffLine'),
392                                                   'lang5' : jabberitGetLang('Show friends Offline'),
393                                                   'lang6' : jabberitGetLang('Save'),
394                                                   'lang7' : jabberitGetLang('Cancel'),
395                                                   'langYes': jabberitGetLang('Yes'),
396                                                   'langNo':  jabberitGetLang('No')                                                                                       
397                                                  };
398                        _win_preferences.content(_xtools.parse(_xtools.xml('preferences_jabberit'), 'preferences_jabberit.xsl', _params));
399                        _win_preferences.wc.lastChild.lastChild.onclick = _win_preferences.close;
400                }
401                else
402                {
403                        var _win_preferences = _window.get('jabberit_preferences');
404                        _win_preferences.wm.style.visibility = "visible";
405                        _win_preferences.position(150,100);                                                     
406                        _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
407                        _win_preferences.size(300,250);
408                }
409
410                if( flagOpenIM.indexOf(';') != -1 )
411                {
412                        var temp = flagOpenIM.split(';');
413                       
414                        // Element openWindowJabberit
415                        var value1 = temp[0].split(':');
416                        var element1 = document.getElementById(value1[0]);
417                        var valueSelect1 = value1[1];
418                       
419                        for(var i = 0; i < element1.options.length; i++)
420                                if( element1.options[i].value == valueSelect1 )
421                                        element1.options[i].selected = true;
422
423                        // Element userOfflineJabberit
424                        var value2 = temp[1].split(':');
425                        var element2 = document.getElementById(value2[0]);
426                        var valueSelect2 = value2[1];
427                       
428                        for(var i = 0; i < element2.options.length; i++)
429                                if( element2.options[i].value == valueSelect2 )
430                                        element2.options[i].selected = true;
431                }
432                else
433                {
434                        // Element openWindowJabberit
435                        var value1 = flagOpenIM.split(':');
436                        var element1 = document.getElementById(value1[0]);
437                        var valueSelect1 = value1[1];
438
439                        for(var i = 0; i < element1.options.length; i++)
440                                if( element1.options[i].value == valueSelect1 )
441                                        element1.options[i].selected = true;
442                }
443        }
444
445        function searchUser()
446        {
447                var element = arguments[0].previousSibling;
448               
449                if( element.value.length >= 4 )
450                        _ldap.search( element.value ); 
451                else
452                        alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
453        }
454       
455        function setPreferences()
456        {
457                // Element openWindowJabberit
458                var elementOpenW = document.getElementById('openWindowJabberit');
459                var value = '';
460                var valueAux = '';
461               
462                for(var i = 0 ; i < elementOpenW.options.length; i++)
463                        if( elementOpenW.options[i].selected == true)
464                        {
465                                value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value;
466                                valueAux = 'openWindowJabberit:' + elementOpenW.options[i].value;
467                        }
468
469                // Element userOfflineJabberit                         
470                var elementUserOff = document.getElementById('userOfflineJabberit');
471               
472                for(var i = 0; i < elementUserOff.options.length; i++)
473                        if( elementUserOff.options[i].selected == true )
474                        {
475                                value += '&preferences2=userOfflineJabberit:' + elementUserOff.options[i].value;
476                                valueAux += ';userOfflineJabberit:' + elementUserOff.options[i].value;
477                        }               
478               
479                _conn.go('$this.db_im.setPreferences',
480                                 function(data)
481                                 {
482                                        if(data == 'true')
483                                        {
484                                                flagOpenIM = valueAux;
485                                                alert(jabberitGetLang('Preferences saved with success!'));
486                                        }
487                                        else
488                                                alert(jabberitGetLang('Error saving your preferences!'));
489                                                                               
490                                        var _win_preferences = _window.get('jabberit_preferences');
491                                                _win_preferences.close();
492                                                                                       
493                                 },
494                                value);
495        }
496       
497        function showDiv()
498        {
499                var _element = ( myWindow ) ? myWindow.document.body.firstChild : null ;
500                if( _element != null )
501                        _element.style.visibility = 'visible';
502        }
503
504        function showWindow()
505        {
506                var _win_contacts = _window.get('jabberit_contacts');
507                if( !is_ie )
508                {
509                        if ( _win_contacts )
510                        {       
511                                _win_contacts.wm.style.visibility = "visible";
512                                _win_contacts.title('.:: Expresso - JMessenger ::.');
513                                _win_contacts.size(215,400);
514                        }
515                        else
516                                openWindow();
517                }
518                else
519                        openPopup();
520        }
521
522        function Load()
523        {
524                addIcon();
525                getPreferences();
526        }
527
528        Load.prototype.adIcon   = addIcon;
529        Load.prototype.cLabel   = changeLabel;
530        Load.prototype.closeW   = closeWindow;
531        Load.prototype.keyPress = keyPressSearch;
532        Load.prototype.openWinParExt = openWindowParticipantsExternal;
533        Load.prototype.search   = searchUser;
534        Load.prototype.setPrefe = setPreferences;
535        Load.prototype.show             = showDiv;
536        Load.prototype.showW    = showWindow;
537
538        window.loadscript = new Load;
539
540})();
Note: See TracBrowser for help on using the repository browser.