1 | (function() |
---|
2 | { |
---|
3 | var _autoStatus; |
---|
4 | var _autoStatusTime = 60000; // 1 minuto |
---|
5 | var addUser = null; |
---|
6 | var conn = null; |
---|
7 | var fullName = ""; |
---|
8 | var path = ""; |
---|
9 | var _preferencesIM = ""; |
---|
10 | var selectEditable = null; |
---|
11 | var showhidden = null; |
---|
12 | var timeoutId = null; |
---|
13 | var userCurrent = null; |
---|
14 | var Xtools = null; |
---|
15 | var zIndex = 9001; |
---|
16 | |
---|
17 | // Images |
---|
18 | var add_user = new Image(); |
---|
19 | add_user.src = path_jabberit + 'templates/default/images/adduser_azul.png'; |
---|
20 | |
---|
21 | var arrow_down = new Image(); |
---|
22 | arrow_down.src = path_jabberit + 'templates/default/images/arrow_down.gif'; |
---|
23 | |
---|
24 | var arrow_right = new Image(); |
---|
25 | arrow_right.src = path_jabberit + 'templates/default/images/arrow_right.gif'; |
---|
26 | |
---|
27 | function actionButton() |
---|
28 | { |
---|
29 | if( arguments.length > 0 ) |
---|
30 | { |
---|
31 | var e = arguments[0]; |
---|
32 | var _element = ( e.target ) ? e.target : e.srcElement; |
---|
33 | var jid = arguments[1]; |
---|
34 | var index = arguments[2]; |
---|
35 | var coord = null; |
---|
36 | |
---|
37 | if ( !e ) |
---|
38 | e = window.event; |
---|
39 | |
---|
40 | var _X = e.clientX + document.body.scrollLeft - document.body.clientLeft; |
---|
41 | var _Y = e.clientY + document.body.scrollTop - document.body.clientTop; |
---|
42 | |
---|
43 | coord = { X : _X, Y : _Y }; |
---|
44 | |
---|
45 | |
---|
46 | var _onContextMenu = function() |
---|
47 | { |
---|
48 | return false; |
---|
49 | }; |
---|
50 | |
---|
51 | window.document.oncontextmenu = _onContextMenu; |
---|
52 | |
---|
53 | if( e.button ) |
---|
54 | { |
---|
55 | if( e.button > 1 ) |
---|
56 | optionsItensContact( jid, index, coord ); |
---|
57 | else |
---|
58 | TrophyIM.rosterClick(jid); |
---|
59 | } |
---|
60 | else if( e.which ) |
---|
61 | { |
---|
62 | if( e.which > 1 ) |
---|
63 | optionsItensContact( jid, index, coord ); |
---|
64 | else |
---|
65 | if( e.target.id ) |
---|
66 | TrophyIM.rosterClick(jid); |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | function addContact() |
---|
72 | { |
---|
73 | if( arguments.length > 0 ) |
---|
74 | addUser.add(); |
---|
75 | else |
---|
76 | addUser.show(); |
---|
77 | } |
---|
78 | |
---|
79 | function addIcon() |
---|
80 | { |
---|
81 | |
---|
82 | var div_write_msg = ( getElement('em_div_write_msg') != null ) ? getElement('em_div_write_msg') : null ; |
---|
83 | var StatusBar = ( getElement('divStatusBar') != null ) ? getElement('divStatusBar') : null ; |
---|
84 | var StatusBarIM = ( getElement('JabberMessenger') != null ) ? getElement('JabberMessenger') : null; |
---|
85 | |
---|
86 | /************************************************************************** |
---|
87 | * |
---|
88 | * Quando estiver habilitada a opção fora de escritório nos filtros. |
---|
89 | * |
---|
90 | */ |
---|
91 | |
---|
92 | if( ( div_write_msg && StatusBarIM ) != null ) |
---|
93 | { |
---|
94 | div_write_msg.parentNode.insertBefore(StatusBarIM, div_write_msg); |
---|
95 | StatusBarIM.style.paddingLeft = '33px'; |
---|
96 | return; |
---|
97 | } |
---|
98 | /**************************************************************************/ |
---|
99 | |
---|
100 | if ( !StatusBarIM ) |
---|
101 | { |
---|
102 | StatusBarIM = document.createElement('div'); |
---|
103 | StatusBarIM.setAttribute('id', 'JabberMessenger'); |
---|
104 | } |
---|
105 | |
---|
106 | if( StatusBar ) |
---|
107 | { |
---|
108 | StatusBar.style.paddingLeft = '33px'; |
---|
109 | |
---|
110 | var _div = document.createElement('div'); |
---|
111 | _div.appendChild(StatusBar.parentNode.removeChild(StatusBar.previousSibling)); |
---|
112 | |
---|
113 | StatusBar.parentNode.insertBefore( _div, StatusBar); |
---|
114 | |
---|
115 | var _fastMenu = top.document.createElement('div'); |
---|
116 | _fastMenu.setAttribute('id', 'fast_menu_jabber_expresso'); |
---|
117 | _fastMenu.style.background = 'no-repeat'; |
---|
118 | _fastMenu.style.backgroundImage = 'url(' + arrow_down.src + ')'; |
---|
119 | _fastMenu.style.float = 'left'; |
---|
120 | _fastMenu.style.height = '15px'; |
---|
121 | _fastMenu.style.left = '7px'; |
---|
122 | _fastMenu.style.margin = '8 0 0 10px'; |
---|
123 | _fastMenu.style.padding = '0px'; |
---|
124 | _fastMenu.style.position = 'absolute'; |
---|
125 | _fastMenu.style.width = '15px'; |
---|
126 | _fastMenu.style.cursor = 'pointer'; |
---|
127 | |
---|
128 | StatusBarIM.insertBefore( _fastMenu, StatusBarIM.firstChild ); |
---|
129 | |
---|
130 | // Add event onclick element _fastMenu |
---|
131 | configEvents( _fastMenu, 'onclick', function(){ fastMenu(_fastMenu); }); |
---|
132 | |
---|
133 | var _statusJabber = top.document.createElement('div'); |
---|
134 | _statusJabber.setAttribute('id','status_jabber_expresso'); |
---|
135 | _statusJabber.style.background = 'no-repeat'; |
---|
136 | _statusJabber.style.backgroundImage = 'url(' + add_user.src +')'; |
---|
137 | _statusJabber.style.float = 'left'; |
---|
138 | _statusJabber.style.height = '18px'; |
---|
139 | _statusJabber.style.left = '19px'; |
---|
140 | _statusJabber.style.margin = '0 0 0 10px'; |
---|
141 | _statusJabber.style.padding = '0px'; |
---|
142 | _statusJabber.style.position = 'absolute'; |
---|
143 | _statusJabber.style.width = '18px'; |
---|
144 | _statusJabber.style.cursor = 'pointer'; |
---|
145 | _statusJabber.style.zindex = '999999'; |
---|
146 | |
---|
147 | StatusBarIM.insertBefore( _statusJabber, StatusBarIM.firstChild ); |
---|
148 | |
---|
149 | StatusBar.insertBefore( StatusBarIM, StatusBar.firstChild ); |
---|
150 | |
---|
151 | // Add event onclick element _statusJabber |
---|
152 | configEvents( _statusJabber, 'onclick', function(){ TrophyIM.load();}); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | function autoStatus() |
---|
157 | { |
---|
158 | var _div_status = ( getElement('status_jabber_expresso') != null ) ? getElement('status_jabber_expresso') : null; |
---|
159 | |
---|
160 | if ( _autoStatus ) |
---|
161 | clearTimeout(_autoStatus); |
---|
162 | |
---|
163 | if ( _div_status != null ) |
---|
164 | { |
---|
165 | var _status = _div_status.style.backgroundImage; |
---|
166 | _status = _status.substr(_status.lastIndexOf('/') + 1); |
---|
167 | _status = _status.substr(0, _status.indexOf('.')); |
---|
168 | |
---|
169 | if( _status == "xa" ) |
---|
170 | { |
---|
171 | TrophyIM.setPresence("available"); |
---|
172 | loadscript.setStatusJabber("Disponível","available"); |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | var TimeStatus = _preferencesIM[2].split(':'); |
---|
177 | |
---|
178 | if( TimeStatus[1] ) |
---|
179 | _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(TimeStatus[1]) * _autoStatusTime ); |
---|
180 | else |
---|
181 | _autoStatus = setTimeout( function(){ autoStatusHandler();}, parseInt(_autoStatusTime)); |
---|
182 | } |
---|
183 | |
---|
184 | function autoStatusHandler() |
---|
185 | { |
---|
186 | var _div_status = ( getElement('status_jabber_expresso') != null ) ? getElement('status_jabber_expresso') : null; |
---|
187 | |
---|
188 | if ( _div_status != null ) |
---|
189 | { |
---|
190 | var _status = _div_status.style.backgroundImage; |
---|
191 | _status = _status.substr(_status.lastIndexOf('/') + 1); |
---|
192 | _status = _status.substr(0, _status.indexOf('.')); |
---|
193 | |
---|
194 | if( _status == "available" ) |
---|
195 | { |
---|
196 | TrophyIM.setPresence("xa"); |
---|
197 | loadscript.setStatusJabber("Não Disponível","xa"); |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | function clrAllContacts() |
---|
203 | { |
---|
204 | getElement("JabberIMRoster").innerHTML = ""; |
---|
205 | } |
---|
206 | |
---|
207 | function configEvents(pObj, pEvent, pHandler) |
---|
208 | { |
---|
209 | if ( typeof pObj == 'object' ) |
---|
210 | { |
---|
211 | if ( pEvent.substring(0, 2) == 'on' ) |
---|
212 | pEvent = pEvent.substring(2, pEvent.length); |
---|
213 | |
---|
214 | if ( pObj.addEventListener ) |
---|
215 | pObj.addEventListener(pEvent, pHandler, false); |
---|
216 | else if ( pObj.attachEvent ) |
---|
217 | pObj.attachEvent('on' + pEvent, pHandler); |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | function fastMenu() |
---|
222 | { |
---|
223 | if( arguments.length > 0 ) |
---|
224 | { |
---|
225 | var element = arguments[0]; |
---|
226 | |
---|
227 | if( showhidden == null ) |
---|
228 | showhidden = new ShowHidden(300); |
---|
229 | |
---|
230 | var _options = [ |
---|
231 | ['Adicionar Contato', 'loadscript.addContact();' ], |
---|
232 | ['Ajuda', 'alert("2")' ], |
---|
233 | ['Preferências', 'loadscript.preferences();'], |
---|
234 | ]; |
---|
235 | |
---|
236 | var _itens = ""; |
---|
237 | |
---|
238 | for( var i in _options ) |
---|
239 | { |
---|
240 | if( _options[i].constructor == Function ) |
---|
241 | continue; |
---|
242 | |
---|
243 | _itens += '<img src="'+arrow_right.src+'"/>'; |
---|
244 | _itens += '<span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>'; |
---|
245 | _itens += _options[i][0] + '</span><br/>'; |
---|
246 | } |
---|
247 | |
---|
248 | var _optionsItens = document.createElement("div"); |
---|
249 | _optionsItens.id = "fastMenu_Jabber"; |
---|
250 | _optionsItens.style.marginTop = "19px"; |
---|
251 | _optionsItens.style.marginLeft = "-8px"; |
---|
252 | _optionsItens.className = "x-menu"; |
---|
253 | _optionsItens.style.zIndex = '999999'; |
---|
254 | _optionsItens.innerHTML = _itens; |
---|
255 | _optionsItens.onclick = function(){ showhidden.hiddenObject(false); }; |
---|
256 | _optionsItens.onmouseout = function(){ showhidden.hiddenObject(false); }; |
---|
257 | _optionsItens.onmouseover = function(){ showhidden.hiddenObject(true); }; |
---|
258 | |
---|
259 | showhidden.action('onmouseover', 'onmouseout', _optionsItens); |
---|
260 | |
---|
261 | element.parentNode.appendChild( _optionsItens ); |
---|
262 | } |
---|
263 | } |
---|
264 | |
---|
265 | function getElement( elementId ) |
---|
266 | { |
---|
267 | return document.getElementById( elementId ); |
---|
268 | } |
---|
269 | |
---|
270 | function getPhotoUser( jid ) |
---|
271 | { |
---|
272 | var _divPhoto = getElement( jid + '__photo' ); |
---|
273 | |
---|
274 | if( _divPhoto.style.backgroundImage.indexOf('photo.png') > 0 ) |
---|
275 | { |
---|
276 | var _imgUser = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date ); |
---|
277 | _imgUser += '&photo_ldap=' + jid; |
---|
278 | |
---|
279 | _divPhoto.style.backgroundImage = 'url(' + _imgUser + ')'; |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | function getUserCurrent() |
---|
284 | { |
---|
285 | return userCurrent; |
---|
286 | } |
---|
287 | |
---|
288 | function getZindex() |
---|
289 | { |
---|
290 | return zIndex++; |
---|
291 | } |
---|
292 | |
---|
293 | function groupsHidden() |
---|
294 | { |
---|
295 | if( arguments.length > 0 ) |
---|
296 | { |
---|
297 | var _element = arguments[0]; |
---|
298 | _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_right.gif') no-repeat center left"; |
---|
299 | _element.onclick = function(){ groupsVisible(_element);}; |
---|
300 | |
---|
301 | // Hidden all |
---|
302 | var _elementNext = _element.nextSibling; |
---|
303 | |
---|
304 | while( _elementNext ) |
---|
305 | { |
---|
306 | if( _elementNext.nodeType == 1 ) |
---|
307 | _elementNext.style.display = "none"; |
---|
308 | |
---|
309 | _elementNext = _elementNext.nextSibling; |
---|
310 | } |
---|
311 | } |
---|
312 | } |
---|
313 | |
---|
314 | function groupsVisible() |
---|
315 | { |
---|
316 | if( arguments.length > 0 ) |
---|
317 | { |
---|
318 | var _element = arguments[0]; |
---|
319 | _element.style.background = "url('"+path_jabberit+"templates/default/images/arrow_down.gif') no-repeat center left"; |
---|
320 | _element.onclick = function(){ groupsHidden(_element);}; |
---|
321 | |
---|
322 | // Display all |
---|
323 | var _elementNext = _element.nextSibling; |
---|
324 | |
---|
325 | while( _elementNext ) |
---|
326 | { |
---|
327 | if( _elementNext.nodeType == 1 ) |
---|
328 | _elementNext.style.display = "block"; |
---|
329 | |
---|
330 | _elementNext = _elementNext.nextSibling; |
---|
331 | } |
---|
332 | } |
---|
333 | } |
---|
334 | |
---|
335 | function keyPressSearch() |
---|
336 | { |
---|
337 | if( arguments.length > 0 ) |
---|
338 | { |
---|
339 | var ev = arguments[0]; |
---|
340 | var element = arguments[1]; |
---|
341 | |
---|
342 | if ( ev.keyCode == 13 ) |
---|
343 | if( element.value.length >= 3 ) |
---|
344 | searchUser( element.value ); |
---|
345 | else |
---|
346 | alert('Your search argument must be longer than 3 characters.'); |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | |
---|
351 | function loginPage() |
---|
352 | { |
---|
353 | var winLoginPage = |
---|
354 | { |
---|
355 | id_window : "window_login_page", |
---|
356 | width : 260, |
---|
357 | height : 150, |
---|
358 | top : 100, |
---|
359 | left : 400, |
---|
360 | draggable : true, |
---|
361 | visible : "display", |
---|
362 | resizable : true, |
---|
363 | zindex : zIndex++, |
---|
364 | title : "Expresso Messenger - Login", |
---|
365 | closeAction : "remove", |
---|
366 | content : Xtools.parse(Xtools.xml("login_page"), "loginPage.xsl") |
---|
367 | }; |
---|
368 | |
---|
369 | _winBuild( winLoginPage ); |
---|
370 | } |
---|
371 | |
---|
372 | function loadScripts(pFiles) |
---|
373 | { |
---|
374 | // Load JavaScript |
---|
375 | var loadJavaScript = function(pJs) |
---|
376 | { |
---|
377 | var newScript = document.createElement("script"); |
---|
378 | newScript.setAttribute("type", "text/javascript"); |
---|
379 | newScript.setAttribute("src", pJs ); |
---|
380 | |
---|
381 | return newScript; |
---|
382 | }; |
---|
383 | |
---|
384 | // Load CSS |
---|
385 | var loadStyleSheet = function(pCss) |
---|
386 | { |
---|
387 | var newStyle = document.createElement("link"); |
---|
388 | newStyle.setAttribute("rel", "stylesheet"); |
---|
389 | newStyle.setAttribute("type", "text/css"); |
---|
390 | newStyle.setAttribute("href", pCss); |
---|
391 | |
---|
392 | return newStyle; |
---|
393 | }; |
---|
394 | |
---|
395 | for(var i = 0; i < pFiles.length; i++) |
---|
396 | { |
---|
397 | if( pFiles[i].indexOf(".js") > -1 ) |
---|
398 | document.getElementsByTagName("head")[0].appendChild(loadJavaScript(pFiles[i])); |
---|
399 | |
---|
400 | if( pFiles[i].indexOf(".css") > -1 ) |
---|
401 | document.getElementsByTagName("head")[0].appendChild(loadStyleSheet(pFiles[i])); |
---|
402 | } |
---|
403 | } |
---|
404 | |
---|
405 | function notificationNewMessage() |
---|
406 | { |
---|
407 | var oldTitle = document.title; |
---|
408 | var newTitle = "## NOVA MENSAGEM ##"; |
---|
409 | var idWindow = arguments[1]; |
---|
410 | |
---|
411 | if( timeoutId == null ) |
---|
412 | { |
---|
413 | timeoutId = setInterval(function() |
---|
414 | { |
---|
415 | document.title = ( document.title == newTitle ) ? oldTitle : newTitle; |
---|
416 | }, 1000); |
---|
417 | |
---|
418 | configEvents( window.document, 'onclick', function() |
---|
419 | { |
---|
420 | clearInterval(timeoutId); |
---|
421 | document.title = oldTitle; |
---|
422 | timeoutId = null; |
---|
423 | }); |
---|
424 | |
---|
425 | configEvents( window.document, 'onkeypress', function() |
---|
426 | { |
---|
427 | clearInterval(timeoutId); |
---|
428 | document.title = oldTitle; |
---|
429 | timeoutId = null; |
---|
430 | }); |
---|
431 | } |
---|
432 | } |
---|
433 | |
---|
434 | function optionsItensContact() |
---|
435 | { |
---|
436 | if( arguments.length > 0 ) |
---|
437 | { |
---|
438 | var jid = arguments[0]; |
---|
439 | var index = arguments[1]; |
---|
440 | var coord = arguments[2]; |
---|
441 | var element = getElement('itenContact_' + jid + '_' + index ); |
---|
442 | var action = ( element.getAttribute("subscription") === "not-in-roster" ) ? "Adicionar" : "Autorizar"; |
---|
443 | |
---|
444 | if( showhidden == null ) |
---|
445 | showhidden = new ShowHidden(300); |
---|
446 | |
---|
447 | var _options = [ |
---|
448 | [ action , 'loadscript.setAutorization(\''+jid+'\',\''+index+'\')'], |
---|
449 | ['Remover' , 'loadscript.removeContact(\''+jid+'\',\''+index+'\')'], |
---|
450 | ['Renomear' , 'loadscript.renameContact(\''+jid+'\',\''+index+'\')'], |
---|
451 | ['Trocar grupo' , 'loadscript.renameGroup(\''+jid+'\',\''+index+'\')'] |
---|
452 | ]; |
---|
453 | |
---|
454 | var _itens = ""; |
---|
455 | |
---|
456 | for( var i in _options ) |
---|
457 | { |
---|
458 | if( typeof(_options[i]) == "object") |
---|
459 | { |
---|
460 | _itens += '<img src="'+arrow_right.src+'"/>'; |
---|
461 | _itens += '<span style="cursor:pointer;margin:3px;font-weight:normal;" onclick='+_options[i][1]+'>'; |
---|
462 | _itens += _options[i][0] + '</span><br/>'; |
---|
463 | } |
---|
464 | } |
---|
465 | |
---|
466 | var _optionsItens = document.createElement("div"); |
---|
467 | _optionsItens.className = "x-menu"; |
---|
468 | _optionsItens.style.top = coord.Y; |
---|
469 | _optionsItens.style.left = ( coord.X - element.offsetLeft ); |
---|
470 | _optionsItens.style.zIndex = getZindex(); |
---|
471 | _optionsItens.innerHTML = _itens; |
---|
472 | _optionsItens.onclick = function(){ showhidden.hiddenObject(false); }; |
---|
473 | _optionsItens.onmouseout = function(){ showhidden.hiddenObject(false); }; |
---|
474 | _optionsItens.onmouseover = function(){ showhidden.hiddenObject(true); }; |
---|
475 | |
---|
476 | showhidden.action('onmouseover', 'onmouseout', _optionsItens); |
---|
477 | |
---|
478 | window.document.body.appendChild(_optionsItens); |
---|
479 | |
---|
480 | |
---|
481 | setTimeout(function() |
---|
482 | { |
---|
483 | window.document.oncontextmenu = function() |
---|
484 | { |
---|
485 | return true; |
---|
486 | }; |
---|
487 | |
---|
488 | },500); |
---|
489 | } |
---|
490 | } |
---|
491 | |
---|
492 | function parse() |
---|
493 | { |
---|
494 | if( arguments.length == 2 ) |
---|
495 | return Xtools.parse(Xtools.xml(arguments[0]), arguments[1] ); |
---|
496 | |
---|
497 | if( arguments.length === 3 ) |
---|
498 | return Xtools.parse(Xtools.xml(arguments[0]), arguments[1], arguments[2] ); |
---|
499 | } |
---|
500 | |
---|
501 | function preferences() |
---|
502 | { |
---|
503 | var paramPreferences = |
---|
504 | { |
---|
505 | 'path' : path, |
---|
506 | 'lang1' : 'Suas Preferências', |
---|
507 | 'lang2' : 'Conexão', |
---|
508 | 'lang3' : 'Conectar Automaticamente o IM', |
---|
509 | 'lang4' : 'Usuários OffLine', |
---|
510 | 'lang5' : 'Exibir amigos Offline', |
---|
511 | 'lang6' : 'Salvar', |
---|
512 | 'lang7' : 'Cancelar', |
---|
513 | 'lang8' : 'Janela de Contatos', |
---|
514 | 'lang9' : 'Abrir janela como Pop-up', |
---|
515 | 'lang10' : 'Ausente', |
---|
516 | 'lang11' : 'Definir status de ausente depois de', |
---|
517 | 'lang12' : 'minutos', |
---|
518 | 'langYes': 'Sim', |
---|
519 | 'langNo' : 'Não' |
---|
520 | }; |
---|
521 | |
---|
522 | |
---|
523 | var _win_preferences = |
---|
524 | { |
---|
525 | id_window : "jabberit_preferences", |
---|
526 | width : 430, |
---|
527 | height : 330, |
---|
528 | top : 150, |
---|
529 | left : 100, |
---|
530 | draggable : true, |
---|
531 | visible : "display", |
---|
532 | resizable : true, |
---|
533 | zindex : zIndex++, |
---|
534 | title : 'Expresso Messenger - Preferências', |
---|
535 | closeAction : "remove", |
---|
536 | content : Xtools.parse(Xtools.xml('preferences'), 'preferences.xsl', paramPreferences) |
---|
537 | }; |
---|
538 | |
---|
539 | _winBuild(_win_preferences); |
---|
540 | |
---|
541 | |
---|
542 | var _pButtons = { |
---|
543 | 'lang1' : 'Salvar', |
---|
544 | 'lang2' : 'Fechar', |
---|
545 | 'onclickClose' : '_winBuild("jabberit_preferences","remove");', |
---|
546 | 'onclickSubmit' : 'javascript:loadscript.setPreferences();' |
---|
547 | }; |
---|
548 | |
---|
549 | document.getElementById('buttons_preferences_jabberit').innerHTML = Xtools.parse(Xtools.xml('buttons_main'), 'buttons.xsl', _pButtons); |
---|
550 | |
---|
551 | // Element openWindowJabberit |
---|
552 | var value1 = _preferencesIM[0].split(':'); |
---|
553 | var element1 = document.getElementById(value1[0]); |
---|
554 | var valueSelect1 = value1[1]; |
---|
555 | |
---|
556 | for(var i = 0; i < element1.options.length; i++) |
---|
557 | if( element1.options[i].value == valueSelect1 ) |
---|
558 | element1.options[i].selected = true; |
---|
559 | |
---|
560 | // Element openWindowJabberitPopUp |
---|
561 | var value2 = _preferencesIM[1].split(':'); |
---|
562 | var element2 = document.getElementById(value2[0]); |
---|
563 | var valueSelect2 = value2[1]; |
---|
564 | |
---|
565 | for(var i = 0; i < element2.options.length; i++) |
---|
566 | if( element2.options[i].value == valueSelect2 ) |
---|
567 | element2.options[i].selected = true; |
---|
568 | |
---|
569 | // Element flagAwayIM |
---|
570 | var value3 = _preferencesIM[2].split(':'); |
---|
571 | var element3 = document.getElementById(value3[0]); |
---|
572 | element3.value = value3[1]; |
---|
573 | } |
---|
574 | |
---|
575 | function removeContact(jid, index) |
---|
576 | { |
---|
577 | setTimeout(function() |
---|
578 | { |
---|
579 | TrophyIM.removeContact(jid, index); |
---|
580 | |
---|
581 | },300); |
---|
582 | } |
---|
583 | |
---|
584 | function removeElement( ) |
---|
585 | { |
---|
586 | if( arguments.length > 0 ) |
---|
587 | { |
---|
588 | var _element = arguments[0] |
---|
589 | var _parent = _element.parentNode; |
---|
590 | |
---|
591 | _parent.removeChild( _element ); |
---|
592 | } |
---|
593 | } |
---|
594 | |
---|
595 | function removeGroup() |
---|
596 | { |
---|
597 | var _parent = arguments[0]; |
---|
598 | |
---|
599 | if( _parent.childNodes.length <= 2 ) |
---|
600 | _parent.parentNode.removeChild(_parent); |
---|
601 | } |
---|
602 | |
---|
603 | function renameContact() |
---|
604 | { |
---|
605 | if( arguments.length > 0 ) |
---|
606 | { |
---|
607 | var _jid = arguments[0]; |
---|
608 | var _index = arguments[1]; |
---|
609 | |
---|
610 | TrophyIM.renameContact( _jid, _index ); |
---|
611 | } |
---|
612 | } |
---|
613 | |
---|
614 | function renameGroup() |
---|
615 | { |
---|
616 | if( arguments.length > 0 ) |
---|
617 | { |
---|
618 | var _jid = arguments[0]; |
---|
619 | var _index = arguments[1]; |
---|
620 | |
---|
621 | TrophyIM.renameGroup( _jid , _index ); |
---|
622 | } |
---|
623 | } |
---|
624 | |
---|
625 | function rosterDiv() |
---|
626 | { |
---|
627 | var paramListContact = |
---|
628 | { |
---|
629 | 'idUser' : Base64.decode(getUserCurrent().jid), |
---|
630 | 'full_name' : (( fullName.length < 25 ) ? fullName : ( fullName.substring( 0, 25) + "...")), |
---|
631 | 'path_jabberit' : path_jabberit, |
---|
632 | 'zIndex_' : zIndex++ |
---|
633 | }; |
---|
634 | |
---|
635 | var winRosterDiv = |
---|
636 | { |
---|
637 | id_window : "window_Roster_im", |
---|
638 | width : 250, |
---|
639 | height : 410, |
---|
640 | top : 50, |
---|
641 | left : 50, |
---|
642 | draggable : true, |
---|
643 | visible : "display", |
---|
644 | resizable : true, |
---|
645 | zindex : zIndex++, |
---|
646 | title : "Expresso Messenger - Contatos", |
---|
647 | closeAction : "hidden", |
---|
648 | content : Xtools.parse(Xtools.xml("contacts_list"),"contactsList.xsl", paramListContact) |
---|
649 | }; |
---|
650 | |
---|
651 | _winBuild( winRosterDiv ); |
---|
652 | |
---|
653 | // Photo User |
---|
654 | getPhotoUser(Base64.decode(getUserCurrent().jid)); |
---|
655 | } |
---|
656 | |
---|
657 | function searchUser() |
---|
658 | { |
---|
659 | var _input = getElement('search_user_jabber'); |
---|
660 | |
---|
661 | if( _input.value.length >= 3 ) |
---|
662 | addUser.search(); |
---|
663 | else |
---|
664 | alert('Your search argument must be longer than 3 characters.'); |
---|
665 | } |
---|
666 | |
---|
667 | function setAutorization(jidTo, indexTo) |
---|
668 | { |
---|
669 | var divItenContact = null; |
---|
670 | |
---|
671 | if( ( divItenContact = getElement('itenContact_' + jidTo + '_' + indexTo ))) |
---|
672 | { |
---|
673 | var subscription = divItenContact.getAttribute('subscription'); |
---|
674 | |
---|
675 | switch(subscription) |
---|
676 | { |
---|
677 | case 'from': |
---|
678 | |
---|
679 | TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe'); |
---|
680 | break; |
---|
681 | |
---|
682 | case 'none' : |
---|
683 | |
---|
684 | TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe'); |
---|
685 | TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed'); |
---|
686 | |
---|
687 | break; |
---|
688 | |
---|
689 | case 'not-in-roster': |
---|
690 | |
---|
691 | setTimeout(function() |
---|
692 | { |
---|
693 | var _add = ""; |
---|
694 | |
---|
695 | if( ( _add = confirm("Deseja adicionar o usuario!")) ) |
---|
696 | { |
---|
697 | addUser.add( jidTo, indexTo ); |
---|
698 | } |
---|
699 | |
---|
700 | },100); |
---|
701 | |
---|
702 | break; |
---|
703 | |
---|
704 | case 'to' : |
---|
705 | |
---|
706 | TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribed'); |
---|
707 | |
---|
708 | case 'subscribe' : |
---|
709 | |
---|
710 | TrophyIM.setAutorization( jidTo, Base64.decode(this.getUserCurrent().jid), 'subscribe'); |
---|
711 | |
---|
712 | break; |
---|
713 | } |
---|
714 | } |
---|
715 | } |
---|
716 | |
---|
717 | |
---|
718 | function setPreferences() |
---|
719 | { |
---|
720 | // Element openWindowJabberit |
---|
721 | var elementOpenW = document.getElementById('openWindowJabberit'); |
---|
722 | var value = ''; |
---|
723 | var flagReload = false; |
---|
724 | |
---|
725 | for(var i = 0 ; i < elementOpenW.options.length; i++) |
---|
726 | if( elementOpenW.options[i].selected == true) |
---|
727 | { |
---|
728 | value = 'preferences1=openWindowJabberit:' + elementOpenW.options[i].value; |
---|
729 | _preferencesIM[0] = 'openWindowJabberit:' + elementOpenW.options[i].value; |
---|
730 | } |
---|
731 | |
---|
732 | // Element openWindowJabberitPopUp |
---|
733 | var elementOpenPop = document.getElementById('openWindowJabberitPopUp'); |
---|
734 | |
---|
735 | for(var i = 0; i < elementOpenPop.options.length; i++ ) |
---|
736 | if( elementOpenPop.options[i].selected == true ) |
---|
737 | { |
---|
738 | value += '&preferences2=openWindowJabberitPopUp:' + elementOpenPop.options[i].value; |
---|
739 | |
---|
740 | if( _preferencesIM[1] != 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value) |
---|
741 | flagReload = true; |
---|
742 | |
---|
743 | _preferencesIM[1] = 'openWindowJabberitPopUp:' + elementOpenPop.options[i].value; |
---|
744 | } |
---|
745 | |
---|
746 | // Element flagAwayIM |
---|
747 | var elementFlagIM = document.getElementById('flagAwayIM'); |
---|
748 | |
---|
749 | if( elementFlagIM.value.length > 0 && parseInt(elementFlagIM.value) > 0 ) |
---|
750 | { |
---|
751 | _preferencesIM[2] = 'flagAwayIM:' + elementFlagIM.value; |
---|
752 | value += '&preferences3=flagAwayIM:' + elementFlagIM.value; |
---|
753 | } |
---|
754 | else |
---|
755 | { |
---|
756 | alert('Informe um valor igual ou maior que 1!'); |
---|
757 | return false; |
---|
758 | } |
---|
759 | |
---|
760 | |
---|
761 | // Save Preferences |
---|
762 | conn.go('p.pf.setPreferences', |
---|
763 | function(data) |
---|
764 | { |
---|
765 | if(data == 'true') |
---|
766 | { |
---|
767 | if( flagReload ) |
---|
768 | { |
---|
769 | window.location.reload(); |
---|
770 | myWindow.close(); |
---|
771 | } |
---|
772 | } |
---|
773 | else{ alert('Erro salvando suas preferências!'); } |
---|
774 | |
---|
775 | _winBuild('jabberit_preferences', 'remove'); |
---|
776 | }, |
---|
777 | value); |
---|
778 | } |
---|
779 | |
---|
780 | function setPresence() |
---|
781 | { |
---|
782 | if( arguments.length > 0 ) |
---|
783 | { |
---|
784 | var element = arguments[0]; |
---|
785 | |
---|
786 | if( showhidden == null ) |
---|
787 | showhidden = new ShowHidden(300); |
---|
788 | |
---|
789 | var _status = [ |
---|
790 | ['Afastado', 'away', '<img src="'+path_jabberit+'templates/default/images/away.gif" />'], |
---|
791 | ['Disponível', 'available', '<img src="'+path_jabberit+'templates/default/images/available.gif" />'], |
---|
792 | ['Livre p/ Conversa', 'chat', '<img src="'+path_jabberit+'templates/default/images/chat.gif" />'], |
---|
793 | ['Não Disponível', 'xa', '<img src="'+path_jabberit+'templates/default/images/xa.gif" />'], |
---|
794 | ['Ocupado', 'dnd', '<img src="'+path_jabberit+'templates/default/images/dnd.gif" />'], |
---|
795 | ['Desconectado', 'unavailable', '<img src="'+path_jabberit+'templates/default/images/unavailable.gif" />'], |
---|
796 | ['Mensagem de Status...', 'status', '<img src="'+path_jabberit+'templates/default/images/message_normal.gif" />'], |
---|
797 | ]; |
---|
798 | |
---|
799 | var _itens = ""; |
---|
800 | |
---|
801 | for( var i in _status ) |
---|
802 | { |
---|
803 | if( typeof( _status[i]) == "object" ) |
---|
804 | { |
---|
805 | _itens += '<span style="cursor:pointer;" onclick="TrophyIM.setPresence(\''+_status[i][1]+'\'); loadscript.setStatusJabber(\''+_status[i][0]+'\',\''+_status[i][1]+'\');">'; |
---|
806 | _itens += _status[i][2]+ "<span style='margin:3px;'>" + _status[i][0] + "</span></span><br/>"; |
---|
807 | } |
---|
808 | } |
---|
809 | |
---|
810 | var _statusItens = document.createElement("div"); |
---|
811 | _statusItens.style.marginTop = "65px"; |
---|
812 | _statusItens.style.marginLeft = "67px"; |
---|
813 | _statusItens.className = "x-menu"; |
---|
814 | _statusItens.style.zIndex = '99999'; |
---|
815 | _statusItens.innerHTML = _itens; |
---|
816 | _statusItens.onclick = function(){ showhidden.hiddenObject(false); }; |
---|
817 | |
---|
818 | showhidden.action('onmouseover', 'onmouseout', _statusItens); |
---|
819 | |
---|
820 | element.parentNode.onmouseout = function(){ showhidden.hiddenObject(false); }; |
---|
821 | element.parentNode.onmouseover = function(){ showhidden.hiddenObject(true); }; |
---|
822 | element.parentNode.appendChild(_statusItens); |
---|
823 | } |
---|
824 | } |
---|
825 | |
---|
826 | function setSelectEditable(element) |
---|
827 | { |
---|
828 | if( getElement('selectBox0') == null ) |
---|
829 | selectEditable.create(element); |
---|
830 | } |
---|
831 | |
---|
832 | function setStatusJabber() |
---|
833 | { |
---|
834 | if( arguments.length > 0 ) |
---|
835 | { |
---|
836 | if( arguments[1] != 'status' ) |
---|
837 | { |
---|
838 | var _text = arguments[0]; |
---|
839 | var _img = arguments[1]; |
---|
840 | |
---|
841 | getElement('statusJabberText').innerHTML = _text; |
---|
842 | getElement('statusJabberImg').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif')"; |
---|
843 | getElement('status_jabber_expresso').style.background = "url('"+path_jabberit+"templates/default/images/"+_img+".gif') no-repeat"; |
---|
844 | } |
---|
845 | } |
---|
846 | } |
---|
847 | |
---|
848 | function teste_meu(_jid, _password ) |
---|
849 | { |
---|
850 | userCurrent = |
---|
851 | { |
---|
852 | 'jid' : _jid.substring(11, _jid.length), |
---|
853 | 'password' : _password.substring(11, _password.length) |
---|
854 | } |
---|
855 | } |
---|
856 | |
---|
857 | function setUserCurrent() |
---|
858 | { |
---|
859 | conn.go('p.ff.data_0', |
---|
860 | function(_User) |
---|
861 | { |
---|
862 | var _user = _User; |
---|
863 | |
---|
864 | conn.go('p.ff.data_1', |
---|
865 | function(_pass) |
---|
866 | { |
---|
867 | teste_meu( _user, _pass ); |
---|
868 | }); |
---|
869 | }); |
---|
870 | } |
---|
871 | |
---|
872 | function loadIM() |
---|
873 | { |
---|
874 | if( arguments.length > 0 ) |
---|
875 | { |
---|
876 | var files = [ |
---|
877 | path_jabberit + 'js/connector.js', |
---|
878 | path_jabberit + 'js/xtools.js', |
---|
879 | path_jabberit + 'js/dragdrop.js', |
---|
880 | path_jabberit + 'js/makeW.js', |
---|
881 | path_jabberit + 'js/show_hidden.js', |
---|
882 | path_jabberit + 'js/trophyim.js', |
---|
883 | path_jabberit + 'js/AddUser.js', |
---|
884 | path_jabberit + 'js/SelectEditable.js', |
---|
885 | path_jabberit + 'templates/default/css/button.css', |
---|
886 | path_jabberit + 'templates/default/css/common.css', |
---|
887 | path_jabberit + 'templates/default/css/selectEditableStyle.css', |
---|
888 | path_jabberit + 'templates/default/css/' + theme_jabberit |
---|
889 | ]; |
---|
890 | // FullName |
---|
891 | fullName = arguments[0]; |
---|
892 | |
---|
893 | // Preferences |
---|
894 | _preferencesIM = arguments[1].split(";"); |
---|
895 | |
---|
896 | loadScripts(files); |
---|
897 | |
---|
898 | setTimeout(function() |
---|
899 | { |
---|
900 | // Object Xtools |
---|
901 | if( Xtools == null ) |
---|
902 | Xtools = new xtools(path_jabberit); |
---|
903 | |
---|
904 | // Object Conector |
---|
905 | if( conn == null ) |
---|
906 | conn = new AjaxConnector(path_jabberit); |
---|
907 | |
---|
908 | // Object Add User |
---|
909 | if( addUser == null ) |
---|
910 | addUser = new addUserIM(Xtools, conn); |
---|
911 | |
---|
912 | |
---|
913 | // Object SelectEditable |
---|
914 | if( selectEditable == null ) |
---|
915 | selectEditable = new SelectEditable(); |
---|
916 | |
---|
917 | // Add Jabber in StatusBar; |
---|
918 | addIcon(); |
---|
919 | |
---|
920 | window.document.oncontextmenu = function() |
---|
921 | { |
---|
922 | return true; |
---|
923 | }; |
---|
924 | |
---|
925 | |
---|
926 | // Auto Connect |
---|
927 | setTimeout(function() |
---|
928 | { |
---|
929 | if( _preferencesIM[0] === 'openWindowJabberit:true' ) |
---|
930 | TrophyIM.load(); |
---|
931 | },1500); |
---|
932 | |
---|
933 | // Auto Status |
---|
934 | autoStatus(); |
---|
935 | configEvents( document, 'onmousemove', autoStatus ); |
---|
936 | configEvents( document, 'onkeypress', autoStatus ); |
---|
937 | |
---|
938 | }, 2000); |
---|
939 | } |
---|
940 | } |
---|
941 | |
---|
942 | loadIM.prototype.adIcon = addIcon; |
---|
943 | loadIM.prototype.actionButton = actionButton; |
---|
944 | loadIM.prototype.addContact = addContact; |
---|
945 | loadIM.prototype.clrAllContacts = clrAllContacts; |
---|
946 | loadIM.prototype.configEvents = configEvents; |
---|
947 | loadIM.prototype.getPhotoUser = getPhotoUser; |
---|
948 | loadIM.prototype.getUserCurrent = getUserCurrent; |
---|
949 | loadIM.prototype.getZIndex = getZindex; |
---|
950 | loadIM.prototype.groupsHidden = groupsHidden; |
---|
951 | loadIM.prototype.groupsVisible = groupsVisible; |
---|
952 | loadIM.prototype.keyPressSearch = keyPressSearch; |
---|
953 | loadIM.prototype.loginPage = loginPage; |
---|
954 | loadIM.prototype.notification = notificationNewMessage; |
---|
955 | loadIM.prototype.parse = parse; |
---|
956 | loadIM.prototype.preferences = preferences; |
---|
957 | loadIM.prototype.searchUser = searchUser |
---|
958 | loadIM.prototype.setAutorization = setAutorization; |
---|
959 | loadIM.prototype.setPreferences = setPreferences; |
---|
960 | loadIM.prototype.setPresence = setPresence; |
---|
961 | loadIM.prototype.setStatusJabber = setStatusJabber; |
---|
962 | loadIM.prototype.setSelectEditable = setSelectEditable; |
---|
963 | loadIM.prototype.setUserCurrent = setUserCurrent; |
---|
964 | loadIM.prototype.removeContact = removeContact; |
---|
965 | loadIM.prototype.removeElement = removeElement; |
---|
966 | loadIM.prototype.removeGroup = removeGroup; |
---|
967 | loadIM.prototype.renameContact = renameContact; |
---|
968 | loadIM.prototype.renameGroup = renameGroup; |
---|
969 | loadIM.prototype.rosterDiv = rosterDiv; |
---|
970 | |
---|
971 | window.LoadIM = loadIM; |
---|
972 | |
---|
973 | })(); |
---|