`); printWindow.document.close(); printWindow.onload = () => { printWindow.print(); printWindow.close(); }; } }); // Mobile Download data document.getElementById('downloadPdf').addEventListener('click', function (e) { e.preventDefault(); if (window.matchMedia("(max-width: 768px)").matches) { const { jsPDF } = window.jspdf; const doc = new jsPDF(); const facilityData = document.querySelector('.facility-box-data'); if (!facilityData) { alert("No results found."); return; } const noDataFound = facilityData.querySelector('.cs_not_fd'); if (noDataFound) { alert("No results found."); return; } const clone = facilityData.cloneNode(true); document.body.appendChild(clone); clone.style.width = "1000px"; clone.style.fontSize = "16px"; const facilityCardData = clone.querySelectorAll('.facility-card-data'); facilityCardData.forEach(card => { card.style.width = '100%'; }); const facilityMaps = clone.querySelectorAll('.facility-map'); facilityMaps.forEach(map => { map.style.display = 'none'; }); html2canvas(clone, { scale: 2 }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const imgWidth = 190; const pageHeight = doc.internal.pageSize.getHeight(); const imgHeight = (canvas.height * imgWidth) / canvas.width; const topMargin = 10; const bottomMargin = 10; let position = topMargin; doc.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); while (position + imgHeight > pageHeight - bottomMargin) { position -= pageHeight; doc.addPage(); position += topMargin; doc.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); } doc.save('Facility-Data.pdf'); document.body.removeChild(clone); }).catch(error => { console.error("Failed to capture the element:", error); }); } }); // Phone link document.addEventListener("DOMContentLoaded", function () { const phoneLinks = document.querySelectorAll(".page-template-Oregon-Search-Result .phone a"); const isMobile = /Mobi|Android|iPhone/i.test(navigator.userAgent); phoneLinks.forEach(link => { if (!isMobile) { // Desktop: Show an alert instead of making a call link.addEventListener("click", function (event) { event.preventDefault(); Swal.fire({ text: 'Click to call works on mobile devices only. To reach this facility by phone, please dial ' + link.textContent.trim(), icon: 'info', customClass: { popup: 'cs-popup', } }); }); } }); });