{"version":3,"file":"developmentsFilter.b0744972.js","sources":["../../../src/js/modules/developments-filter.js"],"sourcesContent":["// Implements live filtering\n// Implements ARIA Live Region to announce that content on the page has updated as a result of user action\n// https://www.scottohara.me/blog/2022/02/05/are-we-live.html\n\nlet filterType = document.querySelector(\"#filterBuildingTypes\");\nlet filterDevelopment = document.querySelector(\"#developmentType\");\nlet filterBedrooms = document.querySelector(\"#filterBedrooms\");\nlet filterPrices = document.querySelector(\"#filterPrice\");\nlet filterHomebuy = document.querySelector(\"#filterHomebuy\");\n\nlet ariaLive = document.querySelector('#ariaLive');\nlet ariaMessage = \"\";\nlet propertiesWrapper = document.querySelector('.theProperties');\n\nconst propertyTypes = document.querySelectorAll(\".theProperties > .propertyType\");\n\nlet homepage = document.querySelector('html');\n\nif (homepage.classList.contains('homepage')) {\n\tlet filterForm = document.querySelector('.filterForm');\n\tpropertiesWrapper.classList.add('uc_hide-for-everyone');\n\tconst showResults = () => {\n\t\tpropertiesWrapper.classList.remove('uc_hide-for-everyone');\n\t}\n\tfilterForm.addEventListener('change', showResults);\n}\n\nconst doFiltering = () => {\n\t// console.log(\"---new run---\");\n\t/*\n\t\tExplanation:\n\t\t- We build a `searchArray` which contains the parameters that the user is searching against, this is taken from the form inputs\n\t\t- We loop through each property type, and test its parameter values against the search parameters, to build a `matchArray`\n\t\t- We stringify both arrays so that we can then compare and see if they are identical - if so, the propertyType was a match for the search criteria\n\t*/\n\n\tpropertyTypes.forEach(propertyType => {\n\t\t// hide all on first run, visually and in the a11y tree\n\t\tpropertyType.classList.add('uc_hide-for-everyone');\n\t\tpropertyType.setAttribute(\"aria-hidden\", \"true\");\n\t\t// console.log( propertyType );\n\n\t\tconst searchArray = []; // what is the user looking for\n\t\tconst matchArray = []; // what matches on this plot\n\n\t\t// build the search array and Aria message. This only adds what PROPERTY needs to be matched, and not the VALUE. Tests are done independently of this array.\n\t\tif( filterType ) {\n\t\t\tif( filterType.value != \"any\" ) { searchArray.push('building-type'); }\n\t\t}\n\t\tif( filterDevelopment ) {\n\t\t\tif( filterDevelopment.value != \"all\" ) { searchArray.push('development-type'); }\n\t\t}\n\t\tif( filterBedrooms.value != \"any\" ) { searchArray.push('bedrooms'); }\n\t\tif( filterPrices.value != \"any\" ) { searchArray.push('prices'); }\n\t\tif( filterHomebuy.value != \"any\" ) { searchArray.push('homebuy'); }\n\t\t// if( filterChildFriendly.checked ) { searchArray.push('childFriendly'); }\n\n\t\t// build the match array\n\t\tif( filterType ) {\n\t\t\tif( filterType.value == propertyType.dataset.buildingType ) {\n\t\t\t\tmatchArray.push('building-type');\n\t\t\t}\n\t\t}\n\t\tif( filterDevelopment ) {\n\t\t\tif( filterDevelopment.value == propertyType.dataset.developmentType ) {\n\t\t\t\tmatchArray.push('development-type');\n\t\t\t}\n\t\t}\n\t\tif( filterBedrooms.value == propertyType.dataset.bedrooms ) {\n\t\t\tmatchArray.push('bedrooms');\n\t\t}\n\t\tif (filterPrices.value != \"any\") {\n\t\t\t// OK, we're looking at the prices, so lets grab the active option so we can compare\n\t\t\tlet theSelectedOption = filterPrices.options[filterPrices.selectedIndex];\n\n\t\t\tif (\n\t\t\t\t(propertyType.dataset.price >= theSelectedOption.dataset.minPrice)\n\t\t\t\t&&\n\t\t\t\t(propertyType.dataset.price < theSelectedOption.dataset.maxPrice)\n\t\t\t) {\n\t\t\t\tmatchArray.push('prices'); // this property is a match for the selected option\n\t\t\t}\n\t\t}\n\t\tif( propertyType.dataset.schemes?.split(',').includes(filterHomebuy.value) ) {\n\t\t\tmatchArray.push('homebuy');\n\t\t}\n\t\t// if( filterChildFriendly.checked && cottage.dataset.childFriendly == 'true' ) {\n\t\t// \tmatchArray.push('childFriendly');\n\t\t// }\n\n\t\t// if the searchArray is the same as the matchArray then the cottage was a complete match on all the searched items and should be shown\n\t\tif( JSON.stringify(searchArray) == JSON.stringify(matchArray) ) {\n\t\t\tpropertyType.classList.remove('uc_hide-for-everyone');\n\t\t\tpropertyType.setAttribute(\"aria-hidden\", \"false\");\n\t\t} else {\n\t\t\tpropertyType.classList.add('uc_hide-for-everyone');\n\t\t\tpropertyType.setAttribute(\"aria-hidden\", \"true\");\n\t\t}\n\n\t\t// console.log( \"searchArray\", JSON.stringify(searchArray) );\n\t\t// console.log( \"matchArray\", JSON.stringify(matchArray) );\n\t});\n\n\tlet numberMatchedPropertyTypes = document.querySelectorAll('.theProperties > .propertyType:not(.uc_hide-for-everyone)').length;\n\tariaLive.innerHTML = \"\"; // empty any old content\n\tariaMessage = `List of property types updated, there ${ numberMatchedPropertyTypes == 1 ? 'is' : 'are' } ${numberMatchedPropertyTypes} match${ (numberMatchedPropertyTypes != 1) ? 'es' : '' } for property types that: `;\n\n\tif (filterType) {\n\t\tif (filterType.value != \"any\") {\n\t\t\tariaMessage += `are a ${filterType.value}, `;\n\t\t}\n\t\telse {\n\t\t\tariaMessage += `are any type of building, `;\n\t\t}\n\t}\n\n\tif (filterDevelopment) {\n\t\tif (filterDevelopment.value != \"all\") {\n\t\t\tariaMessage += `are in the ${filterDevelopment.value} development, `;\n\t\t}\n\t\telse {\n\t\t\tariaMessage += `are in any development, `;\n\t\t}\n\t}\n\n\tif( filterBedrooms.value != \"any\" ) {\n\t\tariaMessage += `with ${filterBedrooms.value} bedrooms, `;\n\t} else { ariaMessage += `with any number of bedrooms, `; }\n\n\tif( filterPrices.value != \"any\" ) {\n\t\tlet ukPrice = new Intl.NumberFormat(`en-GB`, {\n\t\t\tcurrency: `GBP`,\n\t\t\tstyle: `currency`,\n\t\t\ttrailingZeroDisplay: `stripIfInteger`\n\t\t}).format( filterPrices.value );\n\n\t\tariaMessage += `costing more than ${ukPrice}, `;\n\t} else { ariaMessage += `at any price, `; }\n\n\tif( filterHomebuy.value != \"any\" ) {\n\t\tariaMessage += `with the ${ filterHomebuy.value } scheme available.`;\n\t} else { ariaMessage += `with any (or no) homebuy assistance scheme.`; }\n\n\t// if( filterSleeps.value != \"any\" ) {\n\t// \tariaMessage += `sleeping ${filterSleeps.value} people, `;\n\t// } else { ariaMessage += `sleeping any number of people, `; }\n\n\t// if( filterChildFriendly.checked ) {\n\t// \tariaMessage += `that are child friendly, `;\n\t// } else {\n\t// \tariaMessage += `that may or may not be child friendly, `;\n\t// }\n\n\tariaLive.insertAdjacentHTML('beforeend', `
We don't have a property to match your criteria at this time. Please consider changing search options or opt-in to our mailing list to be kept informed regarding future plot releases
`)\n\t}\n\n};\n\n// watch for changes\n\tif( filterType ) {\n\t\tfilterType.addEventListener('change', doFiltering);\n\t}\n\tif( filterDevelopment ) {\n\t\tfilterDevelopment.addEventListener('change', doFiltering);\n\t}\n\tfilterBedrooms.addEventListener('change', doFiltering);\n\tfilterPrices.addEventListener('change', doFiltering);\n\tfilterHomebuy.addEventListener('change', doFiltering);\n\t// filterChildFriendly.addEventListener('change', doFiltering);\n\ndoFiltering();\n\n"],"names":["filterType","filterDevelopment","filterBedrooms","filterPrices","filterHomebuy","ariaLive","ariaMessage","propertiesWrapper","propertyTypes","homepage","filterForm","showResults","doFiltering","_a","propertyType","searchArray","matchArray","theSelectedOption","numberMatchedPropertyTypes"],"mappings":"AAIA,IAAIA,EAAsB,SAAS,cAAc,sBAAsB,EACnEC,EAAsB,SAAS,cAAc,kBAAkB,EAC/DC,EAAsB,SAAS,cAAc,iBAAiB,EAC9DC,EAAsB,SAAS,cAAc,cAAc,EAC3DC,EAAsB,SAAS,cAAc,gBAAgB,EAE7DC,EAAsB,SAAS,cAAc,WAAW,EACxDC,EAAsB,GACtBC,EAAsB,SAAS,cAAc,gBAAgB,EAEjE,MAAMC,EAAgB,SAAS,iBAAiB,gCAAgC,EAEhF,IAAIC,EAAkB,SAAS,cAAc,MAAM,EAEnD,GAAIA,EAAS,UAAU,SAAS,UAAU,EAAG,CAC5C,IAAIC,EAAa,SAAS,cAAc,aAAa,EACrDH,EAAkB,UAAU,IAAI,sBAAsB,EACtD,MAAMI,EAAc,IAAM,CACzBJ,EAAkB,UAAU,OAAO,sBAAsB,CACzD,EACDG,EAAW,iBAAiB,SAAUC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