[903] | 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. |
---|
| 10 | var actualSelectedContact = 0; |
---|
| 11 | var setTimeOutLayer = 0; |
---|
| 12 | var div_message_scroll = 0; |
---|
| 13 | |
---|
| 14 | function 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('"', """); |
---|
| 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 | tmp[1] = tmp[1].replace(tmp_mail, tmp_mail.bold()); |
---|
| 60 | tmp[0] = tmp[0].replace(tmp_mail, tmp_mail.bold()); |
---|
| 61 | if(tmp[0] == '') |
---|
| 62 | match_contacts[match_index] = tmp[0] + ' <' + tmp[1] + '>'; |
---|
| 63 | else |
---|
| 64 | match_contacts[match_index] = '$"' + tmp[0] + '" <' + tmp[1] + '>'; |
---|
| 65 | match_index++; |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | if (match_contacts.length == 0){ |
---|
| 71 | hideTip(); |
---|
| 72 | return; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | var table_contacts_header = "<table style='font-family:arial;font-size:12;color:#0000CF' border=0 cellpadding=0 cellspacing=0>"; |
---|
| 76 | var table_contacts_foot = "</table>"; |
---|
| 77 | var lines = ''; |
---|
| 78 | var REG_EXP = /^[^\#|^\$|^\%|^\!|^\?|^\"|^\']+$/; |
---|
| 79 | var match_cont = ""; |
---|
| 80 | for (var i=0; i<match_contacts.length; i++) |
---|
| 81 | { |
---|
| 82 | var aux = match_contacts[i].split(""); |
---|
| 83 | for(var j in aux){ |
---|
| 84 | if(REG_EXP.test(aux[j])){ |
---|
| 85 | match_cont += aux[j]; |
---|
| 86 | }else{ |
---|
| 87 | match_cont += ""; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | //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>" |
---|
| 91 | 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>" |
---|
| 92 | match_cont = ""; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | // treat especials keys |
---|
| 96 | // key ENTER |
---|
| 97 | if ((key_pressed == 13) && (document.getElementById('tipDiv').style.visibility)) |
---|
| 98 | { |
---|
| 99 | //Bug, sometimes the actualSelectedContact do not exist. |
---|
| 100 | try{ |
---|
| 101 | makeMailList(document.getElementById('td_DD_' + actualSelectedContact).innerHTML,fld_id); |
---|
| 102 | hideTip(); |
---|
| 103 | } |
---|
| 104 | catch(e){} |
---|
| 105 | return; |
---|
| 106 | } |
---|
| 107 | // key lostfocus |
---|
| 108 | if ((key_pressed == 'lostfocus') && (document.getElementById('tipDiv').style.visibility)){ |
---|
| 109 | hideTip(); |
---|
| 110 | return; |
---|
| 111 | } |
---|
| 112 | // key DOWN |
---|
| 113 | if ((key_pressed == 40) && (document.getElementById('tipDiv').style.visibility)){ |
---|
| 114 | if (actualSelectedContact != (match_contacts.length - 1)){ |
---|
| 115 | selectContact(actualSelectedContact + 1); |
---|
| 116 | } |
---|
| 117 | return; |
---|
| 118 | } |
---|
| 119 | // key UP |
---|
| 120 | if ((key_pressed == 38) && (document.getElementById('tipDiv').style.visibility)){ |
---|
| 121 | if (actualSelectedContact != 0){ |
---|
| 122 | selectContact(actualSelectedContact - 1); |
---|
| 123 | return; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | if (lines != ''){ |
---|
| 128 | table_contacts = table_contacts_header + lines + table_contacts_foot |
---|
| 129 | doTooltip(posX, posY, table_contacts) |
---|
| 130 | } |
---|
| 131 | else |
---|
| 132 | hideTip(); |
---|
| 133 | |
---|
| 134 | return true; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | function makeMailList(mail,fld_id) |
---|
| 138 | { |
---|
| 139 | list = Element(fld_id); |
---|
| 140 | for (var i = list.value.length; ((i!=0) && (list.value.substring(i-1,i)!=',')); i--){} |
---|
| 141 | mail = mail.replace(/</g,"<"); |
---|
| 142 | mail = mail.replace(/>/g,">"); |
---|
| 143 | mail = mail.replace(/<[bB]>/g,""); |
---|
| 144 | mail = mail.replace(/<\/[bB]>/g,""); |
---|
| 145 | if (i == 0) |
---|
| 146 | list.value = list.value.substring(0,i) + mail + ', '; |
---|
| 147 | else |
---|
| 148 | list.value = list.value.substring(0,i) + ' ' + mail + ', '; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | function selectContact(newContact){ |
---|
| 152 | //Desabilitar o atual |
---|
| 153 | var elAtual = document.getElementById('td_DD_' + actualSelectedContact); |
---|
| 154 | if(elAtual) |
---|
| 155 | elAtual.bgColor = "#efefef"; |
---|
| 156 | |
---|
| 157 | //Habilitar o novo. |
---|
| 158 | var elNew = document.getElementById('td_DD_' + newContact).bgColor = "#c0e0ff"; |
---|
| 159 | if(elNew) |
---|
| 160 | elNew.bgColor = "#c0e0ff"; |
---|
| 161 | |
---|
| 162 | actualSelectedContact = newContact; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | function doTooltip(x,y,msg) { |
---|
| 166 | if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return; |
---|
| 167 | Tooltip.show(x,y,msg); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | function hideTip() { |
---|
| 171 | if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return; |
---|
| 172 | actualSelectedContact=0; |
---|
| 173 | Tooltip.hide(); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | function findPosX(obj) |
---|
| 177 | { |
---|
| 178 | var curleft = 0; |
---|
| 179 | if (obj.offsetParent) |
---|
| 180 | { |
---|
| 181 | while (obj.offsetParent) |
---|
| 182 | { |
---|
| 183 | curleft += obj.offsetLeft |
---|
| 184 | obj = obj.offsetParent; |
---|
| 185 | } |
---|
| 186 | } |
---|
| 187 | else if (obj.x) |
---|
| 188 | curleft += obj.x; |
---|
| 189 | return curleft; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | function findPosY(obj) |
---|
| 193 | { |
---|
| 194 | var curtop = 0; |
---|
| 195 | if (obj.offsetParent) |
---|
| 196 | { |
---|
| 197 | while (obj.offsetParent) |
---|
| 198 | { |
---|
| 199 | curtop += obj.offsetTop |
---|
| 200 | obj = obj.offsetParent; |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | else if (obj.y) |
---|
| 204 | curtop += obj.y; |
---|
| 205 | return curtop; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | function trim(inputString) { |
---|
| 209 | if (typeof inputString != "string") |
---|
| 210 | return inputString; |
---|
| 211 | |
---|
| 212 | var retValue = inputString; |
---|
| 213 | var ch = retValue.substring(0, 1); |
---|
| 214 | while (ch == " ") { |
---|
| 215 | retValue = retValue.substring(1, retValue.length); |
---|
| 216 | ch = retValue.substring(0, 1); |
---|
| 217 | } |
---|
| 218 | ch = retValue.substring(retValue.length-1, retValue.length); |
---|
| 219 | while (ch == " ") { |
---|
| 220 | retValue = retValue.substring(0, retValue.length-1); |
---|
| 221 | ch = retValue.substring(retValue.length-1, retValue.length); |
---|
| 222 | } |
---|
| 223 | while (retValue.indexOf(" ") != -1) { |
---|
| 224 | retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); |
---|
| 225 | } |
---|
| 226 | return retValue; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | var Tooltip = { |
---|
| 230 | overlaySelects: true, // iframe shim for select lists (ie win) |
---|
| 231 | offX: 0, |
---|
| 232 | offY: 50, |
---|
| 233 | tipID: "tipDiv", |
---|
| 234 | showDelay: 0, |
---|
| 235 | hideDelay: 0, |
---|
| 236 | |
---|
| 237 | ovTimer: 0, // for overlaySelects |
---|
| 238 | ready:false, timer:null, tip:null, shim:null, supportsOverlay:false, |
---|
| 239 | |
---|
| 240 | init: function() { |
---|
| 241 | var el_dropdowncontact = document.createElement("DIV"); |
---|
| 242 | el_dropdowncontact.id = this.tipID; |
---|
| 243 | document.body.appendChild(el_dropdowncontact); |
---|
| 244 | this.supportsOverlay = this.checkOverlaySupport(); |
---|
| 245 | this.ready = true; |
---|
| 246 | }, |
---|
| 247 | |
---|
| 248 | show: function(x, y, msg) { |
---|
| 249 | this.tip = document.getElementById( this.tipID ); |
---|
| 250 | this.writeTip(msg); |
---|
| 251 | |
---|
| 252 | this.positionTipStatic(x,y); |
---|
| 253 | this.handleOverlay(1, this.showDelay, x+this.offX,y+this.offY); |
---|
| 254 | document.getElementById('td_DD_0').bgColor = "#c0e0ff"; |
---|
| 255 | this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'visible')", this.showDelay); |
---|
| 256 | }, |
---|
| 257 | |
---|
| 258 | writeTip: function(msg) { |
---|
| 259 | if ( this.tip && typeof this.tip.innerHTML != "undefined" ) this.tip.innerHTML = msg; |
---|
| 260 | this.tip.style.width = 'auto'; |
---|
| 261 | }, |
---|
| 262 | |
---|
| 263 | positionTipStatic: function(x,y) { |
---|
| 264 | if ( this.tip && this.tip.style ) { |
---|
| 265 | this.tip.style.left = x + this.offX + "px"; |
---|
| 266 | this.tip.style.top = y + this.offY + "px"; |
---|
| 267 | } |
---|
| 268 | }, |
---|
| 269 | |
---|
| 270 | scrollChanged: function() { |
---|
| 271 | Element('tipDiv').style.visibility = 'hidden'; |
---|
| 272 | Tooltip.hide(); |
---|
| 273 | }, |
---|
| 274 | |
---|
| 275 | hide: function() { |
---|
| 276 | if (this.timer) { clearTimeout(this.timer); this.timer = 0; } |
---|
| 277 | this.handleOverlay(0, this.hideDelay); |
---|
| 278 | this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'hidden')", this.hideDelay); |
---|
| 279 | this.tip = null; |
---|
| 280 | }, |
---|
| 281 | |
---|
| 282 | toggleVis: function(id, vis) { // to check for el_dropdowncontact, prevent (rare) error |
---|
| 283 | var el_dropdowncontact = document.getElementById(id); |
---|
| 284 | if (el_dropdowncontact) el_dropdowncontact.style.visibility = vis; |
---|
| 285 | }, |
---|
| 286 | |
---|
| 287 | // check need for and support of iframe shim |
---|
| 288 | checkOverlaySupport: function() { |
---|
| 289 | return (is_ie); |
---|
| 290 | }, |
---|
| 291 | |
---|
| 292 | handleOverlay: function(bVis, d, x ,y) { |
---|
| 293 | var _scrollY = div_message_scroll ? div_message_scroll.scrollTop : 0; |
---|
| 294 | if(_scrollY > 0 && this.tip) { |
---|
| 295 | this.tip.style.top = (findPosY(this.tip) - _scrollY)+ "px"; |
---|
| 296 | } |
---|
| 297 | if ( this.overlaySelects && this.supportsOverlay ) { |
---|
| 298 | if (this.ovTimer) { clearTimeout(this.ovTimer); this.ovTimer = 0; } |
---|
| 299 | switch (bVis) { |
---|
| 300 | case 1 : |
---|
| 301 | if ( !document.getElementById('tipShim') ) |
---|
| 302 | 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>'); |
---|
| 303 | this.shim = document.getElementById('tipShim'); |
---|
| 304 | if (this.shim && this.tip) { |
---|
| 305 | this.shim.style.width = this.tip.offsetWidth + "px"; |
---|
| 306 | this.shim.style.height = this.tip.offsetHeight + "px"; |
---|
| 307 | this.shim.style.top = findPosY(this.tip)+ "px"; |
---|
| 308 | } |
---|
| 309 | this.ovTimer = setTimeout("Tooltip.toggleVis('tipShim', 'visible')", d); |
---|
| 310 | break; |
---|
| 311 | case 0 : |
---|
| 312 | this.ovTimer = setTimeout("Tooltip.toggleVis('tipShim', 'hidden')", d); |
---|
| 313 | if (this.shim) this.shim = null; |
---|
| 314 | break; |
---|
| 315 | } |
---|
| 316 | } |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | Tooltip.init(); |
---|
| 320 | // Criar um estilo no html (tpl) com os seguintes parametros: |
---|
| 321 | //div#tipDiv { |
---|
| 322 | // position:absolute; visibility:hidden; left:0; top:0; z-index:10000; |
---|
| 323 | // background-color:#EFEFEF; border:1px solid #337; |
---|
| 324 | // width:220px; padding:3px; |
---|
| 325 | // color:#000; font-size:11px; line-height:1.2; |
---|
| 326 | // cursor: default; |
---|