
/*!
 * w2d sitepackage v1.0.0 (https://www.web-to-date.com)
 * Copyright 2019-2020 Andrea Moroni
 * Licensed under the GPL-2.0-or-later license
 */
console.log("WE LOVE TYPO3");

$(function() {
    var hash = document.location.hash;
    if (hash.match('#tabcontent')) {
        $('.nav-tabs a[href="#' + hash.split('#')[1] + '"]').tab('show');
    }
});

// Filterizr for gallery
$(function() {
    if ($('.gallery-filter').length === 0) {
        return;
    }

    var $galleryImages = $('.gallery-filter .gallery-filter-items img'),
        // Images loaded is zero because we're going to process a new set of images.
        imagesLoaded = 0,
        // Total images is still the total number of <img> elements on the page.
        totalImages = $galleryImages.length,
        imageLoaded = function () {
            imagesLoaded++;

            if (imagesLoaded === totalImages) {
                allImagesLoaded();
            }
        },
        allImagesLoaded = function () {
            $('.gallery-filter').addClass('js-show-images');

            var filterizd = $('.gallery-filter .gallery-filter-items').filterizr({
                animationDuration: 0.25, // in seconds
                filter: 'all', // Initial filter
                delayMode: 'progressive',
                delay: 25,
                easing: 'ease-out',
                filterOutCss: { // Filtering out animation
                    opacity: 0,
                    transform: 'scale(0.5)'
                },
                filterInCss: { // Filtering in animation
                    opacity: 0,
                    transform: 'scale(1)'
                },
                layout: 'sameSize',
                multifilterLogicalOperator: 'or',
                selector: '.gallery-filter .gallery-filter-items',
                setupControls: true
            });

            $('.gallery-filter-list button').on('click', function () {
                $('.gallery-filter-list button').removeClass('js-active');
                $(this).addClass('js-active');
            });
        };

    // Count the total number of images in a gallery
    $galleryImages.each(function (idx, img) {
        $('<img>')
            .on('load', imageLoaded)
            .attr('src', $(img).attr('src'));
    });
});

// Multilevel Bootstrap Menu
$('.dropdown-menu a.dropdown-toggle').on('click', function (e) {
    if (!$(this).next().hasClass('show')) {
        $(this).parents('.dropdown-menu').first().find('.show').removeClass("show");
    }
    var $subMenu = $(this).next(".dropdown-menu");
    $subMenu.toggleClass('show');

    $(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function (e) {
        $('.dropdown-submenu .show').removeClass("show");
    });

    return false;
});
