File: D:/HostingSpaces/SBogers104/angeliekly.nl/wwwroot/js/productDetail.js
/**
* Created by Pascal on 21/04/17.
*/
$(function () {
var index = 1;
var maxIndex = 1;
$(function(){
initSlider();
});
function initSlider() {
$('figure .controls').css('top', $('.detail-page article header').outerHeight()).show();
index = 0;
maxIndex = $('.ajax-container .post-detail:last-child figure.main .detail-image').length - 1;
$('figure .controls .control.next').click(function () {
nextImage();
resetInterval();
});
$('figure .controls .control.previous').click(function () {
index--;
setImage();
resetInterval();
});
//reset interval if already has been set, because of the ajax content pages
if(typeof loopAnimation !== 'undefined') clearInterval(loopAnimation);
loopAnimation = setInterval(function () {
nextImage();
}, 4000);
if( typeof $.swipe === "undefined") rebindTouchSwipe();
$('figure').swipe({
swipeLeft: function () {
nextImage();
resetInterval();
},
swipeRight: function () {
index--;
setImage();
resetInterval();
}
});
document.onkeydown = function (e) {
if ((e.keyCode || e.which) == 37)
{
nextImage();
resetInterval();
}
if ((e.keyCode || e.which) == 39)
{
index--;
setImage();
resetInterval();
}
}
$('.post-detail .moveDetailUp').click(function () {
$('.post-detail, body, html').animate({
scrollTop: 0
}, 800);
});
$('.post-detail .open-relevant').click(function () {
$('.post-detail .relevant-posts').addClass('active');
});
$('.post-detail .relevant-posts .close, .post-detail .relevant-posts .shader, .post-detail .relevant-posts .post a').click(function () {
$('.post-detail .relevant-posts').removeClass('active');
});
}
function resetInterval() {
clearInterval(loopAnimation);
loopAnimation = setInterval(nextImage, 4000);
}
function nextImage() {
index++;
setImage();
}
function setImage() {
if(maxIndex < index) index = 0;
if(index < 0) index = maxIndex;
$('figure .detail-image').removeClass('active');
$('figure .detail-image[data-image="' + index + '"]').addClass('active');
$('figure .controls .control.next').data('image', index+1);
$('figure .controls .control.previous').data('image', index-1);
}
});