aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/static/js/resources.js
blob: 5c353f971f470288e638cbc547b601300d068ddf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
            }
        });
    });
}