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/BVerhoeven/verhoevendak.nl/wwwroot/js/projects.js
var overview = $('.projects-overview').length > 0;

if (overview) {

    // Load products on change
    $('.categories input[type="checkbox"]').change(function () {
        loadProjects();
    });
}


// Load projects
function loadProjects() {
    console.log('loadProjects');

    var cats = [];
    var $boxes = $('.overview-header .categories input[type="checkbox"]:checked');

    // Set values of checkboxes
    $boxes.each(function () {
        cats.push($(this).val());
    });

    var url = window.location.href;
    if(cats.length > 0) {
        console.log(cats);
        url = updateQueryString('cat', cats.join(','), url);
        window.location.href = url;
    } else {
        url = removeURLParameter('cat', url);
        window.location.href = url;
    }
}

//get url params by name
$.urlParam = function (name) {
    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return results[1] || 0;
};


/* update url string */
function updateQueryString(key, value, urlString) {
    if (!urlString) urlString = window.location.href;

    if (urlString.indexOf(key + '=') > -1) {
        $current = $.urlParam(key);
        if ($current == 0) {
            $split = urlString.split(key + '=');
            $url = $split[0] + key + "=" + value + $split[1];
        }
        else {
            $url = urlString.replace(key + "=" + $current, key + "=" + value);
        }
    } else {
        if (urlString.indexOf('?') == -1) {
            $split = urlString.split('?');
            $url = $split[0] + '?' + key + '=' + value;
        }
        else {
            $url = urlString + '&' + key + '=' + value;
        }
    }
    return $url;
}

function removeURLParameter(key, url) {
    var urlparts= url.split('?');
    if (urlparts.length>=2) {

        var prefix= encodeURIComponent(key)+'=';
        var pars= urlparts[1].split(/[&;]/g);

        //reverse iteration as may be destructive
        for (var i= pars.length; i-- > 0;) {
            //idiom for string.startsWith
            if (pars[i].lastIndexOf(prefix, 0) !== -1) {
                pars.splice(i, 1);
            }
        }

        url= urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : "");
        return url;
    } else {
        return url;
    }
}