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

Revision 439, 12.4 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por Alexandre Correia.
Carrega Fotos do Ldap.
Email: alexandrecorreia@…

  • 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 configEvents(pObj, pEvent, pHandler)
172        {
173                if ( typeof pObj == 'object' )
174                {
175                        if ( pEvent.substring(0, 2) == 'on' )
176                                pEvent = pEvent.substring(2, pEvent.length);
177
178                        if ( pObj.addEventListener )
179                                pObj.addEventListener(pEvent, pHandler, false);
180                        else if ( pObj.attachEvent )
181                                pObj.attachEvent('on' + pEvent, pHandler);
182                }
183        }
184
185        function closeWindow()
186        {
187                myWindow = '';
188        }
189
190        function getFocus()
191        {
192                var pNewWindow = myWindow;
193                for( var i = 15 ; i > 0 ; i-- )
194                {
195                        pNewWindow.moveBy(i,0);
196                        pNewWindow.moveBy(-i,0);
197                }
198                pNewWindow.focus();
199        }
200
201        function helpJabberit()
202        {
203                var myWindowHelp = window.open( path_jabberit + 'help.php', 'HelpjabberIM', 'width=800,height=495,top=50,left=50,scrollbars=yes');
204        }
205
206        function keyPressSearch()
207        {
208                var ev = arguments[0];
209                var element = arguments[1];
210
211                if ( ev.keyCode == 13 )
212                        if( element.value.length >= 4 )
213                                _ldap.search( element.value ); 
214                        else
215                                alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
216        }
217
218        function openPopup()
219        {
220                try{
221                        if( ! myWindow )
222                        {       
223                                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');
224                                myWindow.blur();
225                                configEvents(myWindow,'onbeforeunload', closeWindow );
226                        }else
227                                myWindow.focus();
228                }
229                catch(e)
230                {
231                        delete myWindow;
232                        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');
233                        myWindow.blur();
234                        configEvents(myWindow,'onbeforeunload', closeWindow );
235                }
236        }
237
238        function openWindow()
239        {
240                var _win_contacts = _window.load('jabberit_contacts');
241                if( flagOpenIM == 'openWindowJabberit:false' )
242                {
243                        _win_contacts.size(215,400);
244                }                                       
245                else _win_contacts.size(1,1);
246
247                _win_contacts.position(50,50);
248                _win_contacts.bc.style.display = "none";
249                _win_contacts.bx.style.display = "none";
250
251                if( _win_contacts.bz.removeEventListener )
252                        _win_contacts.bz.removeEventListener('click',_win_contacts.button, false);
253                else
254                        _win_contacts.bz.detachEvent('onclick',_win_contacts.button);
255
256                configEvents(
257                        _win_contacts.bz,
258                        "onclick",
259                        function()
260                        {
261                                _win_contacts.size(1,1);
262                                _win_contacts.wm.style.visibility = 'hidden';
263                                _win_contacts.position(50,50);
264                                _win_contacts.title('');
265                        }
266                );
267
268                var _params = {'path' : path_jabberit};
269                _win_contacts.content(_xtools.parse(_xtools.xml('contacts_jabberit'), 'contacts_jabberit.xsl', _params));
270
271                if( flagOpenIM == 'openWindowJabberit:false' )
272                {
273                        _win_contacts.wm.style.visibility = "visible";
274                        _win_contacts.title('.:: Expresso - JMessenger ::.');
275                }
276                else _win_contacts.wm.style.visibility = "hidden";
277        }
278
279        function getPreferences()
280        {
281                if( flagOpenIM == '' )
282                {
283                        _conn.go("$this.db_im.getPreferences",
284                                         function(data)
285                                         {
286                                                        flagOpenIM = data;
287                                                        if(flagOpenIM == 'openWindowJabberit:true')
288                                                        {
289                                                                setTimeout('loadscript.showW();', 2000);
290                                                        }
291                                         });
292                }
293        }
294
295        function preferences()
296        {
297                if( !(_window.get('jabberit_preferences')) )
298                {
299                        var _win_preferences = _window.load('jabberit_preferences');
300                                _win_preferences.size(300,250);
301                                _win_preferences.position(150,100);
302                                _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
303                                _win_preferences.bc.style.display = "none";
304                                _win_preferences.bx.style.display = "none";
305                                _win_preferences.wc.style.padding = "5px";                                                             
306
307                        if( _win_preferences.bz.removeEventListener )
308                                _win_preferences.bz.removeEventListener('click',_win_preferences.button, false);
309                        else
310                                _win_preferences.bz.detachEvent('onclick',_win_preferences.button);
311                               
312                        configEvents(
313                                _win_preferences.bz,
314                                "onclick",
315                                function()
316                                {
317                                        _win_preferences.size(1,1);
318                                        _win_preferences.wm.style.visibility = 'hidden';
319                                        _win_preferences.position(50,50);
320                                        _win_preferences.title('');
321                                });
322
323                        var _params = {'path'  : path_jabberit,
324                                                   'lang1' : jabberitGetLang('Your Preferences'),       
325                                                   'lang2' : 'Conectar o IM Automaticamente',
326                                                   'lang3' : jabberitGetLang('Save'),
327                                                   'lang4' : jabberitGetLang('Cancel')                                                                             
328                                                  };
329                        _win_preferences.content(_xtools.parse(_xtools.xml('preferences_jabberit'), 'preferences_jabberit.xsl', _params));
330                        _win_preferences.wc.lastChild.lastChild.onclick = _win_preferences.close;
331                }
332                else
333                {
334                        var _win_preferences = _window.get('jabberit_preferences');
335                        _win_preferences.wm.style.visibility = "visible";
336                        _win_preferences.position(150,100);                                                     
337                        _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
338                        _win_preferences.size(300,250);
339                }
340               
341                var value = flagOpenIM.split(':');
342                var elementSelect = document.getElementById(value[0]);
343                var valueSelect = value[1];
344
345
346                // Preenchendo a Select
347                for(var i = 0; i < elementSelect.options.length; i++)
348                        if( elementSelect.options[i].value == valueSelect )
349                                elementSelect.options[i].selected = true;
350        }
351
352        function searchUser()
353        {
354                var element = arguments[0].previousSibling;
355               
356                if( element.value.length >= 4 )
357                        _ldap.search( element.value ); 
358                else
359                        alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
360        }
361       
362        function setPreferences()
363        {
364                var element = document.getElementById('openWindowJabberit');
365               
366                for(var i = 0 ; i < element.options.length; i++)
367                        if( element.options[i].selected == true)
368                                var value = element.options[i].value;
369                               
370                _conn.go('$this.db_im.setPreferences',
371                                 function(data)
372                                 {
373                                        if(data == 'true')
374                                        {
375                                                flagOpenIM = 'openWindowJabberit:' + value;
376                                                alert(jabberitGetLang('Preferences saved with success!'));
377                                        }
378                                        else
379                                                alert(jabberitGetLang('Error saving your preferences!'));
380                                                                               
381                                        var _win_preferences = _window.get('jabberit_preferences');
382                                                _win_preferences.close();
383                                                                                       
384                                 },
385                                'preferences=openWindowJabberit:' + value);
386        }
387       
388        function showDiv()
389        {
390                var _element = ( myWindow ) ? myWindow.document.body.firstChild : null ;
391                if( _element != null )
392                        _element.style.visibility = 'visible';
393        }
394
395        function showWindow()
396        {
397                var _win_contacts = _window.get('jabberit_contacts');
398                if( !is_ie )
399                {
400                        if ( _win_contacts )
401                        {
402                                _win_contacts.wm.style.visibility = "visible";
403                                _win_contacts.title('.:: Expresso - JMessenger ::.');
404                                _win_contacts.size(215,400);
405                        }
406                        else
407                                openWindow();
408                }
409                else
410                        openPopup();
411        }
412
413        function Load()
414        {
415                addIcon();
416                getPreferences();
417        }
418
419        Load.prototype.keyPress = keyPressSearch;
420        Load.prototype.search = searchUser;
421        Load.prototype.show = showDiv;
422        Load.prototype.showW = showWindow;
423        Load.prototype.setPrefe = setPreferences;
424        Load.prototype.closeW = closeWindow;
425        Load.prototype.adIcon = addIcon;
426        window.loadscript = new Load;
427
428})();
Note: See TracBrowser for help on using the repository browser.