From 62170ecf4ca936479a8b290986a9a7b2c57fab43 Mon Sep 17 00:00:00 2001 From: Matteo Manzinello Date: Wed, 15 May 2019 09:23:06 +0200 Subject: [PATCH] added gulp-babel --- dist/mailgo.js | 367 ++++++++++++++++++--------------------------- dist/mailgo.min.js | 2 +- gulpfile.js | 12 ++ package.json | 1 + yarn.lock | 16 +- 5 files changed, 172 insertions(+), 226 deletions(-) diff --git a/dist/mailgo.js b/dist/mailgo.js index f2f8b47..da28c39 100644 --- a/dist/mailgo.js +++ b/dist/mailgo.js @@ -1,190 +1,163 @@ -const V = "0.3.0"; -const MAILTO = "mailto:"; +"use strict"; -// mailgo style -const mailgoCSS = document.createElement("link"); +var V = "0.3.1"; +var MAILTO = "mailto:"; // mailgo style + +var mailgoCSS = document.createElement("link"); mailgoCSS.rel = "stylesheet"; mailgoCSS.type = "text/css"; mailgoCSS.href = "https://unpkg.com/mailgo@" + V + "/dist/mailgo.min.css"; document.head.appendChild(mailgoCSS); - /** * mailgoInit * the function that creates the mailgo element in DOM */ -mailgoInit = () => { + +mailgoInit = function mailgoInit() { // modal - let modal = document.createElement("div"); + var modal = document.createElement("div"); modal.id = "mailgo"; modal.classList.add("mailgo-modal"); - modal.style.display = "none"; + modal.style.display = "none"; // background - // background - let modalBackground = document.createElement("div"); + var modalBackground = document.createElement("div"); modalBackground.className = "mailgo-modal-background"; - modal.appendChild(modalBackground); + modal.appendChild(modalBackground); // modal content - // modal content - let modalContent = document.createElement("div"); + var modalContent = document.createElement("div"); modalContent.className = "mailgo-modal-content"; - modal.appendChild(modalContent); + modal.appendChild(modalContent); // title (email address) - // title (email address) - let title = document.createElement("strong"); + var title = document.createElement("strong"); title.id = "mailgo-title"; title.className = "mailgo-title"; - modalContent.appendChild(title); + modalContent.appendChild(title); // details - // details - let details = document.createElement("div"); + var details = document.createElement("div"); details.id = "mailgo-details"; details.className = "mailgo-details"; - - let detailCc = document.createElement("p"); + var detailCc = document.createElement("p"); detailCc.id = "mailgo-cc"; - let ccSpan = document.createElement("span"); + var ccSpan = document.createElement("span"); ccSpan.className = "mailgo-weight-500"; - let ccContent = document.createTextNode("cc "); + var ccContent = document.createTextNode("cc "); ccSpan.appendChild(ccContent); - let ccValue = document.createElement("span"); + var ccValue = document.createElement("span"); ccValue.id = "mailgo-cc-value"; detailCc.appendChild(ccSpan); detailCc.appendChild(ccValue); details.appendChild(detailCc); - - let detailBcc = document.createElement("p"); + var detailBcc = document.createElement("p"); detailBcc.id = "mailgo-bcc"; - let bccSpan = document.createElement("span"); + var bccSpan = document.createElement("span"); bccSpan.className = "mailgo-weight-500"; - let bccContent = document.createTextNode("bcc "); + var bccContent = document.createTextNode("bcc "); bccSpan.appendChild(bccContent); - let bccValue = document.createElement("span"); + var bccValue = document.createElement("span"); bccValue.id = "mailgo-bcc-value"; detailBcc.appendChild(bccSpan); detailBcc.appendChild(bccValue); details.appendChild(detailBcc); - - let detailSubject = document.createElement("p"); + var detailSubject = document.createElement("p"); detailSubject.id = "mailgo-subject"; - let subjectSpan = document.createElement("span"); + var subjectSpan = document.createElement("span"); subjectSpan.className = "mailgo-weight-500"; - let subjectContent = document.createTextNode("subject"); + var subjectContent = document.createTextNode("subject"); subjectSpan.appendChild(subjectContent); - let subjectValue = document.createElement("span"); + var subjectValue = document.createElement("span"); subjectValue.id = "mailgo-subject-value"; detailSubject.appendChild(subjectSpan); detailSubject.appendChild(subjectValue); details.appendChild(detailSubject); - - let detailBody = document.createElement("p"); + var detailBody = document.createElement("p"); detailBody.id = "mailgo-body"; - let bodySpan = document.createElement("span"); + var bodySpan = document.createElement("span"); bodySpan.className = "mailgo-weight-500"; - let bodyContent = document.createTextNode("body "); + var bodyContent = document.createTextNode("body "); bodySpan.appendChild(bodyContent); - let bodyValue = document.createElement("span"); + var bodyValue = document.createElement("span"); bodyValue.id = "mailgo-body-value"; detailBody.appendChild(bodySpan); detailBody.appendChild(bodyValue); details.appendChild(detailBody); + modalContent.appendChild(details); // Gmail - modalContent.appendChild(details); - - // Gmail - let gmail = document.createElement("a"); + var gmail = document.createElement("a"); gmail.id = "mailgo-gmail"; gmail.classList.add("mailgo-open"); gmail.classList.add("gmail"); - let gmailContent = document.createTextNode("open in "); + var gmailContent = document.createTextNode("open in "); gmail.appendChild(gmailContent); - let gmailSpan = document.createElement("span"); + var gmailSpan = document.createElement("span"); gmailSpan.className = "mailgo-weight-500"; - let gmailSpanContent = document.createTextNode("Gmail"); + var gmailSpanContent = document.createTextNode("Gmail"); gmailSpan.appendChild(gmailSpanContent); gmail.appendChild(gmailSpan); + modalContent.appendChild(gmail); // Outlook - modalContent.appendChild(gmail); - - // Outlook - let outlook = document.createElement("a"); + var outlook = document.createElement("a"); outlook.id = "mailgo-outlook"; outlook.classList.add("mailgo-open"); outlook.classList.add("outlook"); - let outlookContent = document.createTextNode("open in "); + var outlookContent = document.createTextNode("open in "); outlook.appendChild(outlookContent); - let outlookSpan = document.createElement("span"); + var outlookSpan = document.createElement("span"); outlookSpan.className = "mailgo-weight-500"; - let outlookSpanContent = document.createTextNode("Outlook"); + var outlookSpanContent = document.createTextNode("Outlook"); outlookSpan.appendChild(outlookSpanContent); outlook.appendChild(outlookSpan); + modalContent.appendChild(outlook); // open default - modalContent.appendChild(outlook); - - // open default - let open = document.createElement("a"); + var open = document.createElement("a"); open.id = "mailgo-open"; open.href = "#mailgo-open"; open.classList.add("mailgo-open"); open.classList.add("mailgo-weight-500"); - let openContent = document.createTextNode("open"); + var openContent = document.createTextNode("open"); open.appendChild(openContent); + modalContent.appendChild(open); // copy - modalContent.appendChild(open); - - // copy - let copy = document.createElement("a"); + var copy = document.createElement("a"); copy.id = "mailgo-copy"; copy.href = "#mailgo-copy"; copy.classList.add("mailgo-copy"); copy.classList.add("mailgo-weight-500"); - let copyContent = document.createTextNode("copy"); + var copyContent = document.createTextNode("copy"); copy.appendChild(copyContent); + modalContent.appendChild(copy); // by - modalContent.appendChild(copy); - - // by - let by = document.createElement("a"); + var by = document.createElement("a"); by.href = "https://mailgo.js.org"; by.className = "mailgo-by"; by.target = "_blank"; - let textBy = document.createTextNode("mailgo.js.org"); + var textBy = document.createTextNode("mailgo.js.org"); 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); }; - /** * mailgoRender * 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)) { - 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(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"); bcc = urlParams.get("bcc"); subject = urlParams.get("subject"); @@ -192,40 +165,25 @@ mailgoRender = mailgo => { } else { // if the element href="#mailgo" or class="mailgo" // 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(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"); + cc = mailgo.getAttribute("data-cc-address") + "@" + mailgo.getAttribute("data-cc-domain"); // bcc = data-bcc-address + @ + data-bcc-domain - // bcc = data-bcc-address + @ + data-bcc-domain - bcc = - mailgo.getAttribute("data-bcc-address") + - "@" + - mailgo.getAttribute("data-bcc-domain"); + bcc = mailgo.getAttribute("data-bcc-address") + "@" + mailgo.getAttribute("data-bcc-domain"); // subject = data-subject - // subject = data-subject - subject = mailgo.getAttribute("data-subject"); + subject = mailgo.getAttribute("data-subject"); // body = data-body - // body = 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(bcc)) bcc = ""; + if (!validateEmail(bcc)) bcc = ""; // information - // information titleEl = getE("mailgo-title"); detailsEl = getE("mailgo-details"); ccEl = getE("mailgo-cc"); @@ -235,70 +193,36 @@ mailgoRender = mailgo => { subjectEl = getE("mailgo-subject"); subjectValueEl = getE("mailgo-subject-value"); bodyEl = getE("mailgo-body"); - bodyValueEl = getE("mailgo-body-value"); + bodyValueEl = getE("mailgo-body-value"); // actions - // actions gmailButton = getE("mailgo-gmail"); outlookButton = getE("mailgo-outlook"); 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; + titleEl.textContent = mail; // add the details if provided - // add the details if provided - cc - ? ((ccEl.style.display = "block"), (ccValueEl.textContent = cc)) - : (ccEl.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 ? (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 - bcc - ? ((bccEl.style.display = "block"), (bccValueEl.textContent = bcc)) - : (bccEl.style.display = "none"); + 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(/^[$]/, "&"); + 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(); }; - /** * mailgoCheckRender * 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' * ); 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 ( - // first case: it is an 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") || - // fourth case: exists the attribute mailgo in the element - !!e.getAttribute("mailgo") - ) { + if ( // first case: it is an 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") || // fourth case: exists the attribute mailgo in the element + !!e.getAttribute("mailgo")) { // stop the normal execution of the element click - event.preventDefault(); + event.preventDefault(); // render mailgo - // render mailgo mailgoRender(e); } }; - /** * mailgoKeydown * function to manage the keydown event when the modal is showing */ -mailgoKeydown = event => { + + +mailgoKeydown = function mailgoKeydown(event) { switch (event.keyCode) { case 27: // Escape hideMailgo(); break; + default: 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.body.addEventListener("click", mailgoCheckRender, false); +document.addEventListener("DOMContentLoaded", mailgoInit, false); // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered -// 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,}))$/; +document.body.addEventListener("click", mailgoCheckRender, false); // validate the email with regex + +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); -}; +}; // copy of a string -// copy of a string -copyToClipboard = str => { - let el = document.createElement("textarea"); + +copyToClipboard = function copyToClipboard(str) { + var el = document.createElement("textarea"); el.value = str; el.setAttribute("readonly", ""); el.style.position = "absolute"; el.style.left = "-9999px"; document.body.appendChild(el); - let selected = - document.getSelection().rangeCount > 0 - ? document.getSelection().getRangeAt(0) - : false; + var selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; el.select(); document.execCommand("copy"); document.body.removeChild(el); + if (selected) { document.getSelection().removeAllRanges(); 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); -}; +}; // 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); -}; -// decrypt email -mailToEncoded = encoded => (window.location.href = MAILTO + atob(encoded)); +}; // decrypt email -// encode email -encodeEmail = email => btoa(email); -// getE shorthand -getE = id => document.getElementById(id); +mailToEncoded = function mailToEncoded(encoded) { + 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); +}; \ No newline at end of file diff --git a/dist/mailgo.min.js b/dist/mailgo.min.js index 0d07a1a..e0fc647 100644 --- a/dist/mailgo.min.js +++ b/dist/mailgo.min.js @@ -1 +1 @@ -const V="0.3.0",MAILTO="mailto:",mailgoCSS=document.createElement("link");mailgoCSS.rel="stylesheet",mailgoCSS.type="text/css",mailgoCSS.href="https://unpkg.com/mailgo@0.3.0/dist/mailgo.min.css",document.head.appendChild(mailgoCSS),mailgoInit=(()=>{let e=document.createElement("div");e.id="mailgo",e.classList.add("mailgo-modal"),e.style.display="none";let t=document.createElement("div");t.className="mailgo-modal-background",e.appendChild(t);let l=document.createElement("div");l.className="mailgo-modal-content",e.appendChild(l);let a=document.createElement("strong");a.id="mailgo-title",a.className="mailgo-title",l.appendChild(a);let o=document.createElement("div");o.id="mailgo-details",o.className="mailgo-details";let d=document.createElement("p");d.id="mailgo-cc";let n=document.createElement("span");n.className="mailgo-weight-500";let i=document.createTextNode("cc ");n.appendChild(i);let c=document.createElement("span");c.id="mailgo-cc-value",d.appendChild(n),d.appendChild(c),o.appendChild(d);let m=document.createElement("p");m.id="mailgo-bcc";let s=document.createElement("span");s.className="mailgo-weight-500";let g=document.createTextNode("bcc ");s.appendChild(g);let p=document.createElement("span");p.id="mailgo-bcc-value",m.appendChild(s),m.appendChild(p),o.appendChild(m);let u=document.createElement("p");u.id="mailgo-subject";let r=document.createElement("span");r.className="mailgo-weight-500";let E=document.createTextNode("subject");r.appendChild(E);let h=document.createElement("span");h.id="mailgo-subject-value",u.appendChild(r),u.appendChild(h),o.appendChild(u);let b=document.createElement("p");b.id="mailgo-body";let y=document.createElement("span");y.className="mailgo-weight-500";let C=document.createTextNode("body ");y.appendChild(C);let L=document.createElement("span");L.id="mailgo-body-value",b.appendChild(y),b.appendChild(L),o.appendChild(b),l.appendChild(o);let v=document.createElement("a");v.id="mailgo-gmail",v.classList.add("mailgo-open"),v.classList.add("gmail");let k=document.createTextNode("open in ");v.appendChild(k);let w=document.createElement("span");w.className="mailgo-weight-500";let x=document.createTextNode("Gmail");w.appendChild(x),v.appendChild(w),l.appendChild(v);let f=document.createElement("a");f.id="mailgo-outlook",f.classList.add("mailgo-open"),f.classList.add("outlook");let N=document.createTextNode("open in ");f.appendChild(N);let T=document.createElement("span");T.className="mailgo-weight-500";let A=document.createTextNode("Outlook");T.appendChild(A),f.appendChild(T),l.appendChild(f);let S=document.createElement("a");S.id="mailgo-open",S.href="#mailgo-open",S.classList.add("mailgo-open"),S.classList.add("mailgo-weight-500");let j=document.createTextNode("open");S.appendChild(j),l.appendChild(S);let R=document.createElement("a");R.id="mailgo-copy",R.href="#mailgo-copy",R.classList.add("mailgo-copy"),R.classList.add("mailgo-weight-500");let I=document.createTextNode("copy");R.appendChild(I),l.appendChild(R);let M=document.createElement("a");M.href="https://mailgo.js.org",M.className="mailgo-by",M.target="_blank";let B=document.createTextNode("mailgo.js.org");M.appendChild(B),l.appendChild(M),document.body.appendChild(e),t.addEventListener("click",hideMailgo,!1)}),mailgoRender=(e=>{let t="",l="",a="",o="",d="",n="";if(e.href&&e.href.toLowerCase().startsWith(MAILTO)){t=decodeURIComponent(e.href.split("?")[0].split(MAILTO)[1].trim()),l=e.href,url=new URL(l);let i=new URLSearchParams(url.search);a=i.get("cc"),o=i.get("bcc"),d=i.get("subject"),n=i.get("body")}else t=e.getAttribute("data-address")+"@"+e.getAttribute("data-domain"),l=MAILTO+encodeURIComponent(t),url=new URL(l),a=e.getAttribute("data-cc-address")+"@"+e.getAttribute("data-cc-domain"),o=e.getAttribute("data-bcc-address")+"@"+e.getAttribute("data-bcc-domain"),d=e.getAttribute("data-subject"),n=e.getAttribute("data-body");if(!validateEmail(t))return;validateEmail(a)||(a=""),validateEmail(o)||(o=""),titleEl=getE("mailgo-title"),detailsEl=getE("mailgo-details"),ccEl=getE("mailgo-cc"),ccValueEl=getE("mailgo-cc-value"),bccEl=getE("mailgo-bcc"),bccValueEl=getE("mailgo-bcc-value"),subjectEl=getE("mailgo-subject"),subjectValueEl=getE("mailgo-subject-value"),bodyEl=getE("mailgo-body"),bodyValueEl=getE("mailgo-body-value"),gmailButton=getE("mailgo-gmail"),outlookButton=getE("mailgo-outlook"),openButton=getE("mailgo-open"),copyButton=getE("mailgo-copy"),titleEl.textContent=t,a?(ccEl.style.display="block",ccValueEl.textContent=a):ccEl.style.display="none",o?(bccEl.style.display="block",bccValueEl.textContent=o):bccEl.style.display="none",d?(subjectEl.style.display="block",subjectValueEl.textContent=d):subjectEl.style.display="none",n?(bodyEl.style.display="block",bodyValueEl.textContent=n):bodyEl.style.display="none",gmailButton.href="https://mail.google.com/mail?extsrc=mailto&url="+encodeURIComponent(l),outlookButton.href="https://outlook.office.com/owa/?rru=compose&to="+encodeURIComponent(t)+url.search.replace(/^[$]/,"&");let i=encodeEmail(t);openButton.addEventListener("click",()=>{mailToEncoded(i)},!1),copyButton.addEventListener("click",e=>{copyToClipboard(t),copyButton.textContent="copied",setTimeout(()=>{copyButton.textContent="copy"},999)},!1),showMailgo()}),mailgoCheckRender=(e=>{let t=e.target;document.body.contains(getE("mailgo"))&&(t.href&&t.href.toLowerCase().startsWith(MAILTO)&&!t.classList.contains("no-mailgo")||t.href&&"#mailgo"===t.getAttribute("href").toLowerCase()||t.classList.contains("mailgo")||t.getAttribute("mailgo"))&&(e.preventDefault(),mailgoRender(t))}),mailgoKeydown=(e=>{switch(e.keyCode){case 27:hideMailgo();break;default:return}}),document.addEventListener("DOMContentLoaded",mailgoInit,!1),document.body.addEventListener("click",mailgoCheckRender,!1),validateEmail=(e=>{return/^(([^<>()[\]\\.,;:\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,}))$/.test(e)}),copyToClipboard=(e=>{let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t);let l=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),l&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(l))}),showMailgo=(()=>{getE("mailgo").style.display="flex",document.body.addEventListener("keydown",mailgoKeydown,!1)}),hideMailgo=(()=>{getE("mailgo").style.display="none",document.body.removeEventListener("keydown",mailgoKeydown,!1)}),mailToEncoded=(e=>window.location.href=MAILTO+atob(e)),encodeEmail=(e=>btoa(e)),getE=(e=>document.getElementById(e)); \ No newline at end of file +"use strict";var V="0.3.1",MAILTO="mailto:",mailgoCSS=document.createElement("link");mailgoCSS.rel="stylesheet",mailgoCSS.type="text/css",mailgoCSS.href="https://unpkg.com/mailgo@"+V+"/dist/mailgo.min.css",document.head.appendChild(mailgoCSS),mailgoInit=function(){var e=document.createElement("div");e.id="mailgo",e.classList.add("mailgo-modal"),e.style.display="none";var t=document.createElement("div");t.className="mailgo-modal-background",e.appendChild(t);var a=document.createElement("div");a.className="mailgo-modal-content",e.appendChild(a);var o=document.createElement("strong");o.id="mailgo-title",o.className="mailgo-title",a.appendChild(o);var l=document.createElement("div");l.id="mailgo-details",l.className="mailgo-details";var n=document.createElement("p");n.id="mailgo-cc";var d=document.createElement("span");d.className="mailgo-weight-500";var i=document.createTextNode("cc ");d.appendChild(i);var c=document.createElement("span");c.id="mailgo-cc-value",n.appendChild(d),n.appendChild(c),l.appendChild(n);var m=document.createElement("p");m.id="mailgo-bcc";var r=document.createElement("span");r.className="mailgo-weight-500";var s=document.createTextNode("bcc ");r.appendChild(s);var g=document.createElement("span");g.id="mailgo-bcc-value",m.appendChild(r),m.appendChild(g),l.appendChild(m);var p=document.createElement("p");p.id="mailgo-subject";var u=document.createElement("span");u.className="mailgo-weight-500";var E=document.createTextNode("subject");u.appendChild(E);var h=document.createElement("span");h.id="mailgo-subject-value",p.appendChild(u),p.appendChild(h),l.appendChild(p);var v=document.createElement("p");v.id="mailgo-body";var b=document.createElement("span");b.className="mailgo-weight-500";var y=document.createTextNode("body ");b.appendChild(y);var C=document.createElement("span");C.id="mailgo-body-value",v.appendChild(b),v.appendChild(C),l.appendChild(v),a.appendChild(l);var f=document.createElement("a");f.id="mailgo-gmail",f.classList.add("mailgo-open"),f.classList.add("gmail");var L=document.createTextNode("open in ");f.appendChild(L);var k=document.createElement("span");k.className="mailgo-weight-500";var w=document.createTextNode("Gmail");k.appendChild(w),f.appendChild(k),a.appendChild(f);var x=document.createElement("a");x.id="mailgo-outlook",x.classList.add("mailgo-open"),x.classList.add("outlook");var N=document.createTextNode("open in ");x.appendChild(N);var T=document.createElement("span");T.className="mailgo-weight-500";var A=document.createTextNode("Outlook");T.appendChild(A),x.appendChild(T),a.appendChild(x);var S=document.createElement("a");S.id="mailgo-open",S.href="#mailgo-open",S.classList.add("mailgo-open"),S.classList.add("mailgo-weight-500");var j=document.createTextNode("open");S.appendChild(j),a.appendChild(S);var R=document.createElement("a");R.id="mailgo-copy",R.href="#mailgo-copy",R.classList.add("mailgo-copy"),R.classList.add("mailgo-weight-500");var I=document.createTextNode("copy");R.appendChild(I),a.appendChild(R);var M=document.createElement("a");M.href="https://mailgo.js.org",M.className="mailgo-by",M.target="_blank";var B=document.createTextNode("mailgo.js.org");M.appendChild(B),a.appendChild(M),document.body.appendChild(e),t.addEventListener("click",hideMailgo,!1)},mailgoRender=function(e){var t="",a="",o="",l="",n="",d="";if(e.href&&e.href.toLowerCase().startsWith(MAILTO)){t=decodeURIComponent(e.href.split("?")[0].split(MAILTO)[1].trim()),a=e.href,url=new URL(a);var i=new URLSearchParams(url.search);o=i.get("cc"),l=i.get("bcc"),n=i.get("subject"),d=i.get("body")}else t=e.getAttribute("data-address")+"@"+e.getAttribute("data-domain"),a=MAILTO+encodeURIComponent(t),url=new URL(a),o=e.getAttribute("data-cc-address")+"@"+e.getAttribute("data-cc-domain"),l=e.getAttribute("data-bcc-address")+"@"+e.getAttribute("data-bcc-domain"),n=e.getAttribute("data-subject"),d=e.getAttribute("data-body");if(validateEmail(t)){validateEmail(o)||(o=""),validateEmail(l)||(l=""),titleEl=getE("mailgo-title"),detailsEl=getE("mailgo-details"),ccEl=getE("mailgo-cc"),ccValueEl=getE("mailgo-cc-value"),bccEl=getE("mailgo-bcc"),bccValueEl=getE("mailgo-bcc-value"),subjectEl=getE("mailgo-subject"),subjectValueEl=getE("mailgo-subject-value"),bodyEl=getE("mailgo-body"),bodyValueEl=getE("mailgo-body-value"),gmailButton=getE("mailgo-gmail"),outlookButton=getE("mailgo-outlook"),openButton=getE("mailgo-open"),copyButton=getE("mailgo-copy"),titleEl.textContent=t,o?(ccEl.style.display="block",ccValueEl.textContent=o):ccEl.style.display="none",l?(bccEl.style.display="block",bccValueEl.textContent=l):bccEl.style.display="none",n?(subjectEl.style.display="block",subjectValueEl.textContent=n):subjectEl.style.display="none",d?(bodyEl.style.display="block",bodyValueEl.textContent=d):bodyEl.style.display="none",gmailButton.href="https://mail.google.com/mail?extsrc=mailto&url="+encodeURIComponent(a),outlookButton.href="https://outlook.office.com/owa/?rru=compose&to="+encodeURIComponent(t)+url.search.replace(/^[$]/,"&");var c=encodeEmail(t);openButton.addEventListener("click",function(){mailToEncoded(c)},!1),copyButton.addEventListener("click",function(e){copyToClipboard(t),copyButton.textContent="copied",setTimeout(function(){copyButton.textContent="copy"},999)},!1),showMailgo()}},mailgoCheckRender=function(e){var t=e.target;document.body.contains(getE("mailgo"))&&(t.href&&t.href.toLowerCase().startsWith(MAILTO)&&!t.classList.contains("no-mailgo")||t.href&&"#mailgo"===t.getAttribute("href").toLowerCase()||t.classList.contains("mailgo")||t.getAttribute("mailgo"))&&(e.preventDefault(),mailgoRender(t))},mailgoKeydown=function(e){switch(e.keyCode){case 27:hideMailgo();break;default:return}},document.addEventListener("DOMContentLoaded",mailgoInit,!1),document.body.addEventListener("click",mailgoCheckRender,!1),validateEmail=function(e){return/^(([^<>()[\]\\.,;:\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,}))$/.test(e)},copyToClipboard=function(e){var t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t);var a=document.getSelection().rangeCount>0&&document.getSelection().getRangeAt(0);t.select(),document.execCommand("copy"),document.body.removeChild(t),a&&(document.getSelection().removeAllRanges(),document.getSelection().addRange(a))},showMailgo=function(){getE("mailgo").style.display="flex",document.body.addEventListener("keydown",mailgoKeydown,!1)},hideMailgo=function(){getE("mailgo").style.display="none",document.body.removeEventListener("keydown",mailgoKeydown,!1)},mailToEncoded=function(e){return window.location.href=MAILTO+atob(e)},encodeEmail=function(e){return btoa(e)},getE=function(e){return document.getElementById(e)}; \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 9f9d622..75db65e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,17 +5,29 @@ const rename = require("gulp-rename"); const csso = require("gulp-csso"); const replace = require("gulp-replace"); +const babel = require("gulp-babel"); + let version = require("./package.json").version; function js() { return src("src/*.js") .pipe(replace("MAILGO_VERSION", version.toString())) + .pipe( + babel({ + presets: ["@babel/env"] + }) + ) .pipe(dest("dist")); } function jsmin() { return src("src/*.js") .pipe(replace("MAILGO_VERSION", version)) + .pipe( + babel({ + presets: ["@babel/env"] + }) + ) .pipe(terser()) .pipe( rename({ diff --git a/package.json b/package.json index 7e95eb8..c4a1d6d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@babel/core": "^7.4.4", "@babel/preset-env": "^7.4.4", "gulp": "^4.0.2", + "gulp-babel": "^8.0.0", "gulp-csso": "^3.0.1", "gulp-rename": "^1.4.0", "gulp-replace": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index e9e435b..c5f19d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1293,9 +1293,9 @@ editions@^1.3.3: integrity sha512-gzao+mxnYDzIysXKMQi/+M1mjy/rjestjg6OPoYTtI+3Izp23oiGZitsl9lPDPiTGXbcSIk1iJWhliSaglxnUg== electron-to-chromium@^1.3.133: - version "1.3.133" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.133.tgz#c47639c19b91feee3e22fad69f5556142007008c" - integrity sha512-lyoC8aoqbbDqsprb6aPdt9n3DpOZZzdz/T4IZKsR0/dkZIxnJVUjjcpOSwA66jPRIOyDAamCTAUqweU05kKNSg== + version "1.3.134" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.134.tgz#550222bddac43c6bd6c445c3543a0fe8a615021d" + integrity sha512-C3uK2SrtWg/gSWaluLHWSHjyebVZCe4ZC0NVgTAoTq8tCR9FareRK5T7R7AS/nPZShtlEcjVMX1kQ8wi4nU68w== end-of-stream@^1.0.0, end-of-stream@^1.1.0: 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" 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: version "2.2.0" resolved "https://registry.yarnpkg.com/gulp-cli/-/gulp-cli-2.2.0.tgz#5533126eeb7fe415a7e3e84a297d334d5cf70ebc"