Preview: app.js
Size: 9.49 KB
/home/getspomw/royalsquad.us/public/assets/js/app.js
// script first
// function loadChat() {
// if (window.chatLoaded) return;
// window.chatLoaded = true;
// // example: load chat script lazily
// const s = document.createElement("script");
// s.src = "/public/assets/js/chat.js"; // ya third-party chat
// s.async = true;
// document.body.appendChild(s);
// }
// let ticking = false;
// window.addEventListener(
// "scroll",
// () => {
// if (!ticking) {
// requestAnimationFrame(() => {
// loadChat();
// ticking = false;
// });
// ticking = true;
// }
// },
// { passive: true }
// );
// window.addEventListener("load", () => {
// console.log("Owl Carousel is initializing...");
// $(".slider_banner").owlCarousel({
// items: 1,
// loop: true,
// autoplay: false,
// autoplayTimeout: 5000,
// autoplayHoverPause: true,
// nav: false,
// dots: true,
// smartSpeed: 1000,
// });
// });
window.addEventListener(
"scroll",
() => {
const s = document.createElement("script");
s.src = "https://www.googletagmanager.com/gtag/js?id=G-XXXX";
s.async = true;
document.body.appendChild(s);
},
{ once: true }
);
window.addEventListener("load", () => {
setTimeout(() => {
if (typeof WOW !== "undefined") {
new WOW({ mobile: false }).init();
}
}, 1500);
});
window.addEventListener("load", () => {
const slider = document.querySelector(".slider_banner");
if (!slider) return;
requestAnimationFrame(() => {
$(".slider_banner").owlCarousel({
items: 1,
loop: true,
dots: true,
smartSpeed: 1000,
});
});
});
// script second
window.addEventListener("load", () => initSlider());
document.addEventListener("click", function (event) {
fetch("/log-action", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRF-TOKEN": document
.querySelector('meta[name="csrf-token"]')
.getAttribute("content"),
},
body: JSON.stringify({
action: "Clicked on " + event.target.innerText,
url: window.location.href,
}),
});
});
// script third
// document.addEventListener("DOMContentLoaded", function () {
// document.querySelectorAll(".appointment-form").forEach((form) => {
// const emailField = form.querySelector(".email-field");
// const otpField = form.querySelector(".otp-field");
// const otpWrapper = form.querySelector(".otp-field-wrapper");
// const otpStatus = form.querySelector(".otp-status");
// const numberField = form.querySelector(".number-field");
// const numberStatus = form.querySelector(".number-status");
// const countryCode = form.querySelector(".country-code");
// const submitBtn = form.querySelector(".submit-btn");
// let otpVerified = false;
// let numberValid = false;
// const showTempMessage = (element, message, color, duration = 4000) => {
// element.innerText = message;
// element.style.color = color;
// setTimeout(() => {
// if (element.innerText === message) element.innerText = "";
// }, duration);
// };
// // EMAIL OTP HANDLING
// emailField.addEventListener("blur", function () {
// const email = emailField.value.trim();
// if (email) {
// showTempMessage(otpStatus, "Sending OTP...", "blue");
// // fetch("{{ route('send.otp') }}", {
// fetch(SEND_OTP_URLSEND, {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// // "X-CSRF-TOKEN": "{{ csrf_token() }}",
// "X-CSRF-TOKEN": document
// .querySelector('meta[name="csrf-token"]')
// .getAttribute("content"),
// },
// body: JSON.stringify({
// email,
// }),
// })
// .then((res) => res.json())
// .then((data) => {
// if (data.status === "success") {
// otpWrapper.style.display = "block";
// showTempMessage(otpStatus, "OTP sent to your email.", "green");
// } else {
// otpWrapper.style.display = "none";
// showTempMessage(otpStatus, "Failed to send OTP.", "red");
// }
// })
// .catch(() => {
// otpWrapper.style.display = "none";
// showTempMessage(otpStatus, "Error sending OTP.", "red");
// });
// }
// });
// // OTP VERIFY
// otpField.addEventListener("input", function () {
// const otp = otpField.value.trim();
// const email = emailField.value.trim();
// if (otp.length === 6 && email) {
// showTempMessage(otpStatus, "Verifying OTP...", "blue");
// fetch("{{ route('verify.otp') }}", {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// "X-CSRF-TOKEN": "{{ csrf_token() }}",
// },
// body: JSON.stringify({
// email,
// otp,
// }),
// })
// .then((res) => res.json())
// .then((data) => {
// if (data.status === "success") {
// otpVerified = true;
// showTempMessage(otpStatus, "OTP Verified.", "green");
// } else {
// otpVerified = false;
// showTempMessage(otpStatus, "Invalid OTP.", "red");
// }
// })
// .catch(() => {
// otpVerified = false;
// showTempMessage(otpStatus, "Error verifying OTP.", "red");
// });
// }
// });
// // PHONE VALIDATION
// numberField.addEventListener("blur", function () {
// const number = numberField.value.trim();
// const code = countryCode.value.trim();
// numberValid = false;
// if (number && code) {
// const fullNumber = code + number;
// showTempMessage(numberStatus, "Validating number...", "blue");
// fetch(
// `https://apilayer.net/api/validate?access_key=e97128ac0867c4f22657fd8607c6dd20&number=${encodeURIComponent(
// fullNumber
// )}&format=1`
// )
// .then((res) => res.json())
// .then((data) => {
// if (data.valid) {
// numberValid = true;
// showTempMessage(numberStatus, "Number is valid", "green");
// } else {
// numberValid = false;
// showTempMessage(numberStatus, "Invalid phone number", "red");
// }
// })
// .catch(() => {
// numberValid = false;
// showTempMessage(numberStatus, "Error validating number", "red");
// });
// }
// });
// // FORM SUBMIT
// form.addEventListener("submit", function (e) {
// e.preventDefault();
// if (!otpVerified) {
// showTempMessage(otpStatus, "Please verify Email first.", "red");
// return;
// }
// if (!numberValid) {
// showTempMessage(
// numberStatus,
// "Please enter a valid phone number.",
// "red"
// );
// return;
// }
// // remove old errors
// form.querySelectorAll(".error.text-danger").forEach((el) => el.remove());
// const formData = new FormData(form);
// submitBtn.disabled = true;
// submitBtn.innerText = "Please wait...";
// fetch("{{ route('appointments') }}", {
// method: "POST",
// headers: {
// "X-CSRF-TOKEN": "{{ csrf_token() }}",
// },
// body: formData,
// })
// .then((res) => res.json())
// .then((data) => {
// submitBtn.disabled = false;
// submitBtn.innerText = "Submit Query";
// if (data.status === "success") {
// form.reset();
// otpWrapper.style.display = "none";
// otpVerified = false;
// numberValid = false;
// Swal.fire({
// icon: "success",
// title: "Appointment Booked!",
// text: "Thank you for contacting us.",
// });
// } else if (data.status === "validation_error") {
// const errors = data.errors;
// for (const [field, messages] of Object.entries(errors)) {
// const input = form.querySelector(`[name="${field}"]`);
// if (input) {
// const errorEl = document.createElement("div");
// errorEl.classList.add("error", "text-danger");
// errorEl.innerText = messages[0];
// input.parentNode.appendChild(errorEl);
// }
// }
// } else {
// Swal.fire({
// icon: "error",
// title: "Submission Failed",
// text: data.message || "Something went wrong. Try again.",
// });
// }
// })
// .catch(() => {
// submitBtn.disabled = false;
// submitBtn.innerText = "Submit Query";
// Swal.fire({
// icon: "error",
// title: "Error",
// text: "Server error. Please try again later.",
// });
// });
// });
// });
// });
let heavyLoaded = false;
window.addEventListener('scroll', () => {
if (heavyLoaded) return;
heavyLoaded = true;
['YTPlayer.min.js', 'isotope.pkgd.min.js', 'count-to.js'].forEach(f => {
const s = document.createElement('script');
s.src = `/public/assets/js/${f}`;
s.defer = true;
document.body.appendChild(s);
});
}, { once: true });
Directory Contents
Dirs: 0 × Files: 18