The Pope Benedict Code
£ 3.00
Product code: 446584
Description
RRP £6.99 {
touchStartX = e.changedTouches[0].screenX;
});
gallery_container.addEventListener('touchend', (e) => {
touchEndX = e.changedTouches[0].screenX;
handleSwipe();
});
function handleSwipe() {
const threshold = 20;
if (touchEndX < touchStartX - threshold) {
cycleImageGallery(true);
}
if (touchEndX > touchStartX + threshold) {
cycleImageGallery(false);
}
}
}
let image_container = gallery_container.querySelector('.image');
if (!image_container) {
image_container = document.createElement('div');
image_container.classList.add('image');
gallery_container.appendChild(image_container);
}
let img = image_container.querySelector('img');
if (!img) {
img = document.createElement('img');
image_container.appendChild(img);
}
let gallery_count = gallery_container.querySelector('.gallery-count');
if (!gallery_count) {
gallery_count = document.createElement('p');
gallery_count.classList.add('gallery-count');
gallery_container.appendChild(gallery_count);
}
gallery_count.innerText = `${index + 1} / ${image_gallery_images.length}`;
let gallery_indicators = gallery_container.querySelector('.gallery-indicators');
if (!gallery_indicators) {
gallery_indicators = document.createElement('div');
gallery_indicators.classList.add('gallery-indicators');
gallery_container.appendChild(gallery_indicators);
}
gallery_indicators.innerHTML = '';
for (let i=0; i' : '';
gallery_indicators.innerHTML += dot;
}
let prev_button = gallery_container.querySelector('.prev');
let next_button = gallery_container.querySelector('.next');
if (image_gallery_images.length > 1) {
if (!prev_button) {
prev_button = document.createElement('button');
prev_button.type = 'button';
prev_button.setAttribute('onclick', 'cycleImageGallery(false);');
prev_button.classList.add('prev');
prev_button.innerHTML = ``;
gallery_container.appendChild(prev_button);
}
if (!next_button) {
next_button = document.createElement('button');
next_button.type = 'button';
next_button.setAttribute('onclick', 'cycleImageGallery(true);');
next_button.classList.add('next');
next_button.innerHTML = ``;
gallery_container.appendChild(next_button);
}
} else {
if (prev_button) prev_button.remove();
if (next_button) next_button.remove();
}
img.src = imgSrc;
gallery_container.style.display = 'flex';
addGalleryEvent(gallery_container);
}
function cycleImageGallery(next) {
const length = image_gallery_images.length;
let index;
if (next) {
index = (current_image_gallery_index + 1 >= length) ? 0 : current_image_gallery_index + 1;
} else {
index = (current_image_gallery_index - 1 < 0) ? length - 1 : current_image_gallery_index - 1;
}
const image = image_gallery_images[index].querySelector('img');
const src = (image && image.src) ? image.src : 0;
if (!src) return;
displayImageGallery(src, index);
}
for (let i=0; i