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AemB,YAAYN,QAGxB,GAAIF,GAAMZ,EAAc,EAAI,CAC/B,IAAIqB,EAAcrB,EAAc,EAG5Ba,EADDpB,EACW,0BAA4BC,EAAc,kBAAoB2B,EAAc5B,EAE5E,0BAA4BC,EAAc,kBAAoB2B,EAE5EP,EAAS3C,KAAO0C,EAChBC,EAASK,MAAQ,gBACjBL,EAASH,UAAY,IAErBV,EAAemB,YAAYN,QAGxB,GAAIF,GAAMZ,EAAc,EAAI,CAC/B,IAAIsB,EAAatB,EAAc,EAE3Ba,EADDpB,EACW,0BAA4BC,EAAc,kBAAoB4B,EAAa7B,EAE3E,0BAA4BC,EAAc,kBAAoB4B,EAE5ER,EAAS3C,KAAO0C,EAChBC,EAASK,MAAQ,YACjBL,EAASH,UAAY,IAErBV,EAAemB,YAAYN,OAWvCS,IArNc,GAAAtE,OAAA,EAAAA,KAAI,KAA1B,CAAUD,IAAAA,EAAW,KAyNrBY,SAASc,iBAAiB,oBAAoB,KAC7C1B,EAAYC,KAAKqB,W","sources":["webpack://Worthington/./js/containers/news.ts"],"sourcesContent":["namespace Worthington.News {\r\n\r\n const queryString = window.location.search;\r\n const urlParams = new URLSearchParams(queryString);\r\n const year = urlParams.get('Criteria.Year');\r\n\r\n let category = urlParams.get('Criteria.Category');\r\n let loading = document.querySelector('.js-loading');\r\n let selectedCategory = document.querySelector('.js-category-all');\r\n let yearOption = document.getElementById('year-select') as HTMLSelectElement;\r\n\r\n const setSelectedValues = () => {\r\n // check to see if we are filtering by category from URL param\r\n if (!category){\r\n category=\"\";\r\n }\r\n\r\n selectedCategory = document.querySelector('.js-category-' + category);\r\n if(selectedCategory){\r\n selectedCategory.classList.add('selected-category');\r\n }\r\n\r\n //check to see if we are filtering by year\r\n if (year) {\r\n yearOption.value = year;\r\n }\r\n }\r\n\r\n const submitSearchTerms = (yearOption:string, category) => {\r\n // create our new url\r\n let newURL = window.location.href.split('?')[0];\r\n\r\n if (yearOption && category){\r\n newURL = newURL + '?Criteria.Year=' + yearOption\r\n + '&Criteria.Category=' + category;\r\n } else if (yearOption) {\r\n newURL = newURL + '?Criteria.Year=' + yearOption;\r\n } else {\r\n newURL = newURL + '?Criteria.Category=' + category;\r\n }\r\n\r\n location.assign(newURL);\r\n };\r\n\r\n const handleDropDownChange = () => {\r\n if(yearOption){\r\n yearOption.addEventListener('change', () => {\r\n //show loading indicator since we need to refresh page\r\n loading.classList.remove('d-none');\r\n // call function to construct URL string\r\n submitSearchTerms(yearOption.value, category);\r\n });\r\n }\r\n }\r\n\r\n const handleCategoryChange = () => {\r\n let categories = document.querySelectorAll('.js-category');\r\n\r\n if(categories){\r\n categories.forEach(categoryItem => {\r\n categoryItem.addEventListener('click', (e) => {\r\n e.preventDefault();\r\n let item = categoryItem as HTMLElement;\r\n\r\n //show loading indicator since we need to refresh page\r\n loading.classList.remove('d-none');\r\n // call function to construct URL string\r\n submitSearchTerms(yearOption.value, item.dataset.category);\r\n });\r\n });\r\n }\r\n }\r\n\r\n const handleClearFilter = () => {\r\n let clear = document.querySelector('.js-clear-filter');\r\n\r\n if (clear){\r\n clear.addEventListener('click', (e) => {\r\n e.preventDefault();\r\n\r\n //show loading indicator since we need to refresh page\r\n loading.classList.remove('d-none');\r\n // call function to construct URL string\r\n submitSearchTerms('', '');\r\n });\r\n }\r\n }\r\n\r\n const handlePagination = () => {\r\n let newsResults = document.getElementById('news-results');\r\n\r\n // Check to see if news results are on the page\r\n if (newsResults) {\r\n let urlParams = new URLSearchParams(window.location.search);\r\n let newsPerPage = parseInt(urlParams.get('Criteria.ItemsPerPage'));\r\n let yearFilter = urlParams.get('Criteria.Year');\r\n let categoryFilter = urlParams.get('Criteria.Category');\r\n let newsTotal = parseInt(newsResults.dataset.newstotal);\r\n let currentPage = parseInt(urlParams.get('Criteria.Page'));\r\n let newsPagination = document.getElementById('news-pagination');\r\n let newsRange = document.getElementById('news-range');\r\n let range;\r\n let existingFilters;\r\n\r\n // Check for existing filter criteria in the url to add to a string that will be used to\r\n // generate pagination link urls\r\n if (yearFilter && categoryFilter) {\r\n existingFilters = '&Criteria.Year=' + yearFilter + '&Criteria.Category=' + categoryFilter;\r\n } else if (yearFilter) {\r\n existingFilters = '&Criteria.Year=' + yearFilter;\r\n } else if (categoryFilter) {\r\n existingFilters = '&Criteria.Category=' + categoryFilter;\r\n }\r\n\r\n console.log(existingFilters);\r\n\r\n // If no itemsPerPage is specified in the Url params then\r\n // there are 20 items per page by default\r\n if (isNaN(newsPerPage)) {\r\n newsPerPage = 20;\r\n }\r\n\r\n // If no page is specified in the Url params then\r\n // the current page is the first one\r\n if (isNaN(currentPage)) {\r\n currentPage = 0;\r\n }\r\n\r\n // Variable calculations\r\n let lowerRange = (currentPage * newsPerPage) + 1;\r\n let upperRange = (currentPage + 1) * newsPerPage;\r\n let pageTotal = Math.ceil(newsTotal / newsPerPage);\r\n\r\n // If there are more than one page calaculate the item range\r\n if (pageTotal > 1) {\r\n // If on any page but the last one calculate the item range\r\n if ((currentPage + 1) == pageTotal) {\r\n range = \"Viewing \" + lowerRange + \" - \" + newsTotal + \" of \" + newsTotal + \" Results\";\r\n } else {\r\n range = \"Viewing \" + lowerRange + \" - \" + upperRange + \" of \" + newsTotal + \" Results\";\r\n }\r\n\r\n newsRange.innerHTML = range;\r\n } else {\r\n range = \"Viewing 1 - \" + newsTotal + \" of \" + newsTotal + \" Results\";\r\n\r\n newsRange.innerHTML = range;\r\n }\r\n\r\n // Loop through the pages\r\n for (let i = 0; i < pageTotal; i++) {\r\n let pageLink = document.createElement('a');\r\n let linkUrl;\r\n let linkText = document.createTextNode((i + 1).toString());\r\n\r\n // If on the current page then add the class .active\r\n if (i == currentPage) {\r\n pageLink.classList.add('active');\r\n }\r\n\r\n // If on the current page or the one right before or after it set it as a page button\r\n if (i == (currentPage - 1) || i == currentPage || i == (currentPage + 1)) {\r\n if(existingFilters) {\r\n linkUrl = '?Criteria.ItemsPerPage=' + newsPerPage + '&Criteria.Page=' + i + existingFilters;\r\n } else {\r\n linkUrl = '?Criteria.ItemsPerPage=' + newsPerPage + '&Criteria.Page=' + i;\r\n }\r\n\r\n\r\n pageLink.href = linkUrl;\r\n pageLink.title = \"Page \" + (i + 1).toString();\r\n\r\n pageLink.appendChild(linkText);\r\n newsPagination.appendChild(pageLink);\r\n\r\n // Otherwise if on the page two back from the current one set set a prev button\r\n } else if (i == (currentPage - 2)) {\r\n let backPageNum = currentPage - 1;\r\n\r\n if(existingFilters) {\r\n linkUrl = '?Criteria.ItemsPerPage=' + newsPerPage + '&Criteria.Page=' + backPageNum + existingFilters;\r\n } else {\r\n linkUrl = '?Criteria.ItemsPerPage=' + newsPerPage + '&Criteria.Page=' + backPageNum;\r\n }\r\n pageLink.href = linkUrl;\r\n pageLink.title = \"Previous Page\";\r\n pageLink.innerHTML = \"<\";\r\n\r\n newsPagination.appendChild(pageLink);\r\n\r\n // Otherwise if on the page two forward from the current one set a next button\r\n } else if (i == (currentPage + 2)) {\r\n let fwdPageNum = currentPage + 1;\r\n if(existingFilters) {\r\n linkUrl = '?Criteria.ItemsPerPage=' + newsPerPage + '&Criteria.Page=' + fwdPageNum + existingFilters;\r\n } else {\r\n linkUrl = '?Criteria.ItemsPerPage=' + newsPerPage + '&Criteria.Page=' + fwdPageNum;\r\n }\r\n pageLink.href = linkUrl;\r\n pageLink.title = \"Next Page\";\r\n pageLink.innerHTML = \">\";\r\n\r\n newsPagination.appendChild(pageLink);\r\n }\r\n }\r\n }\r\n }\r\n\r\n export const init = () => {\r\n setSelectedValues();\r\n handleDropDownChange();\r\n handleCategoryChange();\r\n handleClearFilter();\r\n handlePagination();\r\n\t};\r\n}\r\n\r\ndocument.addEventListener(\"DOMContentLoaded\", () => {\r\n\tWorthington.News.init();\r\n});\r\n"],"names":["Worthington","News","queryString","window","location","search","urlParams","URLSearchParams","year","get","category","loading","document","querySelector","selectedCategory","yearOption","getElementById","submitSearchTerms","newURL","href","split","assign","init","classList","add","value","addEventListener","remove","categories","querySelectorAll","forEach","categoryItem","e","preventDefault","item","dataset","handleCategoryChange","clear","handleClearFilter","newsResults","range","existingFilters","newsPerPage","parseInt","yearFilter","categoryFilter","newsTotal","newstotal","currentPage","newsPagination","newsRange","console","log","isNaN","lowerRange","upperRange","pageTotal","Math","ceil","innerHTML","i","linkUrl","pageLink","createElement","linkText","createTextNode","toString","title","appendChild","backPageNum","fwdPageNum","handlePagination"],"sourceRoot":""}