Skip to content

Commit 96aeaa0

Browse files
author
SPRINX0\prochazka
committed
detect download modal close
1 parent adf22aa commit 96aeaa0

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

assets/js/modal.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ document.addEventListener("DOMContentLoaded", () => {
66

77
function closeModal($el) {
88
$el.classList.remove("is-active");
9+
if (window.onCloseModal) {
10+
window.onCloseModal($el);
11+
}
912
}
1013

1114
function closeAllModals() {

layouts/shortcodes/download.html

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ <h2>Download DbGate Community</h2>
6262
<div id="download-modal" class="modal">
6363
<div class="modal-background"></div>
6464

65-
<div class="modal-content">
65+
<div class="modal-content" style="width: auto">
6666
<div class="box">
6767
<h2>Please provide your e-mail address</h2>
6868

6969
<div class="field">
7070
<label class="label">Email</label>
7171
<div class="control has-icons-left has-icons-right">
72-
<input class="input" type="email" placeholder="Your e-mail" oninput="emailChanged()"
72+
<input class="input" type="email" placeholder="Your e-mail" oninput="emailChanged()" style="width: 400px"
7373
id="email-input" />
7474
<span class="icon is-small is-left">
7575
<i class="fas fa-envelope"></i>
@@ -105,7 +105,7 @@ <h2>Please provide your e-mail address</h2>
105105
Download
106106
</a>
107107

108-
<p>
108+
<p style="margin-left: 20px">
109109
<a id="download-no-email">Continue without e-mail</a>
110110
</p>
111111
</div>
@@ -117,10 +117,23 @@ <h2>Please provide your e-mail address</h2>
117117

118118
<script lang="text/javascript">
119119
function openDownloadModal(link, event, icon, osname, title, platform) {
120+
window.closeDownloadData = {
121+
email: document.getElementById('email-input').value,
122+
osname: osname,
123+
bundle: title,
124+
platform,
125+
link,
126+
job_title: document.getElementById('job-title-select').value,
127+
event,
128+
action: 'close'
129+
}
130+
120131
const doDownload = () => {
132+
window.closeDownloadData = null;
121133
sendDownloadEventToGoatCounter(event);
122134
const modal = document.getElementById('download-modal');
123135
modal.classList.remove('is-active');
136+
124137
const data = {
125138
email: document.getElementById('email-input').value,
126139
osname: osname,
@@ -129,6 +142,7 @@ <h2>Please provide your e-mail address</h2>
129142
link,
130143
job_title: document.getElementById('job-title-select').value,
131144
event,
145+
action: 'download',
132146
}
133147

134148
fetch(
@@ -166,4 +180,22 @@ <h2>Please provide your e-mail address</h2>
166180
button.classList.add('is-static');
167181
}
168182
}
183+
184+
window.onCloseModal = () => {
185+
setTimeout(() => {
186+
if (window.closeDownloadData) {
187+
fetch(
188+
'https://api.dbgate.io/download/community',
189+
{
190+
method: 'POST',
191+
headers: {
192+
'Content-Type': 'application/json',
193+
},
194+
body: JSON.stringify(window.closeDownloadData),
195+
}
196+
);
197+
}
198+
window.closeDownloadData = null;
199+
}, 1000);
200+
}
169201
</script>

0 commit comments

Comments
 (0)