CMXX - First testing
This commit is contained in:
32
script.js
32
script.js
@@ -16,13 +16,27 @@ searchInput.onkeyup = event => {
|
||||
};
|
||||
if (document.querySelector('.product-img-small')) {
|
||||
let imgs = document.querySelectorAll('.product-img-small img');
|
||||
let mainImg = document.querySelector('.product-img-large img');
|
||||
let originalSrc = mainImg.src; // Store the original image source
|
||||
|
||||
imgs.forEach(img => {
|
||||
img.onmouseover = () => {
|
||||
document.querySelector('.product-img-large img').src = img.src;
|
||||
imgs.forEach(i => i.parentElement.classList.remove('selected'));
|
||||
img.parentElement.classList.add('selected');
|
||||
};
|
||||
/*img.onclick = () => {
|
||||
// On mouse out - restore to the original image
|
||||
img.onmouseout = () => {
|
||||
mainImg.src = originalSrc;
|
||||
imgs.forEach(i => i.parentElement.classList.remove('selected'));
|
||||
// Optionally re-select the original thumbnail
|
||||
imgs.forEach(i => {
|
||||
if (i.src === originalSrc) {
|
||||
i.parentElement.classList.add('selected');
|
||||
}
|
||||
});
|
||||
};
|
||||
img.onclick = () => {
|
||||
document.body.insertAdjacentHTML('beforeend', `
|
||||
<div class="img-modal">
|
||||
<div>
|
||||
@@ -39,13 +53,19 @@ if (document.querySelector('.product-img-small')) {
|
||||
document.querySelector('.img-modal').onclick = event => {
|
||||
if (event.target.classList.contains('img-modal')) document.querySelector('.img-modal').remove();
|
||||
};
|
||||
};*/
|
||||
};
|
||||
});
|
||||
}
|
||||
if (document.querySelector('.product #product-form')) {
|
||||
let updatePrice = () => {
|
||||
let price = parseFloat(document.querySelector('.product .price').dataset.price);
|
||||
let rrp = parseFloat(document.querySelector('.product .rrp').dataset.rrp);
|
||||
|
||||
let rrp = document.querySelector('.product .rrp') ?? 0;
|
||||
|
||||
if (rrp !=0)
|
||||
{
|
||||
rrp = parseFloat(document.querySelector('.product .rrp').dataset.rrp) ?? 0;
|
||||
}
|
||||
|
||||
document.querySelectorAll('.product #product-form .option').forEach(e => {
|
||||
if (e.value) {
|
||||
@@ -62,8 +82,10 @@ if (document.querySelector('.product #product-form')) {
|
||||
}
|
||||
});
|
||||
document.querySelector('.product .price').innerHTML = currency_code + (price > 0.00 ? price.toFixed(2) : 0.00);
|
||||
document.querySelector('.product .rrp').innerHTML = currency_code + (rrp > 0.00 ? rrp.toFixed(2) : 0.00);
|
||||
|
||||
if (rrp !=0)
|
||||
{
|
||||
document.querySelector('.product .rrp').innerHTML = currency_code + (rrp > 0.00 ? rrp.toFixed(2) : 0.00);
|
||||
}
|
||||
};
|
||||
document.querySelectorAll('.product #product-form .option').forEach(ele => ele.onchange = () => updatePrice());
|
||||
updatePrice();
|
||||
|
||||
Reference in New Issue
Block a user