added gulp-babel
This commit is contained in:
parent
0a4c581617
commit
62170ecf4c
|
@ -1,190 +1,163 @@
|
||||||
const V = "0.3.0";
|
"use strict";
|
||||||
const MAILTO = "mailto:";
|
|
||||||
|
|
||||||
// mailgo style
|
var V = "0.3.1";
|
||||||
const mailgoCSS = document.createElement("link");
|
var MAILTO = "mailto:"; // mailgo style
|
||||||
|
|
||||||
|
var mailgoCSS = document.createElement("link");
|
||||||
mailgoCSS.rel = "stylesheet";
|
mailgoCSS.rel = "stylesheet";
|
||||||
mailgoCSS.type = "text/css";
|
mailgoCSS.type = "text/css";
|
||||||
mailgoCSS.href = "https://unpkg.com/mailgo@" + V + "/dist/mailgo.min.css";
|
mailgoCSS.href = "https://unpkg.com/mailgo@" + V + "/dist/mailgo.min.css";
|
||||||
document.head.appendChild(mailgoCSS);
|
document.head.appendChild(mailgoCSS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mailgoInit
|
* mailgoInit
|
||||||
* the function that creates the mailgo element in DOM
|
* the function that creates the mailgo element in DOM
|
||||||
*/
|
*/
|
||||||
mailgoInit = () => {
|
|
||||||
|
mailgoInit = function mailgoInit() {
|
||||||
// modal
|
// modal
|
||||||
let modal = document.createElement("div");
|
var modal = document.createElement("div");
|
||||||
modal.id = "mailgo";
|
modal.id = "mailgo";
|
||||||
modal.classList.add("mailgo-modal");
|
modal.classList.add("mailgo-modal");
|
||||||
modal.style.display = "none";
|
modal.style.display = "none"; // background
|
||||||
|
|
||||||
// background
|
var modalBackground = document.createElement("div");
|
||||||
let modalBackground = document.createElement("div");
|
|
||||||
modalBackground.className = "mailgo-modal-background";
|
modalBackground.className = "mailgo-modal-background";
|
||||||
modal.appendChild(modalBackground);
|
modal.appendChild(modalBackground); // modal content
|
||||||
|
|
||||||
// modal content
|
var modalContent = document.createElement("div");
|
||||||
let modalContent = document.createElement("div");
|
|
||||||
modalContent.className = "mailgo-modal-content";
|
modalContent.className = "mailgo-modal-content";
|
||||||
modal.appendChild(modalContent);
|
modal.appendChild(modalContent); // title (email address)
|
||||||
|
|
||||||
// title (email address)
|
var title = document.createElement("strong");
|
||||||
let title = document.createElement("strong");
|
|
||||||
title.id = "mailgo-title";
|
title.id = "mailgo-title";
|
||||||
title.className = "mailgo-title";
|
title.className = "mailgo-title";
|
||||||
modalContent.appendChild(title);
|
modalContent.appendChild(title); // details
|
||||||
|
|
||||||
// details
|
var details = document.createElement("div");
|
||||||
let details = document.createElement("div");
|
|
||||||
details.id = "mailgo-details";
|
details.id = "mailgo-details";
|
||||||
details.className = "mailgo-details";
|
details.className = "mailgo-details";
|
||||||
|
var detailCc = document.createElement("p");
|
||||||
let detailCc = document.createElement("p");
|
|
||||||
detailCc.id = "mailgo-cc";
|
detailCc.id = "mailgo-cc";
|
||||||
let ccSpan = document.createElement("span");
|
var ccSpan = document.createElement("span");
|
||||||
ccSpan.className = "mailgo-weight-500";
|
ccSpan.className = "mailgo-weight-500";
|
||||||
let ccContent = document.createTextNode("cc ");
|
var ccContent = document.createTextNode("cc ");
|
||||||
ccSpan.appendChild(ccContent);
|
ccSpan.appendChild(ccContent);
|
||||||
let ccValue = document.createElement("span");
|
var ccValue = document.createElement("span");
|
||||||
ccValue.id = "mailgo-cc-value";
|
ccValue.id = "mailgo-cc-value";
|
||||||
detailCc.appendChild(ccSpan);
|
detailCc.appendChild(ccSpan);
|
||||||
detailCc.appendChild(ccValue);
|
detailCc.appendChild(ccValue);
|
||||||
details.appendChild(detailCc);
|
details.appendChild(detailCc);
|
||||||
|
var detailBcc = document.createElement("p");
|
||||||
let detailBcc = document.createElement("p");
|
|
||||||
detailBcc.id = "mailgo-bcc";
|
detailBcc.id = "mailgo-bcc";
|
||||||
let bccSpan = document.createElement("span");
|
var bccSpan = document.createElement("span");
|
||||||
bccSpan.className = "mailgo-weight-500";
|
bccSpan.className = "mailgo-weight-500";
|
||||||
let bccContent = document.createTextNode("bcc ");
|
var bccContent = document.createTextNode("bcc ");
|
||||||
bccSpan.appendChild(bccContent);
|
bccSpan.appendChild(bccContent);
|
||||||
let bccValue = document.createElement("span");
|
var bccValue = document.createElement("span");
|
||||||
bccValue.id = "mailgo-bcc-value";
|
bccValue.id = "mailgo-bcc-value";
|
||||||
detailBcc.appendChild(bccSpan);
|
detailBcc.appendChild(bccSpan);
|
||||||
detailBcc.appendChild(bccValue);
|
detailBcc.appendChild(bccValue);
|
||||||
details.appendChild(detailBcc);
|
details.appendChild(detailBcc);
|
||||||
|
var detailSubject = document.createElement("p");
|
||||||
let detailSubject = document.createElement("p");
|
|
||||||
detailSubject.id = "mailgo-subject";
|
detailSubject.id = "mailgo-subject";
|
||||||
let subjectSpan = document.createElement("span");
|
var subjectSpan = document.createElement("span");
|
||||||
subjectSpan.className = "mailgo-weight-500";
|
subjectSpan.className = "mailgo-weight-500";
|
||||||
let subjectContent = document.createTextNode("subject");
|
var subjectContent = document.createTextNode("subject");
|
||||||
subjectSpan.appendChild(subjectContent);
|
subjectSpan.appendChild(subjectContent);
|
||||||
let subjectValue = document.createElement("span");
|
var subjectValue = document.createElement("span");
|
||||||
subjectValue.id = "mailgo-subject-value";
|
subjectValue.id = "mailgo-subject-value";
|
||||||
detailSubject.appendChild(subjectSpan);
|
detailSubject.appendChild(subjectSpan);
|
||||||
detailSubject.appendChild(subjectValue);
|
detailSubject.appendChild(subjectValue);
|
||||||
details.appendChild(detailSubject);
|
details.appendChild(detailSubject);
|
||||||
|
var detailBody = document.createElement("p");
|
||||||
let detailBody = document.createElement("p");
|
|
||||||
detailBody.id = "mailgo-body";
|
detailBody.id = "mailgo-body";
|
||||||
let bodySpan = document.createElement("span");
|
var bodySpan = document.createElement("span");
|
||||||
bodySpan.className = "mailgo-weight-500";
|
bodySpan.className = "mailgo-weight-500";
|
||||||
let bodyContent = document.createTextNode("body ");
|
var bodyContent = document.createTextNode("body ");
|
||||||
bodySpan.appendChild(bodyContent);
|
bodySpan.appendChild(bodyContent);
|
||||||
let bodyValue = document.createElement("span");
|
var bodyValue = document.createElement("span");
|
||||||
bodyValue.id = "mailgo-body-value";
|
bodyValue.id = "mailgo-body-value";
|
||||||
detailBody.appendChild(bodySpan);
|
detailBody.appendChild(bodySpan);
|
||||||
detailBody.appendChild(bodyValue);
|
detailBody.appendChild(bodyValue);
|
||||||
details.appendChild(detailBody);
|
details.appendChild(detailBody);
|
||||||
|
modalContent.appendChild(details); // Gmail
|
||||||
|
|
||||||
modalContent.appendChild(details);
|
var gmail = document.createElement("a");
|
||||||
|
|
||||||
// Gmail
|
|
||||||
let gmail = document.createElement("a");
|
|
||||||
gmail.id = "mailgo-gmail";
|
gmail.id = "mailgo-gmail";
|
||||||
gmail.classList.add("mailgo-open");
|
gmail.classList.add("mailgo-open");
|
||||||
gmail.classList.add("gmail");
|
gmail.classList.add("gmail");
|
||||||
let gmailContent = document.createTextNode("open in ");
|
var gmailContent = document.createTextNode("open in ");
|
||||||
gmail.appendChild(gmailContent);
|
gmail.appendChild(gmailContent);
|
||||||
let gmailSpan = document.createElement("span");
|
var gmailSpan = document.createElement("span");
|
||||||
gmailSpan.className = "mailgo-weight-500";
|
gmailSpan.className = "mailgo-weight-500";
|
||||||
let gmailSpanContent = document.createTextNode("Gmail");
|
var gmailSpanContent = document.createTextNode("Gmail");
|
||||||
gmailSpan.appendChild(gmailSpanContent);
|
gmailSpan.appendChild(gmailSpanContent);
|
||||||
gmail.appendChild(gmailSpan);
|
gmail.appendChild(gmailSpan);
|
||||||
|
modalContent.appendChild(gmail); // Outlook
|
||||||
|
|
||||||
modalContent.appendChild(gmail);
|
var outlook = document.createElement("a");
|
||||||
|
|
||||||
// Outlook
|
|
||||||
let outlook = document.createElement("a");
|
|
||||||
outlook.id = "mailgo-outlook";
|
outlook.id = "mailgo-outlook";
|
||||||
outlook.classList.add("mailgo-open");
|
outlook.classList.add("mailgo-open");
|
||||||
outlook.classList.add("outlook");
|
outlook.classList.add("outlook");
|
||||||
let outlookContent = document.createTextNode("open in ");
|
var outlookContent = document.createTextNode("open in ");
|
||||||
outlook.appendChild(outlookContent);
|
outlook.appendChild(outlookContent);
|
||||||
let outlookSpan = document.createElement("span");
|
var outlookSpan = document.createElement("span");
|
||||||
outlookSpan.className = "mailgo-weight-500";
|
outlookSpan.className = "mailgo-weight-500";
|
||||||
let outlookSpanContent = document.createTextNode("Outlook");
|
var outlookSpanContent = document.createTextNode("Outlook");
|
||||||
outlookSpan.appendChild(outlookSpanContent);
|
outlookSpan.appendChild(outlookSpanContent);
|
||||||
outlook.appendChild(outlookSpan);
|
outlook.appendChild(outlookSpan);
|
||||||
|
modalContent.appendChild(outlook); // open default
|
||||||
|
|
||||||
modalContent.appendChild(outlook);
|
var open = document.createElement("a");
|
||||||
|
|
||||||
// open default
|
|
||||||
let open = document.createElement("a");
|
|
||||||
open.id = "mailgo-open";
|
open.id = "mailgo-open";
|
||||||
open.href = "#mailgo-open";
|
open.href = "#mailgo-open";
|
||||||
open.classList.add("mailgo-open");
|
open.classList.add("mailgo-open");
|
||||||
open.classList.add("mailgo-weight-500");
|
open.classList.add("mailgo-weight-500");
|
||||||
let openContent = document.createTextNode("open");
|
var openContent = document.createTextNode("open");
|
||||||
open.appendChild(openContent);
|
open.appendChild(openContent);
|
||||||
|
modalContent.appendChild(open); // copy
|
||||||
|
|
||||||
modalContent.appendChild(open);
|
var copy = document.createElement("a");
|
||||||
|
|
||||||
// copy
|
|
||||||
let copy = document.createElement("a");
|
|
||||||
copy.id = "mailgo-copy";
|
copy.id = "mailgo-copy";
|
||||||
copy.href = "#mailgo-copy";
|
copy.href = "#mailgo-copy";
|
||||||
copy.classList.add("mailgo-copy");
|
copy.classList.add("mailgo-copy");
|
||||||
copy.classList.add("mailgo-weight-500");
|
copy.classList.add("mailgo-weight-500");
|
||||||
let copyContent = document.createTextNode("copy");
|
var copyContent = document.createTextNode("copy");
|
||||||
copy.appendChild(copyContent);
|
copy.appendChild(copyContent);
|
||||||
|
modalContent.appendChild(copy); // by
|
||||||
|
|
||||||
modalContent.appendChild(copy);
|
var by = document.createElement("a");
|
||||||
|
|
||||||
// by
|
|
||||||
let by = document.createElement("a");
|
|
||||||
by.href = "https://mailgo.js.org";
|
by.href = "https://mailgo.js.org";
|
||||||
by.className = "mailgo-by";
|
by.className = "mailgo-by";
|
||||||
by.target = "_blank";
|
by.target = "_blank";
|
||||||
let textBy = document.createTextNode("mailgo.js.org");
|
var textBy = document.createTextNode("mailgo.js.org");
|
||||||
by.appendChild(textBy);
|
by.appendChild(textBy);
|
||||||
|
modalContent.appendChild(by); // add the modal at the end of the body
|
||||||
|
|
||||||
modalContent.appendChild(by);
|
document.body.appendChild(modal); // every click outside the modal will hide the modal
|
||||||
|
|
||||||
// add the modal at the end of the body
|
|
||||||
document.body.appendChild(modal);
|
|
||||||
|
|
||||||
// every click outside the modal will hide the modal
|
|
||||||
modalBackground.addEventListener("click", hideMailgo, false);
|
modalBackground.addEventListener("click", hideMailgo, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mailgoRender
|
* mailgoRender
|
||||||
* function to render a single mailgo
|
* function to render a single mailgo
|
||||||
*/
|
*/
|
||||||
mailgoRender = mailgo => {
|
|
||||||
let mail = "",
|
|
||||||
mailtoHref = "",
|
|
||||||
cc = "",
|
|
||||||
bcc = "",
|
|
||||||
subject = "",
|
|
||||||
bodyMail = "";
|
|
||||||
|
|
||||||
// if the element href=^"mailto:"
|
|
||||||
|
mailgoRender = function mailgoRender(mailgo) {
|
||||||
|
var mail = "",
|
||||||
|
mailtoHref = "",
|
||||||
|
cc = "",
|
||||||
|
bcc = "",
|
||||||
|
subject = "",
|
||||||
|
bodyMail = ""; // 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.split("?")[0].split(MAILTO)[1].trim());
|
||||||
mailgo.href
|
|
||||||
.split("?")[0]
|
|
||||||
.split(MAILTO)[1]
|
|
||||||
.trim()
|
|
||||||
);
|
|
||||||
|
|
||||||
mailtoHref = mailgo.href;
|
mailtoHref = mailgo.href;
|
||||||
url = new URL(mailtoHref);
|
url = new URL(mailtoHref);
|
||||||
let urlParams = new URLSearchParams(url.search);
|
var urlParams = new URLSearchParams(url.search); // optional parameters for the email
|
||||||
|
|
||||||
// optional parameters for the email
|
|
||||||
cc = urlParams.get("cc");
|
cc = urlParams.get("cc");
|
||||||
bcc = urlParams.get("bcc");
|
bcc = urlParams.get("bcc");
|
||||||
subject = urlParams.get("subject");
|
subject = urlParams.get("subject");
|
||||||
|
@ -192,40 +165,25 @@ mailgoRender = mailgo => {
|
||||||
} else {
|
} else {
|
||||||
// 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 =
|
mail = mailgo.getAttribute("data-address") + "@" + mailgo.getAttribute("data-domain");
|
||||||
mailgo.getAttribute("data-address") +
|
|
||||||
"@" +
|
|
||||||
mailgo.getAttribute("data-domain");
|
|
||||||
mailtoHref = MAILTO + encodeURIComponent(mail);
|
mailtoHref = MAILTO + encodeURIComponent(mail);
|
||||||
url = new URL(mailtoHref);
|
url = new URL(mailtoHref); // cc = data-cc-address + @ + data-cc-domain
|
||||||
|
|
||||||
// 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
|
bcc = mailgo.getAttribute("data-bcc-address") + "@" + mailgo.getAttribute("data-bcc-domain"); // subject = data-subject
|
||||||
bcc =
|
|
||||||
mailgo.getAttribute("data-bcc-address") +
|
|
||||||
"@" +
|
|
||||||
mailgo.getAttribute("data-bcc-domain");
|
|
||||||
|
|
||||||
// subject = data-subject
|
subject = mailgo.getAttribute("data-subject"); // body = data-body
|
||||||
subject = mailgo.getAttribute("data-subject");
|
|
||||||
|
|
||||||
// body = data-body
|
|
||||||
bodyMail = mailgo.getAttribute("data-body");
|
bodyMail = mailgo.getAttribute("data-body");
|
||||||
}
|
} // validate the email address
|
||||||
|
|
||||||
// validate the email address
|
|
||||||
if (!validateEmail(mail)) return;
|
|
||||||
|
|
||||||
// if cc, bcc is not valid cc, bcc = ""
|
if (!validateEmail(mail)) return; // if cc, bcc is not valid cc, bcc = ""
|
||||||
|
|
||||||
if (!validateEmail(cc)) cc = "";
|
if (!validateEmail(cc)) cc = "";
|
||||||
if (!validateEmail(bcc)) bcc = "";
|
if (!validateEmail(bcc)) bcc = ""; // information
|
||||||
|
|
||||||
// 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");
|
||||||
|
@ -235,70 +193,36 @@ mailgoRender = mailgo => {
|
||||||
subjectEl = getE("mailgo-subject");
|
subjectEl = getE("mailgo-subject");
|
||||||
subjectValueEl = getE("mailgo-subject-value");
|
subjectValueEl = getE("mailgo-subject-value");
|
||||||
bodyEl = getE("mailgo-body");
|
bodyEl = getE("mailgo-body");
|
||||||
bodyValueEl = getE("mailgo-body-value");
|
bodyValueEl = getE("mailgo-body-value"); // actions
|
||||||
|
|
||||||
// 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)
|
||||||
|
|
||||||
// the title of the modal (email address)
|
titleEl.textContent = mail; // add the details if provided
|
||||||
titleEl.textContent = mail;
|
|
||||||
|
|
||||||
// add the details if provided
|
cc ? (ccEl.style.display = "block", ccValueEl.textContent = cc) : ccEl.style.display = "none";
|
||||||
cc
|
bcc ? (bccEl.style.display = "block", bccValueEl.textContent = bcc) : bccEl.style.display = "none";
|
||||||
? ((ccEl.style.display = "block"), (ccValueEl.textContent = cc))
|
subject ? (subjectEl.style.display = "block", subjectValueEl.textContent = subject) : subjectEl.style.display = "none";
|
||||||
: (ccEl.style.display = "none");
|
bodyMail ? (bodyEl.style.display = "block", bodyValueEl.textContent = bodyMail) : bodyEl.style.display = "none"; // add the actions
|
||||||
|
|
||||||
bcc
|
gmailButton.href = "https://mail.google.com/mail?extsrc=mailto&url=" + encodeURIComponent(mailtoHref);
|
||||||
? ((bccEl.style.display = "block"), (bccValueEl.textContent = bcc))
|
outlookButton.href = "https://outlook.office.com/owa/?rru=compose&to=" + encodeURIComponent(mail) + url.search.replace(/^[$]/, "&");
|
||||||
: (bccEl.style.display = "none");
|
var encEmail = encodeEmail(mail);
|
||||||
|
openButton.addEventListener("click", function () {
|
||||||
|
mailToEncoded(encEmail);
|
||||||
|
}, false);
|
||||||
|
copyButton.addEventListener("click", function (event) {
|
||||||
|
copyToClipboard(mail);
|
||||||
|
copyButton.textContent = "copied";
|
||||||
|
setTimeout(function () {
|
||||||
|
copyButton.textContent = "copy";
|
||||||
|
}, 999);
|
||||||
|
}, false); // show the mailgo
|
||||||
|
|
||||||
subject
|
|
||||||
? ((subjectEl.style.display = "block"),
|
|
||||||
(subjectValueEl.textContent = subject))
|
|
||||||
: (subjectEl.style.display = "none");
|
|
||||||
|
|
||||||
bodyMail
|
|
||||||
? ((bodyEl.style.display = "block"), (bodyValueEl.textContent = bodyMail))
|
|
||||||
: (bodyEl.style.display = "none");
|
|
||||||
|
|
||||||
// add the actions
|
|
||||||
gmailButton.href =
|
|
||||||
"https://mail.google.com/mail?extsrc=mailto&url=" +
|
|
||||||
encodeURIComponent(mailtoHref);
|
|
||||||
|
|
||||||
outlookButton.href =
|
|
||||||
"https://outlook.office.com/owa/?rru=compose&to=" +
|
|
||||||
encodeURIComponent(mail) +
|
|
||||||
url.search.replace(/^[$]/, "&");
|
|
||||||
|
|
||||||
let encEmail = encodeEmail(mail);
|
|
||||||
openButton.addEventListener(
|
|
||||||
"click",
|
|
||||||
() => {
|
|
||||||
mailToEncoded(encEmail);
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
copyButton.addEventListener(
|
|
||||||
"click",
|
|
||||||
event => {
|
|
||||||
copyToClipboard(mail);
|
|
||||||
copyButton.textContent = "copied";
|
|
||||||
setTimeout(() => {
|
|
||||||
copyButton.textContent = "copy";
|
|
||||||
}, 999);
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
// show the mailgo
|
|
||||||
showMailgo();
|
showMailgo();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -306,100 +230,99 @@ mailgoRender = mailgo => {
|
||||||
* 'a[href^="mailto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo'
|
* 'a[href^="mailto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo'
|
||||||
* ); and the new a[mailgo]
|
* ); and the new a[mailgo]
|
||||||
*/
|
*/
|
||||||
mailgoCheckRender = event => {
|
|
||||||
// the target element
|
|
||||||
let e = event.target;
|
|
||||||
|
|
||||||
// check if the id=mailgo exists in the body
|
|
||||||
|
mailgoCheckRender = function mailgoCheckRender(event) {
|
||||||
|
// the target element
|
||||||
|
var e = event.target; // check if the id=mailgo exists in the body
|
||||||
|
|
||||||
if (!document.body.contains(getE("mailgo"))) return;
|
if (!document.body.contains(getE("mailgo"))) return;
|
||||||
|
|
||||||
if (
|
if ( // first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
|
||||||
// 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.href && e.getAttribute("href").toLowerCase() === "#mailgo" || // third case: the classList contains mailgo
|
||||||
e.href.toLowerCase().startsWith(MAILTO) &&
|
e.classList.contains("mailgo") || // fourth case: exists the attribute mailgo in the <a> element
|
||||||
!e.classList.contains("no-mailgo")) ||
|
!!e.getAttribute("mailgo")) {
|
||||||
// second case: the href=#mailgo
|
|
||||||
(e.href && e.getAttribute("href").toLowerCase() === "#mailgo") ||
|
|
||||||
// third case: the classList contains mailgo
|
|
||||||
e.classList.contains("mailgo") ||
|
|
||||||
// fourth case: exists the attribute mailgo in the <a> element
|
|
||||||
!!e.getAttribute("mailgo")
|
|
||||||
) {
|
|
||||||
// stop the normal execution of the element click
|
// stop the normal execution of the element click
|
||||||
event.preventDefault();
|
event.preventDefault(); // render mailgo
|
||||||
|
|
||||||
// render mailgo
|
|
||||||
mailgoRender(e);
|
mailgoRender(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mailgoKeydown
|
* mailgoKeydown
|
||||||
* function to manage the keydown event when the modal is showing
|
* function to manage the keydown event when the modal is showing
|
||||||
*/
|
*/
|
||||||
mailgoKeydown = event => {
|
|
||||||
|
|
||||||
|
mailgoKeydown = function mailgoKeydown(event) {
|
||||||
switch (event.keyCode) {
|
switch (event.keyCode) {
|
||||||
case 27:
|
case 27:
|
||||||
// Escape
|
// Escape
|
||||||
hideMailgo();
|
hideMailgo();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
};
|
}; // DOMContentLoaded -> mailgoInit (creates the modal)
|
||||||
|
|
||||||
// DOMContentLoaded -> mailgoInit (creates the modal)
|
|
||||||
document.addEventListener("DOMContentLoaded", mailgoInit, false);
|
|
||||||
|
|
||||||
// event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered
|
document.addEventListener("DOMContentLoaded", mailgoInit, false); // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered
|
||||||
document.body.addEventListener("click", mailgoCheckRender, false);
|
|
||||||
|
|
||||||
// validate the email with regex
|
document.body.addEventListener("click", mailgoCheckRender, false); // validate the email with regex
|
||||||
validateEmail = email => {
|
|
||||||
let re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
validateEmail = function validateEmail(email) {
|
||||||
|
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||||
return re.test(email);
|
return re.test(email);
|
||||||
};
|
}; // copy of a string
|
||||||
|
|
||||||
// copy of a string
|
|
||||||
copyToClipboard = str => {
|
copyToClipboard = function copyToClipboard(str) {
|
||||||
let el = document.createElement("textarea");
|
var el = document.createElement("textarea");
|
||||||
el.value = str;
|
el.value = str;
|
||||||
el.setAttribute("readonly", "");
|
el.setAttribute("readonly", "");
|
||||||
el.style.position = "absolute";
|
el.style.position = "absolute";
|
||||||
el.style.left = "-9999px";
|
el.style.left = "-9999px";
|
||||||
document.body.appendChild(el);
|
document.body.appendChild(el);
|
||||||
let selected =
|
var selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
||||||
document.getSelection().rangeCount > 0
|
|
||||||
? document.getSelection().getRangeAt(0)
|
|
||||||
: false;
|
|
||||||
el.select();
|
el.select();
|
||||||
document.execCommand("copy");
|
document.execCommand("copy");
|
||||||
document.body.removeChild(el);
|
document.body.removeChild(el);
|
||||||
|
|
||||||
if (selected) {
|
if (selected) {
|
||||||
document.getSelection().removeAllRanges();
|
document.getSelection().removeAllRanges();
|
||||||
document.getSelection().addRange(selected);
|
document.getSelection().addRange(selected);
|
||||||
}
|
}
|
||||||
};
|
}; // show the modal
|
||||||
|
|
||||||
|
|
||||||
|
showMailgo = function showMailgo() {
|
||||||
|
getE("mailgo").style.display = "flex"; // add mailgoKeydown
|
||||||
|
|
||||||
// show the modal
|
|
||||||
showMailgo = () => {
|
|
||||||
getE("mailgo").style.display = "flex";
|
|
||||||
// add mailgoKeydown
|
|
||||||
document.body.addEventListener("keydown", mailgoKeydown, false);
|
document.body.addEventListener("keydown", mailgoKeydown, false);
|
||||||
};
|
}; // hide the modal
|
||||||
|
|
||||||
|
|
||||||
|
hideMailgo = function hideMailgo() {
|
||||||
|
getE("mailgo").style.display = "none"; // remove mailgoKeydown
|
||||||
|
|
||||||
// hide the modal
|
|
||||||
hideMailgo = () => {
|
|
||||||
getE("mailgo").style.display = "none";
|
|
||||||
// remove mailgoKeydown
|
|
||||||
document.body.removeEventListener("keydown", mailgoKeydown, false);
|
document.body.removeEventListener("keydown", mailgoKeydown, false);
|
||||||
};
|
}; // decrypt email
|
||||||
// decrypt email
|
|
||||||
mailToEncoded = encoded => (window.location.href = MAILTO + atob(encoded));
|
|
||||||
|
|
||||||
// encode email
|
|
||||||
encodeEmail = email => btoa(email);
|
|
||||||
|
|
||||||
// getE shorthand
|
mailToEncoded = function mailToEncoded(encoded) {
|
||||||
getE = id => document.getElementById(id);
|
return window.location.href = MAILTO + atob(encoded);
|
||||||
|
}; // encode email
|
||||||
|
|
||||||
|
|
||||||
|
encodeEmail = function encodeEmail(email) {
|
||||||
|
return btoa(email);
|
||||||
|
}; // getE shorthand
|
||||||
|
|
||||||
|
|
||||||
|
getE = function getE(id) {
|
||||||
|
return document.getElementById(id);
|
||||||
|
};
|
File diff suppressed because one or more lines are too long
12
gulpfile.js
12
gulpfile.js
|
@ -5,17 +5,29 @@ const rename = require("gulp-rename");
|
||||||
const csso = require("gulp-csso");
|
const csso = require("gulp-csso");
|
||||||
const replace = require("gulp-replace");
|
const replace = require("gulp-replace");
|
||||||
|
|
||||||
|
const babel = require("gulp-babel");
|
||||||
|
|
||||||
let version = require("./package.json").version;
|
let version = require("./package.json").version;
|
||||||
|
|
||||||
function js() {
|
function js() {
|
||||||
return src("src/*.js")
|
return src("src/*.js")
|
||||||
.pipe(replace("MAILGO_VERSION", version.toString()))
|
.pipe(replace("MAILGO_VERSION", version.toString()))
|
||||||
|
.pipe(
|
||||||
|
babel({
|
||||||
|
presets: ["@babel/env"]
|
||||||
|
})
|
||||||
|
)
|
||||||
.pipe(dest("dist"));
|
.pipe(dest("dist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function jsmin() {
|
function jsmin() {
|
||||||
return src("src/*.js")
|
return src("src/*.js")
|
||||||
.pipe(replace("MAILGO_VERSION", version))
|
.pipe(replace("MAILGO_VERSION", version))
|
||||||
|
.pipe(
|
||||||
|
babel({
|
||||||
|
presets: ["@babel/env"]
|
||||||
|
})
|
||||||
|
)
|
||||||
.pipe(terser())
|
.pipe(terser())
|
||||||
.pipe(
|
.pipe(
|
||||||
rename({
|
rename({
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
"@babel/core": "^7.4.4",
|
"@babel/core": "^7.4.4",
|
||||||
"@babel/preset-env": "^7.4.4",
|
"@babel/preset-env": "^7.4.4",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
|
"gulp-babel": "^8.0.0",
|
||||||
"gulp-csso": "^3.0.1",
|
"gulp-csso": "^3.0.1",
|
||||||
"gulp-rename": "^1.4.0",
|
"gulp-rename": "^1.4.0",
|
||||||
"gulp-replace": "^1.0.0",
|
"gulp-replace": "^1.0.0",
|
||||||
|
|
16
yarn.lock
16
yarn.lock
|
@ -1293,9 +1293,9 @@ editions@^1.3.3:
|
||||||
integrity sha512-gzao+mxnYDzIysXKMQi/+M1mjy/rjestjg6OPoYTtI+3Izp23oiGZitsl9lPDPiTGXbcSIk1iJWhliSaglxnUg==
|
integrity sha512-gzao+mxnYDzIysXKMQi/+M1mjy/rjestjg6OPoYTtI+3Izp23oiGZitsl9lPDPiTGXbcSIk1iJWhliSaglxnUg==
|
||||||
|
|
||||||
electron-to-chromium@^1.3.133:
|
electron-to-chromium@^1.3.133:
|
||||||
version "1.3.133"
|
version "1.3.134"
|
||||||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.133.tgz#c47639c19b91feee3e22fad69f5556142007008c"
|
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.134.tgz#550222bddac43c6bd6c445c3543a0fe8a615021d"
|
||||||
integrity sha512-lyoC8aoqbbDqsprb6aPdt9n3DpOZZzdz/T4IZKsR0/dkZIxnJVUjjcpOSwA66jPRIOyDAamCTAUqweU05kKNSg==
|
integrity sha512-C3uK2SrtWg/gSWaluLHWSHjyebVZCe4ZC0NVgTAoTq8tCR9FareRK5T7R7AS/nPZShtlEcjVMX1kQ8wi4nU68w==
|
||||||
|
|
||||||
end-of-stream@^1.0.0, end-of-stream@^1.1.0:
|
end-of-stream@^1.0.0, end-of-stream@^1.1.0:
|
||||||
version "1.4.1"
|
version "1.4.1"
|
||||||
|
@ -1656,6 +1656,16 @@ graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
|
||||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
|
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
|
||||||
integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==
|
integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==
|
||||||
|
|
||||||
|
gulp-babel@^8.0.0:
|
||||||
|
version "8.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/gulp-babel/-/gulp-babel-8.0.0.tgz#e0da96f4f2ec4a88dd3a3030f476e38ab2126d87"
|
||||||
|
integrity sha512-oomaIqDXxFkg7lbpBou/gnUkX51/Y/M2ZfSjL2hdqXTAlSWZcgZtd2o0cOH0r/eE8LWD0+Q/PsLsr2DKOoqToQ==
|
||||||
|
dependencies:
|
||||||
|
plugin-error "^1.0.1"
|
||||||
|
replace-ext "^1.0.0"
|
||||||
|
through2 "^2.0.0"
|
||||||
|
vinyl-sourcemaps-apply "^0.2.0"
|
||||||
|
|
||||||
gulp-cli@^2.2.0:
|
gulp-cli@^2.2.0:
|
||||||
version "2.2.0"
|
version "2.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/gulp-cli/-/gulp-cli-2.2.0.tgz#5533126eeb7fe415a7e3e84a297d334d5cf70ebc"
|
resolved "https://registry.yarnpkg.com/gulp-cli/-/gulp-cli-2.2.0.tgz#5533126eeb7fe415a7e3e84a297d334d5cf70ebc"
|
||||||
|
|
Loading…
Reference in New Issue