53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
import { ensureEurRate } from "/js/fx.js?v=fx1";
|
|
|
|
function ensureFooterEurRate() {
|
|
const enamad = document.querySelector(".footer-enamad");
|
|
if (!enamad) return;
|
|
|
|
let el = document.querySelector("[data-footer-eur-rate]");
|
|
if (!el) {
|
|
el = document.createElement("p");
|
|
el.className = "footer-eur-live";
|
|
el.setAttribute("data-footer-eur-rate", "");
|
|
el.innerHTML =
|
|
'نرخ یورو (بازار آزاد): <strong data-eur-rate-display>…</strong> تومان';
|
|
enamad.insertAdjacentElement("afterend", el);
|
|
} else if (!el.querySelector("[data-eur-rate-display]")) {
|
|
el.innerHTML =
|
|
'نرخ یورو (بازار آزاد): <strong data-eur-rate-display>…</strong> تومان';
|
|
}
|
|
|
|
void ensureEurRate();
|
|
}
|
|
|
|
export function initFooter() {
|
|
const cols = document.querySelectorAll("[data-footer-col]");
|
|
if (cols.length) {
|
|
const mq = window.matchMedia("(min-width: 768px)");
|
|
const sync = () => {
|
|
cols.forEach((el) => {
|
|
if (mq.matches) el.setAttribute("open", "");
|
|
else el.removeAttribute("open");
|
|
});
|
|
};
|
|
sync();
|
|
mq.addEventListener("change", sync);
|
|
}
|
|
|
|
ensureFooterEurRate();
|
|
|
|
const form = document.querySelector("[data-footer-newsletter]");
|
|
if (!form) return;
|
|
const status = form.querySelector("[data-footer-newsletter-status]");
|
|
form.addEventListener("submit", (event) => {
|
|
event.preventDefault();
|
|
const input = form.querySelector('input[type="email"]');
|
|
if (!(input instanceof HTMLInputElement) || !input.value.trim()) return;
|
|
if (status instanceof HTMLElement) {
|
|
status.hidden = false;
|
|
status.textContent = "ثبت شد — ممنون از عضویت شما.";
|
|
}
|
|
input.value = "";
|
|
});
|
|
}
|