actions object
This commit is contained in:
parent
2b9c2fe135
commit
eec0f14a35
60
dist/mailgo.js
vendored
60
dist/mailgo.js
vendored
@ -217,17 +217,17 @@ 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 () {
|
||||||
openGmailAction(mailtoHref);
|
actions.openGmail(mailtoHref);
|
||||||
}, false);
|
}, false);
|
||||||
outlookButton.addEventListener("click", function () {
|
outlookButton.addEventListener("click", function () {
|
||||||
openOutlookAction(mail, url);
|
actions.openOutlook(mail, url);
|
||||||
}, false);
|
}, false);
|
||||||
var encEmail = encodeEmail(mail);
|
var encEmail = encodeEmail(mail);
|
||||||
openButton.addEventListener("click", function () {
|
openButton.addEventListener("click", function () {
|
||||||
openDefaultAction(encEmail);
|
actions.openDefault(encEmail);
|
||||||
}, false);
|
}, false);
|
||||||
copyButton.addEventListener("click", function (event) {
|
copyButton.addEventListener("click", function (event) {
|
||||||
copyAction(mail, copyButton);
|
actions.copy(mail, copyButton);
|
||||||
}, false); // show the mailgo
|
}, false); // show the mailgo
|
||||||
|
|
||||||
showMailgo(); // listener keyDown
|
showMailgo(); // listener keyDown
|
||||||
@ -238,24 +238,23 @@ var mailgoRender = function mailgoRender(mailgo) {
|
|||||||
}; // actions
|
}; // actions
|
||||||
|
|
||||||
|
|
||||||
var openGmailAction = function openGmailAction(mailtoHref) {
|
var actions = {
|
||||||
window.open("https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref), "_blank");
|
openGmail: function openGmail(mailtoHref) {
|
||||||
};
|
window.open("https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref), "_blank");
|
||||||
|
},
|
||||||
var openOutlookAction = function openOutlookAction(mail, url) {
|
openOutlook: function openOutlook(mail, url) {
|
||||||
window.open("https://outlook.office.com/owa/?rru=compose&to=" + encodeURIComponent(mail) + url.search.replace(/^[$]/, "&"), "_blank");
|
window.open("https://outlook.office.com/owa/?rru=compose&to=" + encodeURIComponent(mail) + url.search.replace(/^[$]/, "&"), "_blank");
|
||||||
};
|
},
|
||||||
|
openDefault: function openDefault(encEmail) {
|
||||||
var openDefaultAction = function openDefaultAction(encEmail) {
|
mailToEncoded(encEmail);
|
||||||
mailToEncoded(encEmail);
|
},
|
||||||
};
|
copy: function copy(mail, copyButton) {
|
||||||
|
copyToClipboard(mail);
|
||||||
var copyAction = function copyAction(mail, copyButton) {
|
copyButton.textContent = "copied";
|
||||||
copyToClipboard(mail);
|
var timeout = setTimeout(function () {
|
||||||
copyButton.textContent = "copied";
|
copyButton.textContent = "copy";
|
||||||
var timeout = setTimeout(function () {
|
}, 999);
|
||||||
copyButton.textContent = "copy";
|
}
|
||||||
}, 999);
|
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* mailgoCheckRender
|
* mailgoCheckRender
|
||||||
@ -265,7 +264,6 @@ var copyAction = function copyAction(mail, copyButton) {
|
|||||||
* ); and the new a[mailgo]
|
* ); and the new a[mailgo]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
var mailgoCheckRender = function mailgoCheckRender(event) {
|
var mailgoCheckRender = function mailgoCheckRender(event) {
|
||||||
// the target element
|
// the target element
|
||||||
var e = event.target; // check if the id=mailgo exists in the body
|
var e = event.target; // check if the id=mailgo exists in the body
|
||||||
@ -291,7 +289,7 @@ var mailgoCheckRender = function mailgoCheckRender(event) {
|
|||||||
|
|
||||||
var mailgoKeydown = function mailgoKeydown(mail, url, mailtoHref, encEmail, copyButton) {
|
var mailgoKeydown = function mailgoKeydown(mail, url, mailtoHref, encEmail, copyButton) {
|
||||||
// if mailgo is not showing do nothing
|
// if mailgo is not showing do nothing
|
||||||
if (mailgoHidden()) return;
|
if (!mailgoIsShowing()) return;
|
||||||
|
|
||||||
switch (event.keyCode) {
|
switch (event.keyCode) {
|
||||||
case 27:
|
case 27:
|
||||||
@ -301,23 +299,23 @@ var mailgoKeydown = function mailgoKeydown(mail, url, mailtoHref, encEmail, copy
|
|||||||
|
|
||||||
case 71:
|
case 71:
|
||||||
// g -> open GMail
|
// g -> open GMail
|
||||||
openGmailAction(mailtoHref);
|
actions.openGmail(mailtoHref);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 79:
|
case 79:
|
||||||
// o -> open Outlook
|
// o -> open Outlook
|
||||||
openOutlookAction(mail, url);
|
actions.openOutlook(mail, url);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 32:
|
case 32:
|
||||||
case 13:
|
case 13:
|
||||||
// spacebar or enter -> open default
|
// spacebar or enter -> open default
|
||||||
openDefaultAction(encEmail);
|
actions.openDefault(encEmail);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 67:
|
case 67:
|
||||||
// c -> copy
|
// c -> copy
|
||||||
copyAction(mail, copyButton);
|
actions.copy(mail, copyButton);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -330,7 +328,7 @@ var mailgoKeydown = function mailgoKeydown(mail, url, mailtoHref, encEmail, copy
|
|||||||
|
|
||||||
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, false); // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered
|
||||||
|
|
||||||
document.body.addEventListener("click", mailgoCheckRender, false); // validate the email with regex
|
document.body.addEventListener("click", mailgoCheckRender, true); // 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,}))$/;
|
||||||
@ -367,8 +365,8 @@ var hideMailgo = function hideMailgo() {
|
|||||||
}; // is the modal hidden?
|
}; // is the modal hidden?
|
||||||
|
|
||||||
|
|
||||||
var mailgoHidden = function mailgoHidden() {
|
var mailgoIsShowing = function mailgoIsShowing() {
|
||||||
return getE("mailgo").style.display === "none";
|
return getE("mailgo").style.display === "flex";
|
||||||
}; // decrypt email
|
}; // decrypt email
|
||||||
|
|
||||||
|
|
||||||
|
2
dist/mailgo.min.js
vendored
2
dist/mailgo.min.js
vendored
File diff suppressed because one or more lines are too long
@ -277,7 +277,7 @@ const mailgoRender = mailgo => {
|
|||||||
gmailButton.addEventListener(
|
gmailButton.addEventListener(
|
||||||
"click",
|
"click",
|
||||||
() => {
|
() => {
|
||||||
openGmailAction(mailtoHref);
|
actions.openGmail(mailtoHref);
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -285,7 +285,7 @@ const mailgoRender = mailgo => {
|
|||||||
outlookButton.addEventListener(
|
outlookButton.addEventListener(
|
||||||
"click",
|
"click",
|
||||||
() => {
|
() => {
|
||||||
openOutlookAction(mail, url);
|
actions.openOutlook(mail, url);
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -294,7 +294,7 @@ const mailgoRender = mailgo => {
|
|||||||
openButton.addEventListener(
|
openButton.addEventListener(
|
||||||
"click",
|
"click",
|
||||||
() => {
|
() => {
|
||||||
openDefaultAction(encEmail);
|
actions.openDefault(encEmail);
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -302,7 +302,7 @@ const mailgoRender = mailgo => {
|
|||||||
copyButton.addEventListener(
|
copyButton.addEventListener(
|
||||||
"click",
|
"click",
|
||||||
event => {
|
event => {
|
||||||
copyAction(mail, copyButton);
|
actions.copy(mail, copyButton);
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -321,33 +321,35 @@ const mailgoRender = mailgo => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
let openGmailAction = mailtoHref => {
|
const actions = {
|
||||||
window.open(
|
openGmail: mailtoHref => {
|
||||||
"https://mail.google.com/mail?extsrc=mailto&url=" +
|
window.open(
|
||||||
encodeURIComponent(mailtoHref),
|
"https://mail.google.com/mail?extsrc=mailto&url=" +
|
||||||
"_blank"
|
encodeURIComponent(mailtoHref),
|
||||||
);
|
"_blank"
|
||||||
};
|
);
|
||||||
|
},
|
||||||
|
|
||||||
let openOutlookAction = (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"
|
||||||
);
|
);
|
||||||
};
|
},
|
||||||
|
|
||||||
let openDefaultAction = encEmail => {
|
openDefault: encEmail => {
|
||||||
mailToEncoded(encEmail);
|
mailToEncoded(encEmail);
|
||||||
};
|
},
|
||||||
|
|
||||||
let copyAction = (mail, copyButton) => {
|
copy: (mail, copyButton) => {
|
||||||
copyToClipboard(mail);
|
copyToClipboard(mail);
|
||||||
copyButton.textContent = "copied";
|
copyButton.textContent = "copied";
|
||||||
let timeout = setTimeout(() => {
|
let timeout = setTimeout(() => {
|
||||||
copyButton.textContent = "copy";
|
copyButton.textContent = "copy";
|
||||||
}, 999);
|
}, 999);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -398,20 +400,20 @@ const mailgoKeydown = (mail, url, mailtoHref, encEmail, copyButton) => {
|
|||||||
break;
|
break;
|
||||||
case 71:
|
case 71:
|
||||||
// g -> open GMail
|
// g -> open GMail
|
||||||
openGmailAction(mailtoHref);
|
actions.openGmail(mailtoHref);
|
||||||
break;
|
break;
|
||||||
case 79:
|
case 79:
|
||||||
// o -> open Outlook
|
// o -> open Outlook
|
||||||
openOutlookAction(mail, url);
|
actions.openOutlook(mail, url);
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
case 13:
|
case 13:
|
||||||
// spacebar or enter -> open default
|
// spacebar or enter -> open default
|
||||||
openDefaultAction(encEmail);
|
actions.openDefault(encEmail);
|
||||||
break;
|
break;
|
||||||
case 67:
|
case 67:
|
||||||
// c -> copy
|
// c -> copy
|
||||||
copyAction(mail, copyButton);
|
actions.copy(mail, copyButton);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user