96 lines
3.1 KiB
JavaScript
96 lines
3.1 KiB
JavaScript
|
|
// Custom JavaScript for TPS Petroleums LLP
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Smooth scrolling for anchor links
|
|
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
|
anchor.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
const target = document.querySelector(this.getAttribute('href'));
|
|
if (target) {
|
|
target.scrollIntoView({
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Order Form Submission
|
|
const orderForm = document.getElementById('orderForm');
|
|
if (orderForm) {
|
|
orderForm.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const orderData = {
|
|
companyName: document.getElementById('companyName').value,
|
|
contactPerson: document.getElementById('contactPerson').value,
|
|
email: document.getElementById('email').value,
|
|
phone: document.getElementById('phone').value,
|
|
quantity: document.getElementById('quantity').value,
|
|
deliveryAddress: document.getElementById('deliveryAddress').value
|
|
};
|
|
|
|
fetch('order_handler.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(orderData)
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
alert(data.message);
|
|
if (data.status === 'success') {
|
|
orderForm.reset();
|
|
const orderModal = bootstrap.Modal.getInstance(document.getElementById('orderModal'));
|
|
if(orderModal) {
|
|
orderModal.hide();
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('An error occurred while placing your order. Please try again.');
|
|
});
|
|
});
|
|
}
|
|
|
|
// Scroll-to-top button
|
|
const scrollToTopBtn = document.getElementById('scroll-to-top');
|
|
if (scrollToTopBtn) {
|
|
window.addEventListener('scroll', () => {
|
|
if (window.scrollY > 300) {
|
|
scrollToTopBtn.classList.remove('d-none');
|
|
} else {
|
|
scrollToTopBtn.classList.add('d-none');
|
|
}
|
|
});
|
|
|
|
scrollToTopBtn.addEventListener('click', (e) => {
|
|
e.preventDefault();
|
|
window.scrollTo({
|
|
top: 0,
|
|
behavior: 'smooth'
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
|
|
// Fade-in sections on scroll
|
|
const sections = document.querySelectorAll('section');
|
|
const observer = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('visible');
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.1
|
|
});
|
|
|
|
sections.forEach(section => {
|
|
observer.observe(section);
|
|
});
|
|
});
|