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 = {
|
var actions = {
|
||||||
openGmail: function openGmail(mailtoHref) {
|
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) {
|
openOutlook: function openOutlook(mail, bodyMail, subject) {
|
||||||
return window.open("https://outlook.live.com/owa/?path=/mail/action/compose&to=" + encodeURIComponent(mail) + url.search.replace(/^[$]/, "&"), "_blank");
|
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) {
|
openDefault: function openDefault(encEmail) {
|
||||||
return mailToEncoded(encEmail);
|
mailToEncoded(encEmail);
|
||||||
},
|
},
|
||||||
copy: function copy(mail, copyButton) {
|
copy: function copy(mail, copyButton) {
|
||||||
copyToClipboard(mail);
|
copyToClipboard(mail);
|
||||||
@ -255,6 +259,14 @@ var actions = {
|
|||||||
return copyButton.textContent = "copy";
|
return copyButton.textContent = "copy";
|
||||||
}, 999);
|
}, 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
|
* mailgoCheckRender
|
||||||
@ -264,22 +276,19 @@ var actions = {
|
|||||||
* );
|
* );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
var mailgoCheckRender = function mailgoCheckRender(event) {
|
var mailgoCheckRender = function mailgoCheckRender(event) {
|
||||||
// check if the id=mailgo exists in the body
|
// 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
|
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 (event.path.some(isMailgo)) {
|
||||||
if ( // first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
|
// stop the normal execution of the element click
|
||||||
e.href && e.href.toLowerCase().startsWith(MAILTO) && !e.classList.contains("no-mailgo") || // second case: the href=#mailgo
|
event.preventDefault(); // render mailgo
|
||||||
e.href && e.getAttribute("href").toLowerCase() === "#mailgo" || // third case: the classList contains mailgo
|
|
||||||
e.classList.contains("mailgo")) {
|
mailgoRender(e);
|
||||||
// stop the normal execution of the element click
|
return;
|
||||||
event.preventDefault(); // render mailgo
|
}
|
||||||
|
|
||||||
mailgoRender(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
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
|
// actions
|
||||||
const actions = {
|
const actions = {
|
||||||
openGmail: mailtoHref =>
|
openGmail: mailtoHref => {
|
||||||
window.open(
|
let gmailUrl =
|
||||||
"https://mail.google.com/mail?extsrc=mailto&url=" +
|
"https://mail.google.com/mail?extsrc=mailto&url=" +
|
||||||
encodeURIComponent(mailtoHref),
|
encodeURIComponent(mailtoHref);
|
||||||
"_blank"
|
|
||||||
),
|
|
||||||
|
|
||||||
openOutlook: (mail, url) =>
|
window.open(gmailUrl, "_blank");
|
||||||
window.open(
|
},
|
||||||
|
|
||||||
|
openOutlook: (mail, bodyMail, subject) => {
|
||||||
|
let outlookUrl =
|
||||||
"https://outlook.live.com/owa/?path=/mail/action/compose&to=" +
|
"https://outlook.live.com/owa/?path=/mail/action/compose&to=" +
|
||||||
encodeURIComponent(mail) +
|
encodeURIComponent(mail);
|
||||||
url.search.replace(/^[$]/, "&"),
|
if (subject != "") outlookUrl = outlookUrl + "&subject=" + subject;
|
||||||
"_blank"
|
if (bodyMail != "") outlookUrl = outlookUrl + "&body=" + bodyMail;
|
||||||
),
|
|
||||||
|
|
||||||
openDefault: encEmail => mailToEncoded(encEmail),
|
window.open(outlookUrl, "_blank");
|
||||||
|
},
|
||||||
|
|
||||||
|
openDefault: encEmail => {
|
||||||
|
mailToEncoded(encEmail);
|
||||||
|
},
|
||||||
|
|
||||||
copy: (mail, copyButton) => {
|
copy: (mail, copyButton) => {
|
||||||
copyToClipboard(mail);
|
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
|
* mailgoCheckRender
|
||||||
* function to check if an element is mailgo-enabled or not referencing to the old
|
* 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;
|
if (!document.contains(getE("mailgo"))) return;
|
||||||
|
|
||||||
// go in the event.path to find if the user has clicked on a mailgo element
|
// go in the event.path to find if the user has clicked on a mailgo element
|
||||||
event.path.forEach(e => {
|
if (event.path.some(isMailgo)) {
|
||||||
if (
|
// stop the normal execution of the element click
|
||||||
// first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
|
event.preventDefault();
|
||||||
(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
|
// render mailgo
|
||||||
mailgoRender(e);
|
mailgoRender(e);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user