better arrow functions

This commit is contained in:
Matteo Manzinello 2019-05-23 11:15:17 +02:00
parent fa9cdd3864
commit a321258ba5
3 changed files with 33 additions and 65 deletions

36
dist/mailgo.js vendored
View File

@ -144,7 +144,7 @@ var mailgoInit = function mailgoInit() {
document.body.appendChild(modal); // every click outside the modal will hide the modal document.body.appendChild(modal); // every click outside the modal will hide the modal
modalBackground.addEventListener("click", hideMailgo, false); modalBackground.addEventListener("click", hideMailgo);
}; };
/** /**
* mailgoRender * mailgoRender
@ -217,42 +217,42 @@ var mailgoRender = function mailgoRender(mailgo) {
bodyMail ? (bodyEl.style.display = "block", bodyValueEl.textContent = bodyMail) : bodyEl.style.display = "none"; // add the actions bodyMail ? (bodyEl.style.display = "block", bodyValueEl.textContent = bodyMail) : bodyEl.style.display = "none"; // add the actions
gmailButton.addEventListener("click", function () { gmailButton.addEventListener("click", function () {
actions.openGmail(mailtoHref); return actions.openGmail(mailtoHref);
}, false); });
outlookButton.addEventListener("click", function () { outlookButton.addEventListener("click", function () {
actions.openOutlook(mail, url); return actions.openOutlook(mail, url);
}, false); });
var encEmail = encodeEmail(mail); var encEmail = encodeEmail(mail);
openButton.addEventListener("click", function () { openButton.addEventListener("click", function () {
actions.openDefault(encEmail); return actions.openDefault(encEmail);
}, false); });
copyButton.addEventListener("click", function (event) { copyButton.addEventListener("click", function () {
actions.copy(mail, copyButton); return actions.copy(mail, copyButton);
}, false); // show the mailgo }); // show the mailgo
showMailgo(); // listener keyDown showMailgo(); // listener keyDown
mailgo.addEventListener("keydown", function () { mailgo.addEventListener("keydown", function () {
mailgoKeydown(mail, url, mailtoHref, encEmail, copyButton); return mailgoKeydown(mail, url, mailtoHref, encEmail, copyButton);
}, false); }, false);
}; // actions }; // actions
var actions = { var actions = {
openGmail: function openGmail(mailtoHref) { openGmail: function openGmail(mailtoHref) {
window.open("https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref), "_blank"); return window.open("https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref), "_blank");
}, },
openOutlook: function openOutlook(mail, url) { openOutlook: function openOutlook(mail, url) {
window.open("https://outlook.office.com/owa/?rru=compose&to=" + encodeURIComponent(mail) + url.search.replace(/^[$]/, "&"), "_blank"); return window.open("https://outlook.office.com/owa/?rru=compose&to=" + encodeURIComponent(mail) + url.search.replace(/^[$]/, "&"), "_blank");
}, },
openDefault: function openDefault(encEmail) { openDefault: function openDefault(encEmail) {
mailToEncoded(encEmail); return mailToEncoded(encEmail);
}, },
copy: function copy(mail, copyButton) { copy: function copy(mail, copyButton) {
copyToClipboard(mail); copyToClipboard(mail);
copyButton.textContent = "copied"; copyButton.textContent = "copied";
var timeout = setTimeout(function () { setTimeout(function () {
copyButton.textContent = "copy"; return copyButton.textContent = "copy";
}, 999); }, 999);
} }
}; };
@ -325,9 +325,9 @@ var mailgoKeydown = function mailgoKeydown(mail, url, mailtoHref, encEmail, copy
}; // DOMContentLoaded -> mailgoInit (creates the modal) }; // DOMContentLoaded -> mailgoInit (creates the modal)
document.addEventListener("DOMContentLoaded", mailgoInit, false); // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered document.addEventListener("DOMContentLoaded", mailgoInit); // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered
document.addEventListener("click", mailgoCheckRender, true); // validate the email with regex document.addEventListener("click", mailgoCheckRender); // validate the email with regex
var validateEmail = function validateEmail(email) { var validateEmail = function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

2
dist/mailgo.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -164,7 +164,7 @@ const mailgoInit = () => {
document.body.appendChild(modal); document.body.appendChild(modal);
// every click outside the modal will hide the modal // every click outside the modal will hide the modal
modalBackground.addEventListener("click", hideMailgo, false); modalBackground.addEventListener("click", hideMailgo);
}; };
/** /**
@ -274,38 +274,14 @@ const mailgoRender = mailgo => {
: (bodyEl.style.display = "none"); : (bodyEl.style.display = "none");
// add the actions // add the actions
gmailButton.addEventListener( gmailButton.addEventListener("click", () => actions.openGmail(mailtoHref));
"click",
() => {
actions.openGmail(mailtoHref);
},
false
);
outlookButton.addEventListener( outlookButton.addEventListener("click", () => actions.openOutlook(mail, url));
"click",
() => {
actions.openOutlook(mail, url);
},
false
);
let encEmail = encodeEmail(mail); let encEmail = encodeEmail(mail);
openButton.addEventListener( openButton.addEventListener("click", () => actions.openDefault(encEmail));
"click",
() => {
actions.openDefault(encEmail);
},
false
);
copyButton.addEventListener( copyButton.addEventListener("click", () => actions.copy(mail, copyButton));
"click",
event => {
actions.copy(mail, copyButton);
},
false
);
// show the mailgo // show the mailgo
showMailgo(); showMailgo();
@ -313,42 +289,34 @@ const mailgoRender = mailgo => {
// listener keyDown // listener keyDown
mailgo.addEventListener( mailgo.addEventListener(
"keydown", "keydown",
() => { () => mailgoKeydown(mail, url, mailtoHref, encEmail, copyButton),
mailgoKeydown(mail, url, mailtoHref, encEmail, copyButton);
},
false false
); );
}; };
// actions // actions
const actions = { const actions = {
openGmail: mailtoHref => { openGmail: mailtoHref =>
window.open( window.open(
"https://mail.google.com/mail?extsrc=mailto&url=" + "https://mail.google.com/mail?extsrc=mailto&url=" +
encodeURIComponent(mailtoHref), encodeURIComponent(mailtoHref),
"_blank" "_blank"
); ),
},
openOutlook: (mail, url) => { openOutlook: (mail, url) =>
window.open( window.open(
"https://outlook.office.com/owa/?rru=compose&to=" + "https://outlook.office.com/owa/?rru=compose&to=" +
encodeURIComponent(mail) + encodeURIComponent(mail) +
url.search.replace(/^[$]/, "&"), url.search.replace(/^[$]/, "&"),
"_blank" "_blank"
); ),
},
openDefault: encEmail => { openDefault: encEmail => mailToEncoded(encEmail),
mailToEncoded(encEmail);
},
copy: (mail, copyButton) => { copy: (mail, copyButton) => {
copyToClipboard(mail); copyToClipboard(mail);
copyButton.textContent = "copied"; copyButton.textContent = "copied";
let timeout = setTimeout(() => { setTimeout(() => (copyButton.textContent = "copy"), 999);
copyButton.textContent = "copy";
}, 999);
} }
}; };
@ -420,10 +388,10 @@ const mailgoKeydown = (mail, url, mailtoHref, encEmail, copyButton) => {
}; };
// DOMContentLoaded -> mailgoInit (creates the modal) // DOMContentLoaded -> mailgoInit (creates the modal)
document.addEventListener("DOMContentLoaded", mailgoInit, false); document.addEventListener("DOMContentLoaded", mailgoInit);
// event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered
document.addEventListener("click", mailgoCheckRender, true); document.addEventListener("click", mailgoCheckRender);
// validate the email with regex // validate the email with regex
const validateEmail = email => { const validateEmail = email => {