{"version":3,"sources":["webpack:///./Scripts/filter.js"],"names":["__webpack_require__","r","__webpack_exports__","element","allFilters","allGroups","allProducts","visibleFilterValues","visibleProducts","visibleGroups","hiddenProducts","hiddenGroups","showBtn","clearBtn","showProducts","forEach","product","style","display","removeAttribute","setAttribute","group","dispatchEvent","CustomEvent","includes","Object","keys","key","push","values","join","findProducts","filters","res","visible","filter","filterValues","length","v","val","updateProducts","slice","groupId","orgValues","elements","countElement","filterValue","products","innerText","updateFilterCount","anyFilter","visibleFilter","updateCount","hide","show","querySelector","getAttribute","replace","addEventListener","e","checked","defChecked","parentElement","classList","add","remove","updateValues","groups","querySelectorAll","Array","prototype","call","prod","split","parts","initProducts","obj","value","type","initFilters"],"mappings":"0FAAAA,EAAAC,EAAAC,GAAeA,EAAA,iBAAAC,GACX,IAAIC,KACAC,KACAC,KAEAC,KACAC,KACAC,KACAC,KACAC,KAEAC,EAAU,KACVC,EAAW,KAEXC,EAAe,WACfN,EAAgBO,QAAQ,SAAUC,GAC9BA,EAAQb,QAAQc,MAAMC,QAAU,QAChCF,EAAQb,QAAQgB,gBAAgB,wBAEpCT,EAAeK,QAAQ,SAAUC,GAC7BA,EAAQb,QAAQc,MAAMC,QAAU,OAChCF,EAAQb,QAAQiB,aAAa,qBAAsB,MAEvDX,EAAcM,QAAQ,SAAUM,GAC5BhB,EAAUgB,GAAOJ,MAAMC,QAAU,QACjCb,EAAUgB,GAAOC,cAAc,IAAIC,YAAY,aAEnDZ,EAAaI,QAAQ,SAAUM,GACtBZ,EAAce,SAASH,KACxBhB,EAAUgB,GAAOJ,MAAMC,QAAU,OACjCb,EAAUgB,GAAOC,cAAc,IAAIC,YAAY,cAKvDhB,KACAkB,OAAOC,KAAKtB,GAAYW,QAAQ,SAAUY,GACtCpB,EAAoBqB,KAAKD,EAAM,IAAMvB,EAAWuB,GAAKE,OAAOC,KAAK,SAIrEC,EAAe,SAAUC,GACzB,IAAIC,KAqBJ,OApBA3B,EAAYS,QAAQ,SAAUC,GA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,IAAT+B,GACAD,EAAI/C,OAAOD,KAAKiD,GACpBrC,IACA1B,QAiDZiE,GACAvC,IACA1B","file":"3.js","sourcesContent":["export default element => {\n var allFilters = {};\n var allGroups = {};\n var allProducts = [];\n\n var visibleFilterValues = [];\n var visibleProducts = [];\n var visibleGroups = [];\n var hiddenProducts = [];\n var hiddenGroups = [];\n\n var showBtn = null;\n var clearBtn = null;\n\n var showProducts = function () {\n visibleProducts.forEach(function (product) {\n product.element.style.display = \"block\";\n product.element.removeAttribute(\"data-loadmore-skip\");\n });\n hiddenProducts.forEach(function (product) {\n product.element.style.display = \"none\";\n product.element.setAttribute(\"data-loadmore-skip\", \"\");\n });\n visibleGroups.forEach(function (group) {\n allGroups[group].style.display = \"block\";\n allGroups[group].dispatchEvent(new CustomEvent(\"update\"));\n });\n hiddenGroups.forEach(function (group) {\n if (!visibleGroups.includes(group)) {\n allGroups[group].style.display = \"none\";\n allGroups[group].dispatchEvent(new CustomEvent(\"update\"));\n }\n });\n // showBtn.hide();\n\n visibleFilterValues = [];\n Object.keys(allFilters).forEach(function (key) {\n visibleFilterValues.push(key + \"=\" + allFilters[key].values.join(\";\"));\n });\n };\n\n var findProducts = function (filters) {\n var res = [];\n allProducts.forEach(function (product) {\n var visible = true;\n Object.keys(filters).forEach(function (key) {\n var filter = filters[key];\n var values = product.filterValues[key];\n if (values != null && values.length > 0) {\n if (filter.length > 0) {\n var v = false;\n filter.forEach(function (val) {\n v |= values.includes(val);\n });\n visible &= v;\n }\n } else {\n visible &= filter.length == 0;\n }\n });\n if (visible)\n res.push(product);\n });\n return res;\n };\n\n var updateFilterCount = function () {\n var filters = {};\n Object.keys(allFilters).forEach(function (key) {\n filters[key] = allFilters[key].values.slice();\n });\n\n Object.keys(allFilters).forEach(function (key) {\n var orgValues = filters[key];\n allFilters[key].elements.forEach(function (element) {\n if (element.countElement == null)\n return;\n\n filters[key] = [];\n filters[key].push(element.filterValue);\n\n var products = findProducts(filters);\n element.countElement.innerText = products.length;\n });\n filters[key] = orgValues;\n });\n };\n\n var updateProducts = function () {\n visibleProducts = [];\n visibleGroups = [];\n hiddenProducts = [];\n hiddenGroups = [];\n\n var filters = {};\n Object.keys(allFilters).forEach(function (key) {\n filters[key] = allFilters[key].values.slice();\n });\n\n allProducts.forEach(function (product) {\n product.visible = false;\n });\n\n var products = findProducts(filters);\n products.forEach(function (product) {\n product.visible = true;\n });\n\n allProducts.forEach(function (product) {\n if (product.visible) {\n if (!visibleGroups.includes(product.groupId))\n visibleGroups.push(product.groupId)\n visibleProducts.push(product);\n } else {\n if (!hiddenGroups.includes(product.groupId))\n hiddenGroups.push(product.groupId)\n hiddenProducts.push(product);\n }\n });\n\n updateFilterCount();\n\n var anyFilter = false;\n var visibleFilter = true;\n Object.keys(allFilters).forEach(function (key) {\n visibleFilter &= visibleFilterValues.includes(key + \"=\" + allFilters[key].values.join(\";\"));\n anyFilter |= allFilters[key].values.length > 0;\n });\n\n if (showBtn) {\n showBtn.updateCount();\n\n if (visibleFilter)\n showBtn.hide();\n else\n showBtn.show();\n }\n\n if (clearBtn) {\n if (anyFilter)\n clearBtn.show();\n else\n clearBtn.hide();\n }\n };\n var initProducts = function () {\n var groups = element.querySelectorAll(\"[data-filter-group]\");\n Array.prototype.forEach.call(groups, function (group) {\n var groupId = group.getAttribute(\"data-filter-group\");\n if (allGroups[groupId] == null)\n allGroups[groupId] = group;\n var products = group.querySelectorAll(\"[data-filter-values]\");\n Array.prototype.forEach.call(products, function (product) {\n var prod = {\n groupId: groupId,\n filterValues: {},\n element: product,\n visible: true\n };\n var values = product.getAttribute(\"data-filter-values\").split(\"|\");\n values.forEach(function (val) {\n var parts = val.split(\"=\");\n if (parts[1] != \"\")\n prod.filterValues[parts[0]] = parts[1].split(\";\");\n });\n allProducts.push(prod);\n });\n });\n };\n var initFilters = function () {\n var filters = element.querySelectorAll(\"[data-filter-id]\");\n Array.prototype.forEach.call(filters, function (filter) {\n var key = filter.getAttribute(\"data-filter-id\");\n var obj = allFilters[key];\n if (obj == null) {\n allFilters[key] = obj = {\n key: key,\n values: [],\n elements: [],\n updateValues: function () {\n var values = [];\n obj.elements.forEach(function (e) {\n if (e.checked) {\n var value = e.filterValue;\n if (value != \"\")\n values.push(value);\n }\n });\n obj.values = values;\n }\n };\n }\n filter.filterValue = filter.getAttribute(\"data-filter-value\");\n filter.defChecked = filter.checked;\n if (filter.checked) {\n var value = filter.filterValue;\n if (value != \"\")\n obj.values.push(value);\n }\n obj.elements.push(filter);\n filter.countElement = filter.parentElement.querySelector(\".filter__count\");\n if (filter.type === \"checkbox\") {\n filter.addEventListener(\"btn.show\", function () {\n obj.updateValues();\n updateProducts();\n });\n }\n if (filter.type === \"radio\") {\n filter.addEventListener(\"btn.change\", function () {\n obj.values = [];\n var value = filter.filterValue;\n if (value != \"\")\n obj.values.push(value);\n updateProducts();\n showProducts();\n });\n }\n });\n };\n var init = function () {\n showBtn = element.querySelector(\"[data-show-btn]\");\n\n if (showBtn) {\n showBtn.updateCount = function () {\n showBtn.innerText = showBtn.getAttribute(\"data-show-btn\").replace(\"{0}\", visibleProducts.length);\n showBtn.show();\n };\n showBtn.addEventListener(\"click\", function () {\n showProducts();\n });\n showBtn.show = function () {\n showBtn.style.display = \"\";\n };\n showBtn.hide = function () {\n showBtn.style.display = \"none\";\n };\n }\n\n clearBtn = element.querySelector(\"[data-clear-btn]\");\n if (clearBtn) {\n clearBtn.addEventListener(\"click\", function () {\n Object.keys(allFilters).forEach(function (filter) {\n allFilters[filter].elements.forEach(function (e) {\n e.checked = e.defChecked;\n if (e.defChecked)\n e.parentElement.classList.add('active');\n else\n e.parentElement.classList.remove('active');\n });\n allFilters[filter].updateValues();\n });\n updateProducts();\n showProducts();\n });\n clearBtn.show = function () {\n clearBtn.style.display = \"\";\n };\n clearBtn.hide = function () {\n clearBtn.style.display = \"none\";\n };\n }\n\n initProducts();\n initFilters();\n updateProducts();\n showProducts();\n };\n\n init();\n}"],"sourceRoot":""}