added estimate now live estimate
This commit is contained in:
+31
@@ -6,6 +6,37 @@ import "./styles.css";
|
||||
|
||||
console.log("%cCreated by Sarthak", "font-size:14px;font-weight:700;color:#F2A83B;");
|
||||
|
||||
/* ---------- CTA sample-address estimate (standalone so it always runs) ---------- */
|
||||
(function(){
|
||||
function init(){
|
||||
var form = document.getElementById("ctaForm");
|
||||
var sel = document.getElementById("ctaAddr");
|
||||
var btn = document.getElementById("ctaEstimateBtn");
|
||||
var panel = document.getElementById("ctaEstimate");
|
||||
if(!sel || !panel) return;
|
||||
var money = function(n){ return "$" + Number(n).toLocaleString("en-US"); };
|
||||
var set = function(id, val){ var el = document.getElementById(id); if(el) el.textContent = val; };
|
||||
function render(scroll){
|
||||
var opt = sel.options[sel.selectedIndex];
|
||||
if(!opt || opt.dataset.placeholder){ panel.hidden = true; return; }
|
||||
set("estAddr", opt.value);
|
||||
set("estArea", Number(opt.dataset.area).toLocaleString("en-US") + " sq ft");
|
||||
set("estSquares", opt.dataset.squares + " sq");
|
||||
set("estPitch", opt.dataset.pitch);
|
||||
set("estMaterial", opt.dataset.material);
|
||||
set("estPrice", money(opt.dataset.low) + " – " + money(opt.dataset.high));
|
||||
panel.hidden = false;
|
||||
if(scroll) panel.scrollIntoView({behavior:"smooth", block:"nearest"});
|
||||
}
|
||||
function go(e){ if(e) e.preventDefault(); render(true); }
|
||||
if(form) form.addEventListener("submit", go);
|
||||
if(btn) btn.addEventListener("click", go);
|
||||
sel.addEventListener("change", function(){ if(!panel.hidden) render(false); });
|
||||
}
|
||||
if(document.readyState === "loading") document.addEventListener("DOMContentLoaded", init);
|
||||
else init();
|
||||
})();
|
||||
|
||||
(function(){
|
||||
var reduced = matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
var finePointer = matchMedia("(pointer: fine)").matches;
|
||||
|
||||
Reference in New Issue
Block a user