new listenerOptions, now config is set in mailgo not in init

This commit is contained in:
Matteo Manzinello 2020-07-17 10:45:21 +02:00
parent bf9671c25e
commit b25a3e40ba
8 changed files with 56 additions and 25 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

@ -288,12 +288,10 @@ var gmail, outlook, mailgo_open, telegram, wa, skype, call, copyMail, copyTel;
* the function that creates the mailgo elements in DOM * the function that creates the mailgo elements in DOM
*/ */
var mailgo_mailgoInit = function mailgoInit(mailgoConfig) { var mailgo_mailgoInit = function mailgoInit() {
var _config, _config2; var _config, _config2;
// set the global config // translations
config = mailgoConfig; // translations
var _ref = i18n_namespaceObject, var _ref = i18n_namespaceObject,
translations = _ref.translations; // if a default language is defined use it translations = _ref.translations; // if a default language is defined use it
@ -1053,18 +1051,32 @@ var mailgoStyle = function mailgoStyle() {
}; // mailgo }; // mailgo
function mailgo(config) { function mailgo(mailgoConfig) {
// if the window is defined... // set the global config
config = mailgoConfig; // if the window is defined...
if (window && typeof window !== "undefined") { if (window && typeof window !== "undefined") {
var _config8;
// add the style for mailgo // add the style for mailgo
mailgoStyle(); // if is set an initEvent add the listener mailgoStyle(); // if is set an initEvent add the listener
if (config === null || config === void 0 ? void 0 : config.initEvent) { if ((_config8 = config) === null || _config8 === void 0 ? void 0 : _config8.initEvent) {
document.addEventListener(config.initEvent, function () { var _config9;
mailgo_mailgoInit(config);
}); if ((_config9 = config) === null || _config9 === void 0 ? void 0 : _config9.listenerOptions) {
// listener options specified
document.addEventListener(config.initEvent, function () {
mailgo_mailgoInit();
}, config.listenerOptions);
} else {
// no listener options
document.addEventListener(config.initEvent, function () {
mailgo_mailgoInit();
});
}
} else { } else {
mailgo_mailgoInit(config); mailgo_mailgoInit();
} }
} }
} }

File diff suppressed because one or more lines are too long

7
mailgo.d.ts vendored
View File

@ -5,6 +5,7 @@
declare module "mailgo" { declare module "mailgo" {
export type MailgoConfig = { export type MailgoConfig = {
initEvent?: string; initEvent?: string;
listenerOptions?: ListenerOptions | boolean;
dark?: boolean; dark?: boolean;
lang?: string; lang?: string;
forceLang?: boolean; forceLang?: boolean;
@ -39,5 +40,11 @@ declare module "mailgo" {
translations: MailgoTranslations; translations: MailgoTranslations;
}; };
export type ListenerOptions = {
capture?: boolean;
once?: boolean;
passive?: boolean;
};
export default function mailgo(mailgoConfig?: MailgoConfig): void; export default function mailgo(mailgoConfig?: MailgoConfig): void;
} }

View File

@ -82,10 +82,7 @@ let gmail: HTMLLinkElement,
* mailgoInit * mailgoInit
* the function that creates the mailgo elements in DOM * the function that creates the mailgo elements in DOM
*/ */
const mailgoInit = (mailgoConfig?: MailgoConfig): void => { const mailgoInit = (): void => {
// set the global config
config = mailgoConfig;
// translations // translations
let { let {
translations, translations,
@ -962,7 +959,10 @@ const mailgoStyle = (): void => {
}; };
// mailgo // mailgo
function mailgo(config?: MailgoConfig): void { function mailgo(mailgoConfig?: MailgoConfig): void {
// set the global config
config = mailgoConfig;
// 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
@ -970,11 +970,23 @@ function mailgo(config?: MailgoConfig): void {
// if is set an initEvent add the listener // if is set an initEvent add the listener
if (config?.initEvent) { if (config?.initEvent) {
document.addEventListener(config.initEvent, () => { if (config?.listenerOptions) {
mailgoInit(config); // listener options specified
}); document.addEventListener(
config.initEvent,
() => {
mailgoInit();
},
config.listenerOptions
);
} else {
// no listener options
document.addEventListener(config.initEvent, () => {
mailgoInit();
});
}
} else { } else {
mailgoInit(config); mailgoInit();
} }
} }
} }