aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/responsive/ResponsiveSkipLinks.vue
blob: 18ccc8d790ae8066afe91bcc72ce756e799f2e4c (plain)
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
49
<template>
    <div>
        <Teleport to="#skiplink_list" append>
            <portal-target name="additional-skiplinks"></portal-target>
        </Teleport>
        <portal to="additional-skiplinks">
            <li v-for="(link) in links" :key="link.url">
                <button class="skiplink" role="link" @click.prevent="goto(link.url)">
                    {{ link.label }}
                </button>
            </li>
        </portal>
    </div>
</template>

<script>
export default {
    name: 'ResponsiveSkipLinks',
    props: {
        links: {
            type: Array,
            default: () => []
        }
    },
    methods: {
        goto(url) {
            window.location = url;
        }
    },
    created() {
        const allButtons = document.querySelectorAll('button.skiplink');
        const buttons = document.querySelectorAll('button.skiplink:not([data-in-fullscreen="1"])');
        buttons.forEach(button => {
            button.style.display = 'none';
        });
        this.$nextTick(() => {
            allButtons.forEach(button => {
                document.getElementById('skiplink_list').appendChild(button.parentNode);
            });
        });
    },
    beforeUnmount() {
        const buttons = document.querySelectorAll('button.skiplink:not([data-in-fullscreen="1"])');
        buttons.forEach(button => {
            button.style.display = null;
        });
    }
}
</script>