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/ZelfVerkopen/zelfverkopen.nl/resources/assets/js/site/propertyImagesHandler.js
var PropertyImageHandler = {

    photoSlider: document.getElementById('photoslider'),
    propertyImagesWrapper: document.getElementById('property-image-wrapper'),
    propertySliderOpenLinks: null,
    images: null,
    gallery: null,


    options: {
        index: 0, // start at first slide
        history: false,
        focus: false,
        shareEl: false,
        tapToClose: true,
        closeOnScroll: false,
        showHideOpacity: true,
        bgOpacity: 0.85,

        showAnimationDuration: 0,
        hideAnimationDuration: 0
    },


    init: function () {

        if (isset(PropertyImageHandler.photoSlider) && isset(PropertyImageHandler.propertyImagesWrapper)) {


            // Prepare the images
            var images = [];
            var imageCollection = PropertyImageHandler.propertyImagesWrapper.querySelectorAll('#images-for-slider span');

            if (isset(imageCollection)) {

                var imageAmount = imageCollection.length;
                if (imageAmount !== 0) {

                    for (var i = 0; i < imageAmount; i++) {

                        var image = imageCollection[i];
                        images.push({
                            src: image.getAttribute('data-src'),
                            w: image.getAttribute('data-width'),
                            h: image.getAttribute('data-height')
                        });
                    }
                }
                PropertyImageHandler.images = images;
            }

            // Bind click events to the open slider links
            PropertyImageHandler.propertySliderOpenLinks = PropertyImageHandler.propertyImagesWrapper.querySelectorAll('.open-photo-slider');

            // Only continue if there are even images and links to the slider
            if (isset(PropertyImageHandler.images) && isset(PropertyImageHandler.propertySliderOpenLinks)) {

                // Add the event listeners to the links
                var amountOfLinks = PropertyImageHandler.propertySliderOpenLinks.length;
                for (var i = 0; i < amountOfLinks; i++) {

                    var link = PropertyImageHandler.propertySliderOpenLinks[i];
                    link.addEventListener('click', function () {
                        PropertyImageHandler.openSliderOnIndex(this.getAttribute('data-index'));
                    });
                }
            }
        }
    },

    openSliderOnIndex: function (index) {

        PropertyImageHandler.options.index = parseInt(index);
        // console.log(index);
        // Initializes and opens PhotoSwipe
        PropertyImageHandler.gallery = new PhotoSwipe(PropertyImageHandler.photoSlider, PhotoSwipeUI_Default, PropertyImageHandler.images, PropertyImageHandler.options);
        PropertyImageHandler.gallery.init();

    }
};

PropertyImageHandler.init();