new build
This commit is contained in:
parent
43a6ccc91f
commit
1379cd7114
2
dist/mailgo.min.js
vendored
2
dist/mailgo.min.js
vendored
File diff suppressed because one or more lines are too long
17
mailgo.js
17
mailgo.js
@ -474,32 +474,32 @@ const mailgoCheckRender = (event) => {
|
||||
return;
|
||||
// if a mailgo is already showing do nothing
|
||||
if (mailgoIsShowing(MAIL_TYPE) || mailgoIsShowing(TEL_TYPE))
|
||||
return;
|
||||
return false;
|
||||
// the path of the event
|
||||
let path = (event.composedPath && event.composedPath()) ||
|
||||
composedPath(event.target);
|
||||
if (path) {
|
||||
path.forEach((element) => {
|
||||
if (element instanceof HTMLDocument || element instanceof Window)
|
||||
return;
|
||||
return false;
|
||||
// go in the event.path to find if the user has clicked on a mailgo element
|
||||
if (isMailgo(element, MAIL_TYPE)) {
|
||||
// stop the normal execution of the element click
|
||||
event.preventDefault();
|
||||
// render mailgo
|
||||
mailgoRender(MAIL_TYPE, element);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
if (isMailgo(element, TEL_TYPE)) {
|
||||
// stop the normal execution of the element click
|
||||
event.preventDefault();
|
||||
// render mailgo
|
||||
mailgoRender(TEL_TYPE, element);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* mailgoKeydown
|
||||
@ -568,13 +568,14 @@ const showMailgo = (type = MAIL_TYPE) => {
|
||||
// show mailgo type mail
|
||||
if (type === MAIL_TYPE) {
|
||||
setDisplay("mailgo", "flex");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
// show mailgo type tel
|
||||
if (type === TEL_TYPE) {
|
||||
setDisplay("mailgo-tel", "flex");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
// hide the modal
|
||||
const hideMailgo = () => {
|
||||
@ -649,7 +650,9 @@ const copyToClipboard = (str) => {
|
||||
if (selected) {
|
||||
document.getSelection().removeAllRanges();
|
||||
document.getSelection().addRange(selected);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const mailgoStyle = () => {
|
||||
// mailgo style
|
||||
|
79
mailgo.ts
79
mailgo.ts
@ -299,7 +299,7 @@ const mailgoInit = (): void => {
|
||||
* mailgoRender
|
||||
* function to render a mailgo (mail or tel)
|
||||
*/
|
||||
const mailgoRender = (type = MAIL_TYPE, mailgo: any) => {
|
||||
const mailgoRender = (type = MAIL_TYPE, mailgo: any): void => {
|
||||
// mailgo mail
|
||||
if (type === MAIL_TYPE) {
|
||||
// if the element href=^"mailto:"
|
||||
@ -438,7 +438,7 @@ const mailgoRender = (type = MAIL_TYPE, mailgo: any) => {
|
||||
};
|
||||
|
||||
// actions
|
||||
const openGmail = () => {
|
||||
const openGmail = (): void => {
|
||||
// Gmail url
|
||||
let gmailUrl =
|
||||
"https://mail.google.com/mail/u/0/?view=cm&source=mailto&to=" +
|
||||
@ -457,7 +457,7 @@ const openGmail = () => {
|
||||
hideMailgo();
|
||||
};
|
||||
|
||||
const openOutlook = () => {
|
||||
const openOutlook = (): void => {
|
||||
// Outlook url
|
||||
let outlookUrl =
|
||||
"https://outlook.live.com/owa/?path=/mail/action/compose&to=" +
|
||||
@ -474,12 +474,12 @@ const openOutlook = () => {
|
||||
hideMailgo();
|
||||
};
|
||||
|
||||
const openDefault = () => {
|
||||
const openDefault = (): void => {
|
||||
mailToEncoded(encEmail);
|
||||
hideMailgo();
|
||||
};
|
||||
|
||||
const openTelegram = () => {
|
||||
const openTelegram = (): void => {
|
||||
// Telegram url
|
||||
let tgUrl = "https://t.me/" + telegramUsername;
|
||||
|
||||
@ -490,7 +490,7 @@ const openTelegram = () => {
|
||||
hideMailgo();
|
||||
};
|
||||
|
||||
const openSkype = () => {
|
||||
const openSkype = (): void => {
|
||||
let skype = skypeUsername !== "" ? skypeUsername : tel;
|
||||
|
||||
// Telegram url
|
||||
@ -503,7 +503,7 @@ const openSkype = () => {
|
||||
hideMailgo();
|
||||
};
|
||||
|
||||
const openWhatsApp = () => {
|
||||
const openWhatsApp = (): void => {
|
||||
// WhatsApp url
|
||||
let waUrl = "https://wa.me/" + tel;
|
||||
|
||||
@ -517,13 +517,13 @@ const openWhatsApp = () => {
|
||||
hideMailgo();
|
||||
};
|
||||
|
||||
const callDefault = () => {
|
||||
const callDefault = (): void => {
|
||||
let callUrl = "tel:" + tel;
|
||||
window.open(callUrl);
|
||||
hideMailgo();
|
||||
};
|
||||
|
||||
const copy = (content: string) => {
|
||||
const copy = (content: string): void => {
|
||||
copyToClipboard(content);
|
||||
let activeCopy: HTMLElement;
|
||||
// the correct copyButton (mail or tel)
|
||||
@ -537,7 +537,7 @@ const copy = (content: string) => {
|
||||
};
|
||||
|
||||
// function that returns if an element is a mailgo
|
||||
const isMailgo = (element: HTMLElement, type: string = MAIL_TYPE) => {
|
||||
const isMailgo = (element: HTMLElement, type: string = MAIL_TYPE): boolean => {
|
||||
let href: string = (element as HTMLLinkElement).href;
|
||||
|
||||
// mailgo type mail
|
||||
@ -591,7 +591,7 @@ const isMailgo = (element: HTMLElement, type: string = MAIL_TYPE) => {
|
||||
* 'a[href^="callto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo'
|
||||
* );
|
||||
*/
|
||||
const mailgoCheckRender = (event: Event) => {
|
||||
const mailgoCheckRender = (event: Event): boolean => {
|
||||
// check if the id=mailgo exists in the body
|
||||
if (
|
||||
!document.contains(getE("mailgo")) ||
|
||||
@ -600,7 +600,7 @@ const mailgoCheckRender = (event: Event) => {
|
||||
return;
|
||||
|
||||
// if a mailgo is already showing do nothing
|
||||
if (mailgoIsShowing(MAIL_TYPE) || mailgoIsShowing(TEL_TYPE)) return;
|
||||
if (mailgoIsShowing(MAIL_TYPE) || mailgoIsShowing(TEL_TYPE)) return false;
|
||||
|
||||
// the path of the event
|
||||
let path =
|
||||
@ -609,7 +609,8 @@ const mailgoCheckRender = (event: Event) => {
|
||||
|
||||
if (path) {
|
||||
path.forEach((element: HTMLElement) => {
|
||||
if (element instanceof HTMLDocument || element instanceof Window) return;
|
||||
if (element instanceof HTMLDocument || element instanceof Window)
|
||||
return false;
|
||||
|
||||
// go in the event.path to find if the user has clicked on a mailgo element
|
||||
if (isMailgo(element, MAIL_TYPE)) {
|
||||
@ -619,7 +620,7 @@ const mailgoCheckRender = (event: Event) => {
|
||||
// render mailgo
|
||||
mailgoRender(MAIL_TYPE, element);
|
||||
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
if (isMailgo(element, TEL_TYPE)) {
|
||||
// stop the normal execution of the element click
|
||||
@ -628,19 +629,19 @@ const mailgoCheckRender = (event: Event) => {
|
||||
// render mailgo
|
||||
mailgoRender(TEL_TYPE, element);
|
||||
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* mailgoKeydown
|
||||
* function to manage the keydown event when the modal is showing
|
||||
*/
|
||||
const mailgoKeydown = (event: KeyboardEvent) => {
|
||||
const mailgoKeydown = (event: KeyboardEvent): void => {
|
||||
// if mailgo is showing
|
||||
if (mailgoIsShowing(MAIL_TYPE)) {
|
||||
switch (event.keyCode) {
|
||||
@ -699,21 +700,22 @@ const mailgoKeydown = (event: KeyboardEvent) => {
|
||||
};
|
||||
|
||||
// show the modal
|
||||
const showMailgo = (type = MAIL_TYPE) => {
|
||||
const showMailgo = (type = MAIL_TYPE): boolean => {
|
||||
// show mailgo type mail
|
||||
if (type === MAIL_TYPE) {
|
||||
setDisplay("mailgo", "flex");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
// show mailgo type tel
|
||||
if (type === TEL_TYPE) {
|
||||
setDisplay("mailgo-tel", "flex");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// hide the modal
|
||||
const hideMailgo = () => {
|
||||
const hideMailgo = (): void => {
|
||||
setDisplay("mailgo", "none");
|
||||
setDisplay("mailgo-tel", "none");
|
||||
|
||||
@ -722,7 +724,7 @@ const hideMailgo = () => {
|
||||
};
|
||||
|
||||
// is the mailgo modal hidden?
|
||||
const mailgoIsShowing = (type = MAIL_TYPE) => {
|
||||
const mailgoIsShowing = (type = MAIL_TYPE): boolean => {
|
||||
return type === MAIL_TYPE
|
||||
? getDisplay("mailgo") === "flex"
|
||||
: type === TEL_TYPE
|
||||
@ -730,7 +732,7 @@ const mailgoIsShowing = (type = MAIL_TYPE) => {
|
||||
: false;
|
||||
};
|
||||
|
||||
const byElement = () => {
|
||||
const byElement = (): HTMLLinkElement => {
|
||||
// by
|
||||
let by: HTMLLinkElement = <HTMLLinkElement>createElement("a");
|
||||
by.href = "https://mailgo.js.org?ref=mailgo-modal";
|
||||
@ -743,31 +745,34 @@ const byElement = () => {
|
||||
};
|
||||
|
||||
// create element
|
||||
const createElement = (element: string = "div") =>
|
||||
const createElement = (element: string = "div"): HTMLElement =>
|
||||
document.createElement(element);
|
||||
|
||||
// create text node
|
||||
const createTextNode = (element: string) => document.createTextNode(element);
|
||||
const createTextNode = (element: string): Text =>
|
||||
document.createTextNode(element);
|
||||
|
||||
// decrypt email
|
||||
const mailToEncoded = (encoded: string) =>
|
||||
const mailToEncoded = (encoded: string): string =>
|
||||
(window.location.href = MAILTO + atob(encoded));
|
||||
|
||||
// encode email
|
||||
const encodeEmail = (email: string) => btoa(email);
|
||||
const encodeEmail = (email: string): string => btoa(email);
|
||||
|
||||
// getE shorthand
|
||||
const getE = (id: string) => document.getElementById(id);
|
||||
const getE = (id: string): HTMLElement => document.getElementById(id);
|
||||
|
||||
// get display value
|
||||
const getDisplay = (id: string) => getE(id).style.display;
|
||||
const getDisplay = (id: string): string => getE(id).style.display;
|
||||
|
||||
// get display value
|
||||
const setDisplay = (id: string, value: string) =>
|
||||
const setDisplay = (id: string, value: string): string =>
|
||||
(getE(id).style.display = value);
|
||||
|
||||
// custom composedPath if path or event.composedPath() are not defined
|
||||
const composedPath = (el: HTMLElement) => {
|
||||
const composedPath = (
|
||||
el: HTMLElement
|
||||
): (HTMLElement | Document | (Window & typeof globalThis))[] => {
|
||||
let path = [];
|
||||
|
||||
while (el) {
|
||||
@ -784,16 +789,16 @@ const composedPath = (el: HTMLElement) => {
|
||||
};
|
||||
|
||||
// validate a single email with regex
|
||||
const validateEmail = (email: string) =>
|
||||
const validateEmail = (email: string): boolean =>
|
||||
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(
|
||||
email
|
||||
);
|
||||
|
||||
// validate an array of emails
|
||||
const validateEmails = (arr: string[]) => arr.every(validateEmail);
|
||||
const validateEmails = (arr: string[]): boolean => arr.every(validateEmail);
|
||||
|
||||
// copy of a string
|
||||
const copyToClipboard = (str: string) => {
|
||||
const copyToClipboard = (str: string): boolean => {
|
||||
let el: HTMLInputElement = <HTMLInputElement>createElement("textarea");
|
||||
el.value = str;
|
||||
el.setAttribute("readonly", "");
|
||||
@ -810,10 +815,12 @@ const copyToClipboard = (str: string) => {
|
||||
if (selected) {
|
||||
document.getSelection().removeAllRanges();
|
||||
document.getSelection().addRange(selected);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const mailgoStyle = () => {
|
||||
const mailgoStyle = (): void => {
|
||||
// mailgo style
|
||||
let mailgoCSS: HTMLStyleElement = <HTMLStyleElement>createElement("style");
|
||||
mailgoCSS.id = "mailgo-style";
|
||||
@ -823,7 +830,7 @@ const mailgoStyle = () => {
|
||||
};
|
||||
|
||||
// mailgo
|
||||
const mailgo = (mailgoConfig?: any) => {
|
||||
const mailgo = (mailgoConfig?: any): void => {
|
||||
// if the window is defined...
|
||||
if (window && typeof window !== "undefined") {
|
||||
// add the style for mailgo
|
||||
|
Loading…
x
Reference in New Issue
Block a user