mailymaily/dist/mailgo.min.js
Matteo Manzinello 62170ecf4c added gulp-babel
2019-05-15 09:23:06 +02:00

1 line
6.7 KiB
JavaScript

"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)};