function handleAttributesAndOptionsFilter() { function createAttributeQueryString(name, value, optionId) { const key = 'attr_' + optionId + '-' + name; const encodedValue = encodeURIComponent(value); return {key: key, value: encodedValue}; } $('.add-attribute').click(function() { const title = $(this).data('attribute-title'); const type = $(this).data('attribute-type'); const optionId = $(this).data('option-id'); const optionValue = $(this).data('option-value'); const titleParam = createAttributeQueryString('title', title, optionId); const typeParam = createAttributeQueryString('type', type, optionId); const optionValueParam = createAttributeQueryString('option', optionValue, optionId); const parsedUrl = getUrlVars(); let activeElementIndicator = $(this).children('li'); activeElementIndicator = activeElementIndicator.length > 0 ? activeElementIndicator : $(this); if (activeElementIndicator.hasClass('active')) { activeElementIndicator.removeClass('active'); activeElementIndicator.attr('checked', false); delete parsedUrl[titleParam.key]; delete parsedUrl[typeParam.key]; delete parsedUrl[optionValueParam.key]; } else { activeElementIndicator.addClass('active'); parsedUrl[titleParam.key] = titleParam.value; parsedUrl[typeParam.key] = typeParam.value; parsedUrl[optionValueParam.key] = optionValueParam.value; } makeUrl(parsedUrl); }); }