{"version":3,"sources":["webpack:///./Flugger.Web/Scripts/Flugger/components/page-filters.js"],"names":["_jquery","_interopRequireDefault","require","_listItemLimit","obj","__esModule","default","sectionFilter","wrapper","urlHandle","$wrapper","pageFilter","dropdowns","filterTagContainer","inputNames","$filterListTarget","categoriesOfUsableTags","elem","filterTagCategories","activeKeys","disabledList","uniquTags","filterItems","dataset","choosenTags","activeTags","numberOfVisibleItems","addTag","tag","push","addRemoveTagCommon","troelsRemoveTag","tagToRemove","newChoosenTags","forEach","handleUrlHistory","query","length","choosenTag","index","window","history","pushState","location","pathname","onpopstate","updateTagsFromUrl","toggleActiveDataAndUpdateVisible","console","log","tags","data","active","collectActiveTags","enableEverything","currentCategory","categoriesOfTags","category","name","some","activeTag","value","deactivateInactiveTagsFromOtherCategories","findCurrentCategory","toggleActiveKeys","clearChoosenTagElements","tagInput","find","newTag","$","attr","on","prop","append","addClass","show","removeClass","hide","listitemlimit","clearLimitClass","showHideNoResultsAndClearLimit","enableAllDataItems","choosenTagsInCategories","choosenTagsFromCategory","found","dataTag","toggleActiveDataItemsBasedOnTagCategories","updateVisibleData","each","i","el","parent","inputVal","val","disableUnCheckBoxes","collectAllActiveKeyValues","box","remove","item","element","jqItem","detach","hideElement","filtersValue","URL","href","searchParams","get","filters","split","_loop","chosen","filter","valueKey","selected","chosenTag","splice","html","tagCategories","dd","this","toArray","tagsArray","catObj","prepend","addTagElements","updateTagsFromDropdown","addDropdownToggle","$dropdown","$header","$contentHeader","toggleOpen","e","stopPropagation","toggleClass","siblings","hasClass","closeDropdowns","off","target","parents","change","event","currentTarget","checked","exists","uniq","css","checkboxes","visibleCount","j","not","dataTags","app","pagefilterReset","init","$pagefilters","$filters","domObj","exports","reInit"],"mappings":"mOAAA,IAAAA,EAAAC,EAAAC,EAAA,IACAC,EAAAF,EAAAC,EAAA,KAA8C,SAAAD,EAAAG,GAAA,OAAAA,KAAAC,WAAAD,EAAA,CAAAE,QAAAF,GAE9C,IAAMG,EAAgB,SAASC,EAAS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BO,YAAY,2BAShD,SAAS+E,IACL,IAAMC,GAAe,EAAAvF,WAAE,qBACjBwF,GAAW,EAAAxF,WAAE,qBAEK,IAApBwF,EAASxH,QAAqC,IAApBwH,EAASxH,SAAgB,EAAAgC,WAAE,8BAA8BhC,QAAU,EAC7F9B,GAAc,EAAA8D,WAAE,kBAAkB,GAElCuF,EAAapE,MAAK,SAAUjD,EAAOuH,GAC/BvJ,EAAcuJ,MAQzBC,EAAAzJ,QAEc,CACXqJ,OACAK,OAPJ,WACIxH,OAAOiH,IAAIC,kBACXC","file":"44.d0ecc478762833a47178.chunk.js","sourcesContent":["import $ from 'jquery';\r\nimport listitemlimit from './list-item-limit';\r\n\r\nconst sectionFilter = function(wrapper, urlHandle) {\r\n 'use strict';\r\n\r\n let $wrapper; // section wrapper\r\n let pageFilter;\r\n let dropdowns;\r\n let filterTagContainer;\r\n\r\n let inputNames;\r\n let $filterListTarget;\r\n const filterItems = [];\r\n\r\n const filterNoResultsClass = 'no-result-by-filter';\r\n\r\n const removeAllText = 'Fjern alle';\r\n\r\n /**\r\n * FILTER DEMO INTEGRATION\r\n */\r\n let categoriesOfUsableTags; // Structure example: type: [{ name: 'Blomst', value: 'flower', active: true }, { name: 'plant', active: true },\r\n const dataset = []; // structure example: { name: 'h�ne', tags: ['bird', 'animal', 'red', 'yellow', 'round', 'triangle'], active: true },\r\n let choosenTags = [];\r\n let activeTags = [];\r\n let numberOfVisibleItems = 0;\r\n\r\n function createFilter(elem) {\r\n $wrapper = $(elem);\r\n pageFilter = $wrapper.find('.page-filter');\r\n if (pageFilter.length < 1) return;\r\n\r\n $filterListTarget = $wrapper.find('[data-filterlist]');\r\n $filterListTarget.find('[data-tag]').each(function(i, el) {\r\n filterItems.push($(el));\r\n });\r\n\r\n dropdowns = $(pageFilter.find('.filter-dropdown[data-category]'));\r\n filterTagContainer = pageFilter.find('.filter-tags'); // container for tags\r\n\r\n $(pageFilter.find('.filter-dropdown.js-unobtrusive-filter')).each(function() {\r\n addDropdownToggle(this);\r\n\r\n inputNames = $(this).find('input[type=\"checkbox\"]');\r\n\r\n // checkboxes change\r\n $(inputNames).change(function(event) {\r\n if (event.currentTarget.checked) {\r\n addTag($(this).attr('value'));\r\n } else {\r\n troelsRemoveTag($(this).attr('value'));\r\n }\r\n });\r\n });\r\n\r\n createFilterInit();\r\n }\r\n\r\n function createFilterInit() {\r\n addUIEvents();\r\n removeUnCheckBoxes(getExistingTagsFromListItems(filterItems));\r\n removeEmptyDropdowns();\r\n\r\n categoriesOfUsableTags = collectActiveTagsInCategories();\r\n // build the set of tags that are present in the data, and structure them in the categories from the dropdowns\r\n\r\n\r\n // collect data for dataset\r\n collectDataSet();\r\n\r\n updateTagsFromUI(); // in case some are \"checked\" because of browser memory on back-button\r\n }\r\n\r\n /* MODIFIED END */\r\n\r\n function collectDataSet() {\r\n $filterListTarget.find('[data-tag]').each(function(i, el) {\r\n const data = {};\r\n data.element = el;\r\n data.tags = getTagsFromElement(el);\r\n data.active = true;\r\n dataset.push(data);\r\n });\r\n }\r\n\r\n function getTagsFromElement(element) {\r\n const dataTags = $(element).data('tag').split(' ');\r\n const tags = [];\r\n dataTags.forEach(function(tag) {\r\n tags.push(tag);\r\n });\r\n return tags;\r\n }\r\n\r\n function collectActiveTagsInCategories() {\r\n const filterTagCategories = [];\r\n\r\n dropdowns.each(function() {\r\n const dd = $(this);\r\n const tags = dd.find('input').not('.passive').toArray();\r\n const tagsArray = [];\r\n\r\n tags.forEach(function(element) {\r\n tagsArray.push({\r\n value: $(element).val(),\r\n name: $(element).attr('id'),\r\n active: true\r\n });\r\n });\r\n\r\n const catObj = {\r\n name: dd.data('category'),\r\n tags: tagsArray\r\n };\r\n if (tagsArray.length > 0) {\r\n filterTagCategories.push(catObj);\r\n }\r\n });\r\n return filterTagCategories;\r\n }\r\n\r\n function addTag(tag) {\r\n choosenTags.push(tag);\r\n addRemoveTagCommon(tag);\r\n }\r\n\r\n function troelsRemoveTag(tagToRemove) {\r\n const newChoosenTags = [];\r\n choosenTags.forEach(function(tag) {\r\n if (tag !== tagToRemove) {\r\n newChoosenTags.push(tag);\r\n }\r\n });\r\n choosenTags = newChoosenTags;\r\n addRemoveTagCommon(tagToRemove);\r\n }\r\n\r\n function handleUrlHistory() {\r\n\r\n let query = '';\r\n\r\n if (choosenTags.length === 0) {\r\n query = '';\r\n } else {\r\n query = '?filters=';\r\n\r\n choosenTags.forEach(function (choosenTag, index) {\r\n query += index !== 0\r\n ? ',' + choosenTag\r\n : choosenTag;\r\n });\r\n }\r\n\r\n if (window.history.pushState) {\r\n window.history.pushState({}, null, location.pathname + query);\r\n }\r\n\r\n window.onpopstate = function() {\r\n updateTagsFromUrl();\r\n toggleActiveDataAndUpdateVisible();\r\n\r\n console.log('Chosen: ', choosenTags);\r\n };\r\n }\r\n\r\n function addRemoveTagCommon(tag) {\r\n toggleActiveDataAndUpdateVisible();\r\n collectActiveTags(dataset);\r\n\r\n if (urlHandle) {\r\n handleUrlHistory();\r\n }\r\n\r\n if (choosenTags.length === 0) {\r\n enableEverything();\r\n\r\n } else {\r\n // deactive tags that are no longer relevant\r\n const currentCategory = findCurrentCategory(tag, categoriesOfUsableTags);\r\n deactivateInactiveTagsFromOtherCategories(currentCategory, categoriesOfUsableTags);\r\n }\r\n\r\n toggleActiveKeys();\r\n troelsAddTagElements(choosenTags, categoriesOfUsableTags);\r\n showHideNoResultsAndClearLimit();\r\n }\r\n\r\n function toggleActiveDataAndUpdateVisible() {\r\n toggleActiveDataItemsBasedOnTagCategories(dataset, choosenTags, categoriesOfUsableTags);\r\n updateVisibleData(dataset);\r\n }\r\n\r\n function toggleActiveKeys() {\r\n const activeKeys = collectAllActiveKeyValues(categoriesOfUsableTags);\r\n disableUnCheckBoxes(activeKeys);\r\n }\r\n\r\n function showHideNoResultsAndClearLimit() {\r\n // Show / Hide no results/\r\n if (numberOfVisibleItems < 1) {\r\n pageFilter.addClass(filterNoResultsClass);\r\n $('.js-emptyListText').show();\r\n } else {\r\n pageFilter.removeClass(filterNoResultsClass);\r\n $('.js-emptyListText').hide();\r\n }\r\n // clear limit\r\n listitemlimit.clearLimitClass();\r\n }\r\n\r\n function collectAllActiveKeyValues(categoriesOfTags) {\r\n const activeKeys = [];\r\n categoriesOfTags.forEach(function(category) {\r\n category.tags.forEach(function(tag) {\r\n if (tag.active) activeKeys.push(tag.value);\r\n });\r\n });\r\n return activeKeys;\r\n }\r\n\r\n function troelsAddTagElements(tags) {\r\n clearChoosenTagElements();\r\n tags.forEach(function(tag) {\r\n // console.log(tag);\r\n const tagInput = pageFilter.find('input[value=\"' + tag + '\"]');\r\n const newTag = $('
');\r\n newTag.on('click', function () {\r\n troelsRemoveTag(tag);\r\n tagInput.prop('checked', false);\r\n });\r\n filterTagContainer.append(newTag);\r\n });\r\n }\r\n\r\n function enableEverything() {\r\n enableAllDataItems();\r\n updateVisibleData(dataset);\r\n clearAllCheckBoxes();\r\n enableAllTagsInCategory(categoriesOfUsableTags);\r\n toggleActiveKeys();\r\n clearChoosenTagElements();\r\n }\r\n\r\n function clearChoosenTagElements() {\r\n filterTagContainer.find('.filter-tags__tag:not(.is-static)').remove();\r\n }\r\n\r\n function clearAllCheckBoxes() {\r\n inputNames.each(function(i, box) {\r\n $(box).prop('checked', false);\r\n });\r\n }\r\n\r\n function enableAllTagsInCategory(categoriesOfTags) {\r\n categoriesOfTags.forEach(function(category) {\r\n category.tags.forEach(function(tag) {\r\n tag.active = true;\r\n });\r\n });\r\n }\r\n\r\n function findCurrentCategory(choosenTag, categoriesOfTags) {\r\n let currentCategory;\r\n categoriesOfTags.forEach(function(category) {\r\n category.tags.forEach(function(tag) {\r\n if (choosenTag === tag.value) {\r\n currentCategory = category.name;\r\n }\r\n });\r\n });\r\n return currentCategory;\r\n }\r\n\r\n function enableAllDataItems() {\r\n dataset.forEach(function(data) {\r\n data.active = true;\r\n });\r\n }\r\n\r\n // category { tag OR tag OR tag } AND category { tag OR tag OR tag } AND category { tag OR tag OR tag }\r\n function toggleActiveDataItemsBasedOnTagCategories(dataset, choosenTags) {\r\n // show all data\r\n enableAllDataItems();\r\n\r\n // build the category index of the choosen tags\r\n const choosenTagsInCategories = [];\r\n\r\n let index = 0;\r\n categoriesOfUsableTags.forEach(function(category) {\r\n choosenTagsInCategories.push([]);\r\n category.tags.forEach(function(tag) {\r\n choosenTags.forEach(function(choosenTag) {\r\n if (tag.value === choosenTag) choosenTagsInCategories[index].push(choosenTag);\r\n });\r\n });\r\n index++;\r\n });\r\n\r\n numberOfVisibleItems = 0;\r\n // loop over each category of choosen tags and check if the item has at least one tag from each category\r\n dataset.forEach(function(data) {\r\n choosenTagsInCategories.forEach(function(choosenTagsFromCategory) {\r\n let found = false;\r\n if (choosenTagsFromCategory.length === 0) found = true;\r\n choosenTagsFromCategory.forEach(function(tag) {\r\n data.tags.some(function(dataTag) {\r\n if (dataTag === tag) {\r\n found = true;\r\n return true;\r\n }\r\n });\r\n });\r\n if (!found) {\r\n data.active = false;\r\n }\r\n });\r\n if (data.active) numberOfVisibleItems++;\r\n });\r\n }\r\n\r\n function updateVisibleData(dataset) {\r\n dataset.forEach(function(item) {\r\n if (item.active) {\r\n showElement(item.element);\r\n } else {\r\n hideElement(item.element);\r\n }\r\n });\r\n }\r\n\r\n function hideElement(element) {\r\n const jqItem = $(element);\r\n jqItem.detach();\r\n jqItem.data('filtered', '');\r\n }\r\n\r\n function showElement(element) {\r\n const jqItem = $(element);\r\n jqItem.data('filtered', 'true');\r\n $filterListTarget.append(jqItem);\r\n }\r\n\r\n function collectActiveTags(dataset) {\r\n activeTags = [];\r\n dataset.forEach(function(data) {\r\n if (data.active) {\r\n data.tags.forEach(function(tag) {\r\n activeTags.push(tag);\r\n });\r\n }\r\n });\r\n }\r\n\r\n function deactivateInactiveTagsFromOtherCategories(currentCategory, categoriesOfTags) {\r\n categoriesOfTags.forEach(function(category) {\r\n if (category.name !== currentCategory) {\r\n category.tags.forEach(function(tag) {\r\n // loop over alle tags og deaktiver dem der ikke er med i activeTags\r\n activeTags.some(function(activeTag) {\r\n if (activeTag === tag.value) {\r\n tag.active = true;\r\n return true;\r\n }\r\n tag.active = false;\r\n choosenTags.forEach(function(choosenTag) {\r\n if (tag.value === choosenTag) tag.active = true;\r\n });\r\n\r\n });\r\n });\r\n }\r\n });\r\n }\r\n\r\n //\r\n // EXISTING FILTER STARTS HERE\r\n //\r\n\r\n /**\r\n * MODIFIED BY TROELS\r\n */\r\n\r\n function addUIEvents() {\r\n inputNames = dropdowns.find('input[type=\"checkbox\"]');\r\n\r\n // checkboxes change\r\n $(inputNames).change(function(event) {\r\n // updateTagsFromDropdown();\r\n // console.log(event.currentTarget);\r\n if (event.currentTarget.checked) {\r\n addTag($(this).attr('value'));\r\n } else {\r\n troelsRemoveTag($(this).attr('value'));\r\n }\r\n });\r\n // dropdown\r\n dropdowns.each(function() {\r\n addDropdownToggle(this);\r\n });\r\n }\r\n\r\n function updateTagsFromUrl() {\r\n const url = new URL(window.location.href);\r\n const filtersValue = url.searchParams.get('filters');\r\n if (!filtersValue) {\r\n return;\r\n }\r\n\r\n const filters = filtersValue.split(',');\r\n\r\n for (let index = 0; index < inputNames.length; index++) {\r\n\r\n const value = $(inputNames[index]).val();\r\n\r\n let chosen = false;\r\n filters.forEach(function (filter) {\r\n if (filter === value) {\r\n chosen = true;\r\n }\r\n });\r\n\r\n let selected = false;\r\n choosenTags.forEach(function (chosenTag) {\r\n if (chosenTag === value) {\r\n selected = true;\r\n }\r\n });\r\n\r\n if (chosen) {\r\n if (!selected) {\r\n addTag(value);\r\n $('input[value=' + value + ']').prop('checked', true);\r\n }\r\n } else {\r\n if (selected) {\r\n removeTag(value);\r\n $('input[value=' + value + ']').prop('checked', false);\r\n }\r\n }\r\n }\r\n }\r\n\r\n function updateTagsFromUI(){\r\n $(inputNames).each(function(i, el){\r\n if (el.checked){\r\n addTag($(el).val());\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * MODIFIED END\r\n */\r\n\r\n function getExistingTagsFromListItems(itemsList) {\r\n const uniquTags = [];\r\n itemsList.forEach(function(item) {\r\n const dataTags = item.data('tag').split(' ');\r\n dataTags.forEach(function(tag) {\r\n let exists = false;\r\n uniquTags.forEach(function(uniq) {\r\n if (uniq === tag) {\r\n exists = true;\r\n }\r\n });\r\n if (!exists && tag !== '') {\r\n uniquTags.push(tag);\r\n }\r\n });\r\n });\r\n return uniquTags;\r\n }\r\n\r\n function collectCheckedTagsInCategories() {\r\n const filterTagCategories = [];\r\n dropdowns.each(function() {\r\n const dd = $(this);\r\n const tags = dd.find('input:checked').toArray();\r\n const tagsArray = [];\r\n\r\n tags.forEach(function(element) {\r\n tagsArray.push({\r\n value: $(element).val(),\r\n name: $(element).attr('id')\r\n });\r\n });\r\n\r\n const catObj = {\r\n name: dd.data('category'),\r\n tags: tagsArray\r\n };\r\n if (tagsArray.length > 0) {\r\n filterTagCategories.push(catObj);\r\n }\r\n });\r\n return filterTagCategories;\r\n }\r\n\r\n function addDropdownToggle(filter) {\r\n const $dropdown = $(filter);\r\n const $header = $dropdown.find('.filter-dropdown__title');\r\n const $contentHeader = $dropdown.find('.filter-dropdown__content-title');\r\n $header.prop(\"onclick\", null).off(\"click\");\r\n $header.on('click', toggleOpen);\r\n $contentHeader.prop(\"onclick\", null).off(\"click\");\r\n $contentHeader.on('click', toggleOpen);\r\n\r\n function toggleOpen(e) {\r\n e.stopPropagation();\r\n $dropdown.toggleClass('filter-dropdown--open');\r\n $dropdown.siblings().removeClass('filter-dropdown--open');\r\n\r\n if ($dropdown.hasClass('filter-dropdown--open')) {\r\n $('body').on('click', closeDropdowns);\r\n\r\n } else {\r\n $('body').off('click', closeDropdowns);\r\n }\r\n }\r\n }\r\n\r\n function closeDropdowns(e) {\r\n const hasDropDownParent = $(e.target).parents('.filter-dropdown--open').length;\r\n if (hasDropDownParent === 0) {\r\n $('.filter-dropdown--open').removeClass('filter-dropdown--open');\r\n }\r\n }\r\n\r\n function updateTagsFromDropdown() {\r\n filterTagContainer.html('');\r\n const tagCategories = collectCheckedTagsInCategories();\r\n\r\n addTagElements(tagCategories);\r\n\r\n // adds clears limit for \"see more\" button only if something is choosen\r\n if (tagCategories.length > 0) {\r\n listitemlimit.clearLimitClass();\r\n }\r\n }\r\n\r\n function addTagElements(tagCategories) {\r\n tagCategories.forEach(function(category) {\r\n const tags = category.tags;\r\n tags.forEach(function(el) {\r\n const tag = $(' ');\r\n tag.on('click', function () {\r\n troelsRemoveTag(tag);\r\n });\r\n filterTagContainer.prepend(tag);\r\n });\r\n });\r\n }\r\n\r\n function removeTag(valueKey) {\r\n choosenTags.forEach(function (choosenTag, index) {\r\n if (choosenTag === valueKey) {\r\n choosenTags.splice(index, 1);\r\n }\r\n });\r\n\r\n $('input[value=\"' + valueKey + '\"]').prop('checked', false);\r\n updateTagsFromDropdown();\r\n }\r\n\r\n function disableUnCheckBoxes(activeKeys) {\r\n const disabledList = [];\r\n inputNames.each(function(i, el) {\r\n $(el).removeClass('passive');\r\n $(el).parent('label').removeClass('passive');\r\n let active = false;\r\n const inputVal = $(el).val();\r\n activeKeys.forEach(function(value) {\r\n if (inputVal === value) {\r\n active = true;\r\n }\r\n });\r\n if (!active) {\r\n disabledList.push(el);\r\n }\r\n });\r\n\r\n disabledList.forEach(function(el) {\r\n $(el).addClass('passive');\r\n $(el).parent('label').addClass('passive');\r\n });\r\n }\r\n\r\n function removeUnCheckBoxes(activeKeys) {\r\n const disabledList = [];\r\n inputNames.each(function (i, el) {\r\n if (!$(el).hasClass('alwaysVisible')) {\r\n $(el).removeClass('passive');\r\n let active = false;\r\n const inputVal = $(el).val();\r\n activeKeys.forEach(function(value) {\r\n if (inputVal === value) {\r\n active = true;\r\n }\r\n });\r\n if (!active) {\r\n disabledList.push(el);\r\n }\r\n }\r\n });\r\n\r\n disabledList.forEach(function(el) {\r\n // $($(el).parent(\".filter_dropdown_item\")).remove();\r\n $($(el).parents('.filter_dropdown_item')).css('display', 'none');\r\n });\r\n }\r\n\r\n function removeEmptyDropdowns() {\r\n dropdowns.each(function(i, el) {\r\n const checkboxes = $(el).find('.filter_dropdown_item');\r\n let visibleCount = 0;\r\n checkboxes.each(function(j, item) {\r\n if ($(item).css('display') !== 'none') {\r\n visibleCount++;\r\n }\r\n });\r\n if (visibleCount <= 0) {\r\n $(el).css('display', 'none');\r\n }\r\n });\r\n }\r\n\r\n createFilter(wrapper);\r\n\r\n if (urlHandle) {\r\n updateTagsFromUrl();\r\n }\r\n\r\n function reset() {\r\n choosenTags = [];\r\n enableEverything();\r\n if (urlHandle) {\r\n handleUrlHistory();\r\n }\r\n\r\n dropdowns.each(function (i, el) {\r\n $(el).css('display', '');\r\n const checkboxes = $(el).find('.filter_dropdown_item');\r\n checkboxes.each(function (j, item) {\r\n $(item).css('display', '');\r\n });\r\n });\r\n\r\n //close dropdowns\r\n $('.filter-dropdown--open').removeClass('filter-dropdown--open');\r\n }\r\n\r\n // TODO : KILA: Discuss with Mithun. Only way I can get access to enableEverything()\r\n window.app.pagefilterReset = function () {\r\n reset();\r\n };\r\n};\r\n\r\nfunction init() {\r\n const $pagefilters = $('[data-pagefilter]');\r\n const $filters = $('[data-filterlist]');\r\n\r\n if ($filters.length === 1 || ($filters.length === 0 && $('.js-dropdown-single-select').length >= 1)) {\r\n sectionFilter($('.main-content'), true);\r\n } else {\r\n $pagefilters.each(function (index, domObj) {\r\n sectionFilter(domObj);\r\n });\r\n }\r\n}\r\n\r\nfunction reInit() {\r\n window.app.pagefilterReset();\r\n init();\r\n}\r\n\r\nexport default {\r\n init,\r\n reInit\r\n};\r\n"],"sourceRoot":""}