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/EUmans/umansradepo.be/wwwroot/js/filter.js
/**
 * Created by Pascal on 17/02/16.
 */

$(function () {

    var itemsToShow = {};

    if (typeof $.lazyload === "undefined") rebindLazyLoad();

    $(".references .lazy").lazyload({
        effect: "fadeIn"
    });

    $('span.show-all').click(function () {
        $(this).parent().parent().find('.filter-button input').prop("checked", false).change();
    });

    $('.filter-button input').change(function () {
        itemsToShow = {};

        $('.filter-button input').each(function (index) {
            if ($(this).is(':checked')) {

                objectType = $(this).attr('name');
                if (!(objectType in itemsToShow)) {
                    itemsToShow[objectType] = [$(this).val()];
                }
                else {
                    itemsToShow[objectType].push($(this).val());
                }
            }
        });

        showSelection(itemsToShow);

        return false;

    });

});

function showSelection(filters) {

    //if no filter is set, all reference active
    if (jQuery.isEmptyObject(filters)) {
        $('.reference').addClass('active');
    }

    else {

        //remove active from all reference
        $('.reference').removeClass('active');
        keys = Object.keys(filters);

        //make an array for the filter string
        filterArray = [];

        //create hash for url
        hash = '?';

        //for every filterType that is set, loop through the selected filters
        $.each(keys, function (i, myFilter) {


            //if it's the first filterType in the loop, just append them all to the filter array
            if (filterArray.length === 0) {

                //append the filterType to the URL
                hash += myFilter + '=';

                $.each(filters[myFilter], function (j, val) {
                    valString = val.replace(myFilter +'-','');
                    filterArray.push('.' + val);

                    //append the filter to the URL after the filterType (with extra Komma)
                    hash += valString + ',';
                });

                //if loop is done remove the unnecessary Komma
                hash = hash.slice(0, -1);
            }

            //else you have to get the already set filter strings and append the filter from the following filterType
            else {

                //append extra filterType to the URL
                hash += '&' + myFilter + '=';

                //create and temp array for pushing the new filter strings in
                tempFilterArray = [];

                //loop through the new filterType for the selected filters
                $.each(filters[myFilter], function (j, val) {
                    valString = val.replace(myFilter +'-','');
                    hash += valString + ',';

                    //for every extra filter, loop trough the already set filter strings and append the extra filter
                    $.each(filterArray, function (j, filtersSoFar) {
                        tempFilterArray.push(filtersSoFar + '.' + val);

                        //console.log(filtersSoFar+'.'+val); //enable if you want to see the magic happen
                    });
                });
                //make the temp array the filter array, so when we got more filterTypes the code will run again
                filterArray = tempFilterArray;

                hash = hash.slice(0, -1);
            }
        });

        //now run the filterArray, so we can see the filtered references
        $.each(filterArray, function (v, setFilter) {
            $('.reference' + setFilter).addClass('active');
        });

        //change the URL and append to the href of the references
        //document.location.hash = hash;

        $('.reference a').each(function (index) {
            $(this).attr('href', ($(this).attr('href').split("?")[0] + hash));
        });
    }

}