uptime-kuma/src/mixins/mobile.js

39 lines
770 B
JavaScript
Raw Normal View History

2021-08-10 00:02:46 -07:00
export default {
data() {
return {
windowWidth: window.innerWidth,
2021-09-23 01:31:45 -07:00
};
2021-08-10 00:02:46 -07:00
},
created() {
window.addEventListener("resize", this.onResize);
2021-09-23 01:31:45 -07:00
this.updateBody();
2021-08-10 00:02:46 -07:00
},
methods: {
/** Handle screen resize */
2021-08-10 00:02:46 -07:00
onResize() {
this.windowWidth = window.innerWidth;
2021-09-23 01:31:45 -07:00
this.updateBody();
2021-08-10 00:02:46 -07:00
},
2021-09-23 01:31:45 -07:00
/** Add css-class "mobile" to body if needed */
2021-09-23 01:31:45 -07:00
updateBody() {
if (this.isMobile) {
document.body.classList.add("mobile");
} else {
document.body.classList.remove("mobile");
}
}
2021-08-10 00:02:46 -07:00
},
computed: {
isMobile() {
return this.windowWidth <= 767.98;
},
2021-09-23 01:31:45 -07:00
},
2021-08-10 00:02:46 -07:00
2021-09-23 01:31:45 -07:00
};