The issue you're facing is that the handleClick function is not defined when the page is initially loaded. This is because Alpine.js is not yet initialized at that point. To fix this, you can use the x-init directive to initialize Alpine.js and define the handleClick function.
Here's the updated code:
<div x-data x-init="() => {
handleClick = () => {
let isMobile = false;
if (window.innerWidth <= 640) {
isMobile = true;
}
if (isMobile) {
this.$dispatch('playGame');
this.toggleFullScreen();
} else {
this.$dispatch('playGame');
}
}
}" class="full-screen-identifier responsive-container overflow-hidden relative " scrolling="none"
frameborder="0" style="padding-top: 56.25%; position: relative;">
@if ($loadGame)
<iframe width="560" height="315" class="responsive-iframe rounded-xl absolute top-0 left-0 w-full h-full"
src="{{ $url }}" style="border:0;" allow="autoplay; encrypted-media" allowfullscreen></iframe>
@else
<div class="absolute top-0 left-0 w-full h-full rounded-t-xl rounded-b-md"
style="background-image: linear-gradient(to bottom, rgba(0,0,0,0.5) 40%, rgba(0,0,0,0.8) 100%), url('{{ $image }}'); background-size: cover; background-position: center;"></div>
<button
class="absolute top-1/2 left-1/2 border border-pink-600 transform -translate-x-1/2 -translate-y-1/2 inline-flex h-12 items-center gap-3 rounded-full blue-gradient shadow-lg shadow-blue-400 px-5 hover:scale-105 transition duration-400"
x-on:click="handleClick">
<span class="text-black font-semibold">Play</span>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="stroke-black w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round"
d="M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.348a1.125 1.125 0 010 1.971l-11.54 6.347a1.125 1.125 0 01-1.667-.985V5.653z" />
</svg>
</button>
@endif
</div>
In this updated code, we use the x-data directive without any value to initialize Alpine.js. Then, we use the x-init directive to define the handleClick function. This ensures that the function is defined when the page is initially loaded.
I hope this helps! Let me know if you have any further questions.