HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/signmania.komma.pro/wwwroot/js/projectSlider.js
/**
 * Created by Pascal on 16/06/17.
 */

$(function(){
    initSlider();
});

var index = 0;
var maxIndex = 1;

function initSlider() {
    index = 0;
    maxIndex = $('.ajax-container .projects article').length - 1;

    $('.ajax-container .service-block.image, .ajax-container .open-realisations').click(function () {
        $('.ajax-container .projects').addClass('active');
        $('.ajax-container .close-button').addClass('show');
        $('.ajax-container .next-service').addClass('active');
        $('body').addClass('inProjects');
        document.querySelector('.service-block.content').classList.add('in-active');
        document.querySelector('.service-block.image').classList.add('in-active');
        setProject();

        setTimeout(function () {
            $('.ajax-container .projects article.active .lazyload').lazyload();
        }, 300);
    });

    $('body.services-detail').click(function (event) {
        if(event.target.tagName == 'BODY' || event.target.tagName == 'ASIDE')  closeProjects();
    });

    $('.services-detail .projects').click(function (event) {
        if(event.target.tagName == 'SECTION')  closeProjects();
    });

    $('.services-detail .close-button').click(function () {
        closeProjects();
    });

    $('.ajax-container .projects .navigator .nav-button').click(function () {

        if($(this).hasClass('next')) index++;
        if($(this).hasClass('previous')) index--;
        //console.log(index);
        setProject();
        //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();

    $('.ajax-container .projects').swipe({
        swipeLeft: function () {
            index++;
            setProject();
        },
        swipeRight: function () {
            index--;
            setProject();
        }
    });

    function closeProjects() {
        $('.ajax-container .projects').removeClass('active');
        $('.ajax-container .close-button').removeClass('show');
        $('body').removeClass('inProjects');
        $('.ajax-container .projects article').removeClass('active');
        $('.ajax-container .next-service').removeClass('active');

        document.querySelector('.service-block.content').classList.remove('in-active');
        document.querySelector('.service-block.image').classList.remove('in-active');
    }

    function setProject() {
        if(maxIndex < index) index = 0;
        if(index < 0) index = maxIndex;

        $('.ajax-container .projects article').removeClass('active');

        $('.ajax-container .projects article[data-project="' + index + '"]').addClass('active');
        $('.ajax-container .projects article.active .lazyload').lazyload();
    }

}