a draft of window exists

This commit is contained in:
Matteo Manzinello 2019-10-26 13:30:52 +02:00
parent 815405a19d
commit 335cb19a07

View File

@ -38,6 +38,7 @@ let gmailButton,
callButton, callButton,
copyButton; copyButton;
if (windowExists()) {
// mailgo style (gulp) // mailgo style (gulp)
let mailgoCSS = document.createElement("style"); let mailgoCSS = document.createElement("style");
mailgoCSS.id = "mailgo-style"; mailgoCSS.id = "mailgo-style";
@ -45,6 +46,7 @@ mailgoCSS.type = "text/css";
let mailgoCSSContent = document.createTextNode(`MAILGO_STYLE`); let mailgoCSSContent = document.createTextNode(`MAILGO_STYLE`);
mailgoCSS.appendChild(mailgoCSSContent); mailgoCSS.appendChild(mailgoCSSContent);
document.head.appendChild(mailgoCSS); document.head.appendChild(mailgoCSS);
}
/** /**
* mailgoInit * mailgoInit
@ -759,11 +761,14 @@ const mailgoKeydown = event => {
return; return;
}; };
// if the window object exists...
if (windowExists()) {
// DOMContentLoaded -> mailgoInit (creates the modals) // DOMContentLoaded -> mailgoInit (creates the modals)
document.addEventListener("DOMContentLoaded", mailgoInit); document.addEventListener("DOMContentLoaded", mailgoInit);
// event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered
document.addEventListener("click", mailgoCheckRender); document.addEventListener("click", mailgoCheckRender);
}
// show the modal // show the modal
const showMailgo = (type = MAIL_TYPE) => { const showMailgo = (type = MAIL_TYPE) => {
@ -808,6 +813,9 @@ const encodeEmail = email => btoa(email);
// getE shorthand // getE shorthand
const getE = id => document.getElementById(id); const getE = id => document.getElementById(id);
// window exists
const windowExists = () => window && typeof window !== "undefined";
// get display value // get display value
const getDisplay = id => getE(id).style.display; const getDisplay = id => getE(id).style.display;