source: trunk/instant_messenger/js/im_win.js @ 75

Revision 75, 41.8 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1var im_win = {
2
3   chat_pJid : null,
4   _imWindowTemplate : null,
5   xslWin : false,
6   photo  : false,
7       
8   "load" : function()
9   {
10      try
11      {
12                        var backFantom = func.newEl('div');
13                        func.confEl(backFantom, 'id', 'backFantom');
14                        func.confEl(backFantom, 'style', 'position:absolute;top:0px;left:0px;width:100%;height:100%;z-Index:-1;');
15
16                        var menu_contato = func.newEl('div');
17                        func.confEl(menu_contato, 'id', 'menu_contato');
18                        func.confEl(menu_contato, 'class', 'menu_im');
19                        func.confEl(menu_contato, 'style', 'position:absolute;z-index:99999');
20
21                        var emotions = func.newEl('div');
22                        func.confEl(emotions, 'id', 'shared_emotions');
23                        func.confEl(emotions, 'class', 'emotionFrame');
24                        func.confEl(emotions, 'style', 'position:absolute;padding:1px;left:350px;visibility:hidden;top:0px');
25
26                        var font_name = func.newEl('div');
27                        func.confEl(font_name, 'id', 'shared_fontName');
28                        func.confEl(font_name, 'class', 'statusMenu');
29                        func.confEl(font_name, 'style', 'position:absolute;visibility:hidden;padding:1px;left:400px;top:0px');
30
31                        var font_size = func.newEl('div');
32                        func.confEl(font_size, 'id', 'shared_fontSize');
33                        func.confEl(font_size, 'class', 'statusMenu');
34                        func.confEl(font_size, 'style', 'position:absolute;visibility:hidden;padding:1px;left:400px;top:0px');
35
36                        var font_color = func.newEl('div');
37                        func.confEl(font_color, 'id', 'shared_fontColor');
38                        func.confEl(font_color, 'class', 'statusMenu');
39                        func.confEl(font_color, 'style', 'position:absolute;visibility:hidden;padding:1px;left:400px;top:0px');
40
41                        var font_style = func.newEl('div');
42                        func.confEl(font_style, 'id', 'shared_fontStyle');
43                        func.confEl(font_style, 'class', 'statusMenu');
44                        func.confEl(font_style, 'style', 'position:absolute;visibility:hidden;padding:1px;left:400px;top:0px');
45
46                        func.insEl(backFantom, menu_contato, emotions, font_name, font_size, font_color, font_style, false);
47
48                        emotions.innerHTML = Templates.emotions();
49                        font_name.innerHTML = Templates.font_name();
50                        font_size.innerHTML = Templates.font_size();
51                        font_color.innerHTML = Templates.font_color();
52                        /*font_style.innerHTML = Templates.font_style();*/
53
54                        var pId = 'contacts';
55
56                        var main_menu_all = func.newEl('div');
57                        func.confEl(main_menu_all, 'style', 'margin: 3px;');
58
59                        var main_menu_head = func.newEl('div');
60                        func.confEl(main_menu_head, 'id', pId + '_im_window_body_inner_head');
61                        func.confEl(main_menu_head, 'style', 'margin: 0px 0px 3px 0px; border: 1px solid #809aa9; display: block;');
62
63                        var main_menu_vcard = func.newEl('div');
64                        func.confEl(main_menu_vcard, 'id', 'im_vcard_contacts');
65                        func.confEl(main_menu_vcard, 'style', 'display: none;');
66
67                        var main_menu_body = func.newEl('div');
68                        func.confEl(main_menu_body, 'id', 'div_contacts');
69                        func.confEl(main_menu_body, 'style', 'border: 1px solid #809aa9;');
70                        main_menu_body.innerHTML = '<b>Nenhum Contato</b>';
71
72                        func.insEl(main_menu_head, main_menu_vcard, main_menu_body, main_menu_all);
73
74                        var main_menu_head_picture = func.newEl('img');
75                        func.confEl(main_menu_head_picture, 'id', pId + '_avatar');
76                        func.confEl(main_menu_head_picture, 'src', img_photo.src);
77                        func.confEl(main_menu_head_picture, 'style', 'float: left; height: 65px; margin: 2px; width: 49px;');
78
79                        var main_menu_head_name = func.newEl('span');
80                        func.confEl(main_menu_head_name, 'id', 'span_nickname');
81                        var main_menu_head_name_txt = document.createTextNode(" your nickname");
82                        func.insEl(main_menu_head_name_txt, main_menu_head_name);
83
84                        var br1 = func.newEl('br');
85
86                        var main_menu_head_message = func.newEl('span');
87                        func.confEl(main_menu_head_message, 'id', 'span_message');
88                        var main_menu_head_message_txt = document.createTextNode(' your message');
89                        func.insEl(main_menu_head_message_txt, main_menu_head_message);
90
91                        var br2 = func.newEl('br');
92
93                        func.insEl(main_menu_head_picture, main_menu_head_name, br1, main_menu_head_message, br2, main_menu_head);
94
95                        var main_menu_head_div = func.newEl("div");
96                        func.confEl(main_menu_head_div,'id','menu_preferences');
97                        func.confEl(main_menu_head_div,'class','menu_im');
98                        func.confEl(main_menu_head_div,'style','float: left;cursor:pointer');
99
100                        func.insEl(main_menu_head_div, false);
101
102                    var params = [];
103                        params['body']       = main_menu_all;
104                        params['close']      = true;
105                        params['height']     = 270;
106                        params['left']       = 10;
107                        params['id']         = pId;
108                        params['maximize']   = true;
109                        params['style']      = 'visibility:hidden';
110                        params['title']      = 'Expresso Messenger';
111                        params['top']        = 10;
112                        params['width']      = 210;
113                        this.build(params);
114
115                        this.config(pId);
116
117                        this.windowMinimize(pId + '_im');
118
119                        main_menu_head.innerHTML += '<span id="span_menu_pref" style="float: left;" onmousedown="IM.menu_preferences(event ,\'menu_preferences\'); document.oncontextmenu = new Function(\'return false\');"></span>';
120
121                        var br3 = func.newEl('br');
122                        func.confEl(br3, 'style', 'clear: both');
123
124                        var div_ie = func.newEl('div');
125
126                        func.insEl(br3, div_ie, main_menu_head);
127
128                        main_menu_head_pref_img = func.newEl('img');
129                        func.confEl(main_menu_head_pref_img, 'src', img_group_close.src);
130                        func.confEl(main_menu_head_pref_img, 'id', 'img_pref');
131
132                        main_menu_head_pref_txt = document.createTextNode(IM.get_lang('Options'));
133
134                        func.insEl(main_menu_head_pref_img, main_menu_head_pref_txt, 'span_menu_pref');
135      }
136      catch(e)
137      {
138         alert("load\n\n" + e + "\n\n" + e.description)
139      }
140   },
141
142   "config" : function(pId)
143   {
144      try
145      {
146         ADD_DHTML("backFantom"+NO_DRAG);
147         ADD_DHTML("shared_fontStyle"+NO_DRAG);
148         ADD_DHTML("shared_fontColor"+NO_DRAG);
149         ADD_DHTML("shared_fontSize"+NO_DRAG);
150         ADD_DHTML("shared_fontName"+NO_DRAG);
151         ADD_DHTML("shared_emotions"+NO_DRAG);
152         ADD_DHTML(pId+"_im_window_body_inner"+NO_DRAG);
153         ADD_DHTML(pId+"_im_window"+NO_DRAG);
154         ADD_DHTML(pId+"_im_window_master"+NO_DRAG);
155         ADD_DHTML(pId+"_im_window_fantom"+NO_DRAG);
156         ADD_DHTML(pId+"_im_window_movable"+CURSOR_MOVE);
157         ADD_DHTML(pId+"_im_window_resize"+CURSOR_NW_RESIZE);
158
159
160         dd.elements.backFantom.setOpacity(0);
161         document.getElementById("backFantom").style.zIndex = -1;
162
163
164         dd.elements.contacts_im_window_resize.moveTo(dd.elements.contacts_im_window.x+dd.elements.contacts_im_window.w-dd.elements.contacts_im_window_resize.w-2, dd.elements.contacts_im_window.y+dd.elements.contacts_im_window.h-dd.elements.contacts_im_window_resize.h-2);
165         dd.elements.contacts_im_window_movable.moveTo(dd.elements.contacts_im_window.x, dd.elements.contacts_im_window.y);
166         dd.elements.contacts_im_window_movable.setOpacity(0);
167
168         dd.elements.contacts_im_window_resize.setOpacity(1);
169         dd.elements.contacts_im_window_resize.moveTo(dd.elements.contacts_im_window_fantom.x+dd.elements.contacts_im_window_fantom.w-dd.elements.contacts_im_window_resize.w-2, dd.elements.contacts_im_window_fantom.y+dd.elements.contacts_im_window_fantom.h-dd.elements.contacts_im_window_resize.h-2);
170
171         var contacts_im_window = new Object();
172         contacts_im_window.x = dd.elements.contacts_im_window_master.x;
173         contacts_im_window.y = dd.elements.contacts_im_window_master.y;
174         contacts_im_window.w = dd.elements.contacts_im_window_master.w;
175         contacts_im_window.h = dd.elements.contacts_im_window_master.h;
176         contacts_im_window.state = WINDOW_STATE_REGULAR;
177         windowItems[pId] = contacts_im_window;
178      }
179      catch(e)
180      {
181         alert("config\n\n" + e + "\n\n" + e.description)
182      }
183   },
184
185   "build" : function()
186   {
187      var pBody       = '';
188      var pClose      = true;
189      var pHeight     = 360;
190      var pId         = false;
191      var pLeft       = NaN;
192      var pMaximize   = true;
193      var pMinimize   = true;
194      var pStyle      = '';
195      var pTitle      = '';
196      var pTop        = NaN;
197      var pWidth      = 250;
198
199      for ( var i = 0; i < arguments.length; i++ )
200      {
201            for ( var n in arguments[i] )
202               if ( !func.isUndefined(arguments[i][n]) )
203                  switch ( n )
204                  {
205                     case 'body'    : pBody     = arguments[i][n]; break;
206                     case 'close'   : pClose    = arguments[i][n]; break;
207                     case 'height'  : pHeight   = arguments[i][n]; break;
208                     case 'id'      : pId       = arguments[i][n]; break;
209                     case 'left'    : pLeft     = arguments[i][n]; break;
210                     case 'maximize': pMaximize = arguments[i][n]; break;
211                     case 'minimize': pMinimize = arguments[i][n]; break;
212                     case 'style'   : pStyle    = arguments[i][n]; break;
213                     case 'title'   : pTitle    = arguments[i][n]; break;
214                     case 'top'     : pTop      = arguments[i][n]; break;
215                     case 'width'   : pWidth    = arguments[i][n]; break;
216                  }
217      }
218
219      if ( !pId || pHeight < 60 || pWidth < 100 )
220         return false;
221
222      if ( isNaN(pLeft) )
223         if ( windowItems[pId] )
224            pLeft = windowItems[pId].x;
225         else
226            pLeft = Math.floor(Math.random()*(dd.getWndH()-100));
227
228      if ( isNaN(pTop) )
229         if ( windowItems[pId] )
230            pTop = windowItems[pId].y;
231         else
232            pTop = Math.floor(Math.random()*(dd.getWndW()-pHeight-480))
233
234      if ( windowItems[pId] )
235      {
236         pHeight = dd.elements[pId + "_im_window_body_inner"].h;
237         pWidth = dd.elements[pId + "_im_window_body_inner"].w;
238      }
239
240      if ( !this.xslWin ) this.xslWin = XMLTools.load(im_path + 'xsl/window.xsl?' + Date.parse(new Date));
241      _xmlDoc = '<window id="' + pId + '" title="' + pTitle + '" height="' + pHeight + '" width="' + pWidth + '" left="' + pLeft + '" top="' + pTop + '" minimize="' + pMinimize + '" maximize="' + pMaximize  + '" close="' + pClose + '" style="position:absolute;' + pStyle + '" />';
242
243      a = document.createElement('div');
244
245      if (window.ActiveXObject)
246      {
247         var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
248         xmlDoc.async = "false";
249         xmlDoc.loadXML(_xmlDoc);
250      }
251      else
252      {
253         var parser = new DOMParser();
254         var xmlDoc = parser.parseFromString(_xmlDoc, "text/xml");
255      }
256      a.innerHTML = XMLTools.transform(xmlDoc, this.xslWin);
257      document.getElementsByTagName('body').item(0).appendChild(a);
258
259      switch ( typeof pBody )
260      {
261         case 'object' :
262                        func.insEl(pBody, pId + '_im_window_body_inner');
263         break;
264         case 'string' :
265                        func.byId(pId + '_im_window_body_inner').innerHTML = pBody;
266
267      }
268
269      RoundedTop('div#' + pId + '_im_window_master', '', '#cbdae4');
270      this.windowMaximizeZ(pId);
271
272   },
273
274   "hideAllChatSelections" : function()
275   {
276      this.hideEmotionSelection();
277      this.hideFontNameSelection();
278      this.hideFontSizeSelection();
279      this.hideFontColorSelection();
280      this.hideFontStyleSelection();
281   },
282
283   "hideWindowItem" : function(pId)
284   {
285      try
286      {
287         dd.elements[pId + "_im_window"].hide();
288         dd.elements[pId + "_im_window_master"].hide();
289         dd.elements[pId + "_im_window_fantom"].hide();
290         dd.elements[pId + "_im_window_resize"].hide();
291         dd.elements[pId + "_im_window_movable"].hide();
292         if ( (name_document = document.getElementById(pId + '_divEdita')) )
293         {
294            name_document.innerHTML = '';
295            var contact = func.byId(pId);
296            var _status = IM.vcard_contacts[contact.getAttribute('nuncontact')].online
297            contact.firstChild.src = ( _status == parseInt(1) ) ? img_online.src : img_offline.src;
298         }
299      }
300      catch(e)
301      {}
302   },
303
304   "incZ" : function()
305   {
306      zValue += 5;
307      return zValue;
308   },
309
310   "drag" : function()
311   {
312      try
313      {
314         var objName = dd.obj.name;
315         i = objName.indexOf("_");
316         objName = objName.substr(0,i);
317
318         this.incZ();
319         document.getElementById(objName + "_im_window_fantom").style.zIndex = zValue;
320         dd.elements[objName + "_im_window_fantom"].setOpacity(0.5);
321
322         document.getElementById(objName + "_im_window_fantom").className = "im_window_fantom";
323
324         var posX = dd.obj.x;
325         var posY = dd.obj.y;
326         if ( posX < 0 )
327            posX = 0;
328         if ( posY < 0 )
329            posY = 0;
330
331         dd.elements[objName + "_im_window_resize"].setOpacity(0);
332
333         if ( dd.obj.name == (objName + "_im_window_resize") )
334         {
335            windowState = WINDOW_STATE_REGULAR;
336
337            // check if the re-size goes out of the screen
338            if ( posX > ( dd.getWndW() - 15 ) )
339               posX = dd.getWndW()-15;
340            if ( posY > ( dd.getWndH() - 13 ) )
341               posY = dd.getWndH()-13;
342
343            // everything is fine, let's change the size of all required objects
344            var newW = posX-dd.elements[objName + "_im_window_fantom"].x+15;
345            var newH = posY-dd.elements[objName + "_im_window_fantom"].y+15;
346            if ( newW < 100) newW = 100;
347            if ( newH < 100) newH = 100;
348            dd.elements[objName + "_im_window_fantom"].resizeTo(newW, newH);
349
350                if( document.getElementById(objName + "_chatMessages"))
351                {
352                                func.confEl(document.getElementById(objName + "_chatMessages"),"style","width:" + (newW - 105) +";height:" + (newH - 150) +";margin: 2px 0px 2px 2px; overflow:auto;");
353                                func.confEl(document.getElementById(objName + '_edita'),"style","width:" + (newW - 105) + ";height: 50px;margin: 3px 1px 0px 2px;float: left;");
354                        }
355
356            dd.elements[objName + "_im_window_resize"].moveTo(dd.elements[objName + "_im_window_fantom"].x+dd.elements[objName + "_im_window_fantom"].w-dd.elements[objName + "_im_window_resize"].w-2, dd.elements[objName + "_im_window_fantom"].y+dd.elements[objName + "_im_window_fantom"].h-dd.elements[objName + "_im_window_resize"].h-2);
357            var windowItem = windowItems[objName];
358            windowItem.state = WINDOW_STATE_REGULAR;
359         }
360         else
361         {
362            if ( posX > ( dd.getWndW() - dd.elements[objName + "_im_window_master"].w ) )
363               posX = dd.getWndW() - dd.elements[objName + "_im_window_master"].w;
364
365            if ( posY > ( dd.getWndH() - dd.elements[objName + "_im_window_master"].h ) )
366               posY = dd.getWndH() - dd.elements[objName + "_im_window_master"].h;
367
368            dd.elements[objName + "_im_window_fantom"].moveTo(posX, posY);
369         }
370      }
371      catch(e)
372      {
373      }
374   },
375
376   "drop" : function()
377   {
378      try
379      {
380         document.getElementById("backFantom").style.zIndex = -1;
381
382         var objName = dd.obj.name;
383         i = objName.indexOf("_");
384         objName = objName.substr(0,i);
385
386         var posX = dd.obj.x;
387         var posY = dd.obj.y;
388         if ( posX < 0 )
389            posX = 0;
390         if ( posY < 0 )
391            posY = 0;
392         if ( posX > ( dd.getWndW() - dd.elements[objName + "_im_window_master"].w ) )
393            posX = dd.getWndW() - dd.elements[objName + "_im_window_master"].w;
394         if ( posY > ( dd.getWndH() - dd.elements[objName + "_im_window_master"].h ) )
395            posY = dd.getWndH() - dd.elements[objName + "_im_window_master"].h;
396
397         dd.elements[objName + "_im_window_resize"].setOpacity(1);
398
399         if ( dd.obj.name == (objName + "_im_window_resize") )
400         {
401            var newW = dd.obj.x-dd.elements[objName + "_im_window_fantom"].x+17;
402            var newH = dd.obj.y-dd.elements[objName + "_im_window_fantom"].y+17;
403
404            if ( newW < 100) newW = 100;
405            if ( newH < 100) newH = 100;
406
407            var winW = dd.elements[objName + "_im_window_master"].w - dd.elements[objName + "_im_window"].w;
408            var winH = dd.elements[objName + "_im_window_master"].h - dd.elements[objName + "_im_window"].h;
409
410            dd.elements[objName + "_im_window_fantom"].resizeTo(newW, newH);
411            dd.elements[objName + "_im_window_master"].resizeTo(newW, newH);
412
413            var bodyW = dd.elements[objName + "_im_window"].w - dd.elements[objName + "_im_window_body_inner"].w;
414            var bodyH = dd.elements[objName + "_im_window"].h - dd.elements[objName + "_im_window_body_inner"].h;
415
416            dd.elements[objName + "_im_window"].resizeTo(newW - winW, newH - winH);
417
418            bodyW = dd.elements[objName + "_im_window"].w - bodyW;
419            bodyH = dd.elements[objName + "_im_window"].h - bodyH;
420
421            dd.elements[objName + "_im_window_body_inner"].resizeTo(bodyW, bodyH);
422
423            dd.elements[objName + "_im_window_movable"].resizeTo(newW-55, 25);
424            dd.elements[objName + "_im_window_resize"].moveTo(dd.elements[objName + "_im_window_fantom"].x+dd.elements[objName + "_im_window_fantom"].w-dd.elements[objName + "_im_window_resize"].w-2, dd.elements[objName + "_im_window_fantom"].y+dd.elements[objName + "_im_window_fantom"].h-dd.elements[objName + "_im_window_resize"].h-2);
425         }
426         else
427         {
428            dd.elements[objName + "_im_window_fantom"].moveTo(posX, posY);
429            dd.elements[objName + "_im_window_master"].moveTo(posX, posY);
430            dd.elements[objName + "_im_window"].moveTo(posX, (posY+4));
431            dd.elements[objName + "_im_window_movable"].moveTo(posX, posY);
432            dd.elements[objName + "_im_window_resize"].moveTo(dd.elements[objName + "_im_window_fantom"].x+dd.elements[objName + "_im_window_fantom"].w-dd.elements[objName + "_im_window_resize"].w-3, dd.elements[objName + "_im_window_fantom"].y+dd.elements[objName + "_im_window_fantom"].h-dd.elements[objName + "_im_window_resize"].h-3);
433         }
434
435         this.windowMaximizeZ(objName);
436
437         dd.elements[objName + "_im_window_fantom"].setOpacity(0);
438         var windowItem = windowItems[objName];
439
440         if ( windowItem != null )
441         {
442            windowItem.x = dd.elements[objName + "_im_window_master"].x;
443            windowItem.y = dd.elements[objName + "_im_window_master"].y;
444            windowItem.w = dd.elements[objName + "_im_window_master"].w;
445            windowItem.h = dd.elements[objName + "_im_window_master"].h;
446         }
447      }catch(e){}
448   },
449
450   "pick" : function()
451   {
452      document.getElementById("backFantom").style.zIndex = zValue;
453      this.hideAllChatSelections();
454      var objName = dd.obj.name;
455      i = objName.indexOf("_im");
456      objName = objName.substr(0,i);
457      ACTIVE_OBJECTID = objName;
458   },
459
460   "showWindowItem" : function(pId)
461   {
462      /*
463       * Não tire esta linha
464       * Isso deve estar aqui para a janela 'oculta'
465       * não 'piscar' na tela no momento que é criada.
466       */
467      func.byId(pId + '_im_window_body_inner').style.overflow = 'auto';
468
469      if ( (name_document = document.getElementById(pId + '_divEdita')) )
470      {
471         name_document.innerHTML = '<iframe name="' + pId.replace('@', '_at_').replace(/\./g, '_dot_') + '_edita" class="edit_message" id="' + pId + '_edita" frameborder="0" style="border:margin: 3px 1px 0px 2px; width:220px; height:50px; float:left;"></iframe>';
472
473         name_document = document.getElementById(pId + '_edita');
474         name_document.contentWindow.document.write('<html><body id="' + pId.replace('@', '_at_').replace(/\./g, '_dot_') + '" style="margin:0px;padding:0px"></body></html>');
475         name_document.contentWindow.document.close();
476         name_document.contentWindow.document.designMode = "On";
477
478         func.attachEvent(name_document.contentWindow.document, 'keypress', im_win.getText);
479         func.attachEvent(name_document.contentWindow.document, 'keyup', im_win.clearText);
480
481         name_document.contentWindow.focus();
482      }
483
484      dd.elements[pId + "_im_window_master"].show();
485      dd.elements[pId + "_im_window"].show();
486      dd.elements[pId + "_im_window_fantom"].show();
487      dd.elements[pId + "_im_window_resize"].show();
488      dd.elements[pId + "_im_window_movable"].show();
489     
490   },
491
492   "windowMaximizeZ" : function(objName)
493   {
494      try
495      {
496         this.incZ();
497         document.getElementById(objName + "_im_window_fantom").style.zIndex = zValue-3;
498         document.getElementById(objName + "_im_window_master").style.zIndex = zValue-2;
499         document.getElementById(objName + "_im_window").style.zIndex = zValue-1;
500         document.getElementById(objName + "_im_window_body_inner").style.zIndex = zValue-1;
501         document.getElementById(objName + "_im_window_resize").style.zIndex = zValue;
502         document.getElementById(objName + "_im_window_movable").style.zIndex = zValue;
503         if ( dd.elements[objName + "_im_window_movable"] )
504            dd.elements[objName + "_im_window_movable"].z = zValue+1;
505      }catch(e){}
506   },
507
508   "windowMinimize" : function(objName)
509   {
510      with(objName)
511         objName = substr(0, indexOf('_im'));
512
513      this.hideWindowItem(objName);
514      windowItem = windowItems[objName];
515      if ( windowItem != null )
516      {
517         windowItem.state = WINDOW_STATE_MINIMIZED;
518      }
519
520   },
521
522   "windowMaximizeRestore" : function(objName)
523   {
524      with(objName)
525         objName = substr(0, indexOf('_im'));
526
527      this.hideAllChatSelections();
528
529      windowItem = windowItems[objName];
530
531      if ( windowItem != null )
532      {
533         var bodyW = dd.elements[objName + "_im_window"].w - dd.elements[objName + "_im_window_body_inner"].w;
534         var bodyH = dd.elements[objName + "_im_window"].h - dd.elements[objName + "_im_window_body_inner"].h;
535
536         if ( windowItem.state==WINDOW_STATE_REGULAR )
537         {
538            windowItem.x = dd.elements[objName + "_im_window_master"].x;
539            windowItem.y = dd.elements[objName + "_im_window_master"].y;
540            windowItem.w = dd.elements[objName + "_im_window_master"].w;
541            windowItem.h = dd.elements[objName + "_im_window_master"].h;
542
543            var bodyX = dd.elements[objName + "_im_window_body_inner"].x + dd.elements[objName + "_im_window"].x;
544            var bodyY = dd.elements[objName + "_im_window_body_inner"].y + dd.elements[objName + "_im_window"].y;
545
546            dd.elements[objName + "_im_window_fantom"].moveTo(0, 0);
547            dd.elements[objName + "_im_window_master"].moveTo(0, 0);
548            dd.elements[objName + "_im_window"].moveTo(0, 4);
549
550            dd.elements[objName + "_im_window_fantom"].resizeTo(dd.getWndW(), dd.getWndH());
551            dd.elements[objName + "_im_window_master"].resizeTo(dd.getWndW(), dd.getWndH());
552            dd.elements[objName + "_im_window"].resizeTo(dd.getWndW(), dd.getWndH() - 5);
553            dd.elements[objName + "_im_window_body_inner"].resizeTo(dd.getWndW() - bodyW, dd.getWndH() - bodyH - 5);
554
555            dd.elements[objName + "_im_window_resize"].moveTo(dd.elements[objName + "_im_window_fantom"].x+dd.elements[objName + "_im_window_fantom"].w-dd.elements[objName + "_im_window_resize"].w-2, dd.elements[objName + "_im_window_fantom"].y+dd.elements[objName + "_im_window_fantom"].h-dd.elements[objName + "_im_window_resize"].h-2);
556            windowItem.state = WINDOW_STATE_MAXIMIZED;
557
558            window.status = objName + "'s Z: " + document.getElementById(objName+"_im_window").style.zIndex;
559
560         }
561         else
562         {
563            dd.elements[objName + "_im_window_fantom"].resizeTo(windowItem.w, windowItem.h);
564            dd.elements[objName + "_im_window_master"].resizeTo(windowItem.w, windowItem.h);
565            dd.elements[objName + "_im_window"].resizeTo(windowItem.w, windowItem.h - 5);
566            dd.elements[objName + "_im_window_body_inner"].resizeTo(windowItem.w - bodyW, windowItem.h - bodyH - 5);
567
568            dd.elements[objName + "_im_window_fantom"].moveTo(windowItem.x, windowItem.y);
569            dd.elements[objName + "_im_window_master"].moveTo(windowItem.x, windowItem.y);
570            dd.elements[objName + "_im_window_resize"].moveTo(dd.elements[objName + "_im_window_fantom"].x+dd.elements[objName + "_im_window_fantom"].w-dd.elements[objName + "_im_window_resize"].w-2, dd.elements[objName + "_im_window_fantom"].y+dd.elements[objName + "_im_window_fantom"].h-dd.elements[objName + "_im_window_resize"].h-2);
571            windowItem.state = WINDOW_STATE_REGULAR;
572         }
573
574      dd.elements[objName + "_im_window_movable"].moveTo(dd.elements[objName + "_im_window"].x, dd.elements[objName + "_im_window"].y);
575      dd.elements[objName + "_im_window_movable"].resizeTo(dd.elements[objName + "_im_window"].w-55, 25);
576
577      this.showWindowItem(objName);
578      this.windowMaximizeZ(objName);
579      }
580     
581          if( !this.photo )
582          {
583                setTimeout('im_win.get_photo_ldap(\"user@user\")',1000 );
584                this.photo = true;
585          }
586   },
587
588   "create_window" : function()
589   {
590      pId = arguments[0]['id'];
591
592      if ( document.getElementById(pId + '_im_window'))
593      {
594         this.windowMaximizeZ(pId);
595         this.showWindowItem(pId);
596      }
597      else
598      {
599         this.build(arguments[0]);
600
601         ADD_DHTML(pId + "_im_window_body_inner"+NO_DRAG);
602         ADD_DHTML(pId + "_im_window"+NO_DRAG);
603         ADD_DHTML(pId + "_im_window_master"+NO_DRAG);
604         ADD_DHTML(pId + "_im_window_fantom"+NO_DRAG);
605         ADD_DHTML(pId + "_im_window_movable"+CURSOR_MOVE);
606         ADD_DHTML(pId + "_im_window_resize"+CURSOR_NW_RESIZE);
607
608         dd.elements[pId + "_im_window_movable"].moveTo(dd.elements[pId + "_im_window"].x, dd.elements[pId + "_im_window"].y);
609         dd.elements[pId + "_im_window_movable"].resizeTo(dd.elements[pId + "_im_window"].w-20, 25);
610         dd.elements[pId + "_im_window_movable"].setOpacity(0);
611
612         dd.elements[pId + "_im_window_resize"].setOpacity(1);
613
614         dd.elements[pId + "_im_window_resize"].moveTo(dd.elements[pId + "_im_window"].x+dd.elements[pId + "_im_window"].w-dd.elements[pId + "_im_window_resize"].w-2, dd.elements[pId + "_im_window"].y+dd.elements[pId + "_im_window"].h-dd.elements[pId + "_im_window_resize"].h-2);
615         dd.elements[pId + "_im_window_resize"].moveTo(dd.elements[pId + "_im_window_fantom"].x+dd.elements[pId + "_im_window_fantom"].w-dd.elements[pId + "_im_window_resize"].w-2, dd.elements[pId + "_im_window_fantom"].y+dd.elements[pId + "_im_window_fantom"].h-dd.elements[pId + "_im_window_resize"].h-2);
616
617         var windowItem = new Object();
618         windowItem.x = dd.elements[pId + "_im_window_master"].x;
619         windowItem.y = dd.elements[pId + "_im_window_master"].y;
620         windowItem.w = dd.elements[pId + "_im_window_master"].w;
621         windowItem.h = dd.elements[pId + "_im_window_master"].h;
622         windowItem.state = WINDOW_STATE_MINIMIZED;
623         windowItems[pId] = windowItem;
624
625         title = (arguments[0]['title']) ? arguments[0]['title'] : arguments[0]['id'];
626         this.windowMinimize(pId + '_im');
627         this.windowMaximizeRestore(pId + '_im');
628      }
629   },
630
631   "open_chat" : function(pId)
632   {
633      if ( !func.byId(pId + '_im_window') )
634      {
635         text = '';
636         text += '<div class="border" id="' + pId + '_chatMessages" style="width:220px; height:130px; margin: 2px 0px 2px 2px; overflow:auto;"></div>';
637         text += '<div style="float: left; position: relative; height:130px;">';
638         text += '   <div class="myAvatar">';
639         text += '      <img id="' + pId + '_avatar" alt="Display Picture" title="Display Picture" src="' + im_path + 'templates/default/images/photo.png" width="49" height="65" border="0" />';
640         text += '   </div>';
641         text += '   <div id="' + pId + '_composing" class="composing"><img src="' + img_typing.src + '" /></div>';
642         text += '</div>';
643         text += '<br style="clear:both;"/>';
644         text += '<dl>';
645         text += '   <dd class="small">';
646         text += '      &nbsp;<span id="selectEmotionsDiv" class="des-small" onmouseover="selectDiv(this)" onmouseout="unselectDiv(this)" onclick="im_win.showEmotionSelection(\'' + pId + '\');" title="Select Imotions here!"><img src="' + im_path + 'templates/default/images/img/1.gif" width="15" height="15" alt="Select Imotions here!" style="vertical-align:  text-top;" /></span>';
647         text += '   </dd>';
648         text += '   <dd class="small">|</dd>';
649         text += '   <dd class="small">';
650         text += '      <span id="selectFontNameDiv" class="des-small" onmouseover="selectDiv(this)" onmouseout="unselectDiv(this)" onclick="im_win.showFontNameSelection(\'' + pId + '\');" title="Select Font Name here!" style="height:19px;">'+IM.get_lang('Font')+'</span>';
651         text += '   </dd>';
652         text += '   <dd class="small">|</dd>';
653         text += '   <dd class="small">';
654         text += '      <span id="selectFontSizeDiv" class="des-small" onmouseover="selectDiv(this)" onmouseout="unselectDiv(this)" onclick="im_win.showFontSizeSelection(\'' + pId + '\')" title="Select Font Size here!" style="height:19px;">'+IM.get_lang('Size')+'</span>';
655         text += '   </dd>';
656         text += '   <dd class="small">|</dd>';
657         text += '   <dd class="small">';
658         text += '      <span id="selectFontColorDiv" class="des-small" onmouseover="selectDiv(this)" onmouseout="unselectDiv(this)" onclick="im_win.showFontColorSelection(\'' + pId + '\')" title="Select Font Color here!" style="height:19px;">'+IM.get_lang('Color')+'</span>';
659         text += '   </dd>';
660         text += '   <dd class="small">|</dd>';
661         text += '   <dd class="small">';
662         text += '      <span id="selectFontStyleDiv" class="des-small" onmouseover="selectDiv(this)" onmouseout="unselectDiv(this)" onclick="im_win.showFontStyleSelection(\'' + pId + '\')" title="Select Font Color here!" style="height:19px;">'+IM.get_lang('Style')+'</span>';
663         text += '   </dd>';
664         text += '</dl>';
665         text += '<div id="' + pId + '_divEdita" style="margin: 0px 2px"><iframe name="' + pId.replace('@', '_at_').replace(/\./g, '_dot_') + '_edita" class="edit_message" id="' + pId + '_edita" frameborder="0" style="margin: 3px 1px 0px 2px; width:220px; height:50px; float:left;"></iframe></div>';
666         text += '<br/><a onclick="javascript:IM.sendMessage(\'' + pId + '\')" title="Send a message" style="float:left;margin: 0px 2px;"><img src="' + im_path + 'templates/default/images/send.gif" width="50" height="25" border=0 style="margin-top:3px"></a>';
667         text += '<br style="clear:both" /><span id="' + pId + '_im_window_message" style="margin-left: 2px" />';
668
669         var params = [];
670         params['body']     = text;
671         params['height']   = 225;
672         params['id']       = pId;
673         params['maximize'] = false;
674         params['minimize'] = false;
675         params['title']    = pId;
676         params['width']    = 320;
677         this.create_window(params);
678
679         // Photo Ldap;
680         this.get_photo_ldap(pId);
681               
682         name_document = document.getElementById(pId + '_edita');
683         name_document.contentWindow.document.write('<html><body id="' + pId.replace('@', '_at_').replace(/\./g, '_dot_') + '" style="margin:0px;padding:0px"></body></html>');
684         name_document.contentWindow.document.close();
685         name_document.contentWindow.document.designMode = "On";
686
687         func.attachEvent(name_document.contentWindow.document, 'keypress', im_win.getText);
688         func.attachEvent(name_document.contentWindow.document, 'keyup', im_win.clearText);
689
690         name_document.contentWindow.focus();
691         
692         var status = func.byId(pId + '_im_window');
693         status.firstChild.style.background = 'url('+func.byId(pId).firstChild.src+')';
694      }
695      else
696      {
697         this.showWindowItem(pId);
698      }
699   },
700
701   "get_photo_ldap" : function(IdLdap)
702   {
703                var uid_ldap = IdLdap.substr(0,IdLdap.indexOf('@'));
704                var handler_photo_ldap = function(_XMLdata)
705                {
706                        var data = _XMLdata.getElementsByTagName('retorno').item(0);
707                        data = eval(data.firstChild.nodeValue);
708                        if(data)
709                        {
710                                IdLdap = ( IdLdap == 'user@user' ) ? 'contacts' : IdLdap;
711                                if( document.getElementById(IdLdap + "_avatar") != null ){
712                                        var ph_img = document.getElementById(IdLdap + "_avatar");
713                                        ph_img.src = (im_path + "inc/class.ldap_im.inc.php?user="+uid_ldap) ? im_path + "inc/class.ldap_im.inc.php?user="+uid_ldap : img_photo.src ;
714                                }
715                        }
716                }
717
718            XMLTools.__RETURN_MODE__ = 'XML';
719                XMLTools.request('$this.ldap_im.photo_ldap','POST',handler_photo_ldap,'uid='+uid_ldap);
720   },
721
722   "windowClose" : function(objName)
723   {
724      with(objName)
725         objName = substr(0, indexOf('_im'));
726
727      this.hideWindowItem(objName);
728      this.hideAllChatSelections();
729
730      var windowItem = windowItems[objName];
731      if ( windowItem != null )
732         windowItem.state = WINDOW_STATE_CLOSED;
733
734      if ( objName != 'contacts' )
735      {
736         var win = document.getElementById(objName + '_im_window_master');
737         var resize = document.getElementById(objName + '_im_window_resize');
738         var fantom = document.getElementById(objName + '_im_window_fantom');
739         var movable = document.getElementById(objName + '_im_window_movable');
740
741         win.parentNode.removeChild(win);
742         resize.parentNode.removeChild(resize);
743         fantom.parentNode.removeChild(fantom);
744         movable.parentNode.removeChild(movable);
745
746         //delete windowItem;
747      }
748   },
749
750   "hideEmotionSelection" : function()
751   {
752      emotionsDiv = document.getElementById("shared_emotions");
753      if ( isEmotionSelectionVisible )
754      {
755         emotionsDiv.style.visibility = "hidden";
756         isEmotionSelectionVisible = false;
757      }
758   },
759
760   "highlightie5" : function (e)
761   {
762      if ( e.className == "emotionItem" )
763         e.className = "emotionItem-sel";
764      else if ( e.className == "menuitems" )
765         e.className = "menuitems-sel";
766
767   },
768
769   "lowlightie5" : function(e)
770   {
771      if ( e.className == "emotionItem-sel" )
772         e.className = "emotionItem";
773      else if ( e.className == "menuitems-sel" )
774         e.className = "menuitems";
775   },
776
777   "addEmotion" : function(emotion)
778   {
779      var n_document = document.getElementById(this.chat_pJid + '_edita');
780      var edita = n_document.contentWindow.document.getElementsByTagName('body').item(0);
781      edita.innerHTML += IM.emotions_icons(emotion);
782
783      this.hideEmotionSelection();
784   },
785
786   "showEmotionSelection" : function(objName)
787   {
788      this.chat_pJid = objName;
789      activeChatWindowId = objName;
790      var emotionsDiv = document.getElementById("shared_emotions");
791      if(!isEmotionSelectionVisible)
792      {
793         this.hideAllChatSelections();
794         chatObj = dd.elements[objName + "_im_window"];
795         x = chatObj.x + 6;
796         y = chatObj.y + chatObj.h - 200;
797         dd.elements.shared_emotions.moveTo(x,y);
798         this.incZ();
799         document.getElementById("shared_emotions").style.zIndex = zValue;
800         emotionsDiv.style.visibility = "visible";
801         isEmotionSelectionVisible = true;
802      }
803      else
804      {
805         this.hideAllChatSelections();
806      }
807   },
808
809   "showFontNameSelection" : function(objName)
810   {
811      this.chat_pJid = objName;
812      activeChatWindowId = objName;
813      var objDiv = document.getElementById("shared_fontName");
814      if(!isFontNameSelectionVisible)
815      {
816         this.hideAllChatSelections();
817         chatObj = dd.elements[objName + "_im_window"];
818         x = chatObj.x + 85;
819         y = chatObj.y + chatObj.h - 185;
820         dd.elements.shared_fontName.moveTo(x,y);
821         this.incZ();
822         document.getElementById("shared_fontName").style.zIndex = zValue;
823         objDiv.style.visibility = "visible";
824         isFontNameSelectionVisible = true;
825      }
826      else
827      {
828         this.hideAllChatSelections();
829      }
830   },
831
832   "hideFontNameSelection" : function()
833   {
834      var objDiv = document.getElementById("shared_fontName");
835      if ( isFontNameSelectionVisible )
836      {
837         objDiv.style.visibility = "hidden";
838         isFontNameSelectionVisible = false;
839      }
840   },
841
842   "showFontSizeSelection" : function(objName)
843   {
844
845      this.chat_pJid = objName;
846      activeChatWindowId = objName;
847      var objDiv = document.getElementById("shared_fontSize");
848      if ( !isFontSizeSelectionVisible )
849      {
850         this.hideAllChatSelections();
851         chatObj = dd.elements[objName + "_im_window"];
852         x = chatObj.x + 154;
853         y = chatObj.y + chatObj.h - 200;
854         dd.elements.shared_fontSize.moveTo(x,y);
855         this.incZ();
856         document.getElementById("shared_fontSize").style.zIndex = zValue;
857         objDiv.style.visibility = "visible";
858         isFontSizeSelectionVisible = true;
859      }
860      else
861      {
862         this.hideAllChatSelections();
863      }
864   },
865
866   "hideFontSizeSelection" : function()
867   {
868      var objDiv = document.getElementById("shared_fontSize");
869      if ( isFontSizeSelectionVisible )
870      {
871         objDiv.style.visibility = "hidden";
872         isFontSizeSelectionVisible = false;
873      }
874   },
875
876   "showFontColorSelection" : function(objName)
877   {
878      this.chat_pJid = objName;
879      activeChatWindowId = objName;
880      var objDiv = document.getElementById("shared_fontColor");
881      if ( !isFontColorSelectionVisible )
882      {
883         this.hideAllChatSelections();
884         chatObj = dd.elements[objName + "_im_window"];
885         x = chatObj.x + 191;
886         y = chatObj.y + chatObj.h - 200;
887         dd.elements.shared_fontColor.moveTo(x,y);
888         this.incZ();
889         document.getElementById("shared_fontColor").style.zIndex = zValue;
890         objDiv.style.visibility = "visible";
891         isFontColorSelectionVisible = true;
892      }
893      else
894      {
895         this.hideAllChatSelections();
896      }
897   },
898
899   "showFontStyleSelection" : function(objName)
900   {
901      this.chat_pJid = objName;
902      activeChatWindowId = objName;
903      var objDiv = document.getElementById("shared_fontStyle");
904      if ( !isFontStyleSelectionVisible )
905      {
906         this.hideAllChatSelections();
907         chatObj = dd.elements[objName + "_im_window"];
908         x = chatObj.x + 234;
909         y = chatObj.y + chatObj.h - 181;
910         dd.elements.shared_fontStyle.moveTo(x,y);
911         this.incZ();
912         document.getElementById("shared_fontStyle").style.zIndex = zValue;
913         objDiv.style.visibility = "visible";
914         isFontStyleSelectionVisible = true;
915      }
916      else
917      {
918         this.hideAllChatSelections();
919      }
920   },
921
922   "hideFontColorSelection" : function()
923   {
924      var objDiv = document.getElementById("shared_fontColor");
925      if ( isFontColorSelectionVisible )
926      {
927         objDiv.style.visibility = "hidden";
928         isFontColorSelectionVisible = false;
929      }
930   },
931
932   "hideFontStyleSelection" : function()
933   {
934      var objDiv = document.getElementById("shared_fontStyle");
935      if ( isFontStyleSelectionVisible )
936      {
937         objDiv.style.visibility = "hidden";
938         isFontStyleSelectionVisible = false;
939      }
940   },
941
942   "newMessageNotification" : function()
943   {
944      if ( !focusFlag )
945      {
946         if ( document.title=="......................" )
947            document.title = IM.get_lang("New Message!");
948         else
949            document.title = "......................";
950         
951         this.Mod_Notification();
952
953         if ( newMessageTimer )
954            clearTimeout(newMessageTimer);
955         newMessageTimer = setTimeout("im_win.newMessageNotification()", 1000);
956      }
957      else
958      {
959         if ( newMessageTimer ) clearTimeout(newMessageTimer);
960      }
961     
962   },
963
964   "Mod_Notification" : function()
965   {
966                // Aviso Normal
967                if(eval(IM_Preferences.LoadPreferences('rd_nm')))
968                {
969                }
970                // Aviso Chato           
971                if(eval(IM_Preferences.LoadPreferences('rd_ch')))
972                {
973                        if(self.moveBy)
974                        {
975                                for(i=10;i>0;i--)
976                                {
977                                  self.moveBy(i,0);
978                                  self.moveBy(-i,0);
979                                }
980                        }
981                }
982   },
983
984   "getText" : function(e)
985   {
986      if ( !focusFlag ) windowFocus();
987      evt = e.keyCode;
988      pId = ( e.srcElement ) ? e.srcElement.id : e.target.getElementsByTagName('body').item(0).id;
989      pId = pId.replace('_at_', '@').replace(/_dot_/g, '.')
990      switch ( evt )
991      {
992         case 13 :
993                  if ( !e.shiftKey )
994                     IM.sendMessage(pId);
995                  return false;
996         break;
997         case 27 :
998                  im_win.windowClose(pId + '_im');
999         break;
1000      }
1001   },
1002
1003   "clearText" : function(e)
1004   {
1005      if ( !focusFlag ) windowFocus();
1006      evt = e.keyCode;
1007      _text = ( e.srcElement ) ? e.srcElement.id : e.target.getElementsByTagName('body').item(0);
1008
1009      switch ( evt )
1010      {
1011         case 13 :
1012                  //if ( !e.shiftKey )
1013                     _text.innerHTML = '';
1014                     return false;
1015         break;
1016      }
1017   }
1018}
1019
1020function my_DragFunc()
1021{
1022   im_win.drag();
1023}
1024function my_DropFunc()
1025{
1026   im_win.drop();
1027}
1028function my_PickFunc()
1029{
1030   im_win.pick();
1031}
1032function selectDiv(obj) {
1033  obj.className = "sel-small";
1034}
1035function unselectDiv(obj) {
1036  obj.className = "des-small";
1037}
1038function getElementsBySelector(selector)
1039{
1040   var i;
1041   var s=[];
1042   var selid="";
1043   var selclass="";
1044   var tag=selector;
1045   var objlist=[];
1046   if ( selector.indexOf(" ") > 0 )
1047   {//descendant selector like "tag#id tag"
1048      s=selector.split(" ");
1049      var fs=s[0].split("#");
1050      if ( fs.length == 1 )
1051         return(objlist);
1052      return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
1053   }
1054   if ( selector.indexOf("#") > 0 )
1055   {//id selector like "tag#id"
1056      s=selector.split("#");
1057      tag=s[0];
1058      selid=s[1];
1059   }
1060   if ( selid != "" )
1061   {
1062      objlist.push(document.getElementById(selid));
1063      return(objlist);
1064   }
1065   if ( selector.indexOf(".") > 0 )
1066   {//class selector like "tag.class"
1067      s=selector.split(".");
1068      tag=s[0];
1069      selclass=s[1];
1070   }
1071   var v = document.getElementsByTagName(tag);  // tag selector like "tag"
1072   if ( selclass == "" )
1073      return(v);
1074
1075   for ( i = 0; i < v.length; i++ )
1076      if ( v[i].className ==selclass )
1077         objlist.push(v[i]);
1078
1079   return(objlist);
1080}
1081function AddTop(el,bk,color,size)
1082{
1083   try
1084   {
1085      var i;
1086      var d=document.createElement("b");
1087      var cn="_r";
1088      var lim=4;
1089      if(size && size=="small"){ cn="_rs"; lim=2}
1090      d.className="_rtop";
1091      d.style.backgroundColor=bk;
1092      for(i=1;i<=lim;i++)
1093      {
1094         var x=document.createElement("b");
1095         x.className=cn + i;
1096         x.style.backgroundColor=color;
1097         d.appendChild(x);
1098      }
1099      el.insertBefore(d,el.firstChild);
1100   }
1101   catch(e)
1102   {}
1103}
1104function RoundedTop(selector,bk,color,size){
1105   var i;
1106   var v=getElementsBySelector(selector);
1107   for(i=0;i<v.length;i++)
1108          AddTop(v[i],bk,color,size);
1109}
1110
1111im_win.load();
Note: See TracBrowser for help on using the repository browser.