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

Revision 417, 11.8 KB checked in by niltonneto, 16 years ago (diff)

Vide changelog do módulo.
http://www.expressolivre.org/dev/wiki/jabberit/changelog
Alterações feitas por Alexandre Correia
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                var StatusBar = '';
44                if((StatusBar = document.getElementById('divStatusBar')))
45                {
46                        var _div = document.createElement('div');
47                        _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling));
48                        StatusBar.parentNode.insertBefore(_div,StatusBar);
49
50                        StatusBar.style.paddingLeft = '33px';
51
52                        var _status = top.document.createElement('div');
53                                _status.setAttribute('id', 'jabberit_status');
54                                _status.style.background = 'no-repeat';
55                                _status.style.backgroundImage = 'url(' + jabberit_group_open.src + ')';
56                                _status.style.float = 'left';
57                                _status.style.height = '15px';
58                                _status.style.left = '7px';
59                                _status.style.margin = '8 0 0 10px';
60                                _status.style.padding = '0px';
61                                _status.style.position = 'absolute';
62                                _status.style.width = '15px';
63                                _status.style.cursor = 'pointer';
64
65                        StatusBar.insertBefore(_status, StatusBar.firstChild);
66
67                        var _menu;
68                                _menu = top.document.createElement('span');
69                                _menu.setAttribute('id','fast_menu_jabberit');
70                                _menu.style.backgroundColor = 'cecece';
71                                _menu.style.display = 'none';
72                                _menu.style.margin = '20px 0 0 -15px';
73                                _menu.style.position = 'absolute';
74                                _menu.style.zIndex = '99999';
75                                _menu.style.border = '1px dashed #000';
76                        StatusBar.insertBefore(_menu, StatusBar.firstChild);
77
78                        var _menu_div = top.document.createElement('div');
79                                _menu_div.style.background = 'no-repeat';
80                                _menu_div.style.backgroundImage = 'url(' + jabberit_add_user.src + ')';
81                                _menu_div.style.float = 'left';
82                                _menu_div.style.height = '18px';
83                                _menu_div.style.left = '19px';
84                                _menu_div.style.margin = '0 0 0 10px';
85                                _menu_div.style.padding = '0px';
86                                _menu_div.style.position = 'absolute';
87                                _menu_div.style.width = '18px';
88                                _menu_div.style.cursor = 'pointer';
89                       
90                        StatusBar.insertBefore(_menu_div, StatusBar.firstChild);
91                       
92                        configEvents(_menu_div,'onclick',showWindow);
93
94                        configEvents(
95                                _status,
96                                'onclick',
97                                function()
98                                {
99                                        var _options = [
100                                                ['Add Contacts',addContacts],
101                                                ['Help',helpJabberit],
102                                                ['Preferences', preferences]
103                                        ];
104
105                                        var _style_text = 'cursor: pointer; padding:2px 4px 2px 20px; background: no-repeat url(' + jabberit_group_close.src + ');';
106
107                                        var _xml = _xtools.xml('menu');
108                                        var _option;
109                                        var _item;
110                                        var _action;
111                                        var _style;
112
113                                        for ( var i in _options )
114                                        {
115                                                _option = _xml.createElement('option');
116
117                                                _item = _xml.createElement('item');
118                                                _item.appendChild(_xml.createTextNode(jabberitGetLang(_options[i][0])));
119                                               
120                                                _style = _xml.createElement('style');
121                                                _style.appendChild(_xml.createTextNode(_style_text));
122
123                                                _option.appendChild(_item);
124                                                _option.appendChild(_style);
125
126                                                _xml.documentElement.appendChild(_option);
127                                        }
128
129                                        _menu.innerHTML = _xtools.parse(_xml, 'options.xsl');
130                                        _showhidden.action('onmouseover', 'onmouseout', _menu);
131
132                                        _item = _menu.firstChild;
133
134                                        for ( var i in _options )
135                                        {
136                                                _item.childNodes[i].setAttribute('presence', _options[i]);
137                                                configEvents(
138                                                        _item.childNodes[i],
139                                                        'onclick',
140                                                        _options[i][1]
141                                                );
142                                        }
143                                }
144                        );
145                }
146        }
147
148        function addContacts()
149        {
150                _ldap.add();
151        }
152
153        function configEvents(pObj, pEvent, pHandler)
154        {
155                if ( typeof pObj == 'object' )
156                {
157                        if ( pEvent.substring(0, 2) == 'on' )
158                                pEvent = pEvent.substring(2, pEvent.length);
159
160                        if ( pObj.addEventListener )
161                                pObj.addEventListener(pEvent, pHandler, false);
162                        else if ( pObj.attachEvent )
163                                pObj.attachEvent('on' + pEvent, pHandler);
164                }
165        }
166
167        function closeWindow()
168        {
169                myWindow = '';
170        }
171
172        function getFocus()
173        {
174                var pNewWindow = myWindow;
175                for( var i = 15 ; i > 0 ; i-- )
176                {
177                        pNewWindow.moveBy(i,0);
178                        pNewWindow.moveBy(-i,0);
179                }
180                pNewWindow.focus();
181        }
182
183        function helpJabberit()
184        {
185                var myWindowHelp = window.open( path_jabberit + 'help.php', 'HelpjabberIM', 'width=800,height=495,top=50,left=50,scrollbars=yes');
186        }
187
188        function keyPressSearch()
189        {
190                var ev = arguments[0];
191                var element = arguments[1];
192
193                if ( ev.keyCode == 13 )
194                        if( element.value.length >= 4 )
195                                _ldap.search( element.value ); 
196                        else
197                                alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
198        }
199
200        function openPopup()
201        {
202                try{
203                        if( ! myWindow )
204                        {       
205                                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');
206                                myWindow.blur();
207                                configEvents(myWindow,'onbeforeunload', closeWindow );
208                        }else
209                                myWindow.focus();
210                }
211                catch(e)
212                {
213                        delete myWindow;
214                        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');
215                        myWindow.blur();
216                        configEvents(myWindow,'onbeforeunload', closeWindow );
217                }
218        }
219
220        function openWindow()
221        {
222                var _win_contacts = _window.load('jabberit_contacts');
223                if( flagOpenIM == 'openWindowJabberit:false' )
224                {
225                        _win_contacts.size(215,400);
226                }                                       
227                else _win_contacts.size(1,1);
228
229                _win_contacts.position(50,50);
230                _win_contacts.bc.style.display = "none";
231                _win_contacts.bx.style.display = "none";
232
233                if( _win_contacts.bz.removeEventListener )
234                        _win_contacts.bz.removeEventListener('click',_win_contacts.button, false);
235                else
236                        _win_contacts.bz.detachEvent('onclick',_win_contacts.button);
237
238                configEvents(
239                        _win_contacts.bz,
240                        "onclick",
241                        function()
242                        {
243                                _win_contacts.size(1,1);
244                                _win_contacts.wm.style.visibility = 'hidden';
245                                _win_contacts.position(50,50);
246                                _win_contacts.title('');
247                        }
248                );
249
250                var _params = {'path' : path_jabberit};
251                _win_contacts.content(_xtools.parse(_xtools.xml('contacts_jabberit'), 'contacts_jabberit.xsl', _params));
252
253                if( flagOpenIM == 'openWindowJabberit:false' )
254                {
255                        _win_contacts.wm.style.visibility = "visible";
256                        _win_contacts.title('.:: Expresso - JMessenger ::.');
257                }
258                else _win_contacts.wm.style.visibility = "hidden";
259        }
260
261        function getPreferences()
262        {
263                if( flagOpenIM == '' )
264                {
265                        _conn.go("$this.db_im.getPreferences",
266                                         function(data)
267                                         {
268                                                        flagOpenIM = data;
269                                                        if(flagOpenIM == 'openWindowJabberit:true')
270                                                        {
271                                                                setTimeout('loadscript.showW();', 2000);
272                                                        }
273                                         });
274                }
275        }
276
277        function preferences()
278        {
279                if( !(_window.get('jabberit_preferences')) )
280                {
281                        var _win_preferences = _window.load('jabberit_preferences');
282                                _win_preferences.size(300,250);
283                                _win_preferences.position(150,100);
284                                _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
285                                _win_preferences.bc.style.display = "none";
286                                _win_preferences.bx.style.display = "none";
287                                _win_preferences.wc.style.padding = "5px";                                                             
288
289                        if( _win_preferences.bz.removeEventListener )
290                                _win_preferences.bz.removeEventListener('click',_win_preferences.button, false);
291                        else
292                                _win_preferences.bz.detachEvent('onclick',_win_preferences.button);
293                               
294                        configEvents(
295                                _win_preferences.bz,
296                                "onclick",
297                                function()
298                                {
299                                        _win_preferences.size(1,1);
300                                        _win_preferences.wm.style.visibility = 'hidden';
301                                        _win_preferences.position(50,50);
302                                        _win_preferences.title('');
303                                });
304
305                        var _params = {'path'  : path_jabberit,
306                                                   'lang1' : jabberitGetLang('Your Preferences'),       
307                                                   'lang2' : 'Conectar o IM Automaticamente',
308                                                   'lang3' : jabberitGetLang('Save'),
309                                                   'lang4' : jabberitGetLang('Cancel')                                                                             
310                                                  };
311                        _win_preferences.content(_xtools.parse(_xtools.xml('preferences_jabberit'), 'preferences_jabberit.xsl', _params));
312                        _win_preferences.wc.lastChild.lastChild.onclick = _win_preferences.close;
313                }
314                else
315                {
316                        var _win_preferences = _window.get('jabberit_preferences');
317                        _win_preferences.wm.style.visibility = "visible";
318                        _win_preferences.position(150,100);                                                     
319                        _win_preferences.title('.:: Expresso - JMessenger '+jabberitGetLang('Preferences')+'::.');
320                        _win_preferences.size(300,250);
321                }
322               
323                var value = flagOpenIM.split(':');
324                var elementSelect = document.getElementById(value[0]);
325                var valueSelect = value[1];
326
327
328                // Preenchendo a Select
329                for(var i = 0; i < elementSelect.options.length; i++)
330                        if( elementSelect.options[i].value == valueSelect )
331                                elementSelect.options[i].selected = true;
332        }
333
334        function searchUser()
335        {
336                var element = arguments[0].previousSibling;
337               
338                if( element.value.length >= 4 )
339                        _ldap.search( element.value ); 
340                else
341                        alert(jabberitGetLang('Your search argument must be longer than 4 characters.'));
342        }
343       
344        function setPreferences()
345        {
346                var element = document.getElementById('openWindowJabberit');
347               
348                for(var i = 0 ; i < element.options.length; i++)
349                        if( element.options[i].selected == true)
350                                var value = element.options[i].value;
351                               
352                _conn.go('$this.db_im.setPreferences',
353                                 function(data)
354                                 {
355                                        if(data == 'true')
356                                        {
357                                                flagOpenIM = 'openWindowJabberit:' + value;
358                                                alert(jabberitGetLang('Preferences saved with success!'));
359                                        }
360                                        else
361                                                alert(jabberitGetLang('Error saving your preferences!'));
362                                                                               
363                                        var _win_preferences = _window.get('jabberit_preferences');
364                                                _win_preferences.close();
365                                                                                       
366                                 },
367                                'preferences=openWindowJabberit:' + value);
368        }
369       
370        function showDiv()
371        {
372                var _element = ( myWindow ) ? myWindow.document.body.firstChild : null ;
373                if( _element != null )
374                        _element.style.visibility = 'visible';
375        }
376
377        function showWindow()
378        {
379                var _win_contacts = _window.get('jabberit_contacts');
380                if( !is_ie )
381                {
382                        if ( _win_contacts )
383                        {
384                                _win_contacts.wm.style.visibility = "visible";
385                                _win_contacts.title('.:: Expresso - JMessenger ::.');
386                                _win_contacts.size(215,400);
387                        }
388                        else
389                                openWindow();
390                }
391                else
392                        openPopup();
393        }
394
395        function Load()
396        {
397                addIcon();
398                getPreferences();
399        }
400
401        Load.prototype.keyPress = keyPressSearch;
402        Load.prototype.search = searchUser;
403        Load.prototype.show = showDiv;
404        Load.prototype.showW = showWindow;
405        Load.prototype.setPrefe = setPreferences;
406        Load.prototype.closeW = closeWindow;
407        window.loadscript = new Load;
408
409})();
Note: See TracBrowser for help on using the repository browser.