keyboard commands added! g=gmail, o=outlook, spacebarORenter=default, c=copy

This commit is contained in:
Matteo Manzinello 2019-05-20 18:05:42 +02:00
parent 49597597f4
commit d3744575c1
3 changed files with 36 additions and 21 deletions

30
dist/mailgo.js vendored
View File

@ -230,7 +230,11 @@ var mailgoRender = function mailgoRender(mailgo) {
copyAction(mail, copyButton); copyAction(mail, copyButton);
}, false); // show the mailgo }, false); // show the mailgo
showMailgo(); showMailgo(); // listener keyDown
document.body.addEventListener("keydown", function () {
mailgoKeydown(mail, url, mailtoHref, encEmail, copyButton);
}, false);
}; // actions }; // actions
@ -285,7 +289,10 @@ var mailgoCheckRender = function mailgoCheckRender(event) {
*/ */
var mailgoKeydown = function mailgoKeydown(event) { var mailgoKeydown = function mailgoKeydown(mail, url, mailtoHref, encEmail, copyButton) {
// if mailgo is not showing do nothing
if (mailgoHidden()) return;
switch (event.keyCode) { switch (event.keyCode) {
case 27: case 27:
// Escape // Escape
@ -294,23 +301,23 @@ var mailgoKeydown = function mailgoKeydown(event) {
case 71: case 71:
// g -> open GMail // g -> open GMail
hideMailgo(); openGmailAction(mailtoHref);
break; break;
case 79: case 79:
// o -> open Outlook // o -> open Outlook
hideMailgo(); openOutlookAction(mail, url);
break; break;
case 32: case 32:
case 13: case 13:
// spacebar or enter -> open default // spacebar or enter -> open default
hideMailgo(); openDefaultAction(encEmail);
break; break;
case 67: case 67:
// c -> copy // c -> copy
hideMailgo(); copyAction(mail, copyButton);
break; break;
default: default:
@ -351,16 +358,17 @@ var copyToClipboard = function copyToClipboard(str) {
var showMailgo = function showMailgo() { var showMailgo = function showMailgo() {
getE("mailgo").style.display = "flex"; // add mailgoKeydown getE("mailgo").style.display = "flex";
document.body.addEventListener("keydown", mailgoKeydown, false);
}; // hide the modal }; // hide the modal
var hideMailgo = function hideMailgo() { var hideMailgo = function hideMailgo() {
getE("mailgo").style.display = "none"; // remove mailgoKeydown getE("mailgo").style.display = "none";
}; // is the modal hidden?
document.body.removeEventListener("keydown", mailgoKeydown, false);
var mailgoHidden = function mailgoHidden() {
return getE("mailgo").style.display === "none";
}; // decrypt email }; // decrypt email

2
dist/mailgo.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -309,6 +309,15 @@ const mailgoRender = mailgo => {
// show the mailgo // show the mailgo
showMailgo(); showMailgo();
// listener keyDown
document.body.addEventListener(
"keydown",
() => {
mailgoKeydown(mail, url, mailtoHref, encEmail, copyButton);
},
false
);
}; };
// actions // actions
@ -379,7 +388,9 @@ const mailgoCheckRender = event => {
* mailgoKeydown * mailgoKeydown
* function to manage the keydown event when the modal is showing * function to manage the keydown event when the modal is showing
*/ */
const mailgoKeydown = event => { const mailgoKeydown = (mail, url, mailtoHref, encEmail, copyButton) => {
// if mailgo is not showing do nothing
if (mailgoHidden()) return;
switch (event.keyCode) { switch (event.keyCode) {
case 27: case 27:
// Escape // Escape
@ -387,20 +398,20 @@ const mailgoKeydown = event => {
break; break;
case 71: case 71:
// g -> open GMail // g -> open GMail
hideMailgo(); openGmailAction(mailtoHref);
break; break;
case 79: case 79:
// o -> open Outlook // o -> open Outlook
hideMailgo(); openOutlookAction(mail, url);
break; break;
case 32: case 32:
case 13: case 13:
// spacebar or enter -> open default // spacebar or enter -> open default
hideMailgo(); openDefaultAction(encEmail);
break; break;
case 67: case 67:
// c -> copy // c -> copy
hideMailgo(); copyAction(mail, copyButton);
break; break;
default: default:
return; return;
@ -444,15 +455,11 @@ const copyToClipboard = str => {
// show the modal // show the modal
const showMailgo = () => { const showMailgo = () => {
getE("mailgo").style.display = "flex"; getE("mailgo").style.display = "flex";
// add mailgoKeydown
document.body.addEventListener("keydown", mailgoKeydown, false);
}; };
// hide the modal // hide the modal
const hideMailgo = () => { const hideMailgo = () => {
getE("mailgo").style.display = "none"; getE("mailgo").style.display = "none";
// remove mailgoKeydown
document.body.removeEventListener("keydown", mailgoKeydown, false);
}; };
// is the modal hidden? // is the modal hidden?