From 4160f25c8f5744161141d1df2c39a31b6d9197fa Mon Sep 17 00:00:00 2001 From: Matteo Manzinello Date: Fri, 19 Jul 2019 12:03:21 +0200 Subject: [PATCH] WIP tel: --- src/mailgo.js | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/mailgo.js b/src/mailgo.js index 814f87c..abe87fe 100644 --- a/src/mailgo.js +++ b/src/mailgo.js @@ -458,6 +458,88 @@ const mailgoRender = mailgo => { ); }; +/** + * mailgoTelRender + * function to render a single tel mailgo + */ +const mailgoTelRender = mailgo => { + let tel = "", + msg = ""; + + mail = decodeURIComponent( + mailgo.href + .split("?")[0] + .split(TEL)[1] + .trim() + ); + + url = new URL(mailgo.href); + let urlParams = new URLSearchParams(url.search); + + // information + let titleEl = getE("mailgo-title"); + let detailsEl = getE("mailgo-details"); + let ccEl = getE("mailgo-cc"); + let ccValueEl = getE("mailgo-cc-value"); + let bccEl = getE("mailgo-bcc"); + let bccValueEl = getE("mailgo-bcc-value"); + let subjectEl = getE("mailgo-subject"); + let subjectValueEl = getE("mailgo-subject-value"); + let bodyEl = getE("mailgo-body"); + let bodyValueEl = getE("mailgo-body-value"); + + // actions + let gmailButton = getE("mailgo-gmail"); + let outlookButton = getE("mailgo-outlook"); + let openButton = getE("mailgo-open"); + let copyButton = getE("mailgo-copy"); + + // the title of the modal (email address) + titleEl.innerHTML = mail.split(",").join("
"); + + // add the details if provided + cc + ? ((ccEl.style.display = "block"), + (ccValueEl.innerHTML = cc.split(",").join("
"))) + : (ccEl.style.display = "none"); + + bcc + ? ((bccEl.style.display = "block"), + (bccValueEl.innerHTML = bcc.split(",").join("
"))) + : (bccEl.style.display = "none"); + + subject + ? ((subjectEl.style.display = "block"), + (subjectValueEl.textContent = subject)) + : (subjectEl.style.display = "none"); + + bodyMail + ? ((bodyEl.style.display = "block"), (bodyValueEl.textContent = bodyMail)) + : (bodyEl.style.display = "none"); + + // add the actions + gmailButton.addEventListener("click", () => + actions.openGmail(mail, cc, bcc, subject, bodyMail) + ); + + outlookButton.addEventListener("click", () => + actions.openOutlook(mail, subject, bodyMail) + ); + + let encEmail = encodeEmail(mail); + openButton.addEventListener("click", () => actions.openDefault(encEmail)); + + copyButton.addEventListener("click", () => actions.copy(mail, copyButton)); + + // show the mailgo + showMailgoTel(); + + // listener keyDown + document.addEventListener("keydown", () => + mailgoKeydown(mail, cc, bcc, subject, bodyMail, encEmail, copyButton) + ); +}; + // actions const actions = { openGmail: (mail, cc, bcc, subject, bodyMail) => {