introducing mailgoConfig in window
This commit is contained in:
parent
a7c0f7e48c
commit
cbec242435
2
dist/mailgo.dark.min.js
vendored
2
dist/mailgo.dark.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/mailgo.dark.min.js.map
vendored
2
dist/mailgo.dark.min.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/mailgo.min.js
vendored
2
dist/mailgo.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/mailgo.min.js.map
vendored
2
dist/mailgo.min.js.map
vendored
File diff suppressed because one or more lines are too long
81
examples/index.windowconfig.html
Normal file
81
examples/index.windowconfig.html
Normal file
@ -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>
|
2
extensions/mailgo.chrome.min.js
vendored
2
extensions/mailgo.chrome.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
2
extensions/mailgo.firefox.min.js
vendored
2
extensions/mailgo.firefox.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
@ -290,7 +290,8 @@ var gmail, outlook, mailgo_open, telegram, wa, skype, call, copyMail, copyTel;
|
|||||||
var mailgoInit = function mailgoInit() {
|
var mailgoInit = function mailgoInit() {
|
||||||
var _config, _config2;
|
var _config, _config2;
|
||||||
|
|
||||||
// translations
|
console.log(config); // translations
|
||||||
|
|
||||||
var _ref = i18n,
|
var _ref = i18n,
|
||||||
translations = _ref.translations; // if a default language is defined use it
|
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 strings = translations[lang]; // mailgo mail
|
||||||
|
|
||||||
{
|
{
|
||||||
var _config3;
|
var _config3, _config4, _config5;
|
||||||
|
|
||||||
// modal
|
// modal
|
||||||
modalMailto = createElement();
|
modalMailto = createElement();
|
||||||
@ -431,8 +432,12 @@ var mailgoInit = function mailgoInit() {
|
|||||||
copyMail.classList.add("m-copy");
|
copyMail.classList.add("m-copy");
|
||||||
copyMail.classList.add("w-500");
|
copyMail.classList.add("w-500");
|
||||||
copyMail.appendChild(createTextNode(strings.copy || defaultStrings.copy));
|
copyMail.appendChild(createTextNode(strings.copy || defaultStrings.copy));
|
||||||
modalContent.appendChild(copyMail);
|
modalContent.appendChild(copyMail); // show mailgo.dev in footer only if showFooter == true
|
||||||
modalContent.appendChild(byElement()); // add the modal at the end of the body
|
|
||||||
|
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
|
document.body.appendChild(modalMailto); // every click outside the modal will hide the modal
|
||||||
|
|
||||||
@ -440,7 +445,7 @@ var mailgoInit = function mailgoInit() {
|
|||||||
} // mailgo tel
|
} // mailgo tel
|
||||||
|
|
||||||
{
|
{
|
||||||
var _config4;
|
var _config6, _config7, _config8;
|
||||||
|
|
||||||
// modal
|
// modal
|
||||||
modalTel = createElement();
|
modalTel = createElement();
|
||||||
@ -451,7 +456,7 @@ var mailgoInit = function mailgoInit() {
|
|||||||
modalTel.setAttribute("tabindex", "-1");
|
modalTel.setAttribute("tabindex", "-1");
|
||||||
modalTel.setAttribute("aria-labelledby", "m-tel-title"); // if dark is in config
|
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);
|
enableDarkMode(TEL_TYPE);
|
||||||
} else {
|
} else {
|
||||||
disableDarkMode(TEL_TYPE);
|
disableDarkMode(TEL_TYPE);
|
||||||
@ -540,9 +545,12 @@ var mailgoInit = function mailgoInit() {
|
|||||||
copyTel.classList.add("w-500");
|
copyTel.classList.add("w-500");
|
||||||
copyTel.appendChild(createTextNode(strings.copy || defaultStrings.copy));
|
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
|
document.body.appendChild(modalTel); // every click outside the modal will hide the modal
|
||||||
@ -559,14 +567,14 @@ var mailgoInit = function mailgoInit() {
|
|||||||
|
|
||||||
|
|
||||||
function mailgoRender() {
|
function mailgoRender() {
|
||||||
var _config7;
|
var _config11;
|
||||||
|
|
||||||
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MAIL_TYPE;
|
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MAIL_TYPE;
|
||||||
var mailgoElement = arguments.length > 1 ? arguments[1] : undefined;
|
var mailgoElement = arguments.length > 1 ? arguments[1] : undefined;
|
||||||
|
|
||||||
// mailgo mail
|
// mailgo mail
|
||||||
if (type === MAIL_TYPE) {
|
if (type === MAIL_TYPE) {
|
||||||
var _config5, _config6;
|
var _config9, _config10;
|
||||||
|
|
||||||
// if the element href=^"mailto:"
|
// if the element href=^"mailto:"
|
||||||
if (mailgoElement.href && mailgoElement.href.toLowerCase().startsWith(MAILTO)) {
|
if (mailgoElement.href && mailgoElement.href.toLowerCase().startsWith(MAILTO)) {
|
||||||
@ -593,7 +601,7 @@ function mailgoRender() {
|
|||||||
bodyMail = mailgoElement.getAttribute("data-body");
|
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
|
// validate the email address
|
||||||
if (!validateEmails(mail.split(","))) return; // if cc, bcc are not valid cc, bcc = ""
|
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 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 the element contains dark as class enable dark mode
|
||||||
if (mailgoElement.classList.contains("dark")) {
|
if (mailgoElement.classList.contains("dark")) {
|
||||||
enableDarkMode(type);
|
enableDarkMode(type);
|
||||||
@ -1092,19 +1100,21 @@ var mailgoStyle = function mailgoStyle() {
|
|||||||
|
|
||||||
|
|
||||||
function mailgo(mailgoConfig) {
|
function mailgo(mailgoConfig) {
|
||||||
// set the global config
|
var _ref2;
|
||||||
config = mailgoConfig; // if the window is defined...
|
|
||||||
|
// 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") {
|
if (window && typeof window !== "undefined") {
|
||||||
var _config8;
|
var _config12;
|
||||||
|
|
||||||
// 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 ((_config8 = config) === null || _config8 === void 0 ? void 0 : _config8.initEvent) {
|
if ((_config12 = config) === null || _config12 === void 0 ? void 0 : _config12.initEvent) {
|
||||||
var _config9;
|
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
|
// listener options specified
|
||||||
document.addEventListener(config.initEvent, function () {
|
document.addEventListener(config.initEvent, function () {
|
||||||
mailgoInit();
|
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
|
// show mailgo.dev in footer only if showFooter == true
|
||||||
if (
|
if (
|
||||||
typeof config?.showFooter !== "undefined" &&
|
typeof config?.showFooter === "undefined" ||
|
||||||
config?.showFooter === false
|
config?.showFooter === false
|
||||||
) {
|
) {
|
||||||
modalContent.appendChild(byElement());
|
modalContent.appendChild(byElement());
|
||||||
@ -393,7 +393,7 @@ const mailgoInit = (): void => {
|
|||||||
|
|
||||||
// show mailgo.dev in footer only if showFooter == true
|
// show mailgo.dev in footer only if showFooter == true
|
||||||
if (
|
if (
|
||||||
typeof config?.showFooter !== "undefined" &&
|
typeof config?.showFooter === "undefined" ||
|
||||||
config?.showFooter === false
|
config?.showFooter === false
|
||||||
) {
|
) {
|
||||||
modalContent.appendChild(byElement());
|
modalContent.appendChild(byElement());
|
||||||
@ -1035,8 +1035,8 @@ const mailgoStyle = (): void => {
|
|||||||
|
|
||||||
// mailgo
|
// mailgo
|
||||||
function mailgo(mailgoConfig?: MailgoConfig): void {
|
function mailgo(mailgoConfig?: MailgoConfig): void {
|
||||||
// set the global config
|
// set the global config if passed as parameter or keep it from window
|
||||||
config = mailgoConfig;
|
config = mailgoConfig || (window as any)?.mailgoConfig;
|
||||||
|
|
||||||
// if the window is defined...
|
// if the window is defined...
|
||||||
if (window && typeof window !== "undefined") {
|
if (window && typeof window !== "undefined") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user