diff --git a/public/buyModal.js b/public/buyModal.js index e09e649..4110908 100644 --- a/public/buyModal.js +++ b/public/buyModal.js @@ -1,13 +1,5 @@ -// ======================= -// CONFIGURATION -// ======================= -const WEBHOOK_URL = "https://your-webhook-url.com"; // <-- Set your webhook here +const WEBHOOK_URL = "https://your-webhook-url.com"; -// ======================= -// HELPER FUNCTIONS -// ======================= - -// Create the modal form HTML function createModal() { const modal = document.createElement("div"); modal.id = "buyNowModal"; @@ -23,46 +15,50 @@ function createModal() { modal.style.zIndex = "1000"; modal.innerHTML = ` -
- × -

Buy Product

-
-

-

-

-

-

-

-

-

- +
+ × +

Order Details

+

+ + + + + +
+ + +
+ + + +
`; document.body.appendChild(modal); - - // Close button - document.getElementById("closeModal").onclick = () => { - modal.style.display = "none"; - }; - - // Close modal on outside click - modal.onclick = (e) => { - if (e.target === modal) modal.style.display = "none"; - }; - + document.getElementById("closeModal").onclick = () => { modal.style.display = "none"; }; + modal.onclick = (e) => { if (e.target === modal) modal.style.display = "none"; }; return modal; } -// Show modal and set product function openModal(productHref) { const modal = document.getElementById("buyNowModal"); modal.style.display = "flex"; - modal.querySelector('input[name="product"]').value = productHref; + + let product = productHref; + let price = ""; + if (productHref.includes("/")) { + const parts = productHref.split("/").filter(Boolean); + product = parts[parts.length - 2] || "Product"; + price = parts[parts.length - 1] || "0"; + } + + modal.querySelector('input[name="product"]').value = product; + modal.querySelector('input[name="price"]').value = price; + modal.querySelector("#productText").textContent = `You will buy ${product} for $${price}.`; } -// Handle form submission function handleFormSubmit() { const form = document.getElementById("buyForm"); form.addEventListener("submit", async (e) => { @@ -91,23 +87,20 @@ function handleFormSubmit() { }); } -// Attach modal to buttons function attachButtons() { const buttons = Array.from(document.querySelectorAll("button, a")); buttons.forEach(btn => { - if (btn.textContent.trim() === "Buy Now") { + const text = btn.textContent.trim(); + if (text === "Buy Now" || text === "Book Now") { btn.addEventListener("click", (e) => { e.preventDefault(); - const href = btn.getAttribute("href") || btn.dataset.product || "Unknown Product"; + const href = btn.getAttribute("href") || btn.dataset.product || "Unknown/0"; openModal(href); }); } }); } -// ======================= -// INIT -// ======================= document.addEventListener("DOMContentLoaded", () => { createModal(); handleFormSubmit(); diff --git a/public/index.html.template b/public/index.html.template index 4982fd4..695d499 100644 --- a/public/index.html.template +++ b/public/index.html.template @@ -12,6 +12,9 @@ + + + @@ -212,7 +215,7 @@ Download Agenda
$450.00
per Person
- Book Now @@ -228,7 +231,7 @@ Download Agenda