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

Revision 64, 42.0 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
71                        func.insEl(main_menu_head, main_menu_vcard, main_menu_body, main_menu_all);
72
73                        var main_menu_head_picture = func.newEl('img');
74                        func.confEl(main_menu_head_picture, 'id', pId + '_avatar');
75                        func.confEl(main_menu_head_picture, 'src', img_photo.src);
76                        func.confEl(main_menu_head_picture, 'style', 'float: left; height: 65px; margin: 2px; width: 49px;');
77
78                        var main_menu_head_name = func.newEl('span');
79                        func.confEl(main_menu_head_name, 'id', 'span_nickname');
80                        var main_menu_head_name_txt = document.createTextNode(" your nickname");
81                        func.insEl(main_menu_head_name_txt, main_menu_head_name);
82
83                        var br1 = func.newEl('br');
84
85                        var main_menu_head_message = func.newEl('span');
86                        func.confEl(main_menu_head_message, 'id', 'span_message');
87                        var main_menu_head_message_txt = document.createTextNode(' your message');
88                        func.insEl(main_menu_head_message_txt, main_menu_head_message);
89
90                        var br2 = func.newEl('br');
91
92                        func.insEl(main_menu_head_picture, main_menu_head_name, br1, main_menu_head_message, br2, main_menu_head);
93
94                        var main_menu_head_div = func.newEl("div");
95                        func.confEl(main_menu_head_div,'id','menu_preferences');
96                        func.confEl(main_menu_head_div,'class','menu_im');
97                        func.confEl(main_menu_head_div,'style','float: left;cursor:pointer');
98
99                        func.insEl(main_menu_head_div, false);
100
101                    var params = [];
102                        params['body']       = main_menu_all;
103                        params['close']      = true;
104                        params['height']     = 270;
105                        params['left']       = 10;
106                        params['id']         = pId;
107                        params['maximize']   = true;
108                        params['style']      = 'visibility:hidden';
109                        params['title']      = 'Expresso Messenger';
110                        params['top']        = 10;
111                        params['width']      = 210;
112                        this.build(params);
113
114                        this.config(pId);
115
116                        this.windowMinimize(pId + '_im');
117
118                        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>';
119
120                        var br3 = func.newEl('br');
121                        func.confEl(br3, 'style', 'clear: both');
122
123                        var div_ie = func.newEl('div');
124
125                        func.insEl(br3, div_ie, main_menu_head);
126
127                        main_menu_head_pref_img = func.newEl('img');
128                        func.confEl(main_menu_head_pref_img, 'src', img_group_close.src);
129                        func.confEl(main_menu_head_pref_img, 'id', 'img_pref');
130
131                        main_menu_head_pref_txt = document.createTextNode(IM.get_lang('Options'));
132
133                        func.insEl(main_menu_head_pref_img, main_menu_head_pref_txt, 'span_menu_pref');
134      }
135      catch(e)
136      {
137         alert("load\n\n" + e + "\n\n" + e.description)
138      }
139   },
140
141   "config" : function(pId)
142   {
143      try
144      {
145         ADD_DHTML("backFantom"+NO_DRAG);
146         ADD_DHTML("shared_fontStyle"+NO_DRAG);
147         ADD_DHTML("shared_fontColor"+NO_DRAG);
148         ADD_DHTML("shared_fontSize"+NO_DRAG);
149         ADD_DHTML("shared_fontName"+NO_DRAG);
150         ADD_DHTML("shared_emotions"+NO_DRAG);
151         ADD_DHTML(pId+"_im_window_body_inner"+NO_DRAG);
152         ADD_DHTML(pId+"_im_window"+NO_DRAG);
153         ADD_DHTML(pId+"_im_window_master"+NO_DRAG);
154         ADD_DHTML(pId+"_im_window_fantom"+NO_DRAG);
155         ADD_DHTML(pId+"_im_window_movable"+CURSOR_MOVE);
156         ADD_DHTML(pId+"_im_window_resize"+CURSOR_NW_RESIZE);
157
158
159         dd.elements.backFantom.setOpacity(0);
160         document.getElementById("backFantom").style.zIndex = -1;
161
162
163         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);
164         dd.elements.contacts_im_window_movable.moveTo(dd.elements.contacts_im_window.x, dd.elements.contacts_im_window.y);
165         dd.elements.contacts_im_window_movable.setOpacity(0);
166
167         dd.elements.contacts_im_window_resize.setOpacity(1);
168         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);
169
170         var contacts_im_window = new Object();
171         contacts_im_window.x = dd.elements.contacts_im_window_master.x;
172         contacts_im_window.y = dd.elements.contacts_im_window_master.y;
173         contacts_im_window.w = dd.elements.contacts_im_window_master.w;
174         contacts_im_window.h = dd.elements.contacts_im_window_master.h;
175         contacts_im_window.state = WINDOW_STATE_REGULAR;
176         windowItems[pId] = contacts_im_window;
177      }
178      catch(e)
179      {
180         alert("config\n\n" + e + "\n\n" + e.description)
181      }
182   },
183
184   "build" : function()
185   {
186      var pBody       = '';
187      var pClose      = true;
188      var pHeight     = 360;
189      var pId         = false;
190      var pLeft       = NaN;
191      var pMaximize   = true;
192      var pMinimize   = true;
193      var pStyle      = '';
194      var pTitle      = '';
195      var pTop        = NaN;
196      var pWidth      = 250;
197      //for ( aa in arguments )
198      for ( var i = 0; i < arguments.length; i++ )
199      {
200         //if ( func.isArray(arguments[i]) )
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      }
448      catch(e)
449      {
450         //alert(e)
451      }
452   },
453
454   "pick" : function()
455   {
456      document.getElementById("backFantom").style.zIndex = zValue;
457      this.hideAllChatSelections();
458      var objName = dd.obj.name;
459      i = objName.indexOf("_im");
460      objName = objName.substr(0,i);
461      ACTIVE_OBJECTID = objName;
462   },
463
464   "showWindowItem" : function(pId)
465   {
466      /*
467       * Não tire esta linha
468       * Isso deve estar aqui para a janela 'oculta'
469       * não 'piscar' na tela no momento que é criada.
470       */
471      func.byId(pId + '_im_window_body_inner').style.overflow = 'auto';
472
473      if ( (name_document = document.getElementById(pId + '_divEdita')) )
474      {
475         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>';
476
477         name_document = document.getElementById(pId + '_edita');
478         name_document.contentWindow.document.write('<html><body id="' + pId.replace('@', '_at_').replace(/\./g, '_dot_') + '" style="margin:0px;padding:0px"></body></html>');
479         name_document.contentWindow.document.close();
480         name_document.contentWindow.document.designMode = "On";
481
482         func.attachEvent(name_document.contentWindow.document, 'keypress', im_win.getText);
483         func.attachEvent(name_document.contentWindow.document, 'keyup', im_win.clearText);
484
485         name_document.contentWindow.focus();
486      }
487
488      dd.elements[pId + "_im_window_master"].show();
489      dd.elements[pId + "_im_window"].show();
490      dd.elements[pId + "_im_window_fantom"].show();
491      dd.elements[pId + "_im_window_resize"].show();
492      dd.elements[pId + "_im_window_movable"].show();
493     
494   },
495
496   "windowMaximizeZ" : function(objName)
497   {
498      try
499      {
500         this.incZ();
501         document.getElementById(objName + "_im_window_fantom").style.zIndex = zValue-3;
502         document.getElementById(objName + "_im_window_master").style.zIndex = zValue-2;
503         document.getElementById(objName + "_im_window").style.zIndex = zValue-1;
504         document.getElementById(objName + "_im_window_body_inner").style.zIndex = zValue-1;
505         document.getElementById(objName + "_im_window_resize").style.zIndex = zValue;
506         document.getElementById(objName + "_im_window_movable").style.zIndex = zValue;
507         if ( dd.elements[objName + "_im_window_movable"] )
508            dd.elements[objName + "_im_window_movable"].z = zValue+1;
509      }
510      catch(e)
511      {}
512   },
513
514   "windowMinimize" : function(objName)
515   {
516      with(objName)
517         objName = substr(0, indexOf('_im'));
518
519      this.hideWindowItem(objName);
520      windowItem = windowItems[objName];
521      if ( windowItem != null )
522      {
523         windowItem.state = WINDOW_STATE_MINIMIZED;
524      }
525
526   },
527
528   "windowMaximizeRestore" : function(objName)
529   {
530      with(objName)
531         objName = substr(0, indexOf('_im'));
532
533      this.hideAllChatSelections();
534
535      windowItem = windowItems[objName];
536
537      if ( windowItem != null )
538      {
539         var bodyW = dd.elements[objName + "_im_window"].w - dd.elements[objName + "_im_window_body_inner"].w;
540         var bodyH = dd.elements[objName + "_im_window"].h - dd.elements[objName + "_im_window_body_inner"].h;
541
542         if ( windowItem.state==WINDOW_STATE_REGULAR )
543         {
544            windowItem.x = dd.elements[objName + "_im_window_master"].x;
545            windowItem.y = dd.elements[objName + "_im_window_master"].y;
546            windowItem.w = dd.elements[objName + "_im_window_master"].w;
547            windowItem.h = dd.elements[objName + "_im_window_master"].h;
548
549            var bodyX = dd.elements[objName + "_im_window_body_inner"].x + dd.elements[objName + "_im_window"].x;
550            var bodyY = dd.elements[objName + "_im_window_body_inner"].y + dd.elements[objName + "_im_window"].y;
551
552            dd.elements[objName + "_im_window_fantom"].moveTo(0, 0);
553            dd.elements[objName + "_im_window_master"].moveTo(0, 0);
554            dd.elements[objName + "_im_window"].moveTo(0, 4);
555
556            dd.elements[objName + "_im_window_fantom"].resizeTo(dd.getWndW(), dd.getWndH());
557            dd.elements[objName + "_im_window_master"].resizeTo(dd.getWndW(), dd.getWndH());
558            dd.elements[objName + "_im_window"].resizeTo(dd.getWndW(), dd.getWndH() - 5);
559            dd.elements[objName + "_im_window_body_inner"].resizeTo(dd.getWndW() - bodyW, dd.getWndH() - bodyH - 5);
560
561            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);
562            windowItem.state = WINDOW_STATE_MAXIMIZED;
563
564            window.status = objName + "'s Z: " + document.getElementById(objName+"_im_window").style.zIndex;
565
566         }
567         else
568         {
569            dd.elements[objName + "_im_window_fantom"].resizeTo(windowItem.w, windowItem.h);
570            dd.elements[objName + "_im_window_master"].resizeTo(windowItem.w, windowItem.h);
571            dd.elements[objName + "_im_window"].resizeTo(windowItem.w, windowItem.h - 5);
572            dd.elements[objName + "_im_window_body_inner"].resizeTo(windowItem.w - bodyW, windowItem.h - bodyH - 5);
573
574            dd.elements[objName + "_im_window_fantom"].moveTo(windowItem.x, windowItem.y);
575            dd.elements[objName + "_im_window_master"].moveTo(windowItem.x, windowItem.y);
576            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);
577            windowItem.state = WINDOW_STATE_REGULAR;
578         }
579
580      dd.elements[objName + "_im_window_movable"].moveTo(dd.elements[objName + "_im_window"].x, dd.elements[objName + "_im_window"].y);
581      dd.elements[objName + "_im_window_movable"].resizeTo(dd.elements[objName + "_im_window"].w-55, 25);
582
583      this.showWindowItem(objName);
584      this.windowMaximizeZ(objName);
585      }
586     
587          if( !this.photo )
588          {
589                setTimeout('im_win.get_photo_ldap(\"user@user\")',1000 );
590                this.photo = true;
591          }
592   },
593
594   "create_window" : function()
595   {
596      pId = arguments[0]['id'];
597
598      if ( document.getElementById(pId + '_im_window'))
599      {
600         this.windowMaximizeZ(pId);
601         this.showWindowItem(pId);
602      }
603      else
604      {
605         this.build(arguments[0]);
606
607         ADD_DHTML(pId + "_im_window_body_inner"+NO_DRAG);
608         ADD_DHTML(pId + "_im_window"+NO_DRAG);
609         ADD_DHTML(pId + "_im_window_master"+NO_DRAG);
610         ADD_DHTML(pId + "_im_window_fantom"+NO_DRAG);
611         ADD_DHTML(pId + "_im_window_movable"+CURSOR_MOVE);
612         ADD_DHTML(pId + "_im_window_resize"+CURSOR_NW_RESIZE);
613
614         dd.elements[pId + "_im_window_movable"].moveTo(dd.elements[pId + "_im_window"].x, dd.elements[pId + "_im_window"].y);
615         dd.elements[pId + "_im_window_movable"].resizeTo(dd.elements[pId + "_im_window"].w-20, 25);
616         dd.elements[pId + "_im_window_movable"].setOpacity(0);
617
618         dd.elements[pId + "_im_window_resize"].setOpacity(1);
619
620         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);
621         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);
622
623         var windowItem = new Object();
624         windowItem.x = dd.elements[pId + "_im_window_master"].x;
625         windowItem.y = dd.elements[pId + "_im_window_master"].y;
626         windowItem.w = dd.elements[pId + "_im_window_master"].w;
627         windowItem.h = dd.elements[pId + "_im_window_master"].h;
628         windowItem.state = WINDOW_STATE_MINIMIZED;
629         windowItems[pId] = windowItem;
630
631         title = (arguments[0]['title']) ? arguments[0]['title'] : arguments[0]['id'];
632         this.windowMinimize(pId + '_im');
633         this.windowMaximizeRestore(pId + '_im');
634      }
635   },
636
637   "open_chat" : function(pId)
638   {
639      if ( !func.byId(pId + '_im_window') )
640      {
641         text = '';
642         text += '<div class="border" id="' + pId + '_chatMessages" style="width:220px; height:130px; margin: 2px 0px 2px 2px; overflow:auto;"></div>';
643         text += '<div style="float: left; position: relative; height:130px;">';
644         text += '   <div class="myAvatar">';
645         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" />';
646         text += '   </div>';
647         text += '   <div id="' + pId + '_composing" class="composing"><img src="' + img_typing.src + '" /></div>';
648         text += '</div>';
649         text += '<br style="clear:both;"/>';
650         text += '<dl>';
651         text += '   <dd class="small">';
652         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>';
653         text += '   </dd>';
654         text += '   <dd class="small">|</dd>';
655         text += '   <dd class="small">';
656         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>';
657         text += '   </dd>';
658         text += '   <dd class="small">|</dd>';
659         text += '   <dd class="small">';
660         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>';
661         text += '   </dd>';
662         text += '   <dd class="small">|</dd>';
663         text += '   <dd class="small">';
664         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>';
665         text += '   </dd>';
666         text += '   <dd class="small">|</dd>';
667         text += '   <dd class="small">';
668         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>';
669         text += '   </dd>';
670         text += '</dl>';
671         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>';
672         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>';
673         text += '<br style="clear:both" /><span id="' + pId + '_im_window_message" style="margin-left: 2px" />';
674
675         var params = [];
676         params['body']     = text;
677         params['height']   = 225;
678         params['id']       = pId;
679         params['maximize'] = false;
680         params['minimize'] = false;
681         params['title']    = pId;
682         params['width']    = 320;
683         this.create_window(params);
684
685         // Photo Ldap;
686         this.get_photo_ldap(pId);
687               
688         name_document = document.getElementById(pId + '_edita');
689         name_document.contentWindow.document.write('<html><body id="' + pId.replace('@', '_at_').replace(/\./g, '_dot_') + '" style="margin:0px;padding:0px"></body></html>');
690         name_document.contentWindow.document.close();
691         name_document.contentWindow.document.designMode = "On";
692
693         func.attachEvent(name_document.contentWindow.document, 'keypress', im_win.getText);
694         func.attachEvent(name_document.contentWindow.document, 'keyup', im_win.clearText);
695
696         name_document.contentWindow.focus();
697         
698         var status = func.byId(pId + '_im_window');
699         status.firstChild.style.background = 'url('+func.byId(pId).firstChild.src+')';
700      }
701      else
702      {
703         this.showWindowItem(pId);
704      }
705   },
706
707   "get_photo_ldap" : function(IdLdap)
708   {
709                var uid_ldap = IdLdap.substr(0,IdLdap.indexOf('@'));
710                var handler_photo_ldap = function(_XMLdata)
711                {
712                        var data = _XMLdata.getElementsByTagName('retorno').item(0);
713                        data = eval(data.firstChild.nodeValue);
714                        if(data)
715                        {
716                                IdLdap = ( IdLdap == 'user@user' ) ? 'contacts' : IdLdap;
717                                if( document.getElementById(IdLdap + "_avatar") != null ){
718                                        var ph_img = document.getElementById(IdLdap + "_avatar");
719                                        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 ;
720                                }
721                        }
722                }
723
724            XMLTools.__RETURN_MODE__ = 'XML';
725                XMLTools.request('$this.ldap_im.photo_ldap','POST',handler_photo_ldap,'uid='+uid_ldap);
726   },
727
728   "windowClose" : function(objName)
729   {
730      with(objName)
731         objName = substr(0, indexOf('_im'));
732
733      this.hideWindowItem(objName);
734      this.hideAllChatSelections();
735
736      var windowItem = windowItems[objName];
737      if ( windowItem != null )
738         windowItem.state = WINDOW_STATE_CLOSED;
739
740      if ( objName != 'contacts' )
741      {
742         var win = document.getElementById(objName + '_im_window_master');
743         var resize = document.getElementById(objName + '_im_window_resize');
744         var fantom = document.getElementById(objName + '_im_window_fantom');
745         var movable = document.getElementById(objName + '_im_window_movable');
746
747         win.parentNode.removeChild(win);
748         resize.parentNode.removeChild(resize);
749         fantom.parentNode.removeChild(fantom);
750         movable.parentNode.removeChild(movable);
751
752         // delete windowItem;
753      }
754   },
755
756   "hideEmotionSelection" : function()
757   {
758      emotionsDiv = document.getElementById("shared_emotions");
759      if ( isEmotionSelectionVisible )
760      {
761         emotionsDiv.style.visibility = "hidden";
762         isEmotionSelectionVisible = false;
763      }
764   },
765
766   "highlightie5" : function (e)
767   {
768      if ( e.className == "emotionItem" )
769         e.className = "emotionItem-sel";
770      else if ( e.className == "menuitems" )
771         e.className = "menuitems-sel";
772
773   },
774
775   "lowlightie5" : function(e)
776   {
777      if ( e.className == "emotionItem-sel" )
778         e.className = "emotionItem";
779      else if ( e.className == "menuitems-sel" )
780         e.className = "menuitems";
781   },
782
783   "addEmotion" : function(emotion)
784   {
785      var n_document = document.getElementById(this.chat_pJid + '_edita');
786      var edita = n_document.contentWindow.document.getElementsByTagName('body').item(0);
787      edita.innerHTML += IM.emotions_icons(emotion);
788
789      this.hideEmotionSelection();
790   },
791
792   "showEmotionSelection" : function(objName)
793   {
794      this.chat_pJid = objName;
795      activeChatWindowId = objName;
796      var emotionsDiv = document.getElementById("shared_emotions");
797      if(!isEmotionSelectionVisible)
798      {
799         this.hideAllChatSelections();
800         chatObj = dd.elements[objName + "_im_window"];
801         x = chatObj.x + 6;
802         y = chatObj.y + chatObj.h - 200;
803         dd.elements.shared_emotions.moveTo(x,y);
804         this.incZ();
805         document.getElementById("shared_emotions").style.zIndex = zValue;
806         emotionsDiv.style.visibility = "visible";
807         isEmotionSelectionVisible = true;
808      }
809      else
810      {
811         this.hideAllChatSelections();
812      }
813   },
814
815   "showFontNameSelection" : function(objName)
816   {
817      this.chat_pJid = objName;
818      activeChatWindowId = objName;
819      var objDiv = document.getElementById("shared_fontName");
820      if(!isFontNameSelectionVisible)
821      {
822         this.hideAllChatSelections();
823         chatObj = dd.elements[objName + "_im_window"];
824         x = chatObj.x + 85;
825         y = chatObj.y + chatObj.h - 185;
826         dd.elements.shared_fontName.moveTo(x,y);
827         this.incZ();
828         document.getElementById("shared_fontName").style.zIndex = zValue;
829         objDiv.style.visibility = "visible";
830         isFontNameSelectionVisible = true;
831      }
832      else
833      {
834         this.hideAllChatSelections();
835      }
836   },
837
838   "hideFontNameSelection" : function()
839   {
840      var objDiv = document.getElementById("shared_fontName");
841      if ( isFontNameSelectionVisible )
842      {
843         objDiv.style.visibility = "hidden";
844         isFontNameSelectionVisible = false;
845      }
846   },
847
848   "showFontSizeSelection" : function(objName)
849   {
850
851      this.chat_pJid = objName;
852      activeChatWindowId = objName;
853      var objDiv = document.getElementById("shared_fontSize");
854      if ( !isFontSizeSelectionVisible )
855      {
856         this.hideAllChatSelections();
857         chatObj = dd.elements[objName + "_im_window"];
858         x = chatObj.x + 154;
859         y = chatObj.y + chatObj.h - 200;
860         dd.elements.shared_fontSize.moveTo(x,y);
861         this.incZ();
862         document.getElementById("shared_fontSize").style.zIndex = zValue;
863         objDiv.style.visibility = "visible";
864         isFontSizeSelectionVisible = true;
865      }
866      else
867      {
868         this.hideAllChatSelections();
869      }
870   },
871
872   "hideFontSizeSelection" : function()
873   {
874      var objDiv = document.getElementById("shared_fontSize");
875      if ( isFontSizeSelectionVisible )
876      {
877         objDiv.style.visibility = "hidden";
878         isFontSizeSelectionVisible = false;
879      }
880   },
881
882   "showFontColorSelection" : function(objName)
883   {
884      this.chat_pJid = objName;
885      activeChatWindowId = objName;
886      var objDiv = document.getElementById("shared_fontColor");
887      if ( !isFontColorSelectionVisible )
888      {
889         this.hideAllChatSelections();
890         chatObj = dd.elements[objName + "_im_window"];
891         x = chatObj.x + 191;
892         y = chatObj.y + chatObj.h - 200;
893         dd.elements.shared_fontColor.moveTo(x,y);
894         this.incZ();
895         document.getElementById("shared_fontColor").style.zIndex = zValue;
896         objDiv.style.visibility = "visible";
897         isFontColorSelectionVisible = true;
898      }
899      else
900      {
901         this.hideAllChatSelections();
902      }
903   },
904
905   "showFontStyleSelection" : function(objName)
906   {
907      this.chat_pJid = objName;
908      activeChatWindowId = objName;
909      var objDiv = document.getElementById("shared_fontStyle");
910      if ( !isFontStyleSelectionVisible )
911      {
912         this.hideAllChatSelections();
913         chatObj = dd.elements[objName + "_im_window"];
914         x = chatObj.x + 234;
915         y = chatObj.y + chatObj.h - 181;
916         dd.elements.shared_fontStyle.moveTo(x,y);
917         this.incZ();
918         document.getElementById("shared_fontStyle").style.zIndex = zValue;
919         objDiv.style.visibility = "visible";
920         isFontStyleSelectionVisible = true;
921      }
922      else
923      {
924         this.hideAllChatSelections();
925      }
926   },
927
928   "showMessageHistoryWindow" : function()
929   {
930           // Revisar ALC
931      alert("Função Indisponivel");
932      return false;
933   },
934
935   "hideFontColorSelection" : function()
936   {
937      var objDiv = document.getElementById("shared_fontColor");
938      if ( isFontColorSelectionVisible )
939      {
940         objDiv.style.visibility = "hidden";
941         isFontColorSelectionVisible = false;
942      }
943   },
944
945   "hideFontStyleSelection" : function()
946   {
947      var objDiv = document.getElementById("shared_fontStyle");
948      if ( isFontStyleSelectionVisible )
949      {
950         objDiv.style.visibility = "hidden";
951         isFontStyleSelectionVisible = false;
952      }
953   },
954
955   "newMessageNotification" : function()
956   {
957      if ( !focusFlag )
958      {
959         if ( document.title=="......................" )
960            document.title = IM.get_lang("New Message!");
961         else
962            document.title = "......................";
963         
964         this.Mod_Notification();
965
966         if ( newMessageTimer )
967            clearTimeout(newMessageTimer);
968         newMessageTimer = setTimeout("im_win.newMessageNotification()", 1000);
969      }
970      else
971      {
972         if ( newMessageTimer ) clearTimeout(newMessageTimer);
973      }
974     
975   },
976
977   "Mod_Notification" : function()
978   {
979                // Aviso Normal
980                if(eval(IM_Preferences.LoadPreferences('rd_nm')))
981                {
982                }
983                // Aviso Chato           
984                if(eval(IM_Preferences.LoadPreferences('rd_ch')))
985                {
986                        if(self.moveBy)
987                        {
988                                for(i=10;i>0;i--)
989                                {
990                                  self.moveBy(i,0);
991                                  self.moveBy(-i,0);
992                                }
993                        }
994                }
995   },
996
997   "getText" : function(e)
998   {
999      if ( !focusFlag ) windowFocus();
1000      evt = e.keyCode;
1001      pId = ( e.srcElement ) ? e.srcElement.id : e.target.getElementsByTagName('body').item(0).id;
1002      pId = pId.replace('_at_', '@').replace(/_dot_/g, '.')
1003      switch ( evt )
1004      {
1005         case 13 :
1006                  if ( !e.shiftKey )
1007                     IM.sendMessage(pId);
1008                  return false;
1009         break;
1010         case 27 :
1011                  im_win.windowClose(pId + '_im');
1012         break;
1013      }
1014   },
1015
1016   "clearText" : function(e)
1017   {
1018      if ( !focusFlag ) windowFocus();
1019      evt = e.keyCode;
1020      _text = ( e.srcElement ) ? e.srcElement.id : e.target.getElementsByTagName('body').item(0);
1021
1022      switch ( evt )
1023      {
1024         case 13 :
1025                  //if ( !e.shiftKey )
1026                     _text.innerHTML = '';
1027                     return false;
1028         break;
1029      }
1030   }
1031}
1032
1033function my_DragFunc()
1034{
1035   im_win.drag();
1036}
1037function my_DropFunc()
1038{
1039   im_win.drop();
1040}
1041function my_PickFunc()
1042{
1043   im_win.pick();
1044}
1045function selectDiv(obj) {
1046  obj.className = "sel-small";
1047}
1048function unselectDiv(obj) {
1049  obj.className = "des-small";
1050}
1051function getElementsBySelector(selector)
1052{
1053   var i;
1054   var s=[];
1055   var selid="";
1056   var selclass="";
1057   var tag=selector;
1058   var objlist=[];
1059   if ( selector.indexOf(" ") > 0 )
1060   {//descendant selector like "tag#id tag"
1061      s=selector.split(" ");
1062      var fs=s[0].split("#");
1063      if ( fs.length == 1 )
1064         return(objlist);
1065      return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
1066   }
1067   if ( selector.indexOf("#") > 0 )
1068   {//id selector like "tag#id"
1069      s=selector.split("#");
1070      tag=s[0];
1071      selid=s[1];
1072   }
1073   if ( selid != "" )
1074   {
1075      objlist.push(document.getElementById(selid));
1076      return(objlist);
1077   }
1078   if ( selector.indexOf(".") > 0 )
1079   {//class selector like "tag.class"
1080      s=selector.split(".");
1081      tag=s[0];
1082      selclass=s[1];
1083   }
1084   var v = document.getElementsByTagName(tag);  // tag selector like "tag"
1085   if ( selclass == "" )
1086      return(v);
1087
1088   for ( i = 0; i < v.length; i++ )
1089      if ( v[i].className ==selclass )
1090         objlist.push(v[i]);
1091
1092   return(objlist);
1093}
1094function AddTop(el,bk,color,size)
1095{
1096   try
1097   {
1098      var i;
1099      var d=document.createElement("b");
1100      var cn="_r";
1101      var lim=4;
1102      if(size && size=="small"){ cn="_rs"; lim=2}
1103      d.className="_rtop";
1104      d.style.backgroundColor=bk;
1105      for(i=1;i<=lim;i++)
1106      {
1107         var x=document.createElement("b");
1108         x.className=cn + i;
1109         x.style.backgroundColor=color;
1110         d.appendChild(x);
1111      }
1112      el.insertBefore(d,el.firstChild);
1113   }
1114   catch(e)
1115   {}
1116}
1117function RoundedTop(selector,bk,color,size){
1118   var i;
1119   var v=getElementsBySelector(selector);
1120   for(i=0;i<v.length;i++)
1121          AddTop(v[i],bk,color,size);
1122}
1123
1124im_win.load();
Note: See TracBrowser for help on using the repository browser.