now modals are global objects

This commit is contained in:
Matteo Manzinello 2020-07-16 12:59:09 +02:00
parent d455cf2849
commit ddfd1611db
7 changed files with 43 additions and 45 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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

@ -263,7 +263,9 @@ var pHTMLTag = "p"; // global mailgo config object
var config; // default language
var lang = DEFAULT_LANG; // mailgo variables
var lang = DEFAULT_LANG; // modals global object
var modalMailto, modalTel; // mailgo variables
var url,
mail = "",
@ -317,23 +319,23 @@ var mailgo_mailgoInit = function mailgoInit(mailgoConfig) {
var _config3;
// modal
var modal = createElement();
modal.style.display = "none";
modal.id = "mailgo";
modal.classList.add("m-modal"); // if dark is in config
modalMailto = createElement();
modalMailto.style.display = "none";
modalMailto.id = "mailgo";
modalMailto.classList.add("m-modal"); // if dark is in config
if ((_config3 = config) === null || _config3 === void 0 ? void 0 : _config3.dark) {
modal.classList.add("m-dark");
modalMailto.classList.add("m-dark");
} // background
var modalBackground = createElement();
modalBackground.className = "m-modal-back";
modal.appendChild(modalBackground); // modal content
modalMailto.appendChild(modalBackground); // modal content
var modalContent = createElement();
modalContent.className = "m-modal-content";
modal.appendChild(modalContent); // title (email address)
modalMailto.appendChild(modalContent); // title (email address)
title = createElement("strong");
title.id = "m-title";
@ -430,7 +432,7 @@ var mailgo_mailgoInit = function mailgoInit(mailgoConfig) {
modalContent.appendChild(copyMail);
modalContent.appendChild(byElement()); // add the modal at the end of the body
document.body.appendChild(modal); // every click outside the modal will hide the modal
document.body.appendChild(modalMailto); // every click outside the modal will hide the modal
modalBackground.addEventListener("click", hideMailgo);
} // mailgo tel
@ -439,32 +441,25 @@ var mailgo_mailgoInit = function mailgoInit(mailgoConfig) {
var _config4;
// modal
var _modal = createElement();
_modal.style.display = "none";
_modal.id = "mailgo-tel";
_modal.classList.add("m-modal"); // if dark is in config
modalTel = createElement();
modalTel.style.display = "none";
modalTel.id = "mailgo-tel";
modalTel.classList.add("m-modal"); // if dark is in config
if ((_config4 = config) === null || _config4 === void 0 ? void 0 : _config4.dark) {
_modal.classList.add("m-dark");
modalTel.classList.add("m-dark");
} // background
var _modalBackground = createElement();
_modalBackground.className = "m-modal-back";
_modal.appendChild(_modalBackground); // modal content
modalTel.appendChild(_modalBackground); // modal content
var _modalContent = createElement();
_modalContent.className = "m-modal-content";
_modal.appendChild(_modalContent); // title (telephone number)
modalTel.appendChild(_modalContent); // title (telephone number)
titleTel = createElement("strong");
titleTel.id = "m-tel-title";
@ -543,7 +538,7 @@ var mailgo_mailgoInit = function mailgoInit(mailgoConfig) {
_modalContent.appendChild(byElement()); // add the modal at the end of the body
document.body.appendChild(_modal); // every click outside the modal will hide the modal
document.body.appendChild(modalTel); // every click outside the modal will hide the modal
_modalBackground.addEventListener("click", hideMailgo);
} // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered

File diff suppressed because one or more lines are too long

View File

@ -37,6 +37,9 @@ let config: MailgoConfig;
// default language
let lang: string = DEFAULT_LANG;
// modals global object
let modalMailto: HTMLElement, modalTel: HTMLElement;
// mailgo variables
let url: URL,
mail: string = "",
@ -111,25 +114,25 @@ const mailgoInit = (mailgoConfig?: MailgoConfig): void => {
// mailgo mail
{
// modal
let modal: HTMLElement = createElement();
modal.style.display = "none";
modal.id = "mailgo";
modal.classList.add("m-modal");
modalMailto = createElement() as HTMLElement;
modalMailto.style.display = "none";
modalMailto.id = "mailgo";
modalMailto.classList.add("m-modal");
// if dark is in config
if (config?.dark) {
modal.classList.add("m-dark");
modalMailto.classList.add("m-dark");
}
// background
let modalBackground: HTMLElement = createElement();
modalBackground.className = "m-modal-back";
modal.appendChild(modalBackground);
modalMailto.appendChild(modalBackground);
// modal content
let modalContent: HTMLElement = createElement();
modalContent.className = "m-modal-content";
modal.appendChild(modalContent);
modalMailto.appendChild(modalContent);
// title (email address)
title = createElement("strong");
@ -255,7 +258,7 @@ const mailgoInit = (mailgoConfig?: MailgoConfig): void => {
modalContent.appendChild(byElement());
// add the modal at the end of the body
document.body.appendChild(modal);
document.body.appendChild(modalMailto);
// every click outside the modal will hide the modal
modalBackground.addEventListener("click", hideMailgo);
@ -263,25 +266,25 @@ const mailgoInit = (mailgoConfig?: MailgoConfig): void => {
// mailgo tel
{
// modal
let modal: HTMLElement = createElement();
modal.style.display = "none";
modal.id = "mailgo-tel";
modal.classList.add("m-modal");
modalTel = createElement() as HTMLElement;
modalTel.style.display = "none";
modalTel.id = "mailgo-tel";
modalTel.classList.add("m-modal");
// if dark is in config
if (config?.dark) {
modal.classList.add("m-dark");
modalTel.classList.add("m-dark");
}
// background
let modalBackground: HTMLElement = createElement();
modalBackground.className = "m-modal-back";
modal.appendChild(modalBackground);
modalTel.appendChild(modalBackground);
// modal content
let modalContent: HTMLElement = createElement();
modalContent.className = "m-modal-content";
modal.appendChild(modalContent);
modalTel.appendChild(modalContent);
// title (telephone number)
titleTel = createElement("strong");
@ -374,7 +377,7 @@ const mailgoInit = (mailgoConfig?: MailgoConfig): void => {
modalContent.appendChild(byElement());
// add the modal at the end of the body
document.body.appendChild(modal);
document.body.appendChild(modalTel);
// every click outside the modal will hide the modal
modalBackground.addEventListener("click", hideMailgo);