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,
copyButton;
if (windowExists()) {
// mailgo style (gulp)
let mailgoCSS = document.createElement("style");
mailgoCSS.id = "mailgo-style";
@ -45,6 +46,7 @@ mailgoCSS.type = "text/css";
let mailgoCSSContent = document.createTextNode(`MAILGO_STYLE`);
mailgoCSS.appendChild(mailgoCSSContent);
document.head.appendChild(mailgoCSS);
}
/**
* mailgoInit
@ -759,11 +761,14 @@ 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) => {
@ -808,6 +813,9 @@ const encodeEmail = email => btoa(email);
// getE shorthand
const getE = id => document.getElementById(id);
// window exists
const windowExists = () => window && typeof window !== "undefined";
// get display value
const getDisplay = id => getE(id).style.display;