go on with typescript, support for ssr and configuration

This commit is contained in:
Matteo Manzinello 2020-04-24 22:21:06 +02:00
parent 50b3a5ff2e
commit d696299389
3 changed files with 10 additions and 19 deletions

2
index.d.ts vendored
View File

@ -4,4 +4,4 @@
export as namespace Mailgo; export as namespace Mailgo;
export function mailgo(mailgoConfig: any | undefined): void; export function mailgo(mailgoConfig?: any): void;

View File

@ -1,2 +1,3 @@
import { mailgoDOMContentLoaded } from "../mailgo"; import { mailgoDOMContentLoaded } from "../mailgo";
mailgoDOMContentLoaded();
mailgoDOMContentLoaded({ initEvent: "DOMContentLoaded" });

View File

@ -823,28 +823,18 @@ const mailgoStyle = () => {
}; };
// start default mailgo // start default mailgo
export const mailgoDOMContentLoaded = () => { export const mailgo = (mailgoConfig?: any) => {
// if the window is defined... // if the window is defined...
if (window && typeof window !== "undefined") { if (window && typeof window !== "undefined") {
// add the style for mailgo // add the style for mailgo
mailgoStyle(); mailgoStyle();
// DOMContentLoaded -> mailgoInit (creates the modals) // if is set an initEvent add the listener
document.addEventListener("DOMContentLoaded", mailgoInit); if (mailgoConfig.initEvent) {
document.addEventListener(mailgoConfig.initEvent, mailgoInit);
// event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered } else {
document.addEventListener("click", mailgoCheckRender); mailgoInit();
} }
};
export const mailgo = () => {
// if the window is defined...
if (window && typeof window !== "undefined") {
// add the style for mailgo
mailgoStyle();
// mailgo init
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);