removed isMailgoTel (unified with isMailgo)

This commit is contained in:
Matteo Manzinello 2019-09-17 09:09:03 +02:00
parent d1b209e2f1
commit 776c4627d7

View File

@ -304,7 +304,7 @@ const mailgoInit = () => {
/** /**
* mailgoRender * mailgoRender
* function to render a single mailgo * function to render a mailgo (mail or tel)
*/ */
const mailgoRender = (type = MAIL_TYPE, mailgo) => { const mailgoRender = (type = MAIL_TYPE, mailgo) => {
// mailgo mail // mailgo mail
@ -446,13 +446,10 @@ const mailgoRender = (type = MAIL_TYPE, mailgo) => {
// the title of the modal (tel) // the title of the modal (tel)
titleEl.innerHTML = tel; titleEl.innerHTML = tel;
// add the actions // add the actions to buttons
waButton.addEventListener("click", () => actions.openWhatsApp()); waButton.addEventListener("click", () => actions.openWhatsApp());
telegramButton.addEventListener("click", () => actions.openTelegram()); telegramButton.addEventListener("click", () => actions.openTelegram());
callButton.addEventListener("click", () => actions.callDefault()); callButton.addEventListener("click", () => actions.callDefault());
copyButton.addEventListener("click", () => actions.copy(tel)); copyButton.addEventListener("click", () => actions.copy(tel));
} }
@ -466,28 +463,38 @@ const mailgoRender = (type = MAIL_TYPE, mailgo) => {
// actions // actions
const actions = { const actions = {
openGmail: () => { openGmail: () => {
// Gmail url
let gmailUrl = let gmailUrl =
"https://mail.google.com/mail/u/0/?view=cm&source=mailto&to=" + "https://mail.google.com/mail/u/0/?view=cm&source=mailto&to=" +
encodeURIComponent(mail); encodeURIComponent(mail);
// the details if provided
if (cc) gmailUrl = gmailUrl.concat("&cc=" + encodeURIComponent(cc)); if (cc) gmailUrl = gmailUrl.concat("&cc=" + encodeURIComponent(cc));
if (bcc) gmailUrl = gmailUrl.concat("&bcc=" + encodeURIComponent(bcc)); if (bcc) gmailUrl = gmailUrl.concat("&bcc=" + encodeURIComponent(bcc));
if (subject) gmailUrl = gmailUrl.concat("&subject=" + subject); if (subject) gmailUrl = gmailUrl.concat("&subject=" + subject);
if (bodyMail) gmailUrl = gmailUrl.concat("&body=" + bodyMail); if (bodyMail) gmailUrl = gmailUrl.concat("&body=" + bodyMail);
// open the link
window.open(gmailUrl, "_blank"); window.open(gmailUrl, "_blank");
// hide the modal
hideMailgo(); hideMailgo();
}, },
openOutlook: () => { openOutlook: () => {
// Outlook url
let outlookUrl = let outlookUrl =
"https://outlook.live.com/owa/?path=/mail/action/compose&to=" + "https://outlook.live.com/owa/?path=/mail/action/compose&to=" +
encodeURIComponent(mail); encodeURIComponent(mail);
// the details if provided
if (subject) outlookUrl = outlookUrl.concat("&subject=" + subject); if (subject) outlookUrl = outlookUrl.concat("&subject=" + subject);
if (bodyMail) outlookUrl = outlookUrl.concat("&body=" + bodyMail); if (bodyMail) outlookUrl = outlookUrl.concat("&body=" + bodyMail);
// open the link
window.open(outlookUrl, "_blank"); window.open(outlookUrl, "_blank");
// hide the modal
hideMailgo(); hideMailgo();
}, },
@ -497,14 +504,20 @@ const actions = {
}, },
openTelegram: () => { openTelegram: () => {
// Telegram url
let tgUrl = "tg://msg?text=" + msg + "&to=" + tel; let tgUrl = "tg://msg?text=" + msg + "&to=" + tel;
// open the url
window.open(tgUrl, "_blank"); window.open(tgUrl, "_blank");
// hide the modal
hideMailgo(); hideMailgo();
}, },
openWhatsApp: () => { openWhatsApp: () => {
// WhatsApp url
let waUrl = "https://wa.me/" + tel; let waUrl = "https://wa.me/" + tel;
// open the url
window.open(waUrl, "_blank"); window.open(waUrl, "_blank");
// hide the modal
hideMailgo(); hideMailgo();
}, },
@ -516,19 +529,24 @@ const actions = {
copy: content => { copy: content => {
copyToClipboard(content); copyToClipboard(content);
// the correct copyButton (mail or tel)
mailgoIsShowing(MAIL_TYPE) mailgoIsShowing(MAIL_TYPE)
? (copyButton = getE("mailgo-copy")) ? (copyButton = getE("mailgo-copy"))
: (copyButton = getE("mailgo-tel-copy")); : (copyButton = getE("mailgo-tel-copy"));
copyButton.textContent = "copied"; copyButton.textContent = "copied";
setTimeout(() => { setTimeout(() => {
copyButton.textContent = "copy"; copyButton.textContent = "copy";
// hide after the timeout
hideMailgo(); hideMailgo();
}, 999); }, 999);
} }
}; };
// function that returns if an element is a mailgo // function that returns if an element is a mailgo
const isMailgo = element => const isMailgo = (element, type = MAIL_TYPE) => {
// mailgo type mail
if (type === MAIL_TYPE) {
return (
// first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList // first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
(element.href && (element.href &&
element.href.toLowerCase().startsWith(MAILTO) && element.href.toLowerCase().startsWith(MAILTO) &&
@ -538,10 +556,13 @@ const isMailgo = element =>
((element.href && ((element.href &&
element.getAttribute("href").toLowerCase() === "#mailgo") || element.getAttribute("href").toLowerCase() === "#mailgo") ||
// third case: the classList contains mailgo // third case: the classList contains mailgo
(element.classList && element.classList.contains("mailgo")))); (element.classList && element.classList.contains("mailgo"))))
);
}
// function that returns if an element is a mailgo-tel // mailgo type tel
const isMailgoTel = element => if (type === TEL_TYPE) {
return (
// first case: it is an <a> element with "tel:..." or "callto:..." in href and no no-mailgo in classList // first case: it is an <a> element with "tel:..." or "callto:..." in href and no no-mailgo in classList
(element.href && (element.href &&
(element.href.toLowerCase().startsWith(TEL) || (element.href.toLowerCase().startsWith(TEL) ||
@ -552,7 +573,12 @@ const isMailgoTel = element =>
(element.href && (element.href &&
element.getAttribute("href").toLowerCase() === "#mailgo")) || element.getAttribute("href").toLowerCase() === "#mailgo")) ||
// third case: the classList contains mailgo // third case: the classList contains mailgo
(element.classList && element.classList.contains("mailgo"))); (element.classList && element.classList.contains("mailgo")))
);
}
return false;
};
/** /**
* mailgoCheckRender * mailgoCheckRender
@ -586,7 +612,7 @@ const mailgoCheckRender = event => {
if (element instanceof HTMLDocument || element instanceof Window) return; if (element instanceof HTMLDocument || element instanceof Window) return;
// go in the event.path to find if the user has clicked on a mailgo element // go in the event.path to find if the user has clicked on a mailgo element
if (isMailgo(element)) { if (isMailgo(element, MAIL_TYPE)) {
// stop the normal execution of the element click // stop the normal execution of the element click
event.preventDefault(); event.preventDefault();
@ -595,7 +621,7 @@ const mailgoCheckRender = event => {
return; return;
} }
if (isMailgoTel(element)) { if (isMailgo(element, TEL_TYPE)) {
// stop the normal execution of the element click // stop the normal execution of the element click
event.preventDefault(); event.preventDefault();