Thank you so much. Need help with one last question (hopefully). I added a open in maps button but nothing is happening when i click on it. Thanks in advance!
$w.onReady(function () {
// Set “Get in Touch” text (optional via code, can be static too)
try {
$w(“
#getInTouchLabel”).text = “Get in Touch”;
} catch (err) {
console.warn(“Text element ‘
#getInTouchLabel’ not found.”);
}
displayOperatingHours();
setupDirectionsButton();
});
function displayOperatingHours() {
const operatingHours = [
{ day: “Sunday”, hours: “Closed” },
{ day: “Monday”, hours: “9:00 AM – 5:00 PM” },
{ day: “Tuesday”, hours: “9:00 AM – 5:00 PM” },
{ day: “Wednesday”, hours: “9:00 AM – 5:00 PM” },
{ day: “Thursday”, hours: “9:00 AM – 5:00 PM” },
{ day: “Friday”, hours: “9:00 AM – 6:00 PM” },
{ day: “Saturday”, hours: “10:00 AM – 2:00 PM” }
];
const today = new Date();
const currentDayIndex = today.getDay();
const currentDayHours = operatingHours[currentDayIndex].hours;
let hoursHtmlContent = "";
operatingHours.forEach((item, index) => {
let line = `<span style="font-size: 16px;">${item.day}: ${item.hours}</span>`;
if (index === currentDayIndex) {
line = `<span style="font-weight: bold; color: #0070c0; font-size: 16px;">${item.day}: ${item.hours} (Today)</span>`;
}
hoursHtmlContent += line + "<br>";
});
try {
$w("#hoursTextDisplay").html = hoursHtmlContent;
} catch (err) {
console.warn("Text element '#hoursTextDisplay' not found.");
}
let statusMessage = "";
const nowInMinutes = today.getHours() * 60 + today.getMinutes();
if (currentDayHours.toLowerCase() === "closed") {
statusMessage = "We are currently closed today.";
} else {
const parseTimeInMinutes = (timeStr) => {
const [time, ampm] = timeStr.split(' ');
let [hours, minutes] = time.split(':').map(Number);
if (ampm.toLowerCase() === 'pm' && hours !== 12) hours += 12;
if (ampm.toLowerCase() === 'am' && hours === 12) hours = 0;
return hours * 60 + minutes;
};
const [openTimeStr, closeTimeStr] = currentDayHours.split(' – ');
const openTimeInMinutes = parseTimeInMinutes(openTimeStr);
const closeTimeInMinutes = parseTimeInMinutes(closeTimeStr);
statusMessage = (nowInMinutes >= openTimeInMinutes && nowInMinutes <= closeTimeInMinutes)
? "We are currently open!"
: "We are currently closed.";
}
try {
$w("#openClosedStatus").text = statusMessage;
} catch (err) {
console.warn("Text element '#openClosedStatus' not found.");
}
}
function setupDirectionsButton() {
const address = “2828 1st Ave, Suite 204, Huntington, WV 25702”;
const encodedAddress = encodeURIComponent(address);
const googleMapsUrl = https://www.google.com/maps?daddr=${encodedAddress}
;
const appleMapsUrl = https://maps.apple.com/?daddr=${encodedAddress}
;
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
const isIOS = /iPad|iPhone|iPod/.test(userAgent) && !window.MSStream;
const mapsUrl = isIOS ? appleMapsUrl : googleMapsUrl;
try {
$w("#directionsButton").onClick(() => {
const opened = window.open(mapsUrl, "_blank");
if (!opened) {
console.error("Popup blocker prevented maps from opening.");
alert("Please allow popups to open directions in a new tab.");
}
});
} catch (err) {
console.warn("Button '#directionsButton' not found.");
}
}