introducing mailgoConfig in window

This commit is contained in:
Matteo Manzinello
2020-07-29 15:50:38 +02:00
parent a7c0f7e48c
commit cbec242435
12 changed files with 122 additions and 31 deletions

View File

@@ -290,7 +290,8 @@ var gmail, outlook, mailgo_open, telegram, wa, skype, call, copyMail, copyTel;
var mailgoInit = function mailgoInit() {
var _config, _config2;
// translations
console.log(config); // translations
var _ref = i18n,
translations = _ref.translations; // if a default language is defined use it
@@ -313,7 +314,7 @@ var mailgoInit = function mailgoInit() {
var strings = translations[lang]; // mailgo mail
{
var _config3;
var _config3, _config4, _config5;
// modal
modalMailto = createElement();
@@ -431,8 +432,12 @@ var mailgoInit = function mailgoInit() {
copyMail.classList.add("m-copy");
copyMail.classList.add("w-500");
copyMail.appendChild(createTextNode(strings.copy || defaultStrings.copy));
modalContent.appendChild(copyMail);
modalContent.appendChild(byElement()); // add the modal at the end of the body
modalContent.appendChild(copyMail); // show mailgo.dev in footer only if showFooter == true
if (typeof ((_config4 = config) === null || _config4 === void 0 ? void 0 : _config4.showFooter) === "undefined" || ((_config5 = config) === null || _config5 === void 0 ? void 0 : _config5.showFooter) === false) {
modalContent.appendChild(byElement());
} // add the modal at the end of the body
document.body.appendChild(modalMailto); // every click outside the modal will hide the modal
@@ -440,7 +445,7 @@ var mailgoInit = function mailgoInit() {
} // mailgo tel
{
var _config4;
var _config6, _config7, _config8;
// modal
modalTel = createElement();
@@ -451,7 +456,7 @@ var mailgoInit = function mailgoInit() {
modalTel.setAttribute("tabindex", "-1");
modalTel.setAttribute("aria-labelledby", "m-tel-title"); // if dark is in config
if ((_config4 = config) === null || _config4 === void 0 ? void 0 : _config4.dark) {
if ((_config6 = config) === null || _config6 === void 0 ? void 0 : _config6.dark) {
enableDarkMode(TEL_TYPE);
} else {
disableDarkMode(TEL_TYPE);
@@ -540,9 +545,12 @@ var mailgoInit = function mailgoInit() {
copyTel.classList.add("w-500");
copyTel.appendChild(createTextNode(strings.copy || defaultStrings.copy));
_modalContent.appendChild(copyTel);
_modalContent.appendChild(copyTel); // show mailgo.dev in footer only if showFooter == true
_modalContent.appendChild(byElement()); // add the modal at the end of the body
if (typeof ((_config7 = config) === null || _config7 === void 0 ? void 0 : _config7.showFooter) === "undefined" || ((_config8 = config) === null || _config8 === void 0 ? void 0 : _config8.showFooter) === false) {
_modalContent.appendChild(byElement());
} // add the modal at the end of the body
document.body.appendChild(modalTel); // every click outside the modal will hide the modal
@@ -559,14 +567,14 @@ var mailgoInit = function mailgoInit() {
function mailgoRender() {
var _config7;
var _config11;
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MAIL_TYPE;
var mailgoElement = arguments.length > 1 ? arguments[1] : undefined;
// mailgo mail
if (type === MAIL_TYPE) {
var _config5, _config6;
var _config9, _config10;
// if the element href=^"mailto:"
if (mailgoElement.href && mailgoElement.href.toLowerCase().startsWith(MAILTO)) {
@@ -593,7 +601,7 @@ function mailgoRender() {
bodyMail = mailgoElement.getAttribute("data-body");
}
if (typeof ((_config5 = config) === null || _config5 === void 0 ? void 0 : _config5.validateEmail) === "undefined" || ((_config6 = config) === null || _config6 === void 0 ? void 0 : _config6.validateEmail) === true) {
if (typeof ((_config9 = config) === null || _config9 === void 0 ? void 0 : _config9.validateEmail) === "undefined" || ((_config10 = config) === null || _config10 === void 0 ? void 0 : _config10.validateEmail) === true) {
// validate the email address
if (!validateEmails(mail.split(","))) return; // if cc, bcc are not valid cc, bcc = ""
@@ -661,7 +669,7 @@ function mailgoRender() {
} // if config.dark is set to true then all the modals will be in dark mode
if (!((_config7 = config) === null || _config7 === void 0 ? void 0 : _config7.dark)) {
if (!((_config11 = config) === null || _config11 === void 0 ? void 0 : _config11.dark)) {
// if the element contains dark as class enable dark mode
if (mailgoElement.classList.contains("dark")) {
enableDarkMode(type);
@@ -1092,19 +1100,21 @@ var mailgoStyle = function mailgoStyle() {
function mailgo(mailgoConfig) {
// set the global config
config = mailgoConfig; // if the window is defined...
var _ref2;
// set the global config if passed as parameter or keep it from window
config = mailgoConfig || ((_ref2 = window) === null || _ref2 === void 0 ? void 0 : _ref2.mailgoConfig); // if the window is defined...
if (window && typeof window !== "undefined") {
var _config8;
var _config12;
// add the style for mailgo
mailgoStyle(); // if is set an initEvent add the listener
if ((_config8 = config) === null || _config8 === void 0 ? void 0 : _config8.initEvent) {
var _config9;
if ((_config12 = config) === null || _config12 === void 0 ? void 0 : _config12.initEvent) {
var _config13;
if ((_config9 = config) === null || _config9 === void 0 ? void 0 : _config9.listenerOptions) {
if ((_config13 = config) === null || _config13 === void 0 ? void 0 : _config13.listenerOptions) {
// listener options specified
document.addEventListener(config.initEvent, function () {
mailgoInit();

File diff suppressed because one or more lines are too long