summaryrefslogtreecommitdiffstats
path: root/src/mixins/mobile.js
blob: c44edcff3dc4c4688c78a919d395075d7da5356e (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
export default {

    data() {
        return {
            windowWidth: window.innerWidth,
        };
    },

    created() {
        window.addEventListener("resize", this.onResize);
        this.updateBody();
    },

    methods: {
        /**
         * Handle screen resize
         * @returns {void}
         */
        onResize() {
            this.windowWidth = window.innerWidth;
            this.updateBody();
        },

        /**
         * Add css-class "mobile" to body if needed
         * @returns {void}
         */
        updateBody() {
            if (this.isMobile) {
                document.body.classList.add("mobile");
            } else {
                document.body.classList.remove("mobile");
            }
        }

    },

    computed: {
        isMobile() {
            return this.windowWidth <= 767.98;
        },
    },

};