nascondo il modal al clic fuori

This commit is contained in:
Matteo Manzinello 2019-05-03 12:58:59 +02:00
parent 4950af8359
commit 110f9c6de3
3 changed files with 31 additions and 11 deletions

20
dist/mailgo.js vendored
View File

@ -8,7 +8,7 @@ let styles = `
right: 0; right: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
background-color: black; background-color: rgba(10,10,10,.86);
opacity: 0.8; opacity: 0.8;
} }
.mailgo-modal { .mailgo-modal {
@ -26,10 +26,12 @@ let styles = `
} }
.mailgo-modal-content { .mailgo-modal-content {
z-index: 1000; z-index: 1000;
border-radius: 8px; background-color: #fff;
background: white; border-radius: 6px;
padding: 24px; box-shadow: 0 2px 3px rgba(10,10,10,.1), 0 0 0 1px rgba(10,10,10,.1);
margin: 24px; color: #4a4a4a;
display: block;
padding: 1.25rem;
} }
`; `;
@ -71,4 +73,12 @@ mailgos.forEach((mailgo, index) => {
}, },
false false
); );
modalBackground.addEventListener(
"click",
event => {
mailgo.nextElementSibling.classList.remove("is-active");
},
false
);
}); });

2
dist/mailgo.min.js vendored
View File

@ -1 +1 @@
let mailgos=document.querySelectorAll('a[href^="mailto:"]:not(.no-mailgo)'),styles="\n .mailgo-modal-background {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background-color: black;\n opacity: 0.8;\n }\n .mailgo-modal {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n display: none;\n }\n .mailgo-modal.is-active {\n display: flex;\n justify-content: center;\n align-items: center;\n }\n .mailgo-modal-content {\n z-index: 1000;\n border-radius: 8px;\n background: white;\n padding: 24px;\n margin: 24px;\n }\n",styleSheet=document.createElement("style");styleSheet.type="text/css",styleSheet.innerText=styles,document.head.appendChild(styleSheet),console.log("mailgo is WIP!"),mailgos.forEach((e,n)=>{let t=document.createElement("div");t.className="mailgo-modal",t.id="mailgo-modal-"+n;let l=document.createElement("div");l.className="mailgo-modal-background",t.appendChild(l);let o=document.createElement("div");o.className="mailgo-modal-content",t.appendChild(o);let a=document.createTextNode("mailgo");o.appendChild(a),e.parentNode.insertBefore(t,e.nextSibling),e.addEventListener("click",n=>{n.preventDefault(),e.nextElementSibling.classList.add("is-active")},!1)}); let mailgos=document.querySelectorAll('a[href^="mailto:"]:not(.no-mailgo)'),styles="\n .mailgo-modal-background {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n background-color: rgba(10,10,10,.86);\n opacity: 0.8;\n }\n .mailgo-modal {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n display: none;\n }\n .mailgo-modal.is-active {\n display: flex;\n justify-content: center;\n align-items: center;\n }\n .mailgo-modal-content {\n z-index: 1000;\n background-color: #fff;\n border-radius: 6px;\n box-shadow: 0 2px 3px rgba(10,10,10,.1), 0 0 0 1px rgba(10,10,10,.1);\n color: #4a4a4a;\n display: block;\n padding: 1.25rem;\n }\n",styleSheet=document.createElement("style");styleSheet.type="text/css",styleSheet.innerText=styles,document.head.appendChild(styleSheet),console.log("mailgo is WIP!"),mailgos.forEach((e,n)=>{let t=document.createElement("div");t.className="mailgo-modal",t.id="mailgo-modal-"+n;let l=document.createElement("div");l.className="mailgo-modal-background",t.appendChild(l);let o=document.createElement("div");o.className="mailgo-modal-content",t.appendChild(o);let a=document.createTextNode("mailgo");o.appendChild(a),e.parentNode.insertBefore(t,e.nextSibling),e.addEventListener("click",n=>{n.preventDefault(),e.nextElementSibling.classList.add("is-active")},!1),l.addEventListener("click",n=>{e.nextElementSibling.classList.remove("is-active")},!1)});

View File

@ -8,7 +8,7 @@ let styles = `
right: 0; right: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
background-color: black; background-color: rgba(10,10,10,.86);
opacity: 0.8; opacity: 0.8;
} }
.mailgo-modal { .mailgo-modal {
@ -26,10 +26,12 @@ let styles = `
} }
.mailgo-modal-content { .mailgo-modal-content {
z-index: 1000; z-index: 1000;
border-radius: 8px; background-color: #fff;
background: white; border-radius: 6px;
padding: 24px; box-shadow: 0 2px 3px rgba(10,10,10,.1), 0 0 0 1px rgba(10,10,10,.1);
margin: 24px; color: #4a4a4a;
display: block;
padding: 1.25rem;
} }
`; `;
@ -71,4 +73,12 @@ mailgos.forEach((mailgo, index) => {
}, },
false false
); );
modalBackground.addEventListener(
"click",
event => {
mailgo.nextElementSibling.classList.remove("is-active");
},
false
);
}); });