Skip to content

Commit cf78394

Browse files
adding fallback for mailto
1 parent 286ab95 commit cf78394

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

src/components/jobs/jobHeader.astro

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ if (
232232
{
233233
job.applyEmail && (
234234
<li>
235-
<a
236-
href={`mailto:${job.applyEmail}`}
237-
target="_blank"
238-
class="block px-4 cursor-pointer py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"
235+
<button
236+
id="applyEmailBtn"
237+
data-email={job.applyEmail}
238+
class="block w-full text-left px-4 cursor-pointer py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"
239239
>
240240
Enviar Correo Electrónico
241-
</a>
241+
</button>
242242
</li>
243243
)
244244
}
@@ -260,3 +260,37 @@ if (
260260

261261
<ShareThisModal />
262262
<ReportModal />
263+
264+
<script>
265+
document.addEventListener('DOMContentLoaded', async () => {
266+
const { showToast } = await import('../toast/toast.js');
267+
const applyEmailBtn = document.getElementById('applyEmailBtn');
268+
269+
if (applyEmailBtn) {
270+
applyEmailBtn.addEventListener('click', async () => {
271+
const email = applyEmailBtn.dataset.email;
272+
273+
if (!email) {
274+
console.error('Email address not found in data-email attribute.');
275+
return;
276+
}
277+
278+
const mailtoLink = `mailto:${email}`;
279+
280+
const mailtoWindow = window.open(mailtoLink, '_blank');
281+
282+
setTimeout(async () => {
283+
if (!mailtoWindow || mailtoWindow.closed || mailtoWindow.outerHeight === 0) {
284+
try {
285+
await navigator.clipboard.writeText(email);
286+
showToast('¡Email copiado!');
287+
} catch (err) {
288+
console.error('Failed to copy email: ', err);
289+
showToast('Error al copiar el email.', true);
290+
}
291+
}
292+
}, 100);
293+
});
294+
}
295+
});
296+
</script>

0 commit comments

Comments
 (0)