added a lot of comments

This commit is contained in:
Matteo Manzinello 2019-05-12 00:21:38 +02:00
parent c981beb50f
commit 6daffab8bf
3 changed files with 32 additions and 15 deletions

5
dist/mailgo.js vendored
View File

@ -1,12 +1,11 @@
const VERSION = "0.3.0"; const V = "0.3.0";
const MAILTO = "mailto:"; const MAILTO = "mailto:";
// mailgo style // mailgo style
const styleSheet = document.createElement("link"); const styleSheet = document.createElement("link");
styleSheet.rel = "stylesheet"; styleSheet.rel = "stylesheet";
styleSheet.type = "text/css"; styleSheet.type = "text/css";
styleSheet.href = styleSheet.href = "https://unpkg.com/mailgo@" + V + "/dist/mailgo.min.css";
"https://unpkg.com/mailgo@" + VERSION + "/dist/mailgo.min.css";
document.head.appendChild(styleSheet); document.head.appendChild(styleSheet);
/** /**

2
dist/mailgo.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,11 @@
const VERSION = "MAILGO_VERSION"; const V = "MAILGO_VERSION";
const MAILTO = "mailto:"; const MAILTO = "mailto:";
// mailgo style // mailgo style
const styleSheet = document.createElement("link"); const styleSheet = document.createElement("link");
styleSheet.rel = "stylesheet"; styleSheet.rel = "stylesheet";
styleSheet.type = "text/css"; styleSheet.type = "text/css";
styleSheet.href = styleSheet.href = "https://unpkg.com/mailgo@" + V + "/dist/mailgo.min.css";
"https://unpkg.com/mailgo@" + VERSION + "/dist/mailgo.min.css";
document.head.appendChild(styleSheet); document.head.appendChild(styleSheet);
/** /**
@ -186,7 +185,7 @@ mailgoRender = mailgo => {
subject = "", subject = "",
bodyMail = ""; bodyMail = "";
// mailgo all the element with href=^"mailto:" // if the element href=^"mailto:"
if (mailgo.href && mailgo.href.toLowerCase().startsWith(MAILTO)) { if (mailgo.href && mailgo.href.toLowerCase().startsWith(MAILTO)) {
mail = decodeURIComponent( mail = decodeURIComponent(
mailgo.href mailgo.href
@ -205,7 +204,7 @@ mailgoRender = mailgo => {
subject = urlParams.get("subject"); subject = urlParams.get("subject");
bodyMail = urlParams.get("body"); bodyMail = urlParams.get("body");
} else { } else {
// mailgo all the element with href="#mailgo" or class="mailgo" // if the element href="#mailgo" or class="mailgo"
// email = data-address + @ + data-domain // email = data-address + @ + data-domain
mail = mail =
mailgo.getAttribute("data-address") + mailgo.getAttribute("data-address") +
@ -218,6 +217,7 @@ mailgoRender = mailgo => {
// validate the email address // validate the email address
if (!validateEmail(mail)) return; if (!validateEmail(mail)) return;
// information
titleEl = getE("mailgo-title"); titleEl = getE("mailgo-title");
detailsEl = getE("mailgo-details"); detailsEl = getE("mailgo-details");
ccEl = getE("mailgo-cc"); ccEl = getE("mailgo-cc");
@ -229,22 +229,34 @@ mailgoRender = mailgo => {
bodyEl = getE("mailgo-body"); bodyEl = getE("mailgo-body");
bodyValueEl = getE("mailgo-body-value"); bodyValueEl = getE("mailgo-body-value");
// actions
gmailButton = getE("mailgo-gmail"); gmailButton = getE("mailgo-gmail");
outlookButton = getE("mailgo-outlook"); outlookButton = getE("mailgo-outlook");
openButton = getE("mailgo-open"); openButton = getE("mailgo-open");
copyButton = getE("mailgo-copy"); copyButton = getE("mailgo-copy");
// the title of the modal (email address)
titleEl.textContent = mail; titleEl.textContent = mail;
cc ? (ccValueEl.textContent = cc) : (ccEl.style.display = "none"); // add the details if provided
bcc ? (bccValueEl.textContent = bcc) : (bccEl.style.display = "none"); cc
? ((ccEl.style.display = "block"), (ccValueEl.textContent = cc))
: (ccEl.style.display = "none");
bcc
? ((bccEl.style.display = "block"), (bccValueEl.textContent = bcc))
: (bccEl.style.display = "none");
subject subject
? (subjectValueEl.textContent = subject) ? ((subjectEl.style.display = "block"),
(subjectValueEl.textContent = subject))
: (subjectEl.style.display = "none"); : (subjectEl.style.display = "none");
bodyMail bodyMail
? (bodyValueEl.textContent = bodyMail) ? ((bodyEl.style.display = "block"), (bodyValueEl.textContent = bodyMail))
: (bodyEl.style.display = "none"); : (bodyEl.style.display = "none");
// add the actions
gmailButton.href = gmailButton.href =
"https://mail.google.com/mail?extsrc=mailto&url=" + "https://mail.google.com/mail?extsrc=mailto&url=" +
encodeURIComponent(mailtoHref); encodeURIComponent(mailtoHref);
@ -275,15 +287,21 @@ mailgoRender = mailgo => {
false false
); );
// show the mailgo
showMailgo(); showMailgo();
}; };
/**
* mailgoCheckRender
* function to check if an element is mailgo-enabled or not referencing to the old
* document.querySelectorAll(
* 'a[href^="mailto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo'
* );
*/
mailgoCheckRender = event => { mailgoCheckRender = event => {
// the target element // the target element
let e = event.target; let e = event.target;
console.log(e);
// check if the id=mailgo exists in the body // check if the id=mailgo exists in the body
if (!document.body.contains(getE("mailgo"))) return; if (!document.body.contains(getE("mailgo"))) return;