use of some()
This commit is contained in:
parent
bfae93f898
commit
8f4c8dae2d
39
dist/mailgo.js
vendored
39
dist/mailgo.js
vendored
@ -240,13 +240,17 @@ var mailgoRender = function mailgoRender(mailgo) {
|
||||
|
||||
var actions = {
|
||||
openGmail: function openGmail(mailtoHref) {
|
||||
return window.open("https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref), "_blank");
|
||||
var gmailUrl = "https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref);
|
||||
window.open(gmailUrl, "_blank");
|
||||
},
|
||||
openOutlook: function openOutlook(mail, url) {
|
||||
return window.open("https://outlook.live.com/owa/?path=/mail/action/compose&to=" + encodeURIComponent(mail) + url.search.replace(/^[$]/, "&"), "_blank");
|
||||
openOutlook: function openOutlook(mail, bodyMail, subject) {
|
||||
var outlookUrl = "https://outlook.live.com/owa/?path=/mail/action/compose&to=" + encodeURIComponent(mail);
|
||||
if (subject != "") outlookUrl = outlookUrl + "&subject=" + subject;
|
||||
if (bodyMail != "") outlookUrl = outlookUrl + "&body=" + bodyMail;
|
||||
window.open(outlookUrl, "_blank");
|
||||
},
|
||||
openDefault: function openDefault(encEmail) {
|
||||
return mailToEncoded(encEmail);
|
||||
mailToEncoded(encEmail);
|
||||
},
|
||||
copy: function copy(mail, copyButton) {
|
||||
copyToClipboard(mail);
|
||||
@ -255,6 +259,14 @@ var actions = {
|
||||
return copyButton.textContent = "copy";
|
||||
}, 999);
|
||||
}
|
||||
}; // function that returns if an element is a mailgo
|
||||
|
||||
var isMailgo = function isMailgo(element) {
|
||||
return (// first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
|
||||
element.href && element.href.toLowerCase().startsWith(MAILTO) && !element.classList.contains("no-mailgo") || // second case: the href=#mailgo
|
||||
element.href && element.getAttribute("href").toLowerCase() === "#mailgo" || // third case: the classList contains mailgo
|
||||
element.classList.contains("mailgo")
|
||||
);
|
||||
};
|
||||
/**
|
||||
* mailgoCheckRender
|
||||
@ -264,22 +276,19 @@ var actions = {
|
||||
* );
|
||||
*/
|
||||
|
||||
|
||||
var mailgoCheckRender = function mailgoCheckRender(event) {
|
||||
// check if the id=mailgo exists in the body
|
||||
if (!document.contains(getE("mailgo"))) return; // go in the event.path to find if the user has clicked on a mailgo element
|
||||
|
||||
event.path.forEach(function (e) {
|
||||
if ( // first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
|
||||
e.href && e.href.toLowerCase().startsWith(MAILTO) && !e.classList.contains("no-mailgo") || // second case: the href=#mailgo
|
||||
e.href && e.getAttribute("href").toLowerCase() === "#mailgo" || // third case: the classList contains mailgo
|
||||
e.classList.contains("mailgo")) {
|
||||
// stop the normal execution of the element click
|
||||
event.preventDefault(); // render mailgo
|
||||
if (event.path.some(isMailgo)) {
|
||||
// stop the normal execution of the element click
|
||||
event.preventDefault(); // render mailgo
|
||||
|
||||
mailgoRender(e);
|
||||
return;
|
||||
}
|
||||
|
||||
mailgoRender(e);
|
||||
return;
|
||||
}
|
||||
});
|
||||
return;
|
||||
};
|
||||
/**
|
||||
|
2
dist/mailgo.min.js
vendored
2
dist/mailgo.min.js
vendored
File diff suppressed because one or more lines are too long
@ -296,22 +296,27 @@ const mailgoRender = mailgo => {
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
openGmail: mailtoHref =>
|
||||
window.open(
|
||||
openGmail: mailtoHref => {
|
||||
let gmailUrl =
|
||||
"https://mail.google.com/mail?extsrc=mailto&url=" +
|
||||
encodeURIComponent(mailtoHref),
|
||||
"_blank"
|
||||
),
|
||||
encodeURIComponent(mailtoHref);
|
||||
|
||||
openOutlook: (mail, url) =>
|
||||
window.open(
|
||||
window.open(gmailUrl, "_blank");
|
||||
},
|
||||
|
||||
openOutlook: (mail, bodyMail, subject) => {
|
||||
let outlookUrl =
|
||||
"https://outlook.live.com/owa/?path=/mail/action/compose&to=" +
|
||||
encodeURIComponent(mail) +
|
||||
url.search.replace(/^[$]/, "&"),
|
||||
"_blank"
|
||||
),
|
||||
encodeURIComponent(mail);
|
||||
if (subject != "") outlookUrl = outlookUrl + "&subject=" + subject;
|
||||
if (bodyMail != "") outlookUrl = outlookUrl + "&body=" + bodyMail;
|
||||
|
||||
openDefault: encEmail => mailToEncoded(encEmail),
|
||||
window.open(outlookUrl, "_blank");
|
||||
},
|
||||
|
||||
openDefault: encEmail => {
|
||||
mailToEncoded(encEmail);
|
||||
},
|
||||
|
||||
copy: (mail, copyButton) => {
|
||||
copyToClipboard(mail);
|
||||
@ -320,6 +325,17 @@ const actions = {
|
||||
}
|
||||
};
|
||||
|
||||
// function that returns if an element is a mailgo
|
||||
const isMailgo = element =>
|
||||
// first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
|
||||
(element.href &&
|
||||
element.href.toLowerCase().startsWith(MAILTO) &&
|
||||
!element.classList.contains("no-mailgo")) ||
|
||||
// second case: the href=#mailgo
|
||||
(element.href && element.getAttribute("href").toLowerCase() === "#mailgo") ||
|
||||
// third case: the classList contains mailgo
|
||||
element.classList.contains("mailgo");
|
||||
|
||||
/**
|
||||
* mailgoCheckRender
|
||||
* function to check if an element is mailgo-enabled or not referencing to the old
|
||||
@ -332,26 +348,15 @@ const mailgoCheckRender = event => {
|
||||
if (!document.contains(getE("mailgo"))) return;
|
||||
|
||||
// go in the event.path to find if the user has clicked on a mailgo element
|
||||
event.path.forEach(e => {
|
||||
if (
|
||||
// first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
|
||||
(e.href &&
|
||||
e.href.toLowerCase().startsWith(MAILTO) &&
|
||||
!e.classList.contains("no-mailgo")) ||
|
||||
// second case: the href=#mailgo
|
||||
(e.href && e.getAttribute("href").toLowerCase() === "#mailgo") ||
|
||||
// third case: the classList contains mailgo
|
||||
e.classList.contains("mailgo")
|
||||
) {
|
||||
// stop the normal execution of the element click
|
||||
event.preventDefault();
|
||||
if (event.path.some(isMailgo)) {
|
||||
// stop the normal execution of the element click
|
||||
event.preventDefault();
|
||||
|
||||
// render mailgo
|
||||
mailgoRender(e);
|
||||
// render mailgo
|
||||
mailgoRender(e);
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user