CoreFiles by mySites.guru
joomla-hidden-mail.js50 lines, 1,605 bytes, from Joomla_4.0.0-alpha5-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha3
md5
6c266e54ede86c64a107a37e54a5c95a
sha1
3366c0115441917d7144b2d1d70f8ba6c3da1347
sha256
887ddc0d46222f49190fdbdc4e681232a31bc8f17bfcbd6c6f04bbb43aaa8a7a
;customElements.define('joomla-hidden-mail', class extends HTMLElement {
	connectedCallback() {
		let newEl;
		let base = this.getAttribute('base') + '/';

		if (this.getAttribute('is-link') === '1') {
			newEl = document.createElement('a');
			newEl.setAttribute('href', 'mailto:' + this.b64DecodeUnicode(this.getAttribute('first')) + '@' + this.b64DecodeUnicode(this.getAttribute('last')));

			// Get all of the original element attributes, and pass them to the link
			for(let i = 0, l = this.attributes.length; i < l; ++i){
				const nodeName  = this.attributes.item(i).nodeName;

				if (nodeName) {
					// We do care for some attributes
					if (['is-link', 'is-email', 'first', 'last', 'text'].indexOf(nodeName) > -1) {
						continue;
					}

					const nodeValue = this.attributes.item(i).nodeValue;

					newEl.setAttribute(nodeName, nodeValue);
				}
			}
		} else {
			newEl = document.createElement('span');
		}

		if (this.getAttribute('text')) {
			let innerStr = this.b64DecodeUnicode(this.getAttribute('text'));

			innerStr = innerStr.replace('src="images/', `src="${base}images/`).replace('src="media/', `src="${base}media/`);
			newEl.innerHTML = innerStr;
		} else {
			newEl.innerText = window.atob(this.getAttribute('first')) + '@' + window.atob(this.getAttribute('last'));
		}

		// Remove the noscript message
		this.innerText = '';

		// Display the new element
		this.appendChild(newEl);
	}

	b64DecodeUnicode(str) {
		return decodeURIComponent(Array.prototype.map.call(atob(str), (c) => {
			return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
		}).join(''))
	}
});

The same content is in 2 releases, Joomla 4.0.0-alpha3 to 4.0.0-alpha5. See them all, or every version of this file.