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