diff --git a/dist/mailgo.min.js b/dist/mailgo.min.js index 6f2ebab..496fb55 100644 --- a/dist/mailgo.min.js +++ b/dist/mailgo.min.js @@ -1 +1 @@ -"use strict";var gmailButton,outlookButton,openButton,telegramButton,waButton,skypeButton,callButton,copyButton,V="0.7.8",windowExists=function(){return window&&"undefined"!=typeof window},MAILTO="mailto:",TEL="tel:",CALLTO="callto:",MAIL_TYPE="mail",TEL_TYPE="tel",DEFAULT_BTN_HREF="javascript:void(0);",url="",mail="",encEmail="",cc="",bcc="",subject="",bodyMail="",tel="",msg="",telegramUsername="",skypeUsername="";if(windowExists()){var mailgoCSS=document.createElement("style");mailgoCSS.id="mailgo-style",mailgoCSS.type="text/css";var mailgoCSSContent=document.createTextNode('.mailgo-modal{position:fixed;top:0;right:0;bottom:0;left:0;-webkit-box-pack:center;-webkit-justify-content:center;-moz-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center;-moz-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-moz-box-orient:vertical;-moz-box-direction:normal;-ms-flex-direction:column;flex-direction:column;overflow:hidden;font-size:15px;z-index:10000}.mailgo-modal a,.mailgo-modal p,.mailgo-modal span,.mailgo-modal strong{margin:0;padding:0;font-size:100%;line-height:1;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"}.mailgo-modal strong{font-weight:700}.mailgo-modal .mailgo-modal-background{position:absolute;z-index:10001;top:0;right:0;bottom:0;left:0;background-color:rgba(32,35,42,.75);opacity:.8}.mailgo-modal .mailgo-modal-content{position:relative;z-index:10002;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;text-align:center;min-width:200px;max-width:240px;background-color:#fff;opacity:.97;-webkit-border-radius:8px;-moz-border-radius:8px;border-radius:8px;-webkit-box-shadow:0 3px 20px rgba(32,35,42,.5);-moz-box-shadow:0 3px 20px rgba(32,35,42,.5);box-shadow:0 3px 20px rgba(32,35,42,.5);color:#4a4a4a;display:-webkit-box;display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-moz-box-orient:vertical;-moz-box-direction:normal;-ms-flex-direction:column;flex-direction:column;overflow:auto;padding:20px;-webkit-transition:.5s -webkit-box-shadow;transition:.5s -webkit-box-shadow;-o-transition:.5s box-shadow;-moz-transition:.5s box-shadow,.5s -moz-box-shadow;transition:.5s box-shadow;transition:.5s box-shadow,.5s -webkit-box-shadow,.5s -moz-box-shadow}.mailgo-modal .mailgo-modal-content:hover{opacity:1;-webkit-box-shadow:0 7px 20px rgba(32,35,42,.85);-moz-box-shadow:0 7px 20px rgba(32,35,42,.85);box-shadow:0 7px 20px rgba(32,35,42,.85)}.mailgo-modal .mailgo-modal-content .mailgo-title{margin-bottom:8px;overflow:hidden;white-space:nowrap;-o-text-overflow:ellipsis;text-overflow:ellipsis}.mailgo-modal .mailgo-modal-content .mailgo-details{margin-bottom:10px}.mailgo-modal .mailgo-modal-content .mailgo-details p{font-size:12px;margin-top:3px;margin-bottom:3px}.mailgo-modal .mailgo-modal-content a{padding:10px;color:#4a4a4a;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;text-decoration:none}.mailgo-modal .mailgo-modal-content a.mailgo-gmail{color:#d44638}.mailgo-modal .mailgo-modal-content a.mailgo-outlook{color:#0072c6}.mailgo-modal .mailgo-modal-content a.mailgo-wa{color:#00bfa5}.mailgo-modal .mailgo-modal-content a.mailgo-telegram{color:#08c}.mailgo-modal .mailgo-modal-content a.mailgo-skype{color:#00aff0}.mailgo-modal .mailgo-modal-content a.mailgo-copy{padding:16px 10px;font-size:16px}.mailgo-modal .mailgo-modal-content a.mailgo-copy:hover,.mailgo-modal .mailgo-modal-content a.mailgo-default:hover{background-color:rgba(0,0,0,.08);color:#4a4a4a}.mailgo-modal .mailgo-modal-content a.mailgo-gmail:hover{background-color:rgba(212,70,56,.08);color:#d44638}.mailgo-modal .mailgo-modal-content a.mailgo-outlook:hover{background-color:rgba(0,114,198,.08);color:#0072c6}.mailgo-modal .mailgo-modal-content a.mailgo-telegram:hover{background-color:rgba(0,114,198,.08);color:#08c}.mailgo-modal .mailgo-modal-content a.mailgo-wa:hover{background-color:rgba(0,191,165,.08);color:#00bfa5}.mailgo-modal .mailgo-modal-content a.mailgo-skype:hover{background-color:rgba(0,175,240,.08);color:#00aff0}.mailgo-modal .mailgo-modal-content a.mailgo-by{font-size:8px;margin-top:.8rem;padding:5px;color:#4a4a4a;opacity:.5}.mailgo-modal .mailgo-modal-content a.mailgo-by:hover{opacity:1}.mailgo-modal .mailgo-modal-content .mailgo-weight-500{font-weight:500}');mailgoCSS.appendChild(mailgoCSSContent),document.head.appendChild(mailgoCSS)}var mailgoInit=function(){var e=document.createElement("div");e.style.display="none",e.id="mailgo",e.classList.add("mailgo-modal");var a=document.createElement("div");a.className="mailgo-modal-background",e.appendChild(a);var o=document.createElement("div");o.className="mailgo-modal-content",e.appendChild(o);var t=document.createElement("strong");t.id="mailgo-title",t.className="mailgo-title",o.appendChild(t);var i=document.createElement("div");i.id="mailgo-details",i.className="mailgo-details";var l=document.createElement("p");l.id="mailgo-cc";var n=document.createElement("span");n.className="mailgo-weight-500";var d=document.createTextNode("cc ");n.appendChild(d);var c=document.createElement("span");c.id="mailgo-cc-value",l.appendChild(n),l.appendChild(c),i.appendChild(l);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),i.appendChild(m);var p=document.createElement("p");p.id="mailgo-subject";var u=document.createElement("span");u.className="mailgo-weight-500";var b=document.createTextNode("subject ");u.appendChild(b);var h=document.createElement("span");h.id="mailgo-subject-value",p.appendChild(u),p.appendChild(h),i.appendChild(p);var E=document.createElement("p");E.id="mailgo-body";var v=document.createElement("span");v.className="mailgo-weight-500";var f=document.createTextNode("body ");v.appendChild(f);var y=document.createElement("span");y.id="mailgo-body-value",E.appendChild(v),E.appendChild(y),i.appendChild(E),o.appendChild(i);var x=document.createElement("a");x.id="mailgo-gmail",x.href=DEFAULT_BTN_HREF,x.classList.add("mailgo-open"),x.classList.add("mailgo-gmail");var w=document.createTextNode("open in ");x.appendChild(w);var L=document.createElement("span");L.className="mailgo-weight-500";var C=document.createTextNode("Gmail");L.appendChild(C),x.appendChild(L),o.appendChild(x);var k=document.createElement("a");k.id="mailgo-outlook",k.href=DEFAULT_BTN_HREF,k.classList.add("mailgo-open"),k.classList.add("mailgo-outlook");var T=document.createTextNode("open in ");k.appendChild(T);var A=document.createElement("span");A.className="mailgo-weight-500";var M=document.createTextNode("Outlook");A.appendChild(M),k.appendChild(A),o.appendChild(k);var N=document.createElement("a");N.id="mailgo-open",N.href=DEFAULT_BTN_HREF,N.classList.add("mailgo-open"),N.classList.add("mailgo-default");var _=document.createElement("span");_.className="mailgo-weight-500";var B=document.createTextNode("open");_.appendChild(B);var I=document.createTextNode(" default");N.appendChild(_),N.appendChild(I),o.appendChild(N);var S=document.createElement("a");S.id="mailgo-copy",S.href=DEFAULT_BTN_HREF,S.classList.add("mailgo-copy"),S.classList.add("mailgo-weight-500");var U=document.createTextNode("copy");S.appendChild(U),o.appendChild(S);var j=document.createElement("a");j.href="https://mailgo.js.org?ref=mailgo-modal",j.className="mailgo-by",j.target="_blank",j.rel="noopener noreferrer";var R=document.createTextNode("mailgo.js.org");j.appendChild(R),o.appendChild(j),document.body.appendChild(e),a.addEventListener("click",hideMailgo);var D=document.createElement("div");D.style.display="none",D.id="mailgo-tel",D.classList.add("mailgo-modal");var z=document.createElement("div");z.className="mailgo-modal-background",D.appendChild(z);var P=document.createElement("div");P.className="mailgo-modal-content",D.appendChild(P);var Y=document.createElement("strong");Y.id="mailgo-tel-title",Y.className="mailgo-title",P.appendChild(Y);var F=document.createElement("a");F.id="mailgo-telegram",F.href=DEFAULT_BTN_HREF,F.classList.add("mailgo-open"),F.classList.add("mailgo-telegram"),F.style.display="none";var H=document.createTextNode("open in ");F.appendChild(H);var O=document.createElement("span");O.className="mailgo-weight-500";var W=document.createTextNode("Telegram");O.appendChild(W),F.appendChild(O),P.appendChild(F);var G=document.createElement("a");G.id="mailgo-wa",G.href=DEFAULT_BTN_HREF,G.classList.add("mailgo-open"),G.classList.add("mailgo-wa");var K=document.createTextNode("open in ");G.appendChild(K);var Z=document.createElement("span");Z.className="mailgo-weight-500";var V=document.createTextNode("WhatsApp");Z.appendChild(V),G.appendChild(Z),P.appendChild(G);var $=document.createElement("a");$.id="mailgo-skype",$.href=DEFAULT_BTN_HREF,$.classList.add("mailgo-open"),$.classList.add("mailgo-skype");var q=document.createTextNode("open in ");$.appendChild(q);var J=document.createElement("span");J.className="mailgo-weight-500";var Q=document.createTextNode("Skype");J.appendChild(Q),$.appendChild(J),P.appendChild($);var X=document.createElement("a");X.id="mailgo-call",X.href=DEFAULT_BTN_HREF,X.classList.add("mailgo-open"),X.classList.add("mailgo-default");var ee=document.createElement("span");ee.className="mailgo-weight-500";var ae=document.createTextNode("call");ee.appendChild(ae);var oe=document.createTextNode(" as default");X.appendChild(ee),X.appendChild(oe),P.appendChild(X);var te=document.createElement("a");te.id="mailgo-tel-copy",te.href=DEFAULT_BTN_HREF,te.classList.add("mailgo-copy"),te.classList.add("mailgo-weight-500");var ie=document.createTextNode("copy");te.appendChild(ie),P.appendChild(te);var le=document.createElement("a");le.href="https://mailgo.js.org?ref=mailgo-modal",le.className="mailgo-by",le.target="_blank",le.rel="noopener noreferrer";var ne=document.createTextNode("mailgo.js.org");le.appendChild(ne),P.appendChild(le),document.body.appendChild(D),z.addEventListener("click",hideMailgo)},mailgoRender=function(e,a){var o=0"),cc?(n.style.display="block",d.innerHTML=cc.split(",").join("
")):n.style.display="none",bcc?(c.style.display="block",m.innerHTML=bcc.split(",").join("
")):c.style.display="none",subject?(r.style.display="block",s.textContent=subject):r.style.display="none",bodyMail?(g.style.display="block",p.textContent=bodyMail):g.style.display="none",gmailButton.addEventListener("click",function(){return actions.openGmail()}),outlookButton.addEventListener("click",function(){return actions.openOutlook()}),encEmail=encodeEmail(mail),openButton.addEventListener("click",function(){return actions.openDefault()}),copyButton.addEventListener("click",function(){return actions.copy(mail||tel)})}if(o===TEL_TYPE){t.href&&t.href.toLowerCase().startsWith(TEL)?tel=decodeURIComponent(t.href.split("?")[0].split(TEL)[1].trim()):t.href&&t.href.toLowerCase().startsWith(CALLTO)?tel=decodeURIComponent(t.href.split("?")[0].split(CALLTO)[1].trim()):t.hasAttribute("data-tel")&&(tel=t.getAttribute("data-tel"),msg=t.getAttribute("data-msg"));var u=getE("mailgo-tel-title");t.hasAttribute("data-telegram")&&(telegramUsername=t.getAttribute("data-telegram")),t.hasAttribute("data-skype")&&(skypeUsername=t.getAttribute("data-skype")),telegramButton=getE("mailgo-telegram"),waButton=getE("mailgo-wa"),skypeButton=getE("mailgo-skype"),callButton=getE("mailgo-call"),copyButton=getE("mailgo-tel-copy"),u.innerHTML=tel,waButton.addEventListener("click",function(){return actions.openWhatsApp()}),telegramUsername&&(setDisplay("mailgo-telegram","block"),telegramButton.addEventListener("click",function(){return actions.openTelegram()})),skypeButton.addEventListener("click",function(){return actions.openSkype()}),callButton.addEventListener("click",function(){return actions.callDefault()}),copyButton.addEventListener("click",function(){return actions.copy(tel)})}showMailgo(o),document.addEventListener("keydown",mailgoKeydown)},actions={openGmail:function(){var e="https://mail.google.com/mail/u/0/?view=cm&source=mailto&to="+encodeURIComponent(mail);cc&&(e=e.concat("&cc="+encodeURIComponent(cc))),bcc&&(e=e.concat("&bcc="+encodeURIComponent(bcc))),subject&&(e=e.concat("&subject="+subject)),bodyMail&&(e=e.concat("&body="+bodyMail)),window.open(e,"_blank"),hideMailgo()},openOutlook:function(){var e="https://outlook.live.com/owa/?path=/mail/action/compose&to="+encodeURIComponent(mail);subject&&(e=e.concat("&subject="+subject)),bodyMail&&(e=e.concat("&body="+bodyMail)),window.open(e,"_blank"),hideMailgo()},openDefault:function(){mailToEncoded(encEmail),hideMailgo()},openTelegram:function(){var e="https://t.me/"+telegramUsername;window.open(e,"_blank"),hideMailgo()},openSkype:function(){var e="skype:"+(""!==skypeUsername?skypeUsername:tel);window.open(e,"_blank"),hideMailgo()},openWhatsApp:function(){var e="https://wa.me/"+tel;window.open(e,"_blank"),hideMailgo()},callDefault:function(){var e="tel:"+tel;window.open(e),hideMailgo()},copy:function(e){copyToClipboard(e),(copyButton=mailgoIsShowing(MAIL_TYPE)?getE("mailgo-copy"):getE("mailgo-tel-copy")).textContent="copied",setTimeout(function(){copyButton.textContent="copy",hideMailgo()},999)}},isMailgo=function(e,a){var o=1()[\]\\.,;:\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)},validateEmails=function(e){return e.every(validateEmail)},copyToClipboard=function(e){var a=document.createElement("textarea");a.value=e,a.setAttribute("readonly",""),a.style.position="absolute",a.style.left="-9999px",document.body.appendChild(a);var o=0"),S?(l.style.display="block",d.innerHTML=S.split(",").join("
")):l.style.display="none",I?(c.style.display="block",m.innerHTML=I.split(",").join("
")):c.style.display="none",W?(r.style.display="block",s.textContent=W):r.style.display="none",M?(p.style.display="block",g.textContent=M):p.style.display="none",h.addEventListener("click",function(){return G.openGmail()}),b.addEventListener("click",function(){return G.openOutlook()}),U=F(R),v.addEventListener("click",function(){return G.openDefault()}),k.addEventListener("click",function(){return G.copy(R||H)})}if(o===z){t.href&&t.href.toLowerCase().startsWith(L)?H=decodeURIComponent(t.href.split("?")[0].split(L)[1].trim()):t.href&&t.href.toLowerCase().startsWith(N)?H=decodeURIComponent(t.href.split("?")[0].split(N)[1].trim()):t.hasAttribute("data-tel")&&(H=t.getAttribute("data-tel"),t.getAttribute("data-msg"));var u=$("mailgo-tel-title");t.hasAttribute("data-telegram")&&(_=t.getAttribute("data-telegram")),t.hasAttribute("data-skype")&&(O=t.getAttribute("data-skype")),f=$("mailgo-telegram"),x=$("mailgo-wa"),w=$("mailgo-skype"),y=$("mailgo-call"),k=$("mailgo-tel-copy"),u.innerHTML=H,x.addEventListener("click",function(){return G.openWhatsApp()}),_&&(q("mailgo-telegram","block"),f.addEventListener("click",function(){return G.openTelegram()})),w.addEventListener("click",function(){return G.openSkype()}),y.addEventListener("click",function(){return G.callDefault()}),k.addEventListener("click",function(){return G.copy(H)})}Z(o),document.addEventListener("keydown",P)}function D(e,a){var o=1()[\]\\.,;:\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)}var h,b,v,f,x,w,y,k,C="mailto:",L="tel:",N="callto:",T="mail",z="tel",de="javascript:void(0);",j="",R="",U="",S="",I="",W="",M="",H="",_="",O="",G={openGmail:function(){var e="https://mail.google.com/mail/u/0/?view=cm&source=mailto&to="+encodeURIComponent(R);S&&(e=e.concat("&cc="+encodeURIComponent(S))),I&&(e=e.concat("&bcc="+encodeURIComponent(I))),W&&(e=e.concat("&subject="+W)),M&&(e=e.concat("&body="+M)),window.open(e,"_blank"),ce()},openOutlook:function(){var e="https://outlook.live.com/owa/?path=/mail/action/compose&to="+encodeURIComponent(R);W&&(e=e.concat("&subject="+W)),M&&(e=e.concat("&body="+M)),window.open(e,"_blank"),ce()},openDefault:function(){e(U),ce()},openTelegram:function(){var e="https://t.me/"+_;window.open(e,"_blank"),ce()},openSkype:function(){var e="skype:"+(""!==O?O:H);window.open(e,"_blank"),ce()},openWhatsApp:function(){var e="https://wa.me/"+H;window.open(e,"_blank"),ce()},callDefault:function(){var e="tel:"+H;window.open(e),ce()},copy:function(e){a(e),(k=o(T)?$("mailgo-copy"):$("mailgo-tel-copy")).textContent="copied",setTimeout(function(){k.textContent="copy",ce()},999)}},P=function(e){if(o(T))switch(e.keyCode){case 27:ce();break;case 71:G.openGmail();break;case 79:G.openOutlook();break;case 32:case 13:G.openDefault();break;case 67:G.copy(R);break;default:return}else if(o(z))switch(e.keyCode){case 27:ce();break;case 84:G.openTelegram();break;case 87:G.openWhatsApp();break;case 32:case 13:G.callDefault();break;case 67:G.copy(H);break;default:return}},Z=function(e){var a=0"),x?(T.style.display="block",j.innerHTML=x.split(",").join("
")):T.style.display="none",y?(z.style.display="block",U.innerHTML=y.split(",").join("
")):z.style.display="none",w?(_.style.display="block",I.textContent=w):_.style.display="none",k?(W.style.display="block",P.textContent=k):W.style.display="none",t.addEventListener("click",(function(){return A.openGmail()})),n.addEventListener("click",(function(){return A.openOutlook()})),v=M(f),i.addEventListener("click",(function(){return A.openDefault()})),m.addEventListener("click",(function(){return A.copy(f||C)}))}if("tel"===o){s.href&&s.href.toLowerCase().startsWith(g)?C=decodeURIComponent(s.href.split("?")[0].split(g)[1].trim()):s.href&&s.href.toLowerCase().startsWith(u)?C=decodeURIComponent(s.href.split("?")[0].split(u)[1].trim()):s.hasAttribute("data-tel")&&(C=s.getAttribute("data-tel"),s.getAttribute("data-msg"));var H=O("mailgo-tel-title");s.hasAttribute("data-telegram")&&(E=s.getAttribute("data-telegram")),s.hasAttribute("data-skype")&&(L=s.getAttribute("data-skype")),l=O("mailgo-telegram"),d=O("mailgo-wa"),r=O("mailgo-skype"),c=O("mailgo-call"),m=O("mailgo-tel-copy"),H.innerHTML=C,d.addEventListener("click",(function(){return A.openWhatsApp()})),E&&(D("mailgo-telegram","block"),l.addEventListener("click",(function(){return A.openTelegram()}))),r.addEventListener("click",(function(){return A.openSkype()})),c.addEventListener("click",(function(){return A.callDefault()})),m.addEventListener("click",(function(){return A.copy(C)}))}R(o),document.addEventListener("keydown",S)},A={openGmail:function(){var e="https://mail.google.com/mail/u/0/?view=cm&source=mailto&to="+encodeURIComponent(f);x&&(e=e.concat("&cc="+encodeURIComponent(x))),y&&(e=e.concat("&bcc="+encodeURIComponent(y))),w&&(e=e.concat("&subject="+w)),k&&(e=e.concat("&body="+k)),window.open(e,"_blank"),U()},openOutlook:function(){var e="https://outlook.live.com/owa/?path=/mail/action/compose&to="+encodeURIComponent(f);w&&(e=e.concat("&subject="+w)),k&&(e=e.concat("&body="+k)),window.open(e,"_blank"),U()},openDefault:function(){I(v),U()},openTelegram:function(){var e="https://t.me/"+E;window.open(e,"_blank"),U()},openSkype:function(){var e="skype:"+(""!==L?L:C);window.open(e,"_blank"),U()},openWhatsApp:function(){var e="https://wa.me/"+C;window.open(e,"_blank"),U()},callDefault:function(){var e="tel:"+C;window.open(e),U()},copy:function(e){B(e),(m=_("mail")?O("mailgo-copy"):O("mailgo-tel-copy")).textContent="copied",setTimeout((function(){m.textContent="copy",U()}),999)}},z=function(e,a){var o=1()[\]\\.,;:\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)},G=function(e){return e.every(H)},B=function(e){var a=document.createElement("textarea");a.value=e,a.setAttribute("readonly",""),a.style.position="absolute",a.style.left="-9999px",document.body.appendChild(a);var o=0"),k?(R.style.display="block",U.innerHTML=k.split(",").join("
")):R.style.display="none",C?(_.style.display="block",O.innerHTML=C.split(",").join("
")):_.style.display="none",E?(D.style.display="block",H.textContent=E):D.style.display="none",L?(G.style.display="block",B.textContent=L):G.style.display="none",i.addEventListener("click",(function(){return A.openGmail()})),l.addEventListener("click",(function(){return A.openOutlook()})),w=I(y),d.addEventListener("click",(function(){return A.openDefault()})),p.addEventListener("click",(function(){return A.copy(y||N)}))}if(o===h){t.href&&t.href.toLowerCase().startsWith(u)?N=decodeURIComponent(t.href.split("?")[0].split(u)[1].trim()):t.href&&t.href.toLowerCase().startsWith(b)?N=decodeURIComponent(t.href.split("?")[0].split(b)[1].trim()):t.hasAttribute("data-tel")&&(N=t.getAttribute("data-tel"),t.getAttribute("data-msg"));var Z=M("mailgo-tel-title");t.hasAttribute("data-telegram")&&(T=t.getAttribute("data-telegram")),t.hasAttribute("data-skype")&&(j=t.getAttribute("data-skype")),r=M("mailgo-telegram"),c=M("mailgo-wa"),m=M("mailgo-skype"),s=M("mailgo-call"),p=M("mailgo-tel-copy"),Z.innerHTML=N,c.addEventListener("click",(function(){return A.openWhatsApp()})),T&&(W("mailgo-telegram","block"),r.addEventListener("click",(function(){return A.openTelegram()}))),m.addEventListener("click",(function(){return A.openSkype()})),s.addEventListener("click",(function(){return A.callDefault()})),p.addEventListener("click",(function(){return A.copy(N)}))}S(o),document.addEventListener("keydown",z)}function o(e,a){var o=1()[\]\\.,;:\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)}var i,l,d,r,c,m,s,p,g="mailto:",u="tel:",b="callto:",f="mail",h="tel",v="javascript:void(0);",x="",y="",w="",k="",C="",E="",L="",N="",T="",j="",A={openGmail:function(){var e="https://mail.google.com/mail/u/0/?view=cm&source=mailto&to="+encodeURIComponent(y);k&&(e=e.concat("&cc="+encodeURIComponent(k))),C&&(e=e.concat("&bcc="+encodeURIComponent(C))),E&&(e=e.concat("&subject="+E)),L&&(e=e.concat("&body="+L)),window.open(e,"_blank"),R()},openOutlook:function(){var e="https://outlook.live.com/owa/?path=/mail/action/compose&to="+encodeURIComponent(y);E&&(e=e.concat("&subject="+E)),L&&(e=e.concat("&body="+L)),window.open(e,"_blank"),R()},openDefault:function(){_(w),R()},openTelegram:function(){var e="https://t.me/"+T;window.open(e,"_blank"),R()},openSkype:function(){var e="skype:"+(""!==j?j:N);window.open(e,"_blank"),R()},openWhatsApp:function(){var e="https://wa.me/"+N;window.open(e,"_blank"),R()},callDefault:function(){var e="tel:"+N;window.open(e),R()},copy:function(e){H(e),(p=U(f)?M("mailgo-copy"):M("mailgo-tel-copy")).textContent="copied",setTimeout((function(){p.textContent="copy",R()}),999)}},z=function(e){if(U(f))switch(e.keyCode){case 27:R();break;case 71:A.openGmail();break;case 79:A.openOutlook();break;case 32:case 13:A.openDefault();break;case 67:A.copy(y);break;default:return}else if(U(h))switch(e.keyCode){case 27:R();break;case 84:A.openTelegram();break;case 87:A.openWhatsApp();break;case 32:case 13:A.callDefault();break;case 67:A.copy(N);break;default:return}},S=function(e){var a=0 { + const V = "MAILGO_VERSION"; -// window exists -const windowExists = () => window && typeof window !== "undefined"; + // links + const MAILTO = "mailto:"; + const TEL = "tel:"; + const CALLTO = "callto:"; -// links -const MAILTO = "mailto:"; -const TEL = "tel:"; -const CALLTO = "callto:"; + // mailgo types + const MAIL_TYPE = "mail"; + const TEL_TYPE = "tel"; -// mailgo types -const MAIL_TYPE = "mail"; -const TEL_TYPE = "tel"; + // default href for links + const DEFAULT_BTN_HREF = "javascript:void(0);"; -// default href for links -const DEFAULT_BTN_HREF = "javascript:void(0);"; + // mailgo variables + let url = "", + mail = "", + encEmail = "", + cc = "", + bcc = "", + subject = "", + bodyMail = ""; -// mailgo variables -let url = "", - mail = "", - encEmail = "", - cc = "", - bcc = "", - subject = "", - bodyMail = ""; + // mailgo tel variables + let tel = "", + msg = "", + telegramUsername = "", + skypeUsername = ""; -// mailgo tel variables -let tel = "", - msg = "", - telegramUsername = "", - skypeUsername = ""; + // mailgo buttons + let gmailButton, + outlookButton, + openButton, + telegramButton, + waButton, + skypeButton, + callButton, + copyButton; -// mailgo buttons -let gmailButton, - outlookButton, - openButton, - telegramButton, - waButton, - skypeButton, - callButton, - copyButton; + /** + * mailgoInit + * the function that creates the mailgo elements in DOM + */ + const mailgoInit = () => { + // mailgo mail + { + // modal + let modal = document.createElement("div"); + modal.style.display = "none"; + modal.id = "mailgo"; + modal.classList.add("mailgo-modal"); -if (windowExists()) { - // mailgo style (gulp) - let mailgoCSS = document.createElement("style"); - mailgoCSS.id = "mailgo-style"; - mailgoCSS.type = "text/css"; - let mailgoCSSContent = document.createTextNode(`MAILGO_STYLE`); - mailgoCSS.appendChild(mailgoCSSContent); - document.head.appendChild(mailgoCSS); -} + // background + let modalBackground = document.createElement("div"); + modalBackground.className = "mailgo-modal-background"; + modal.appendChild(modalBackground); -/** - * mailgoInit - * the function that creates the mailgo elements in DOM - */ -const mailgoInit = () => { - // mailgo mail - { - // modal - let modal = document.createElement("div"); - modal.style.display = "none"; - modal.id = "mailgo"; - modal.classList.add("mailgo-modal"); + // modal content + let modalContent = document.createElement("div"); + modalContent.className = "mailgo-modal-content"; + modal.appendChild(modalContent); - // background - let modalBackground = document.createElement("div"); - modalBackground.className = "mailgo-modal-background"; - modal.appendChild(modalBackground); + // title (email address) + let title = document.createElement("strong"); + title.id = "mailgo-title"; + title.className = "mailgo-title"; + modalContent.appendChild(title); - // modal content - let modalContent = document.createElement("div"); - modalContent.className = "mailgo-modal-content"; - modal.appendChild(modalContent); + // details + let details = document.createElement("div"); + details.id = "mailgo-details"; + details.className = "mailgo-details"; - // title (email address) - let title = document.createElement("strong"); - title.id = "mailgo-title"; - title.className = "mailgo-title"; - modalContent.appendChild(title); + let detailCc = document.createElement("p"); + detailCc.id = "mailgo-cc"; + let ccSpan = document.createElement("span"); + ccSpan.className = "mailgo-weight-500"; + let ccContent = document.createTextNode("cc "); + ccSpan.appendChild(ccContent); + let ccValue = document.createElement("span"); + ccValue.id = "mailgo-cc-value"; + detailCc.appendChild(ccSpan); + detailCc.appendChild(ccValue); + details.appendChild(detailCc); - // details - let details = document.createElement("div"); - details.id = "mailgo-details"; - details.className = "mailgo-details"; + let detailBcc = document.createElement("p"); + detailBcc.id = "mailgo-bcc"; + let bccSpan = document.createElement("span"); + bccSpan.className = "mailgo-weight-500"; + let bccContent = document.createTextNode("bcc "); + bccSpan.appendChild(bccContent); + let bccValue = document.createElement("span"); + bccValue.id = "mailgo-bcc-value"; + detailBcc.appendChild(bccSpan); + detailBcc.appendChild(bccValue); + details.appendChild(detailBcc); - let detailCc = document.createElement("p"); - detailCc.id = "mailgo-cc"; - let ccSpan = document.createElement("span"); - ccSpan.className = "mailgo-weight-500"; - let ccContent = document.createTextNode("cc "); - ccSpan.appendChild(ccContent); - let ccValue = document.createElement("span"); - ccValue.id = "mailgo-cc-value"; - detailCc.appendChild(ccSpan); - detailCc.appendChild(ccValue); - details.appendChild(detailCc); + let detailSubject = document.createElement("p"); + detailSubject.id = "mailgo-subject"; + let subjectSpan = document.createElement("span"); + subjectSpan.className = "mailgo-weight-500"; + let subjectContent = document.createTextNode("subject "); + subjectSpan.appendChild(subjectContent); + let subjectValue = document.createElement("span"); + subjectValue.id = "mailgo-subject-value"; + detailSubject.appendChild(subjectSpan); + detailSubject.appendChild(subjectValue); + details.appendChild(detailSubject); - let detailBcc = document.createElement("p"); - detailBcc.id = "mailgo-bcc"; - let bccSpan = document.createElement("span"); - bccSpan.className = "mailgo-weight-500"; - let bccContent = document.createTextNode("bcc "); - bccSpan.appendChild(bccContent); - let bccValue = document.createElement("span"); - bccValue.id = "mailgo-bcc-value"; - detailBcc.appendChild(bccSpan); - detailBcc.appendChild(bccValue); - details.appendChild(detailBcc); + let detailBody = document.createElement("p"); + detailBody.id = "mailgo-body"; + let bodySpan = document.createElement("span"); + bodySpan.className = "mailgo-weight-500"; + let bodyContent = document.createTextNode("body "); + bodySpan.appendChild(bodyContent); + let bodyValue = document.createElement("span"); + bodyValue.id = "mailgo-body-value"; + detailBody.appendChild(bodySpan); + detailBody.appendChild(bodyValue); + details.appendChild(detailBody); - let detailSubject = document.createElement("p"); - detailSubject.id = "mailgo-subject"; - let subjectSpan = document.createElement("span"); - subjectSpan.className = "mailgo-weight-500"; - let subjectContent = document.createTextNode("subject "); - subjectSpan.appendChild(subjectContent); - let subjectValue = document.createElement("span"); - subjectValue.id = "mailgo-subject-value"; - detailSubject.appendChild(subjectSpan); - detailSubject.appendChild(subjectValue); - details.appendChild(detailSubject); + modalContent.appendChild(details); - let detailBody = document.createElement("p"); - detailBody.id = "mailgo-body"; - let bodySpan = document.createElement("span"); - bodySpan.className = "mailgo-weight-500"; - let bodyContent = document.createTextNode("body "); - bodySpan.appendChild(bodyContent); - let bodyValue = document.createElement("span"); - bodyValue.id = "mailgo-body-value"; - detailBody.appendChild(bodySpan); - detailBody.appendChild(bodyValue); - details.appendChild(detailBody); + // Gmail + let gmail = document.createElement("a"); + gmail.id = "mailgo-gmail"; + gmail.href = DEFAULT_BTN_HREF; + gmail.classList.add("mailgo-open"); + gmail.classList.add("mailgo-gmail"); + let gmailContent = document.createTextNode("open in "); + gmail.appendChild(gmailContent); + let gmailSpan = document.createElement("span"); + gmailSpan.className = "mailgo-weight-500"; + let gmailSpanContent = document.createTextNode("Gmail"); + gmailSpan.appendChild(gmailSpanContent); + gmail.appendChild(gmailSpan); - modalContent.appendChild(details); + modalContent.appendChild(gmail); - // Gmail - let gmail = document.createElement("a"); - gmail.id = "mailgo-gmail"; - gmail.href = DEFAULT_BTN_HREF; - gmail.classList.add("mailgo-open"); - gmail.classList.add("mailgo-gmail"); - let gmailContent = document.createTextNode("open in "); - gmail.appendChild(gmailContent); - let gmailSpan = document.createElement("span"); - gmailSpan.className = "mailgo-weight-500"; - let gmailSpanContent = document.createTextNode("Gmail"); - gmailSpan.appendChild(gmailSpanContent); - gmail.appendChild(gmailSpan); + // Outlook + let outlook = document.createElement("a"); + outlook.id = "mailgo-outlook"; + outlook.href = DEFAULT_BTN_HREF; + outlook.classList.add("mailgo-open"); + outlook.classList.add("mailgo-outlook"); + let outlookContent = document.createTextNode("open in "); + outlook.appendChild(outlookContent); + let outlookSpan = document.createElement("span"); + outlookSpan.className = "mailgo-weight-500"; + let outlookSpanContent = document.createTextNode("Outlook"); + outlookSpan.appendChild(outlookSpanContent); + outlook.appendChild(outlookSpan); - modalContent.appendChild(gmail); + modalContent.appendChild(outlook); - // Outlook - let outlook = document.createElement("a"); - outlook.id = "mailgo-outlook"; - outlook.href = DEFAULT_BTN_HREF; - outlook.classList.add("mailgo-open"); - outlook.classList.add("mailgo-outlook"); - let outlookContent = document.createTextNode("open in "); - outlook.appendChild(outlookContent); - let outlookSpan = document.createElement("span"); - outlookSpan.className = "mailgo-weight-500"; - let outlookSpanContent = document.createTextNode("Outlook"); - outlookSpan.appendChild(outlookSpanContent); - outlook.appendChild(outlookSpan); + // open default + let open = document.createElement("a"); + open.id = "mailgo-open"; + open.href = DEFAULT_BTN_HREF; + open.classList.add("mailgo-open"); + open.classList.add("mailgo-default"); + let openSpan = document.createElement("span"); + openSpan.className = "mailgo-weight-500"; + let openSpanContent = document.createTextNode("open"); + openSpan.appendChild(openSpanContent); + let openContent = document.createTextNode(" default"); + open.appendChild(openSpan); + open.appendChild(openContent); - modalContent.appendChild(outlook); + modalContent.appendChild(open); - // open default - let open = document.createElement("a"); - open.id = "mailgo-open"; - open.href = DEFAULT_BTN_HREF; - open.classList.add("mailgo-open"); - open.classList.add("mailgo-default"); - let openSpan = document.createElement("span"); - openSpan.className = "mailgo-weight-500"; - let openSpanContent = document.createTextNode("open"); - openSpan.appendChild(openSpanContent); - let openContent = document.createTextNode(" default"); - open.appendChild(openSpan); - open.appendChild(openContent); + // copy + let copy = document.createElement("a"); + copy.id = "mailgo-copy"; + copy.href = DEFAULT_BTN_HREF; + copy.classList.add("mailgo-copy"); + copy.classList.add("mailgo-weight-500"); + let copyContent = document.createTextNode("copy"); + copy.appendChild(copyContent); - modalContent.appendChild(open); + modalContent.appendChild(copy); - // copy - let copy = document.createElement("a"); - copy.id = "mailgo-copy"; - copy.href = DEFAULT_BTN_HREF; - copy.classList.add("mailgo-copy"); - copy.classList.add("mailgo-weight-500"); - let copyContent = document.createTextNode("copy"); - copy.appendChild(copyContent); + // by + let by = document.createElement("a"); + by.href = "https://mailgo.js.org?ref=mailgo-modal"; + by.className = "mailgo-by"; + by.target = "_blank"; + by.rel = "noopener noreferrer"; + let textBy = document.createTextNode("mailgo.js.org"); + by.appendChild(textBy); - modalContent.appendChild(copy); + modalContent.appendChild(by); - // by - let by = document.createElement("a"); - by.href = "https://mailgo.js.org?ref=mailgo-modal"; - by.className = "mailgo-by"; - by.target = "_blank"; - by.rel = "noopener noreferrer"; - let textBy = document.createTextNode("mailgo.js.org"); - by.appendChild(textBy); + // add the modal at the end of the body + document.body.appendChild(modal); - modalContent.appendChild(by); + // every click outside the modal will hide the modal + modalBackground.addEventListener("click", hideMailgo); + } + // mailgo tel + { + // modal + let modal = document.createElement("div"); + modal.style.display = "none"; + modal.id = "mailgo-tel"; + modal.classList.add("mailgo-modal"); - // add the modal at the end of the body - document.body.appendChild(modal); + // background + let modalBackground = document.createElement("div"); + modalBackground.className = "mailgo-modal-background"; + modal.appendChild(modalBackground); - // every click outside the modal will hide the modal - modalBackground.addEventListener("click", hideMailgo); - } - // mailgo tel - { - // modal - let modal = document.createElement("div"); - modal.style.display = "none"; - modal.id = "mailgo-tel"; - modal.classList.add("mailgo-modal"); + // modal content + let modalContent = document.createElement("div"); + modalContent.className = "mailgo-modal-content"; + modal.appendChild(modalContent); - // background - let modalBackground = document.createElement("div"); - modalBackground.className = "mailgo-modal-background"; - modal.appendChild(modalBackground); + // title (telephone number) + let title = document.createElement("strong"); + title.id = "mailgo-tel-title"; + title.className = "mailgo-title"; + modalContent.appendChild(title); - // modal content - let modalContent = document.createElement("div"); - modalContent.className = "mailgo-modal-content"; - modal.appendChild(modalContent); + // Telegram + let telegram = document.createElement("a"); + telegram.id = "mailgo-telegram"; + telegram.href = DEFAULT_BTN_HREF; + telegram.classList.add("mailgo-open"); + telegram.classList.add("mailgo-telegram"); - // title (telephone number) - let title = document.createElement("strong"); - title.id = "mailgo-tel-title"; - title.className = "mailgo-title"; - modalContent.appendChild(title); + // by default not display + telegram.style.display = "none"; - // Telegram - let telegram = document.createElement("a"); - telegram.id = "mailgo-telegram"; - telegram.href = DEFAULT_BTN_HREF; - telegram.classList.add("mailgo-open"); - telegram.classList.add("mailgo-telegram"); + let telegramContent = document.createTextNode("open in "); + telegram.appendChild(telegramContent); + let telegramSpan = document.createElement("span"); + telegramSpan.className = "mailgo-weight-500"; + let telegramSpanContent = document.createTextNode("Telegram"); + telegramSpan.appendChild(telegramSpanContent); + telegram.appendChild(telegramSpan); - // by default not display - telegram.style.display = "none"; + modalContent.appendChild(telegram); - let telegramContent = document.createTextNode("open in "); - telegram.appendChild(telegramContent); - let telegramSpan = document.createElement("span"); - telegramSpan.className = "mailgo-weight-500"; - let telegramSpanContent = document.createTextNode("Telegram"); - telegramSpan.appendChild(telegramSpanContent); - telegram.appendChild(telegramSpan); + // WhatsApp + let wa = document.createElement("a"); + wa.id = "mailgo-wa"; + wa.href = DEFAULT_BTN_HREF; + wa.classList.add("mailgo-open"); + wa.classList.add("mailgo-wa"); + let waContent = document.createTextNode("open in "); + wa.appendChild(waContent); + let waSpan = document.createElement("span"); + waSpan.className = "mailgo-weight-500"; + let waSpanContent = document.createTextNode("WhatsApp"); + waSpan.appendChild(waSpanContent); + wa.appendChild(waSpan); - modalContent.appendChild(telegram); + modalContent.appendChild(wa); - // WhatsApp - let wa = document.createElement("a"); - wa.id = "mailgo-wa"; - wa.href = DEFAULT_BTN_HREF; - wa.classList.add("mailgo-open"); - wa.classList.add("mailgo-wa"); - let waContent = document.createTextNode("open in "); - wa.appendChild(waContent); - let waSpan = document.createElement("span"); - waSpan.className = "mailgo-weight-500"; - let waSpanContent = document.createTextNode("WhatsApp"); - waSpan.appendChild(waSpanContent); - wa.appendChild(waSpan); + // Skype + let skype = document.createElement("a"); + skype.id = "mailgo-skype"; + skype.href = DEFAULT_BTN_HREF; + skype.classList.add("mailgo-open"); + skype.classList.add("mailgo-skype"); + let skypeContent = document.createTextNode("open in "); + skype.appendChild(skypeContent); + let skypeSpan = document.createElement("span"); + skypeSpan.className = "mailgo-weight-500"; + let skypeSpanContent = document.createTextNode("Skype"); + skypeSpan.appendChild(skypeSpanContent); + skype.appendChild(skypeSpan); - modalContent.appendChild(wa); + modalContent.appendChild(skype); - // Skype - let skype = document.createElement("a"); - skype.id = "mailgo-skype"; - skype.href = DEFAULT_BTN_HREF; - skype.classList.add("mailgo-open"); - skype.classList.add("mailgo-skype"); - let skypeContent = document.createTextNode("open in "); - skype.appendChild(skypeContent); - let skypeSpan = document.createElement("span"); - skypeSpan.className = "mailgo-weight-500"; - let skypeSpanContent = document.createTextNode("Skype"); - skypeSpan.appendChild(skypeSpanContent); - skype.appendChild(skypeSpan); + // call default + let call = document.createElement("a"); + call.id = "mailgo-call"; + call.href = DEFAULT_BTN_HREF; + call.classList.add("mailgo-open"); + call.classList.add("mailgo-default"); + let callSpan = document.createElement("span"); + callSpan.className = "mailgo-weight-500"; + let callSpanContent = document.createTextNode("call"); + callSpan.appendChild(callSpanContent); + let callContent = document.createTextNode(" as default"); + call.appendChild(callSpan); + call.appendChild(callContent); - modalContent.appendChild(skype); + modalContent.appendChild(call); - // call default - let call = document.createElement("a"); - call.id = "mailgo-call"; - call.href = DEFAULT_BTN_HREF; - call.classList.add("mailgo-open"); - call.classList.add("mailgo-default"); - let callSpan = document.createElement("span"); - callSpan.className = "mailgo-weight-500"; - let callSpanContent = document.createTextNode("call"); - callSpan.appendChild(callSpanContent); - let callContent = document.createTextNode(" as default"); - call.appendChild(callSpan); - call.appendChild(callContent); + // copy + let copy = document.createElement("a"); + copy.id = "mailgo-tel-copy"; + copy.href = DEFAULT_BTN_HREF; + copy.classList.add("mailgo-copy"); + copy.classList.add("mailgo-weight-500"); + let copyContent = document.createTextNode("copy"); + copy.appendChild(copyContent); - modalContent.appendChild(call); + modalContent.appendChild(copy); - // copy - let copy = document.createElement("a"); - copy.id = "mailgo-tel-copy"; - copy.href = DEFAULT_BTN_HREF; - copy.classList.add("mailgo-copy"); - copy.classList.add("mailgo-weight-500"); - let copyContent = document.createTextNode("copy"); - copy.appendChild(copyContent); + // by + let by = document.createElement("a"); + by.href = "https://mailgo.js.org?ref=mailgo-modal"; + by.className = "mailgo-by"; + by.target = "_blank"; + by.rel = "noopener noreferrer"; + let textBy = document.createTextNode("mailgo.js.org"); + by.appendChild(textBy); - modalContent.appendChild(copy); + modalContent.appendChild(by); - // by - let by = document.createElement("a"); - by.href = "https://mailgo.js.org?ref=mailgo-modal"; - by.className = "mailgo-by"; - by.target = "_blank"; - by.rel = "noopener noreferrer"; - let textBy = document.createTextNode("mailgo.js.org"); - by.appendChild(textBy); + // add the modal at the end of the body + document.body.appendChild(modal); - modalContent.appendChild(by); + // every click outside the modal will hide the modal + modalBackground.addEventListener("click", hideMailgo); + } + }; - // add the modal at the end of the body - document.body.appendChild(modal); + /** + * mailgoRender + * function to render a mailgo (mail or tel) + */ + const mailgoRender = (type = MAIL_TYPE, mailgo) => { + // mailgo mail + if (type === MAIL_TYPE) { + // if the element href=^"mailto:" + if (mailgo.href && mailgo.href.toLowerCase().startsWith(MAILTO)) { + mail = decodeURIComponent( + mailgo.href + .split("?")[0] + .split(MAILTO)[1] + .trim() + ); - // every click outside the modal will hide the modal - modalBackground.addEventListener("click", hideMailgo); - } -}; + url = new URL(mailgo.href); + let urlParams = new URLSearchParams(url.search); -/** - * mailgoRender - * function to render a mailgo (mail or tel) - */ -const mailgoRender = (type = MAIL_TYPE, mailgo) => { - // mailgo mail - if (type === MAIL_TYPE) { - // if the element href=^"mailto:" - if (mailgo.href && mailgo.href.toLowerCase().startsWith(MAILTO)) { - mail = decodeURIComponent( - mailgo.href - .split("?")[0] - .split(MAILTO)[1] - .trim() - ); + // optional parameters for the email + cc = urlParams.get("cc"); + bcc = urlParams.get("bcc"); + subject = urlParams.get("subject"); + bodyMail = urlParams.get("body"); + } else { + // if the element href="#mailgo" or class="mailgo" + // mail = data-address + @ + data-domain + mail = + mailgo.getAttribute("data-address") + + "@" + + mailgo.getAttribute("data-domain"); - url = new URL(mailgo.href); - let urlParams = new URLSearchParams(url.search); + url = new URL(MAILTO + encodeURIComponent(mail)); - // optional parameters for the email - cc = urlParams.get("cc"); - bcc = urlParams.get("bcc"); - subject = urlParams.get("subject"); - bodyMail = urlParams.get("body"); - } else { - // if the element href="#mailgo" or class="mailgo" - // mail = data-address + @ + data-domain - mail = - mailgo.getAttribute("data-address") + - "@" + - mailgo.getAttribute("data-domain"); + // cc = data-cc-address + @ + data-cc-domain + cc = + mailgo.getAttribute("data-cc-address") + + "@" + + mailgo.getAttribute("data-cc-domain"); - url = new URL(MAILTO + encodeURIComponent(mail)); + // bcc = data-bcc-address + @ + data-bcc-domain + bcc = + mailgo.getAttribute("data-bcc-address") + + "@" + + mailgo.getAttribute("data-bcc-domain"); - // cc = data-cc-address + @ + data-cc-domain - cc = - mailgo.getAttribute("data-cc-address") + - "@" + - mailgo.getAttribute("data-cc-domain"); + // subject = data-subject + subject = mailgo.getAttribute("data-subject"); - // bcc = data-bcc-address + @ + data-bcc-domain - bcc = - mailgo.getAttribute("data-bcc-address") + - "@" + - mailgo.getAttribute("data-bcc-domain"); + // body = data-body + bodyMail = mailgo.getAttribute("data-body"); + } - // subject = data-subject - subject = mailgo.getAttribute("data-subject"); + // validate the email address + if (!validateEmails(mail.split(","))) return; - // body = data-body - bodyMail = mailgo.getAttribute("data-body"); + // if cc, bcc is not valid cc, bcc = "" + if (cc && !validateEmails(cc.split(","))) cc = ""; + if (bcc && !validateEmails(bcc.split(","))) bcc = ""; + + // information + let titleEl = getE("mailgo-title"); + let detailsEl = getE("mailgo-details"); + let ccEl = getE("mailgo-cc"); + let ccValueEl = getE("mailgo-cc-value"); + let bccEl = getE("mailgo-bcc"); + let bccValueEl = getE("mailgo-bcc-value"); + let subjectEl = getE("mailgo-subject"); + let subjectValueEl = getE("mailgo-subject-value"); + let bodyEl = getE("mailgo-body"); + let bodyValueEl = getE("mailgo-body-value"); + + // actions + gmailButton = getE("mailgo-gmail"); + outlookButton = getE("mailgo-outlook"); + openButton = getE("mailgo-open"); + copyButton = getE("mailgo-copy"); + + // the title of the modal (email address) + titleEl.innerHTML = mail.split(",").join("
"); + + // add the details if provided + cc + ? ((ccEl.style.display = "block"), + (ccValueEl.innerHTML = cc.split(",").join("
"))) + : (ccEl.style.display = "none"); + + bcc + ? ((bccEl.style.display = "block"), + (bccValueEl.innerHTML = bcc.split(",").join("
"))) + : (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 + gmailButton.addEventListener("click", () => actions.openGmail()); + + outlookButton.addEventListener("click", () => actions.openOutlook()); + + encEmail = encodeEmail(mail); + openButton.addEventListener("click", () => actions.openDefault()); + + copyButton.addEventListener("click", () => actions.copy(mail || tel)); + } + // mailgo tel + if (type === TEL_TYPE) { + if (mailgo.href && mailgo.href.toLowerCase().startsWith(TEL)) { + tel = decodeURIComponent( + mailgo.href + .split("?")[0] + .split(TEL)[1] + .trim() + ); + } else if (mailgo.href && mailgo.href.toLowerCase().startsWith(CALLTO)) { + tel = decodeURIComponent( + mailgo.href + .split("?")[0] + .split(CALLTO)[1] + .trim() + ); + } else if (mailgo.hasAttribute("data-tel")) { + tel = mailgo.getAttribute("data-tel"); + msg = mailgo.getAttribute("data-msg"); + } + + // information + let titleEl = getE("mailgo-tel-title"); + + // Telegram username + if (mailgo.hasAttribute("data-telegram")) { + telegramUsername = mailgo.getAttribute("data-telegram"); + } + + // Telegram username + if (mailgo.hasAttribute("data-skype")) { + skypeUsername = mailgo.getAttribute("data-skype"); + } + + // actions + telegramButton = getE("mailgo-telegram"); + waButton = getE("mailgo-wa"); + skypeButton = getE("mailgo-skype"); + callButton = getE("mailgo-call"); + copyButton = getE("mailgo-tel-copy"); + + // the title of the modal (tel) + titleEl.innerHTML = tel; + + // add the actions to buttons + waButton.addEventListener("click", () => actions.openWhatsApp()); + + if (telegramUsername) { + setDisplay("mailgo-telegram", "block"); + telegramButton.addEventListener("click", () => actions.openTelegram()); + } + + skypeButton.addEventListener("click", () => actions.openSkype()); + + callButton.addEventListener("click", () => actions.callDefault()); + + copyButton.addEventListener("click", () => actions.copy(tel)); } - // validate the email address - if (!validateEmails(mail.split(","))) return; + // show the mailgo + showMailgo(type); - // if cc, bcc is not valid cc, bcc = "" - if (cc && !validateEmails(cc.split(","))) cc = ""; - if (bcc && !validateEmails(bcc.split(","))) bcc = ""; + // add listener keyDown + document.addEventListener("keydown", mailgoKeydown); + }; - // information - let titleEl = getE("mailgo-title"); - let detailsEl = getE("mailgo-details"); - let ccEl = getE("mailgo-cc"); - let ccValueEl = getE("mailgo-cc-value"); - let bccEl = getE("mailgo-bcc"); - let bccValueEl = getE("mailgo-bcc-value"); - let subjectEl = getE("mailgo-subject"); - let subjectValueEl = getE("mailgo-subject-value"); - let bodyEl = getE("mailgo-body"); - let bodyValueEl = getE("mailgo-body-value"); + // actions + const actions = { + openGmail: () => { + // Gmail url + let gmailUrl = + "https://mail.google.com/mail/u/0/?view=cm&source=mailto&to=" + + encodeURIComponent(mail); - // actions - gmailButton = getE("mailgo-gmail"); - outlookButton = getE("mailgo-outlook"); - openButton = getE("mailgo-open"); - copyButton = getE("mailgo-copy"); + // the details if provided + if (cc) gmailUrl = gmailUrl.concat("&cc=" + encodeURIComponent(cc)); + if (bcc) gmailUrl = gmailUrl.concat("&bcc=" + encodeURIComponent(bcc)); + if (subject) gmailUrl = gmailUrl.concat("&subject=" + subject); + if (bodyMail) gmailUrl = gmailUrl.concat("&body=" + bodyMail); - // the title of the modal (email address) - titleEl.innerHTML = mail.split(",").join("
"); + // open the link + window.open(gmailUrl, "_blank"); - // add the details if provided - cc - ? ((ccEl.style.display = "block"), - (ccValueEl.innerHTML = cc.split(",").join("
"))) - : (ccEl.style.display = "none"); - - bcc - ? ((bccEl.style.display = "block"), - (bccValueEl.innerHTML = bcc.split(",").join("
"))) - : (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 - gmailButton.addEventListener("click", () => actions.openGmail()); - - outlookButton.addEventListener("click", () => actions.openOutlook()); - - encEmail = encodeEmail(mail); - openButton.addEventListener("click", () => actions.openDefault()); - - copyButton.addEventListener("click", () => actions.copy(mail || tel)); - } - // mailgo tel - if (type === TEL_TYPE) { - if (mailgo.href && mailgo.href.toLowerCase().startsWith(TEL)) { - tel = decodeURIComponent( - mailgo.href - .split("?")[0] - .split(TEL)[1] - .trim() - ); - } else if (mailgo.href && mailgo.href.toLowerCase().startsWith(CALLTO)) { - tel = decodeURIComponent( - mailgo.href - .split("?")[0] - .split(CALLTO)[1] - .trim() - ); - } else if (mailgo.hasAttribute("data-tel")) { - tel = mailgo.getAttribute("data-tel"); - msg = mailgo.getAttribute("data-msg"); - } - - // information - let titleEl = getE("mailgo-tel-title"); - - // Telegram username - if (mailgo.hasAttribute("data-telegram")) { - telegramUsername = mailgo.getAttribute("data-telegram"); - } - - // Telegram username - if (mailgo.hasAttribute("data-skype")) { - skypeUsername = mailgo.getAttribute("data-skype"); - } - - // actions - telegramButton = getE("mailgo-telegram"); - waButton = getE("mailgo-wa"); - skypeButton = getE("mailgo-skype"); - callButton = getE("mailgo-call"); - copyButton = getE("mailgo-tel-copy"); - - // the title of the modal (tel) - titleEl.innerHTML = tel; - - // add the actions to buttons - waButton.addEventListener("click", () => actions.openWhatsApp()); - - if (telegramUsername) { - setDisplay("mailgo-telegram", "block"); - telegramButton.addEventListener("click", () => actions.openTelegram()); - } - - skypeButton.addEventListener("click", () => actions.openSkype()); - - callButton.addEventListener("click", () => actions.callDefault()); - - copyButton.addEventListener("click", () => actions.copy(tel)); - } - - // show the mailgo - showMailgo(type); - - // add listener keyDown - document.addEventListener("keydown", mailgoKeydown); -}; - -// actions -const actions = { - openGmail: () => { - // Gmail url - let gmailUrl = - "https://mail.google.com/mail/u/0/?view=cm&source=mailto&to=" + - encodeURIComponent(mail); - - // the details if provided - if (cc) gmailUrl = gmailUrl.concat("&cc=" + encodeURIComponent(cc)); - if (bcc) gmailUrl = gmailUrl.concat("&bcc=" + encodeURIComponent(bcc)); - if (subject) gmailUrl = gmailUrl.concat("&subject=" + subject); - if (bodyMail) gmailUrl = gmailUrl.concat("&body=" + bodyMail); - - // open the link - window.open(gmailUrl, "_blank"); - - // hide the modal - hideMailgo(); - }, - - openOutlook: () => { - // Outlook url - let outlookUrl = - "https://outlook.live.com/owa/?path=/mail/action/compose&to=" + - encodeURIComponent(mail); - - // the details if provided - if (subject) outlookUrl = outlookUrl.concat("&subject=" + subject); - if (bodyMail) outlookUrl = outlookUrl.concat("&body=" + bodyMail); - - // open the link - window.open(outlookUrl, "_blank"); - - // hide the modal - hideMailgo(); - }, - - openDefault: () => { - mailToEncoded(encEmail); - hideMailgo(); - }, - - openTelegram: () => { - // Telegram url - let tgUrl = "https://t.me/" + telegramUsername; - // open the url - window.open(tgUrl, "_blank"); - // hide the modal - hideMailgo(); - }, - - openSkype: () => { - let skype = skypeUsername !== "" ? skypeUsername : tel; - // Telegram url - let skypeUrl = "skype:" + skype; - // open the url - window.open(skypeUrl, "_blank"); - // hide the modal - hideMailgo(); - }, - - openWhatsApp: () => { - // WhatsApp url - let waUrl = "https://wa.me/" + tel; - // open the url - window.open(waUrl, "_blank"); - // hide the modal - hideMailgo(); - }, - - callDefault: () => { - let callUrl = "tel:" + tel; - window.open(callUrl); - hideMailgo(); - }, - - copy: content => { - copyToClipboard(content); - // the correct copyButton (mail or tel) - mailgoIsShowing(MAIL_TYPE) - ? (copyButton = getE("mailgo-copy")) - : (copyButton = getE("mailgo-tel-copy")); - copyButton.textContent = "copied"; - setTimeout(() => { - copyButton.textContent = "copy"; - // hide after the timeout + // hide the modal hideMailgo(); - }, 999); - } -}; + }, -// function that returns if an element is a mailgo -const isMailgo = (element, type = MAIL_TYPE) => { - // mailgo type mail - if (type === MAIL_TYPE) { - return ( - // first case: it is an element with "mailto:..." in href and no no-mailgo in classList - (element.href && - element.href.toLowerCase().startsWith(MAILTO) && - !element.classList.contains("no-mailgo")) || - (element.hasAttribute("data-address") && - // second case: the href=#mailgo - ((element.href && - element.getAttribute("href").toLowerCase() === "#mailgo") || - // third case: the classList contains mailgo - (element.classList && element.classList.contains("mailgo")))) - ); - } + openOutlook: () => { + // Outlook url + let outlookUrl = + "https://outlook.live.com/owa/?path=/mail/action/compose&to=" + + encodeURIComponent(mail); - // mailgo type tel - if (type === TEL_TYPE) { - return ( - // first case: it is an element with "tel:..." or "callto:..." in href and no no-mailgo in classList - (element.href && - (element.href.toLowerCase().startsWith(TEL) || - element.href.toLowerCase().startsWith(CALLTO)) && - !element.classList.contains("no-mailgo")) || - ((element.hasAttribute("data-tel") && - // second case: the href=#mailgo + // the details if provided + if (subject) outlookUrl = outlookUrl.concat("&subject=" + subject); + if (bodyMail) outlookUrl = outlookUrl.concat("&body=" + bodyMail); + + // open the link + window.open(outlookUrl, "_blank"); + + // hide the modal + hideMailgo(); + }, + + openDefault: () => { + mailToEncoded(encEmail); + hideMailgo(); + }, + + openTelegram: () => { + // Telegram url + let tgUrl = "https://t.me/" + telegramUsername; + // open the url + window.open(tgUrl, "_blank"); + // hide the modal + hideMailgo(); + }, + + openSkype: () => { + let skype = skypeUsername !== "" ? skypeUsername : tel; + // Telegram url + let skypeUrl = "skype:" + skype; + // open the url + window.open(skypeUrl, "_blank"); + // hide the modal + hideMailgo(); + }, + + openWhatsApp: () => { + // WhatsApp url + let waUrl = "https://wa.me/" + tel; + // open the url + window.open(waUrl, "_blank"); + // hide the modal + hideMailgo(); + }, + + callDefault: () => { + let callUrl = "tel:" + tel; + window.open(callUrl); + hideMailgo(); + }, + + copy: content => { + copyToClipboard(content); + // the correct copyButton (mail or tel) + mailgoIsShowing(MAIL_TYPE) + ? (copyButton = getE("mailgo-copy")) + : (copyButton = getE("mailgo-tel-copy")); + copyButton.textContent = "copied"; + setTimeout(() => { + copyButton.textContent = "copy"; + // hide after the timeout + hideMailgo(); + }, 999); + } + }; + + // function that returns if an element is a mailgo + const isMailgo = (element, type = MAIL_TYPE) => { + // mailgo type mail + if (type === MAIL_TYPE) { + return ( + // first case: it is an element with "mailto:..." in href and no no-mailgo in classList (element.href && - element.getAttribute("href").toLowerCase() === "#mailgo")) || - // third case: the classList contains mailgo - (element.classList && element.classList.contains("mailgo"))) - ); - } + element.href.toLowerCase().startsWith(MAILTO) && + !element.classList.contains("no-mailgo")) || + (element.hasAttribute("data-address") && + // second case: the href=#mailgo + ((element.href && + element.getAttribute("href").toLowerCase() === "#mailgo") || + // third case: the classList contains mailgo + (element.classList && element.classList.contains("mailgo")))) + ); + } - return false; -}; + // mailgo type tel + if (type === TEL_TYPE) { + return ( + // first case: it is an element with "tel:..." or "callto:..." in href and no no-mailgo in classList + (element.href && + (element.href.toLowerCase().startsWith(TEL) || + element.href.toLowerCase().startsWith(CALLTO)) && + !element.classList.contains("no-mailgo")) || + ((element.hasAttribute("data-tel") && + // second case: the href=#mailgo + (element.href && + element.getAttribute("href").toLowerCase() === "#mailgo")) || + // third case: the classList contains mailgo + (element.classList && element.classList.contains("mailgo"))) + ); + } + + return false; + }; + + /** + * mailgoCheckRender + * function to check if an element is mailgo-enabled or not referencing to + * mail: + * document.querySelectorAll( + * 'a[href^="mailto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo' + * ); + * tel: + * document.querySelectorAll( + * 'a[href^="tel:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo' + * ); + * or + * document.querySelectorAll( + * 'a[href^="callto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo' + * ); + */ + const mailgoCheckRender = event => { + // check if the id=mailgo exists in the body + if ( + !document.contains(getE("mailgo")) || + !document.contains(getE("mailgo-tel")) + ) + return; + + // if a mailgo is already showing do nothing + if (mailgoIsShowing(MAIL_TYPE) || mailgoIsShowing(TEL_TYPE)) return; + + // the path of the event + let path = + event.path || + (event.composedPath && event.composedPath()) || + composedPath(event.target); + + if (path) { + path.forEach(element => { + if (element instanceof HTMLDocument || element instanceof Window) + return; + + // go in the event.path to find if the user has clicked on a mailgo element + if (isMailgo(element, MAIL_TYPE)) { + // stop the normal execution of the element click + event.preventDefault(); + + // render mailgo + mailgoRender(MAIL_TYPE, element); + + return; + } + if (isMailgo(element, TEL_TYPE)) { + // stop the normal execution of the element click + event.preventDefault(); + + // render mailgo + mailgoRender(TEL_TYPE, element); + + return; + } + }); + } -/** - * mailgoCheckRender - * function to check if an element is mailgo-enabled or not referencing to - * mail: - * document.querySelectorAll( - * 'a[href^="mailto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo' - * ); - * tel: - * document.querySelectorAll( - * 'a[href^="tel:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo' - * ); - * or - * document.querySelectorAll( - * 'a[href^="callto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo' - * ); - */ -const mailgoCheckRender = event => { - // check if the id=mailgo exists in the body - if ( - !document.contains(getE("mailgo")) || - !document.contains(getE("mailgo-tel")) - ) return; + }; - // if a mailgo is already showing do nothing - if (mailgoIsShowing(MAIL_TYPE) || mailgoIsShowing(TEL_TYPE)) return; - - // the path of the event - let path = - event.path || - (event.composedPath && event.composedPath()) || - composedPath(event.target); - - if (path) { - path.forEach(element => { - if (element instanceof HTMLDocument || element instanceof Window) return; - - // go in the event.path to find if the user has clicked on a mailgo element - if (isMailgo(element, MAIL_TYPE)) { - // stop the normal execution of the element click - event.preventDefault(); - - // render mailgo - mailgoRender(MAIL_TYPE, element); - - return; + /** + * mailgoKeydown + * function to manage the keydown event when the modal is showing + */ + const mailgoKeydown = event => { + // if mailgo is showing + if (mailgoIsShowing(MAIL_TYPE)) { + switch (event.keyCode) { + case 27: + // Escape + hideMailgo(); + break; + case 71: + // g -> open GMail + actions.openGmail(); + break; + case 79: + // o -> open Outlook + actions.openOutlook(); + break; + case 32: + case 13: + // spacebar or enter -> open default + actions.openDefault(); + break; + case 67: + // c -> copy + actions.copy(mail); + break; + default: + return; } - if (isMailgo(element, TEL_TYPE)) { - // stop the normal execution of the element click - event.preventDefault(); - - // render mailgo - mailgoRender(TEL_TYPE, element); - - return; + } else if (mailgoIsShowing(TEL_TYPE)) { + switch (event.keyCode) { + case 27: + // Escape + hideMailgo(); + break; + case 84: + // t -> open Telegram + actions.openTelegram(); + break; + case 87: + // w -> open WhatsApp + actions.openWhatsApp(); + break; + case 32: + case 13: + // spacebar or enter -> call default + actions.callDefault(); + break; + case 67: + // c -> copy + actions.copy(tel); + break; + default: + return; } - }); - } - - return; -}; - -/** - * mailgoKeydown - * function to manage the keydown event when the modal is showing - */ -const mailgoKeydown = event => { - // if mailgo is showing - if (mailgoIsShowing(MAIL_TYPE)) { - switch (event.keyCode) { - case 27: - // Escape - hideMailgo(); - break; - case 71: - // g -> open GMail - actions.openGmail(); - break; - case 79: - // o -> open Outlook - actions.openOutlook(); - break; - case 32: - case 13: - // spacebar or enter -> open default - actions.openDefault(); - break; - case 67: - // c -> copy - actions.copy(mail); - break; - default: - return; } - } else if (mailgoIsShowing(TEL_TYPE)) { - switch (event.keyCode) { - case 27: - // Escape - hideMailgo(); - break; - case 84: - // t -> open Telegram - actions.openTelegram(); - break; - case 87: - // w -> open WhatsApp - actions.openWhatsApp(); - break; - case 32: - case 13: - // spacebar or enter -> call default - actions.callDefault(); - break; - case 67: - // c -> copy - actions.copy(tel); - break; - default: - return; - } - } - return; -}; - -// if the window object exists... -if (windowExists()) { - // DOMContentLoaded -> mailgoInit (creates the modals) - document.addEventListener("DOMContentLoaded", mailgoInit); - - // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered - document.addEventListener("click", mailgoCheckRender); -} - -// show the modal -const showMailgo = (type = MAIL_TYPE) => { - // show mailgo type mail - if (type === MAIL_TYPE) { - setDisplay("mailgo", "flex"); return; - } - // show mailgo type tel - if (type === TEL_TYPE) { - setDisplay("mailgo-tel", "flex"); - return; - } -}; + }; -// hide the modal -const hideMailgo = () => { - setDisplay("mailgo", "none"); - setDisplay("mailgo-tel", "none"); - - // remove listener keyDown - document.removeEventListener("keydown", mailgoKeydown); -}; - -// is the mailgo modal hidden? -const mailgoIsShowing = (type = MAIL_TYPE) => { - if (type === MAIL_TYPE) { - return getDisplay("mailgo") === "flex"; - } else if (type === TEL_TYPE) { - return getDisplay("mailgo-tel") === "flex"; - } - return false; -}; - -// decrypt email -const mailToEncoded = encoded => - (window.location.href = MAILTO + atob(encoded)); - -// encode email -const encodeEmail = email => btoa(email); - -// getE shorthand -const getE = id => document.getElementById(id); - -// get display value -const getDisplay = id => getE(id).style.display; - -// get display value -const setDisplay = (id, value) => (getE(id).style.display = value); - -// custom composedPath if path or event.composedPath() are not defined -const composedPath = el => { - let path = []; - - while (el) { - path.push(el); - - if (el.tagName === "HTML") { - path.push(document); - path.push(window); - return path; + // show the modal + const showMailgo = (type = MAIL_TYPE) => { + // show mailgo type mail + if (type === MAIL_TYPE) { + setDisplay("mailgo", "flex"); + return; } + // show mailgo type tel + if (type === TEL_TYPE) { + setDisplay("mailgo-tel", "flex"); + return; + } + }; - el = el.parentElement; - } -}; + // hide the modal + const hideMailgo = () => { + setDisplay("mailgo", "none"); + setDisplay("mailgo-tel", "none"); -// validate a single email with regex -const 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,}))$/; - return re.test(email); -}; + // remove listener keyDown + document.removeEventListener("keydown", mailgoKeydown); + }; -// validate an array of emails -const validateEmails = arr => arr.every(validateEmail); + // is the mailgo modal hidden? + const mailgoIsShowing = (type = MAIL_TYPE) => { + if (type === MAIL_TYPE) { + return getDisplay("mailgo") === "flex"; + } else if (type === TEL_TYPE) { + return getDisplay("mailgo-tel") === "flex"; + } + return false; + }; -// copy of a string -const copyToClipboard = str => { - let 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; - el.select(); - document.execCommand("copy"); - document.body.removeChild(el); - if (selected) { - document.getSelection().removeAllRanges(); - document.getSelection().addRange(selected); - } -}; + // window exists + const windowExists = () => window && typeof window !== "undefined"; + + // decrypt email + const mailToEncoded = encoded => + (window.location.href = MAILTO + atob(encoded)); + + // encode email + const encodeEmail = email => btoa(email); + + // getE shorthand + const getE = id => document.getElementById(id); + + // get display value + const getDisplay = id => getE(id).style.display; + + // get display value + const setDisplay = (id, value) => (getE(id).style.display = value); + + // custom composedPath if path or event.composedPath() are not defined + const composedPath = el => { + let path = []; + + while (el) { + path.push(el); + + if (el.tagName === "HTML") { + path.push(document); + path.push(window); + return path; + } + + el = el.parentElement; + } + }; + + // validate a single email with regex + const 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,}))$/; + return re.test(email); + }; + + // validate an array of emails + const validateEmails = arr => arr.every(validateEmail); + + // copy of a string + const copyToClipboard = str => { + let 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; + el.select(); + document.execCommand("copy"); + document.body.removeChild(el); + if (selected) { + document.getSelection().removeAllRanges(); + document.getSelection().addRange(selected); + } + }; + + // start mailgo + (() => { + // if the window object exists... + if (windowExists()) { + // mailgo style (gulp) + let mailgoCSS = document.createElement("style"); + mailgoCSS.id = "mailgo-style"; + mailgoCSS.type = "text/css"; + let mailgoCSSContent = document.createTextNode(`MAILGO_STYLE`); + mailgoCSS.appendChild(mailgoCSSContent); + document.head.appendChild(mailgoCSS); + + // DOMContentLoaded -> mailgoInit (creates the modals) + document.addEventListener("DOMContentLoaded", mailgoInit); + + // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered + document.addEventListener("click", mailgoCheckRender); + } + })(); +})();