Skip to content

Commit

Permalink
Update fullscreen button component to use Vue 3 composition API
Browse files Browse the repository at this point in the history
  • Loading branch information
ilumos committed Sep 8, 2024
1 parent 9e13760 commit 75a80a6
Showing 1 changed file with 56 additions and 59 deletions.
115 changes: 56 additions & 59 deletions resources/js/components/fullscreen-button.vue
Original file line number Diff line number Diff line change
@@ -1,70 +1,67 @@
<template>
<transition name="fade">
<div id="fullscreen-button" class="btn" v-show="visible">
<span class="fa fa-solid fa-expand" title="Enter full screen" aria-hidden="true"></span>
<div id="fullscreen-button" class="btn" v-show="visible" @click="toggleFullscreen">
<span class="fa fa-solid fa-expand" :title="Fullscreen" aria-hidden="true"></span>
</div>
</transition>
</template>

<script>
export default {
data() {
return {
visible: false,
};
},
mounted: function () {
this.$el.addEventListener('click', this.toggleFullscreen)
window.addEventListener('mousemove', this.showFullscreenButton)
},
beforeDestroy: function () {
this.$el.removeEventListener('click', this.toggleFullscreen)
window.removeEventListener('mousemove', this.showFullscreenButton)
},
methods: {
toggleFullscreen: function () {
if (
document.fullscreenElement ||
document.webkitFullscreenElement ||
document.msFullscreenElement
) {
this.exitFullscreen();
} else {
this.enterFullscreen();
}
},
enterFullscreen: function () {
var d = document.documentElement;
if (d.requestFullscreen) {
d.requestFullscreen();
} else if (d.mozRequestFullScreen) { /* Firefox */
d.mozRequestFullScreen();
} else if (d.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
d.webkitRequestFullscreen();
} else if (d.msRequestFullscreen) { /* IE/Edge */
d.msRequestFullscreen();
}
},
exitFullscreen: function () {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) { /* Safari */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE11 */
document.msExitFullscreen();
}
},
showFullscreenButton: function () {
if (this.visible != true) {
this.visible = true;
setTimeout(() => {
this.visible = false;
}, 2000);
}
<script setup>
import {ref, onMounted, onBeforeUnmount} from 'vue';
}
}
const visible = ref(false);
const toggleFullscreen = () => {
if (
document.fullscreenElement ||
document.webkitFullscreenElement ||
document.msFullscreenElement
) {
exitFullscreen();
} else {
enterFullscreen();
}
};
const enterFullscreen = () => {
const d = document.documentElement;
if (d.requestFullscreen) {
d.requestFullscreen();
} else if (d.mozRequestFullScreen) {
d.mozRequestFullScreen();
} else if (d.webkitRequestFullscreen) {
d.webkitRequestFullscreen();
} else if (d.msRequestFullscreen) {
d.msRequestFullscreen();
}
};
const exitFullscreen = () => {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
};
const showFullscreenButton = () => {
if (!visible.value) {
visible.value = true;
setTimeout(() => {
visible.value = false;
}, 2000);
}
};
onMounted(() => {
window.addEventListener('mousemove', showFullscreenButton);
});
onBeforeUnmount(() => {
window.removeEventListener('mousemove', showFullscreenButton);
});
</script>

<style>
Expand Down

0 comments on commit 75a80a6

Please sign in to comment.