aggiunti molti commenti
This commit is contained in:
parent
6f8f825636
commit
87f4f94114
@ -1,4 +1,5 @@
|
|||||||
function mailgoInit() {
|
function mailgoInit() {
|
||||||
|
// style di mailgo
|
||||||
const styles = `
|
const styles = `
|
||||||
.mailgo-title {
|
.mailgo-title {
|
||||||
display: block;
|
display: block;
|
||||||
@ -118,12 +119,14 @@ function mailgoInit() {
|
|||||||
url = new URL(mailtoHref);
|
url = new URL(mailtoHref);
|
||||||
let urlParams = new URLSearchParams(url.search);
|
let urlParams = new URLSearchParams(url.search);
|
||||||
|
|
||||||
|
// ottengo i parametri aggiuntivi
|
||||||
cc = urlParams.get("cc");
|
cc = urlParams.get("cc");
|
||||||
bcc = urlParams.get("bcc");
|
bcc = urlParams.get("bcc");
|
||||||
subject = urlParams.get("subject");
|
subject = urlParams.get("subject");
|
||||||
bodyMail = urlParams.get("body");
|
bodyMail = urlParams.get("body");
|
||||||
} else {
|
} else {
|
||||||
// caso in cui applico mailgo ad <a> con class="mailgo"
|
// caso in cui applico mailgo ad <a> con class="mailgo" o href=#mailgo
|
||||||
|
// compongo l'email con data-address e data-domain passati nell'elemento
|
||||||
mail =
|
mail =
|
||||||
mailgo.getAttribute("data-address") +
|
mailgo.getAttribute("data-address") +
|
||||||
"@" +
|
"@" +
|
||||||
@ -132,6 +135,7 @@ function mailgoInit() {
|
|||||||
url = new URL(mailtoHref);
|
url = new URL(mailtoHref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// valido l'email, se non valida non abilito mailgo per il singolo elemento
|
||||||
if (!validateEmail(mail)) return;
|
if (!validateEmail(mail)) return;
|
||||||
|
|
||||||
let modal = document.createElement("div");
|
let modal = document.createElement("div");
|
||||||
@ -143,6 +147,7 @@ function mailgoInit() {
|
|||||||
modalBackground.className = "mailgo-modal-background";
|
modalBackground.className = "mailgo-modal-background";
|
||||||
modal.appendChild(modalBackground);
|
modal.appendChild(modalBackground);
|
||||||
|
|
||||||
|
// modal content
|
||||||
let modalContent = document.createElement("div");
|
let modalContent = document.createElement("div");
|
||||||
modalContent.className = "mailgo-modal-content";
|
modalContent.className = "mailgo-modal-content";
|
||||||
modal.appendChild(modalContent);
|
modal.appendChild(modalContent);
|
||||||
@ -239,7 +244,7 @@ function mailgoInit() {
|
|||||||
|
|
||||||
modalContent.appendChild(outlook);
|
modalContent.appendChild(outlook);
|
||||||
|
|
||||||
// default
|
// open default
|
||||||
let open = document.createElement("a");
|
let open = document.createElement("a");
|
||||||
open.href = mailtoHref;
|
open.href = mailtoHref;
|
||||||
open.classList.add("mailgo-open");
|
open.classList.add("mailgo-open");
|
||||||
@ -268,19 +273,19 @@ function mailgoInit() {
|
|||||||
);
|
);
|
||||||
modalContent.appendChild(copy);
|
modalContent.appendChild(copy);
|
||||||
|
|
||||||
// details
|
// by
|
||||||
let by = document.createElement("a");
|
let by = document.createElement("a");
|
||||||
by.href = "https://mailgo.js.org";
|
by.href = "https://mailgo.js.org";
|
||||||
by.className = "mailgo-by";
|
by.className = "mailgo-by";
|
||||||
by.target = "_blank";
|
by.target = "_blank";
|
||||||
|
|
||||||
let textBy = document.createTextNode("mailgo.js.org");
|
let textBy = document.createTextNode("mailgo.js.org");
|
||||||
by.appendChild(textBy);
|
by.appendChild(textBy);
|
||||||
|
|
||||||
modalContent.appendChild(by);
|
modalContent.appendChild(by);
|
||||||
|
|
||||||
|
// aggiungo il modal dopo l'elemento
|
||||||
mailgo.parentNode.insertBefore(modal, mailgo.nextSibling);
|
mailgo.parentNode.insertBefore(modal, mailgo.nextSibling);
|
||||||
|
|
||||||
|
// se clicco sull'elemento appare il modal
|
||||||
mailgo.addEventListener(
|
mailgo.addEventListener(
|
||||||
"click",
|
"click",
|
||||||
function(event) {
|
function(event) {
|
||||||
@ -293,6 +298,7 @@ function mailgoInit() {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// se clicco fuori scompare
|
||||||
modalBackground.addEventListener(
|
modalBackground.addEventListener(
|
||||||
"click",
|
"click",
|
||||||
function(event) {
|
function(event) {
|
||||||
@ -303,13 +309,16 @@ function mailgoInit() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// aggiungo l'init di mailgo al DOMContentLoaded
|
||||||
document.addEventListener("DOMContentLoaded", mailgoInit, false);
|
document.addEventListener("DOMContentLoaded", mailgoInit, false);
|
||||||
|
|
||||||
|
// funzionalità di validazione dell'email con regex
|
||||||
function validateEmail(email) {
|
function validateEmail(email) {
|
||||||
let re = /^(([^<>()[\]\\.,;:\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,}))$/;
|
let re = /^(([^<>()[\]\\.,;:\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,}))$/;
|
||||||
return re.test(email);
|
return re.test(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// funzionalità di copia di una stringa
|
||||||
function copyToClipboard(str) {
|
function copyToClipboard(str) {
|
||||||
const el = document.createElement("textarea");
|
const el = document.createElement("textarea");
|
||||||
el.value = str;
|
el.value = str;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user