diff options
author | 2022-01-23 13:33:40 +0100 | |
---|---|---|
committer | 2022-01-23 13:33:40 +0100 | |
commit | fbe32815927c41f55deedaac4f795e147796f3a4 (patch) | |
tree | df15b67c8e53040501f166c2454e7562ead24363 /pydis_site/static | |
parent | Always add a link icon for the primary URL. (diff) |
Move evil <script> tag into a .js file.
Diffstat (limited to 'pydis_site/static')
-rw-r--r-- | pydis_site/static/js/resources.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/pydis_site/static/js/resources.js b/pydis_site/static/js/resources.js new file mode 100644 index 00000000..5c353f97 --- /dev/null +++ b/pydis_site/static/js/resources.js @@ -0,0 +1,48 @@ +"use strict"; +const initialParams = new URLSearchParams(window.location.search); +const checkboxOptions = ['topic', 'type', 'payment', 'complexity']; + +const createQuerySelect = (opt) => { + return "input[name=" + opt + "]" +} + +checkboxOptions.forEach((option) => { + document.querySelectorAll(createQuerySelect(option)).forEach((checkbox) => { + if (initialParams.get(option).includes(checkbox.value)) { + checkbox.checked = true + } + }); +}); + +function buildQueryParams() { + let params = new URLSearchParams(window.location.search); + checkboxOptions.forEach((option) => { + let tempOut = "" + document.querySelectorAll(createQuerySelect(option)).forEach((checkbox) => { + if (checkbox.checked) { + tempOut += checkbox.value + ","; + } + }); + params.set(option, tempOut); + }); + + window.location.search = params; +} + +function clearQueryParams() { + checkboxOptions.forEach((option) => { + document.querySelectorAll(createQuerySelect(option)).forEach((checkbox) => { + checkbox.checked = false; + }); + }); +} + +function selectAllQueryParams(column) { + checkboxOptions.forEach((option) => { + document.querySelectorAll(createQuerySelect(option)).forEach((checkbox) => { + if (checkbox.className == column) { + checkbox.checked = true; + } + }); + }); +} |