self-invoking functions

This commit is contained in:
Matteo Manzinello 2019-10-27 14:05:42 +01:00
parent e43f387097
commit b0ec8a49cf
3 changed files with 794 additions and 789 deletions

2
dist/mailgo.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,6 @@
(() => {
const V = "MAILGO_VERSION";
// window exists
const windowExists = () => window && typeof window !== "undefined";
// links
const MAILTO = "mailto:";
const TEL = "tel:";
@ -40,16 +38,6 @@ let gmailButton,
callButton,
copyButton;
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);
}
/**
* mailgoInit
* the function that creates the mailgo elements in DOM
@ -430,7 +418,8 @@ const mailgoRender = (type = MAIL_TYPE, mailgo) => {
: (subjectEl.style.display = "none");
bodyMail
? ((bodyEl.style.display = "block"), (bodyValueEl.textContent = bodyMail))
? ((bodyEl.style.display = "block"),
(bodyValueEl.textContent = bodyMail))
: (bodyEl.style.display = "none");
// add the actions
@ -674,7 +663,8 @@ const mailgoCheckRender = event => {
if (path) {
path.forEach(element => {
if (element instanceof HTMLDocument || element instanceof Window) return;
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)) {
@ -763,15 +753,6 @@ const mailgoKeydown = event => {
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
@ -805,6 +786,9 @@ const mailgoIsShowing = (type = MAIL_TYPE) => {
return false;
};
// window exists
const windowExists = () => window && typeof window !== "undefined";
// decrypt email
const mailToEncoded = encoded =>
(window.location.href = MAILTO + atob(encoded));
@ -867,3 +851,24 @@ const copyToClipboard = str => {
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);
}
})();
})();