|
|
|
@ -2,10 +2,21 @@ |
|
|
|
<div class="small-12 medium-6 large-3 my-block"> |
|
|
|
<div class="small-12 medium-6 large-3 my-block"> |
|
|
|
<div class="bubble"> |
|
|
|
<div class="bubble"> |
|
|
|
{% if product.image %} |
|
|
|
{% if product.image %} |
|
|
|
<img id="product-image-{{ product.id }}" |
|
|
|
<div class="slider-container" id="slider-{{ product.id }}"> |
|
|
|
src="{% color_image_url product.image product.colors.all.0.name product.sku %}" |
|
|
|
{% color_images_url product.image product.colors.all.0.name product.sku as images %} |
|
|
|
alt="{{ product.title }}" |
|
|
|
<div class="slides"> |
|
|
|
class="product-image"> |
|
|
|
{% for image_url in images %} |
|
|
|
|
|
|
|
<img src="{{ image_url }}" |
|
|
|
|
|
|
|
alt="{{ product.title }}" |
|
|
|
|
|
|
|
class="product-image {% if forloop.first %}active{% endif %}" |
|
|
|
|
|
|
|
id="product-image-{{ product.id }}-{{ forloop.counter0 }}"> |
|
|
|
|
|
|
|
{% endfor %} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
{% if images|length > 1 %} |
|
|
|
|
|
|
|
<button class="prev" onclick="changeSlide({{ product.id }}, -1)">❮</button> |
|
|
|
|
|
|
|
<button class="next" onclick="changeSlide({{ product.id }}, 1)">❯</button> |
|
|
|
|
|
|
|
{% endif %} |
|
|
|
|
|
|
|
</div> |
|
|
|
{% else %} |
|
|
|
{% else %} |
|
|
|
<div class="no-image">No Image Available</div> |
|
|
|
<div class="no-image">No Image Available</div> |
|
|
|
{% endif %} |
|
|
|
{% endif %} |
|
|
|
@ -28,17 +39,19 @@ |
|
|
|
<input type="hidden" name="color" id="color-{{ product.id }}" value="{{ product.colors.all.0.id }}" required> |
|
|
|
<input type="hidden" name="color" id="color-{{ product.id }}" value="{{ product.colors.all.0.id }}" required> |
|
|
|
<div class="color-samples"> |
|
|
|
<div class="color-samples"> |
|
|
|
{% for color in product.colors.all %} |
|
|
|
{% for color in product.colors.all %} |
|
|
|
|
|
|
|
{% color_images_url product.image color.name product.sku as color_images %} |
|
|
|
<div class="color-sample {% if forloop.first %}selected{% endif %}" |
|
|
|
<div class="color-sample {% if forloop.first %}selected{% endif %}" |
|
|
|
{% if color.secondary_hex_color %} |
|
|
|
{% if color.secondary_hex_color %} |
|
|
|
style="background-image: linear-gradient(to right, {{ color.colorHex }} 50%, {{ color.secondary_hex_color }} 50%);" |
|
|
|
style="background-image: linear-gradient(to right, {{ color.colorHex }} 50%, {{ color.secondary_hex_color }} 50%);" |
|
|
|
{% else %} |
|
|
|
{% else %} |
|
|
|
style="background-color: {{ color.colorHex }};" |
|
|
|
style="background-color: {{ color.colorHex }};" |
|
|
|
{% endif %} |
|
|
|
{% endif %} |
|
|
|
title="{{ color.name }}" |
|
|
|
title="{{ color.name }}" |
|
|
|
data-color-id="{{ color.id }}" |
|
|
|
data-color-id="{{ color.id }}" |
|
|
|
data-color-name="{{ color.name }}" |
|
|
|
data-color-name="{{ color.name }}" |
|
|
|
data-color-image="{% color_image_url product.image color.name product.sku %}" |
|
|
|
data-color-images="{{ color_images|join:',' }}" |
|
|
|
onclick="selectColor('{{ product.id }}', '{{ color.id }}', '{{ color.name }}', this)"></div> |
|
|
|
onclick="selectColor('{{ product.id }}', '{{ color.id }}', '{{ color.name }}', this)"> |
|
|
|
|
|
|
|
</div> |
|
|
|
{% endfor %} |
|
|
|
{% endfor %} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
{% endif %} |
|
|
|
{% endif %} |
|
|
|
@ -129,14 +142,30 @@ function selectColor(productId, colorId, colorName, element) { |
|
|
|
// Add selected class to clicked color |
|
|
|
// Add selected class to clicked color |
|
|
|
element.classList.add('selected'); |
|
|
|
element.classList.add('selected'); |
|
|
|
|
|
|
|
|
|
|
|
// Update product image based on selected color |
|
|
|
// Update product images based on selected color |
|
|
|
const productImage = document.getElementById(`product-image-${productId}`); |
|
|
|
const slider = document.getElementById(`slider-${productId}`); |
|
|
|
|
|
|
|
if (slider) { |
|
|
|
|
|
|
|
const colorImages = element.getAttribute('data-color-images').split(','); |
|
|
|
|
|
|
|
const slidesContainer = slider.querySelector('.slides'); |
|
|
|
|
|
|
|
|
|
|
|
if (productImage) { |
|
|
|
// Clear existing slides |
|
|
|
const colorImage = element.getAttribute('data-color-image'); |
|
|
|
slidesContainer.innerHTML = ''; |
|
|
|
if (colorImage) { |
|
|
|
|
|
|
|
productImage.src = colorImage; |
|
|
|
// Add new slides |
|
|
|
} |
|
|
|
colorImages.forEach((imageUrl, index) => { |
|
|
|
|
|
|
|
const img = document.createElement('img'); |
|
|
|
|
|
|
|
img.src = imageUrl; |
|
|
|
|
|
|
|
img.alt = colorName; |
|
|
|
|
|
|
|
img.className = `product-image ${index === 0 ? 'active' : ''}`; |
|
|
|
|
|
|
|
img.id = `product-image-${productId}-${index}`; |
|
|
|
|
|
|
|
slidesContainer.appendChild(img); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update navigation buttons visibility |
|
|
|
|
|
|
|
const navButtons = slider.querySelectorAll('.prev, .next'); |
|
|
|
|
|
|
|
navButtons.forEach(button => { |
|
|
|
|
|
|
|
button.style.display = colorImages.length > 1 ? 'block' : 'none'; |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -212,4 +241,21 @@ function addToCartAjax(productId) { |
|
|
|
}, 3000); |
|
|
|
}, 3000); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function changeSlide(productId, direction) { |
|
|
|
|
|
|
|
const slides = document.querySelectorAll(`#slider-${productId} .product-image`); |
|
|
|
|
|
|
|
let activeIndex = Array.from(slides).findIndex(slide => slide.classList.contains('active')); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove active class from current slide |
|
|
|
|
|
|
|
slides[activeIndex].classList.remove('active'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate new index |
|
|
|
|
|
|
|
activeIndex = activeIndex + direction; |
|
|
|
|
|
|
|
if (activeIndex >= slides.length) activeIndex = 0; |
|
|
|
|
|
|
|
if (activeIndex < 0) activeIndex = slides.length - 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add active class to new slide |
|
|
|
|
|
|
|
slides[activeIndex].classList.add('active'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|