introducing mailgoConfig in window
This commit is contained in:
parent
a7c0f7e48c
commit
cbec242435
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,81 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>mailgo examples</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>mailto:</h1>
|
||||
|
||||
<a href="mailto:matteo@manzinello.dev">matteo@manzinello.dev</a>
|
||||
<br />
|
||||
<a href="mailto:matteo@manzinello.dev?cc=matteomanzinello@gmail.com"
|
||||
><p>matteo@manzinello.dev</p></a
|
||||
>
|
||||
<br />
|
||||
<a href="mailto:matteo@manzinello.dev,matteomanzinello@gmail.com?cc=ciao"
|
||||
>matteo@manzinello.dev</a
|
||||
>
|
||||
<br />
|
||||
<a href="mailto:matteo@manzinello.dev?subject=ciao">ciao</a>
|
||||
<br />
|
||||
<a href="" class="mailgo" data-address="matteo" data-domain="manzinello.dev"
|
||||
>scrivimi!</a
|
||||
>
|
||||
<br />
|
||||
<a href="#mailgo" data-address="matteo" data-domain="manzinello.dev"
|
||||
>scrivimi!</a
|
||||
>
|
||||
|
||||
<a
|
||||
href="#mailgo"
|
||||
data-address="matteo"
|
||||
data-domain="manzinello.dev"
|
||||
data-cc="matteomanzinello@gmail.com,m@m.it"
|
||||
>more cc</a
|
||||
>
|
||||
<br />
|
||||
<a
|
||||
href="mailto:matteo@manzinello.dev?cc=matteomanzinello@gmail.com&bcc=test"
|
||||
>matteo@manzinello.dev</a
|
||||
>
|
||||
<br />
|
||||
<br />
|
||||
<h3>Dark mode</h3>
|
||||
<a class="dark" href="mailto:matteo@manzinello.dev"
|
||||
>matteo@manzinello.dev dark mode</a
|
||||
>
|
||||
<br />
|
||||
<a
|
||||
class="dark"
|
||||
href="mailto:matteo@manzinello.dev?cc=matteomanzinello@gmail.com&bcc=test"
|
||||
>matteo@manzinello.dev dark mode</a
|
||||
>
|
||||
|
||||
<h1>tel:</h1>
|
||||
<a href="#mailgo" data-tel="123456568" data-telegram="telegram">chiamami</a>
|
||||
<br />
|
||||
<a href="tel:+39 123-456-78">skype</a>
|
||||
<br />
|
||||
<a href="callto:+39 123-456-78">callto</a>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<h3>Dark mode</h3>
|
||||
|
||||
<a class="dark" href="callto:+39 123-456-78">callto dark mode</a>
|
||||
|
||||
<br />
|
||||
<a class="dark" href="#mailgo" data-tel="123456568" data-telegram="telegram"
|
||||
>chiamami dark mode</a
|
||||
>
|
||||
|
||||
<script>
|
||||
window.mailgoConfig = {
|
||||
dark: true,
|
||||
};
|
||||
</script>
|
||||
|
||||
<script src="../dist/mailgo.min.js"></script>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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
|
@ -263,7 +263,7 @@ const mailgoInit = (): void => {
|
|||
|
||||
// show mailgo.dev in footer only if showFooter == true
|
||||
if (
|
||||
typeof config?.showFooter !== "undefined" &&
|
||||
typeof config?.showFooter === "undefined" ||
|
||||
config?.showFooter === false
|
||||
) {
|
||||
modalContent.appendChild(byElement());
|
||||
|
@ -393,7 +393,7 @@ const mailgoInit = (): void => {
|
|||
|
||||
// show mailgo.dev in footer only if showFooter == true
|
||||
if (
|
||||
typeof config?.showFooter !== "undefined" &&
|
||||
typeof config?.showFooter === "undefined" ||
|
||||
config?.showFooter === false
|
||||
) {
|
||||
modalContent.appendChild(byElement());
|
||||
|
@ -1035,8 +1035,8 @@ const mailgoStyle = (): void => {
|
|||
|
||||
// mailgo
|
||||
function mailgo(mailgoConfig?: MailgoConfig): void {
|
||||
// set the global config
|
||||
config = mailgoConfig;
|
||||
// set the global config if passed as parameter or keep it from window
|
||||
config = mailgoConfig || (window as any)?.mailgoConfig;
|
||||
|
||||
// if the window is defined...
|
||||
if (window && typeof window !== "undefined") {
|
||||
|
|
Loading…
Reference in New Issue