removed obj actions

This commit is contained in:
Matteo Manzinello 2019-10-28 08:36:59 +01:00
parent 08ce4c434b
commit 09e57d1730
3 changed files with 113 additions and 115 deletions

2
dist/mailgo.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -392,7 +392,7 @@
let bodyEl = getE("mailgo-body"); let bodyEl = getE("mailgo-body");
let bodyValueEl = getE("mailgo-body-value"); let bodyValueEl = getE("mailgo-body-value");
// actions // action buttons
gmailButton = getE("mailgo-gmail"); gmailButton = getE("mailgo-gmail");
outlookButton = getE("mailgo-outlook"); outlookButton = getE("mailgo-outlook");
openButton = getE("mailgo-open"); openButton = getE("mailgo-open");
@ -423,14 +423,14 @@
: (bodyEl.style.display = "none"); : (bodyEl.style.display = "none");
// add the actions // add the actions
gmailButton.addEventListener("click", () => actions.openGmail()); gmailButton.addEventListener("click", () => openGmail());
outlookButton.addEventListener("click", () => actions.openOutlook()); outlookButton.addEventListener("click", () => openOutlook());
encEmail = encodeEmail(mail); encEmail = encodeEmail(mail);
openButton.addEventListener("click", () => actions.openDefault()); openButton.addEventListener("click", () => openDefault());
copyButton.addEventListener("click", () => actions.copy(mail || tel)); copyButton.addEventListener("click", () => copy(mail || tel));
} }
// mailgo tel // mailgo tel
if (type === TEL_TYPE) { if (type === TEL_TYPE) {
@ -477,18 +477,18 @@
titleEl.innerHTML = tel; titleEl.innerHTML = tel;
// add the actions to buttons // add the actions to buttons
waButton.addEventListener("click", () => actions.openWhatsApp()); waButton.addEventListener("click", () => openWhatsApp());
if (telegramUsername) { if (telegramUsername) {
setDisplay("mailgo-telegram", "block"); setDisplay("mailgo-telegram", "block");
telegramButton.addEventListener("click", () => actions.openTelegram()); telegramButton.addEventListener("click", () => openTelegram());
} }
skypeButton.addEventListener("click", () => actions.openSkype()); skypeButton.addEventListener("click", () => openSkype());
callButton.addEventListener("click", () => actions.callDefault()); callButton.addEventListener("click", () => callDefault());
copyButton.addEventListener("click", () => actions.copy(tel)); copyButton.addEventListener("click", () => copy(tel));
} }
// show the mailgo // show the mailgo
@ -499,105 +499,103 @@
}; };
// actions // actions
const actions = { openGmail = () => {
openGmail: () => { // Gmail url
// 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 // 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 // open the link
window.open(gmailUrl, "_blank"); window.open(gmailUrl, "_blank");
// hide the modal // hide the modal
hideMailgo();
};
openOutlook = () => {
// Outlook url
let outlookUrl =
"https://outlook.live.com/owa/?path=/mail/action/compose&to=" +
encodeURIComponent(mail);
// the details if provided
if (subject) outlookUrl = outlookUrl.concat("&subject=" + subject);
if (bodyMail) outlookUrl = outlookUrl.concat("&body=" + bodyMail);
// open the link
window.open(outlookUrl, "_blank");
// hide the modal
hideMailgo();
};
openDefault = () => {
mailToEncoded(encEmail);
hideMailgo();
};
openTelegram = () => {
// Telegram url
let tgUrl = "https://t.me/" + telegramUsername;
// open the url
window.open(tgUrl, "_blank");
// hide the modal
hideMailgo();
};
openSkype = () => {
let skype = skypeUsername !== "" ? skypeUsername : tel;
// Telegram url
let skypeUrl = "skype:" + skype;
// open the url
window.open(skypeUrl, "_blank");
// hide the modal
hideMailgo();
};
openWhatsApp = () => {
// WhatsApp url
let waUrl = "https://wa.me/" + tel;
// the details if provided
if (msg) waUrl + "?text=" + msg;
// open the url
window.open(waUrl, "_blank");
// hide the modal
hideMailgo();
};
callDefault = () => {
let callUrl = "tel:" + tel;
window.open(callUrl);
hideMailgo();
};
copy = content => {
copyToClipboard(content);
// the correct copyButton (mail or tel)
mailgoIsShowing(MAIL_TYPE)
? (copyButton = getE("mailgo-copy"))
: (copyButton = getE("mailgo-tel-copy"));
copyButton.textContent = "copied";
setTimeout(() => {
copyButton.textContent = "copy";
// hide after the timeout
hideMailgo(); hideMailgo();
}, }, 999);
openOutlook: () => {
// Outlook url
let outlookUrl =
"https://outlook.live.com/owa/?path=/mail/action/compose&to=" +
encodeURIComponent(mail);
// the details if provided
if (subject) outlookUrl = outlookUrl.concat("&subject=" + subject);
if (bodyMail) outlookUrl = outlookUrl.concat("&body=" + bodyMail);
// open the link
window.open(outlookUrl, "_blank");
// hide the modal
hideMailgo();
},
openDefault: () => {
mailToEncoded(encEmail);
hideMailgo();
},
openTelegram: () => {
// Telegram url
let tgUrl = "https://t.me/" + telegramUsername;
// open the url
window.open(tgUrl, "_blank");
// hide the modal
hideMailgo();
},
openSkype: () => {
let skype = skypeUsername !== "" ? skypeUsername : tel;
// Telegram url
let skypeUrl = "skype:" + skype;
// open the url
window.open(skypeUrl, "_blank");
// hide the modal
hideMailgo();
},
openWhatsApp: () => {
// WhatsApp url
let waUrl = "https://wa.me/" + tel;
// the details if provided
if (msg) waUrl + "?text=" + msg;
// open the url
window.open(waUrl, "_blank");
// hide the modal
hideMailgo();
},
callDefault: () => {
let callUrl = "tel:" + tel;
window.open(callUrl);
hideMailgo();
},
copy: content => {
copyToClipboard(content);
// the correct copyButton (mail or tel)
mailgoIsShowing(MAIL_TYPE)
? (copyButton = getE("mailgo-copy"))
: (copyButton = getE("mailgo-tel-copy"));
copyButton.textContent = "copied";
setTimeout(() => {
copyButton.textContent = "copy";
// hide after the timeout
hideMailgo();
}, 999);
}
}; };
// function that returns if an element is a mailgo // function that returns if an element is a mailgo
@ -715,20 +713,20 @@
break; break;
case 71: case 71:
// g -> open GMail // g -> open GMail
actions.openGmail(); openGmail();
break; break;
case 79: case 79:
// o -> open Outlook // o -> open Outlook
actions.openOutlook(); openOutlook();
break; break;
case 32: case 32:
case 13: case 13:
// spacebar or enter -> open default // spacebar or enter -> open default
actions.openDefault(); openDefault();
break; break;
case 67: case 67:
// c -> copy // c -> copy
actions.copy(mail); copy(mail);
break; break;
default: default:
return; return;
@ -741,20 +739,20 @@
break; break;
case 84: case 84:
// t -> open Telegram // t -> open Telegram
actions.openTelegram(); openTelegram();
break; break;
case 87: case 87:
// w -> open WhatsApp // w -> open WhatsApp
actions.openWhatsApp(); openWhatsApp();
break; break;
case 32: case 32:
case 13: case 13:
// spacebar or enter -> call default // spacebar or enter -> call default
actions.callDefault(); callDefault();
break; break;
case 67: case 67:
// c -> copy // c -> copy
actions.copy(tel); copy(tel);
break; break;
default: default:
return; return;