removed isMailgoTel (unified with isMailgo)
This commit is contained in:
parent
d1b209e2f1
commit
776c4627d7
@ -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,43 +529,56 @@ 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) => {
|
||||||
// first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
|
// mailgo type mail
|
||||||
(element.href &&
|
if (type === MAIL_TYPE) {
|
||||||
element.href.toLowerCase().startsWith(MAILTO) &&
|
return (
|
||||||
!element.classList.contains("no-mailgo")) ||
|
// first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
|
||||||
(element.hasAttribute("data-address") &&
|
(element.href &&
|
||||||
// second case: the href=#mailgo
|
element.href.toLowerCase().startsWith(MAILTO) &&
|
||||||
((element.href &&
|
!element.classList.contains("no-mailgo")) ||
|
||||||
element.getAttribute("href").toLowerCase() === "#mailgo") ||
|
(element.hasAttribute("data-address") &&
|
||||||
// third case: the classList contains mailgo
|
// second case: the href=#mailgo
|
||||||
(element.classList && element.classList.contains("mailgo"))));
|
((element.href &&
|
||||||
|
element.getAttribute("href").toLowerCase() === "#mailgo") ||
|
||||||
|
// third case: the 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) {
|
||||||
// first case: it is an <a> element with "tel:..." or "callto:..." in href and no no-mailgo in classList
|
return (
|
||||||
(element.href &&
|
// first case: it is an <a> element with "tel:..." or "callto:..." in href and no no-mailgo in classList
|
||||||
(element.href.toLowerCase().startsWith(TEL) ||
|
(element.href &&
|
||||||
element.href.toLowerCase().startsWith(CALLTO)) &&
|
(element.href.toLowerCase().startsWith(TEL) ||
|
||||||
!element.classList.contains("no-mailgo")) ||
|
element.href.toLowerCase().startsWith(CALLTO)) &&
|
||||||
((element.hasAttribute("data-tel") &&
|
!element.classList.contains("no-mailgo")) ||
|
||||||
// second case: the href=#mailgo
|
((element.hasAttribute("data-tel") &&
|
||||||
(element.href &&
|
// second case: the href=#mailgo
|
||||||
element.getAttribute("href").toLowerCase() === "#mailgo")) ||
|
(element.href &&
|
||||||
// third case: the classList contains mailgo
|
element.getAttribute("href").toLowerCase() === "#mailgo")) ||
|
||||||
(element.classList && element.classList.contains("mailgo")));
|
// third case: the 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();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user