fixed ISSUE #26
This commit is contained in:
parent
371a3b3879
commit
3f24fe3188
27
dist/mailgo.js
vendored
27
dist/mailgo.js
vendored
@ -154,9 +154,8 @@ var mailgoInit = function mailgoInit() {
|
|||||||
|
|
||||||
|
|
||||||
var mailgoRender = function mailgoRender(mailgo) {
|
var mailgoRender = function mailgoRender(mailgo) {
|
||||||
var mail = "",
|
var url = "",
|
||||||
url = "",
|
mail = "",
|
||||||
mailtoHref = "",
|
|
||||||
cc = "",
|
cc = "",
|
||||||
bcc = "",
|
bcc = "",
|
||||||
subject = "",
|
subject = "",
|
||||||
@ -164,8 +163,7 @@ var mailgoRender = function mailgoRender(mailgo) {
|
|||||||
|
|
||||||
if (mailgo.href && mailgo.href.toLowerCase().startsWith(MAILTO)) {
|
if (mailgo.href && mailgo.href.toLowerCase().startsWith(MAILTO)) {
|
||||||
mail = decodeURIComponent(mailgo.href.split("?")[0].split(MAILTO)[1].trim());
|
mail = decodeURIComponent(mailgo.href.split("?")[0].split(MAILTO)[1].trim());
|
||||||
mailtoHref = mailgo.href;
|
url = new URL(mailgo.href);
|
||||||
url = new URL(mailtoHref);
|
|
||||||
var urlParams = new URLSearchParams(url.search); // optional parameters for the email
|
var urlParams = new URLSearchParams(url.search); // optional parameters for the email
|
||||||
|
|
||||||
cc = urlParams.get("cc");
|
cc = urlParams.get("cc");
|
||||||
@ -176,8 +174,7 @@ var mailgoRender = function mailgoRender(mailgo) {
|
|||||||
// if the element href="#mailgo" or class="mailgo"
|
// if the element href="#mailgo" or class="mailgo"
|
||||||
// mail = data-address + @ + data-domain
|
// mail = data-address + @ + data-domain
|
||||||
mail = mailgo.getAttribute("data-address") + "@" + mailgo.getAttribute("data-domain");
|
mail = mailgo.getAttribute("data-address") + "@" + mailgo.getAttribute("data-domain");
|
||||||
mailtoHref = MAILTO + encodeURIComponent(mail);
|
url = new URL(MAILTO + encodeURIComponent(mail)); // cc = data-cc-address + @ + data-cc-domain
|
||||||
url = new URL(mailtoHref); // cc = data-cc-address + @ + data-cc-domain
|
|
||||||
|
|
||||||
cc = mailgo.getAttribute("data-cc-address") + "@" + mailgo.getAttribute("data-cc-domain"); // bcc = data-bcc-address + @ + data-bcc-domain
|
cc = mailgo.getAttribute("data-cc-address") + "@" + mailgo.getAttribute("data-cc-domain"); // bcc = data-bcc-address + @ + data-bcc-domain
|
||||||
|
|
||||||
@ -218,7 +215,7 @@ 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 () {
|
||||||
return actions.openGmail(mailtoHref);
|
return actions.openGmail(mail, cc, bcc, subject, bodyMail);
|
||||||
});
|
});
|
||||||
outlookButton.addEventListener("click", function () {
|
outlookButton.addEventListener("click", function () {
|
||||||
return actions.openOutlook(mail, subject, bodyMail);
|
return actions.openOutlook(mail, subject, bodyMail);
|
||||||
@ -234,14 +231,18 @@ var mailgoRender = function mailgoRender(mailgo) {
|
|||||||
showMailgo(); // listener keyDown
|
showMailgo(); // listener keyDown
|
||||||
|
|
||||||
document.addEventListener("keydown", function () {
|
document.addEventListener("keydown", function () {
|
||||||
return mailgoKeydown(mail, cc, bcc, subject, bodyMail, url, mailtoHref, encEmail, copyButton);
|
return mailgoKeydown(mail, cc, bcc, subject, bodyMail, encEmail, copyButton);
|
||||||
});
|
});
|
||||||
}; // actions
|
}; // actions
|
||||||
|
|
||||||
|
|
||||||
var actions = {
|
var actions = {
|
||||||
openGmail: function openGmail(mailtoHref) {
|
openGmail: function openGmail(mail, cc, bcc, subject, bodyMail) {
|
||||||
var gmailUrl = "https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref);
|
var gmailUrl = "https://mail.google.com/mail/u/0/?view=cm&source=mailto&to=" + encodeURIComponent(mail);
|
||||||
|
if (cc) gmailUrl = gmailUrl.concat("&cc=" + encodeURIComponent(cc));
|
||||||
|
if (bcc) gmailUrl = gmailUrl.concat("&bcc=" + encodeURIComponent(bcc));
|
||||||
|
if (subject) gmailUrl = gmailUrl.concat("&subject=" + subject);
|
||||||
|
if (bodyMail) gmailUrl = gmailUrl.concat("&body=" + bodyMail);
|
||||||
window.open(gmailUrl, "_blank");
|
window.open(gmailUrl, "_blank");
|
||||||
},
|
},
|
||||||
openOutlook: function openOutlook(mail, subject, bodyMail) {
|
openOutlook: function openOutlook(mail, subject, bodyMail) {
|
||||||
@ -305,7 +306,7 @@ var mailgoCheckRender = function mailgoCheckRender(event) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
var mailgoKeydown = function mailgoKeydown(mail, cc, bcc, subject, bodyMail, url, mailtoHref, encEmail, copyButton) {
|
var mailgoKeydown = function mailgoKeydown(mail, cc, bcc, subject, bodyMail, encEmail, copyButton) {
|
||||||
// if mailgo is not showing do nothing
|
// if mailgo is not showing do nothing
|
||||||
if (!mailgoIsShowing()) return;
|
if (!mailgoIsShowing()) return;
|
||||||
|
|
||||||
@ -317,7 +318,7 @@ var mailgoKeydown = function mailgoKeydown(mail, cc, bcc, subject, bodyMail, url
|
|||||||
|
|
||||||
case 71:
|
case 71:
|
||||||
// g -> open GMail
|
// g -> open GMail
|
||||||
actions.openGmail(mailtoHref);
|
actions.openGmail(mail, cc, bcc, subject, bodyMail);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 79:
|
case 79:
|
||||||
|
2
dist/mailgo.min.js
vendored
2
dist/mailgo.min.js
vendored
File diff suppressed because one or more lines are too long
@ -173,9 +173,8 @@ const mailgoInit = () => {
|
|||||||
* function to render a single mailgo
|
* function to render a single mailgo
|
||||||
*/
|
*/
|
||||||
const mailgoRender = mailgo => {
|
const mailgoRender = mailgo => {
|
||||||
let mail = "",
|
let url = "",
|
||||||
url = "",
|
mail = "",
|
||||||
mailtoHref = "",
|
|
||||||
cc = "",
|
cc = "",
|
||||||
bcc = "",
|
bcc = "",
|
||||||
subject = "",
|
subject = "",
|
||||||
@ -190,8 +189,7 @@ const mailgoRender = mailgo => {
|
|||||||
.trim()
|
.trim()
|
||||||
);
|
);
|
||||||
|
|
||||||
mailtoHref = mailgo.href;
|
url = new URL(mailgo.href);
|
||||||
url = new URL(mailtoHref);
|
|
||||||
let urlParams = new URLSearchParams(url.search);
|
let urlParams = new URLSearchParams(url.search);
|
||||||
|
|
||||||
// optional parameters for the email
|
// optional parameters for the email
|
||||||
@ -206,8 +204,8 @@ const mailgoRender = mailgo => {
|
|||||||
mailgo.getAttribute("data-address") +
|
mailgo.getAttribute("data-address") +
|
||||||
"@" +
|
"@" +
|
||||||
mailgo.getAttribute("data-domain");
|
mailgo.getAttribute("data-domain");
|
||||||
mailtoHref = MAILTO + encodeURIComponent(mail);
|
|
||||||
url = new URL(mailtoHref);
|
url = new URL(MAILTO + encodeURIComponent(mail));
|
||||||
|
|
||||||
// cc = data-cc-address + @ + data-cc-domain
|
// cc = data-cc-address + @ + data-cc-domain
|
||||||
cc =
|
cc =
|
||||||
@ -275,7 +273,9 @@ const mailgoRender = mailgo => {
|
|||||||
: (bodyEl.style.display = "none");
|
: (bodyEl.style.display = "none");
|
||||||
|
|
||||||
// add the actions
|
// add the actions
|
||||||
gmailButton.addEventListener("click", () => actions.openGmail(mailtoHref));
|
gmailButton.addEventListener("click", () =>
|
||||||
|
actions.openGmail(mail, cc, bcc, subject, bodyMail)
|
||||||
|
);
|
||||||
|
|
||||||
outlookButton.addEventListener("click", () =>
|
outlookButton.addEventListener("click", () =>
|
||||||
actions.openOutlook(mail, subject, bodyMail)
|
actions.openOutlook(mail, subject, bodyMail)
|
||||||
@ -291,26 +291,21 @@ const mailgoRender = mailgo => {
|
|||||||
|
|
||||||
// listener keyDown
|
// listener keyDown
|
||||||
document.addEventListener("keydown", () =>
|
document.addEventListener("keydown", () =>
|
||||||
mailgoKeydown(
|
mailgoKeydown(mail, cc, bcc, subject, bodyMail, encEmail, copyButton)
|
||||||
mail,
|
|
||||||
cc,
|
|
||||||
bcc,
|
|
||||||
subject,
|
|
||||||
bodyMail,
|
|
||||||
url,
|
|
||||||
mailtoHref,
|
|
||||||
encEmail,
|
|
||||||
copyButton
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
const actions = {
|
const actions = {
|
||||||
openGmail: mailtoHref => {
|
openGmail: (mail, cc, bcc, subject, bodyMail) => {
|
||||||
let gmailUrl =
|
let gmailUrl =
|
||||||
"https://mail.google.com/mail?extsrc=mailto&url=" +
|
"https://mail.google.com/mail/u/0/?view=cm&source=mailto&to=" +
|
||||||
encodeURIComponent(mailtoHref);
|
encodeURIComponent(mail);
|
||||||
|
|
||||||
|
if (cc) gmailUrl = gmailUrl.concat("&cc=" + encodeURIComponent(cc));
|
||||||
|
if (bcc) gmailUrl = gmailUrl.concat("&bcc=" + encodeURIComponent(bcc));
|
||||||
|
if (subject) gmailUrl = gmailUrl.concat("&subject=" + subject);
|
||||||
|
if (bodyMail) gmailUrl = gmailUrl.concat("&body=" + bodyMail);
|
||||||
|
|
||||||
window.open(gmailUrl, "_blank");
|
window.open(gmailUrl, "_blank");
|
||||||
},
|
},
|
||||||
@ -392,8 +387,6 @@ const mailgoKeydown = (
|
|||||||
bcc,
|
bcc,
|
||||||
subject,
|
subject,
|
||||||
bodyMail,
|
bodyMail,
|
||||||
url,
|
|
||||||
mailtoHref,
|
|
||||||
encEmail,
|
encEmail,
|
||||||
copyButton
|
copyButton
|
||||||
) => {
|
) => {
|
||||||
@ -406,7 +399,7 @@ const mailgoKeydown = (
|
|||||||
break;
|
break;
|
||||||
case 71:
|
case 71:
|
||||||
// g -> open GMail
|
// g -> open GMail
|
||||||
actions.openGmail(mailtoHref);
|
actions.openGmail(mail, cc, bcc, subject, bodyMail);
|
||||||
break;
|
break;
|
||||||
case 79:
|
case 79:
|
||||||
// o -> open Outlook
|
// o -> open Outlook
|
||||||
|
Loading…
x
Reference in New Issue
Block a user