diff options
Diffstat (limited to 'pydis_site')
| -rw-r--r-- | pydis_site/static/js/resources.js | 48 | ||||
| -rw-r--r-- | pydis_site/templates/resources/resources.html | 52 | 
2 files changed, 48 insertions, 52 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; +            } +        }); +    }); +} diff --git a/pydis_site/templates/resources/resources.html b/pydis_site/templates/resources/resources.html index f509d9ab..427f417e 100644 --- a/pydis_site/templates/resources/resources.html +++ b/pydis_site/templates/resources/resources.html @@ -143,56 +143,4 @@      {% else %}      <h2 class="title is-3 has-text-centered pt-0 pb-6 ">No resources matching search.</p>      {% endif %} - -<script> -    "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; -            } -        }); -    }); -    } - -</script>  {% endblock %} | 
