-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplaceAddress.js
51 lines (47 loc) · 1.53 KB
/
replaceAddress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**************************************************************
Script : ReplaceAddress
Version : .5
Authors : Stephen M James (http://InteractiveLlama.com)
Desc : Javascript email obfuscation
Licence : Open Source MIT Licence
**************************************************************/
ReplaceAddress = function() {
var replace = function(newAddress) {
if (document.getElementById) {
element = document.getElementById(newAddress.id);
if (typeof(element) != 'undefined' && element != null) {
newId = (newAddress.id.split('-'))[1];
if (newId !== newAddress.id) {
newAddress.id = newId;
}
element.innerHTML = '<a id="' + newAddress.id + '" href="' + 'mai' + 'lto:' + newAddress.address.reverse().join('') + '">' + newAddress.linktext.join('') + '</a>';
}
} // if
};
return { // public methods
add: function(newAddress) {
if (newAddress instanceof Array) {
for (var i = 0, max = newAddress.length; i < max; i++) {
replace(newAddress[i]);
}
} else {
replace(newAddress);
}
}
};
}();
/* ReplaceAddress: Specify an object or array of objects in order to
replace element with stated id with 'mailto:' link.
If hyphen is in element id, then split and make second half of id
the new id. The address array is REVERSED. */
var addressList = [{
id: 'replaceText-mail1',
address: ['com', '.', 'domain', '@', 'account'],
linktext: ['email me']
},
{
id: 'replaceText-mail2',
address: ['com', '.', 'domain2', '@', 'account'],
linktext: ['email me2']
}];
ReplaceAddress.add(addressList);