(addr)
| 1293 | |
| 1294 | |
| 1295 | var _EncodeEmailAddress = function(addr) { |
| 1296 | // |
| 1297 | // Input: an email address, e.g. "foo@example.com" |
| 1298 | // |
| 1299 | // Output: the email address as a mailto link, with each character |
| 1300 | // of the address encoded as either a decimal or hex entity, in |
| 1301 | // the hopes of foiling most address harvesting spam bots. E.g.: |
| 1302 | // |
| 1303 | // <a href="mailto:foo@e |
| 1304 | // xample.com">foo |
| 1305 | // @example.com</a> |
| 1306 | // |
| 1307 | // Based on a filter by Matthew Wickline, posted to the BBEdit-Talk |
| 1308 | // mailing list: <http://tinyurl.com/yu7ue> |
| 1309 | // |
| 1310 | |
| 1311 | // attacklab: why can't javascript speak hex? |
| 1312 | function char2hex(ch) { |
| 1313 | var hexDigits = '0123456789ABCDEF'; |
| 1314 | var dec = ch.charCodeAt(0); |
| 1315 | return(hexDigits.charAt(dec>>4) + hexDigits.charAt(dec&15)); |
| 1316 | } |
| 1317 | |
| 1318 | var encode = [ |
| 1319 | function(ch){return "&#"+ch.charCodeAt(0)+";";}, |
| 1320 | function(ch){return "&#x"+char2hex(ch)+";";}, |
| 1321 | function(ch){return ch;} |
| 1322 | ]; |
| 1323 | |
| 1324 | addr = "mailto:" + addr; |
| 1325 | |
| 1326 | addr = addr.replace(/./g, function(ch) { |
| 1327 | if (ch == "@") { |
| 1328 | // this *must* be encoded. I insist. |
| 1329 | ch = encode[Math.floor(Math.random()*2)](ch); |
| 1330 | } else if (ch !=":") { |
| 1331 | // leave ':' alone (to spot mailto: later) |
| 1332 | var r = Math.random(); |
| 1333 | // roughly 10% raw, 45% hex, 45% dec |
| 1334 | ch = ( |
| 1335 | r > .9 ? encode[2](ch) : |
| 1336 | r > .45 ? encode[1](ch) : |
| 1337 | encode[0](ch) |
| 1338 | ); |
| 1339 | } |
| 1340 | return ch; |
| 1341 | }); |
| 1342 | |
| 1343 | addr = "<a href=\"" + addr + "\">" + addr + "</a>"; |
| 1344 | addr = addr.replace(/">.+:/g,"\">"); // strip the mailto: from the visible part |
| 1345 | |
| 1346 | return addr; |
| 1347 | } |
| 1348 | |
| 1349 | |
| 1350 | var _UnescapeSpecialChars = function(text) { |
no test coverage detected