1(function (Drupal) { 2 'use strict'; 3 4 function init(context) { 5 var elements = context.querySelectorAll('[data-mail-to]'); 6 var clickable = context.querySelectorAll('[data-mail-click-link]'); 7 8 if (!elements) { 9 return; 10 } 11 12 /** 13 * Shift the string with rot 13. 14 * Rewrite from Jonas Raoni Soares Silva 15 * 16 * @see http://jsfromhell.com/string/rot13 [rev. #1] 17 * 18 * @param string 19 * @returns string 20 */ 21 function rot13(string) { 22 return string.replace(/[a-zA-Z]/g, function (c) { 23 return String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26); 24 }); 25 } 26 27 /** 28 * Decrypt the string to an email. 29 * 30 * @param string 31 * @returns string 32 */ 33 function normalizeEncryptEmail(string) { 34 string = rot13(string); 35 string = string.replace(/\/dot\//g, '.'); 36 string = string.replace(/\/at\//g, '@'); 37 38 var encodedString = Drupal.checkPlain(string); 39 // revert encoding of ampersands as this is invalid for mailto: links 40 encodedString = encodedString.replace(/&/g, '&') 41 return encodedString; 42 } 43 44 function setMailAddress(element) { 45 var mailTo = normalizeEncryptEmail(element.getAttribute('data-mail-to')); 46 var replaceInner = element.getAttribute('data-replace-inner'); 47 48 element.removeAttribute('data-mail-to'); 49 element.removeAttribute('data-replace-inner'); 50 51 // set href if anchor tag 52 if (element.tagName === 'A') { 53 element.setAttribute('href', 'mailto:' + mailTo); 54 } 55 56 // replace whole string 57 if (replaceInner === 'true' || replaceInner === '') { 58 element.innerHTML = mailTo; 59 60 return; 61 } 62 63 // replace the token given in [data-replace-inner] 64 if (replaceInner) { 65 element.innerHTML = element.innerHTML.replace(replaceInner, mailTo); 66 } 67 } 68 69 if (clickable.length) { 70 Array.prototype.slice.call(elements).forEach( function(element) { 71 element.addEventListener('click', function (event) { 72 if (element.className.split(/\s+/).indexOf('link-processed') === -1) { 73 event.preventDefault(); 74 setMailAddress(element); 75 element.classList.add('link-processed'); 76 } 77 }); 78 }); 79 80 return; 81 } 82 83 NodeList.prototype.forEach = Array.prototype.forEach; 84 85 elements.forEach(function (element) { 86 setMailAddress(element); 87 }); 88 } 89 90 Drupal.behaviors.obfuscateEmailField = { 91 attach: init 92 }; 93})(Drupal);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.