source: sandbox/2.2.0.2/expressoMail1_2/js/DropDownContacts.js @ 4304

Revision 4304, 10.5 KB checked in by airton, 13 years ago (diff)

Ticket #1820 - Corrigido erro para traduzir pasta pela funcao lang_folder - r4292

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1/**********************************************************************************\
2* Written by Joao Alfredo Knopik Junior (JakJr) <joao.alfredo@gmail.com>          *
3* ------------------------------------------------------------------------------- *
4*  This program is free software; you can redistribute it and/or modify it        *
5*  under the terms of the GNU General Public License as published by the              *
6*  Free Software Foundation; either version 2 of the License, or (at your option) *
7*  any later version.                                                             *
8\**********************************************************************************/
9// variavel global que salva o contato atual selecionado.
10var actualSelectedContact = 0;
11var setTimeOutLayer = 0;
12var div_message_scroll = 0;
13var tst_i = 0;
14function search_contacts(key_pressed, fld_id)
15{
16        div_message_scroll = Element('div_message_scroll_'+ fld_id.substring(fld_id.length - 1, fld_id.length));
17
18        var string_contacts = contacts
19        if (Element(fld_id))
20                var mail = Element(fld_id).value;
21        else
22                return;
23       
24        var array_contacts = string_contacts.split(",");
25        var tmp = mail.split(",");
26        mail = trim(tmp[tmp.length - 1]);
27        tmp_mail = mail;
28       
29        seekDot = /\./gi;
30        mail = mail.replace(seekDot, "[.]");
31        mail = mail.replace('"', "&quot;");
32        mail = mail.replace("\n", "");
33        mail = mail.replace("\r", "");
34        mail = mail.replace("\t", "");
35        posX = findPosX(document.getElementById(fld_id));
36        posY = findPosY(document.getElementById(fld_id));
37
38        if ((!string_contacts) || (string_contacts.length==0) || (mail.length==0)){
39                hideTip();
40                return;
41        }
42               
43        if (mail.length == 0){
44                hideTip();
45                return;
46        }
47       
48        var RegExp_name = new RegExp(mail, "i");
49        var RegExp_mail = new RegExp(mail+".*@", "i");
50
51        var match_contacts = new Array();
52        var match_index = 0;
53
54        for (var i=0; i<array_contacts.length; i++){
55                tmp = array_contacts[i].split(";");
56                if ( (RegExp_name.test(tmp[0])) || (RegExp_mail.test(tmp[1])) ){
57                        if (tmp[1])
58                        {
59                                var _tmp1 = RegExp_mail.exec(tmp[1]);
60                                if ( _tmp1 )
61                                        tmp[1] = tmp[1].replace(RegExp_mail, _tmp1[0].bold());
62                                var _tmp0 = RegExp_name.exec(tmp[0]);
63                                if ( _tmp0 )
64                                        tmp[0] = tmp[0].replace(RegExp_name, _tmp0[0].bold());
65                                match_contacts[match_index] = '&quot;' + tmp[0] + '&quot; &lt;' + tmp[1] + '&gt;';
66                                match_index++;
67                        }
68                }
69        }
70
71        if (match_contacts.length == 0){
72                hideTip();
73                return;
74        }
75
76        var table_contacts_header = "<table style='font-family:arial;font-size:12;color:#0000CF' border=0 cellpadding=0 cellspacing=0>";
77        var table_contacts_foot = "</table>";
78        var lines = '';
79        var REG_EXP = /^[^\#|^\$|^\%|^\!|^\?|^\"|^\']+$/;
80        var match_cont = "";
81        for (var i=0; i<match_contacts.length; i++)
82        {
83                match_contacts[i] = unescape(match_contacts[i]);
84                var aux = match_contacts[i].split("");
85                for(var j in aux){
86                        if(REG_EXP.test(aux[j])){
87                                match_cont += aux[j];
88                        }else{
89                                match_cont += "";
90                        }
91                }
92                //lines = lines + "<tr><td id=td_DD_"+i+" onClick=\"javascript:hideTip();makeMailList('"+match_contacts[i]+"','"+fld_id+"');document.getElementById('" + fld_id + "').focus();\" onmouseover=\"selectContact("+i+")\">" + match_contacts[i] + "</td></tr>"
93                lines = lines + "<tr><td id=td_DD_"+i+" onMouseDown=\"javascript:hideTip();makeMailList('"+match_cont+"','"+fld_id+"');setTimeout('document.getElementById(\\'"+fld_id+"\\').focus()',300);\" onmouseover=\"selectContact("+i+")\">" + match_cont + "</td></tr>"
94                match_cont = "";
95        }
96
97       
98        if (document.getElementById('tipDiv')){
99                document.getElementById('tipDiv').focus();
100        }
101
102
103        // treat especials keys
104        // key ENTER
105        if ((key_pressed == 13) && (document.getElementById('tipDiv').style.visibility))
106        {
107                //Bug, sometimes the actualSelectedContact do not exist.
108                try{
109                        makeMailList(document.getElementById('td_DD_' + actualSelectedContact).innerHTML,fld_id);
110                        hideTip();
111                }
112                catch(e){}
113                return;
114        }
115        // key lostfocus
116        if ((key_pressed == 'lostfocus') && (document.getElementById('tipDiv').style.visibility)){
117                hideTip();
118                return;
119        }
120       
121        // key LEFT and RIGHT (when pressed, keeps the actual selection preventing lost of focus selection on pressing "up" or "down" keys)
122        if (((key_pressed == 37) && (document.getElementById('tipDiv').style.visibility)) || ((key_pressed == 39) && (document.getElementById('tipDiv').style.visibility)))
123        {
124                selectContact(actualSelectedContact);
125                return;
126        }
127
128        // key DOWN
129        if ((key_pressed == 40) && (document.getElementById('tipDiv').style.visibility)){
130                if (actualSelectedContact != (match_contacts.length - 1)){
131                        selectContact(actualSelectedContact + 1);
132                }
133                return;
134        }
135        // key UP
136        if ((key_pressed == 38) && (document.getElementById('tipDiv').style.visibility)){
137                if (actualSelectedContact != 0){                       
138                        selectContact(actualSelectedContact - 1);
139                        return;
140                }
141        }
142
143        if (lines != ''){
144                table_contacts = table_contacts_header + lines + table_contacts_foot
145                doTooltip(posX, posY, table_contacts)
146        }
147        else
148                hideTip();
149               
150        return true;
151}
152
153function makeMailList(mail,fld_id)
154{
155        list = Element(fld_id);
156        for (var i = list.value.length; ((i!=0) && (list.value.substring(i-1,i)!=',')); i--){}
157        mail = mail.replace(/&lt;/g,"<");
158        mail = mail.replace(/&gt;/g,">");
159        mail = mail.replace(/<[bB]>/g,"");
160        mail = mail.replace(/<\/[bB]>/g,"");
161        if (i == 0)
162                list.value = list.value.substring(0,i) + mail + ', ';
163        else
164                list.value = list.value.substring(0,i) + ' ' + mail + ', ';
165}
166
167function selectContact(newContact){     
168        //Desabilitar o atual
169        var elAtual = document.getElementById('td_DD_' + actualSelectedContact);
170        if(elAtual)
171                elAtual.bgColor = "#efefef";   
172               
173        //Habilitar o novo.             
174        var elNew = document.getElementById('td_DD_' + newContact).bgColor = "#c0e0ff";
175        if(elNew)
176                elNew.bgColor = "#c0e0ff";
177
178        actualSelectedContact = newContact;
179}
180
181function doTooltip(x,y,msg) {
182        if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
183        Tooltip.show(x,y,msg);
184}
185
186function hideTip() {
187        if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
188        actualSelectedContact=0;
189        Tooltip.hide();
190}
191
192function findPosX(obj)
193{
194        var curleft = 0;
195        if (obj.offsetParent)
196        {
197                while (obj.offsetParent)
198                {
199                        curleft += obj.offsetLeft
200                        obj = obj.offsetParent;
201                }
202        }
203        else if (obj.x)
204                curleft += obj.x;
205        return curleft;
206}
207
208function findPosY(obj)
209{
210        var curtop = 0;
211        if (obj.offsetParent)
212        {
213                while (obj.offsetParent)
214                {
215                        curtop += obj.offsetTop
216                        obj = obj.offsetParent;
217                }
218        }
219        else if (obj.y)
220                curtop += obj.y;
221        return curtop;
222}
223
224function trim(inputString) {
225   if (typeof inputString != "string")
226        return inputString;
227     
228   var retValue = inputString;
229   var ch = retValue.substring(0, 1);
230   while (ch == " ") {
231          retValue = retValue.substring(1, retValue.length);
232          ch = retValue.substring(0, 1);
233   }
234   ch = retValue.substring(retValue.length-1, retValue.length);
235   while (ch == " ") {
236          retValue = retValue.substring(0, retValue.length-1);
237          ch = retValue.substring(retValue.length-1, retValue.length);
238   }
239   while (retValue.indexOf("  ") != -1) {
240          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
241   }
242   return retValue;
243}
244
245var Tooltip = {
246    overlaySelects: true,  // iframe shim for select lists (ie win)
247    offX: 0,
248    offY: 50,
249    tipID: "tipDiv",
250    showDelay: 0,
251    hideDelay: 0,
252   
253    ovTimer: 0, // for overlaySelects
254    ready:false, timer:null, tip:null, shim:null, supportsOverlay:false,
255 
256    init: function() {
257            var el_dropdowncontact = document.createElement("DIV");
258                        el_dropdowncontact.id = this.tipID;
259                        document.body.appendChild(el_dropdowncontact);
260            this.supportsOverlay = this.checkOverlaySupport();
261            this.ready = true;
262    },
263   
264    show: function(x, y, msg) {
265        this.tip = document.getElementById( this.tipID );
266        this.writeTip(msg);
267       
268        this.positionTipStatic(x,y);
269                this.handleOverlay(1, this.showDelay, x+this.offX,y+this.offY);
270                document.getElementById('td_DD_0').bgColor = "#c0e0ff";
271        this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'visible')", this.showDelay);
272    },
273   
274    writeTip: function(msg) {
275        if ( this.tip && typeof this.tip.innerHTML != "undefined" ) this.tip.innerHTML = msg;
276        this.tip.style.width = 'auto';
277    },
278   
279    positionTipStatic: function(x,y) {
280        if ( this.tip && this.tip.style ) {
281                        this.tip.style.left = x + this.offX + "px";
282                        this.tip.style.top = y + this.offY + "px";
283        }
284     },
285
286        scrollChanged: function() {
287                Element('tipDiv').style.visibility = 'hidden';
288                Tooltip.hide();
289        },
290
291    hide: function() {
292        if (this.timer) { clearTimeout(this.timer);     this.timer = 0; }
293                this.handleOverlay(0, this.hideDelay);
294        this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'hidden')", this.hideDelay);
295        this.tip = null;
296    },
297   
298  toggleVis: function(id, vis) { // to check for el_dropdowncontact, prevent (rare) error
299      var el_dropdowncontact = document.getElementById(id);
300      if (el_dropdowncontact) el_dropdowncontact.style.visibility = vis;
301  },
302
303        // check need for and support of iframe shim
304        checkOverlaySupport: function() {
305                return (is_ie);
306        },
307   
308        handleOverlay: function(bVis, d, x ,y) {
309                var _scrollY = div_message_scroll ? div_message_scroll.scrollTop : 0;
310        if(_scrollY > 0 && this.tip) {
311                this.tip.style.top = (findPosY(this.tip) - _scrollY)+ "px";
312            }
313                if ( this.overlaySelects && this.supportsOverlay ) {
314                        if (this.ovTimer) { clearTimeout(this.ovTimer); this.ovTimer = 0; }
315                        switch (bVis) {
316                        case 1 :
317                                if ( !document.getElementById('tipShim') )
318                                        document.body.insertAdjacentHTML("beforeEnd", '<iframe id="tipShim" src="about:blank" style="position:absolute; left:' + x + '; top:' + y + '; z-index:500; visibility:hidden" scrolling="no" frameborder="0"></iframe>');
319                                        this.shim = document.getElementById('tipShim');
320                                        if (this.shim && this.tip) {
321                                                this.shim.style.width = this.tip.offsetWidth + "px";
322                        this.shim.style.height = this.tip.offsetHeight + "px";
323                        this.shim.style.top = findPosY(this.tip)+ "px";
324                                        }
325                                        this.ovTimer = setTimeout("Tooltip.toggleVis('tipShim', 'visible')", d);
326                                break;
327                        case 0 :
328                                this.ovTimer = setTimeout("Tooltip.toggleVis('tipShim', 'hidden')", d);
329                                if (this.shim) this.shim = null;
330                                break;
331                        }
332                }
333        }
334}
335Tooltip.init();
336// Criar um estilo no html (tpl) com os seguintes parametros:
337//div#tipDiv {
338//  position:absolute; visibility:hidden; left:0; top:0; z-index:10000;
339//  background-color:#EFEFEF; border:1px solid #337;
340//  width:220px; padding:3px;
341//  color:#000; font-size:11px; line-height:1.2;
342//  cursor: default;
Note: See TracBrowser for help on using the repository browser.