From e4877ab3a9c821c7725f9f761f8a705187d2b870 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 25 Oct 2021 09:23:06 +0100 Subject: [PATCH] only get one click --- app/static/js/film.js | 82 +++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/app/static/js/film.js b/app/static/js/film.js index d992d1e..825a8bc 100644 --- a/app/static/js/film.js +++ b/app/static/js/film.js @@ -16,51 +16,57 @@ function setVideoSrc(video, src) { } video.src = src.replace('.webm', videoExtension) } +var video document.querySelector('a#play-fullscreen').addEventListener('click', event => { event.preventDefault() event.stopPropagation() - var video = document.createElement('video') - video.classList.add('player') - setVideoSrc(video, 'https://pad.ma/' + film.id + '/480p.webm') - video.controls = true - document.querySelector('main').appendChild(video) - video.style.display = 'none' - if (continueTimecode) { - video.currentTime = continueTimecode - } - function enterFullscreen(event) { - if (video.webkitEnterFullScreen) { - video.webkitEnterFullScreen(); - } else { - video.requestFullscreen().catch(err => { - console.log(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`); - video.remove() - }); + if (!video) { + video = document.createElement('video') + video.classList.add('player') + setVideoSrc(video, 'https://pad.ma/' + film.id + '/480p.webm') + video.controls = true + document.querySelector('main').appendChild(video) + video.style.display = 'none' + if (continueTimecode) { + video.currentTime = continueTimecode } - video.removeEventListener('play', enterFullscreen); - setTimeout(() => { - video.style.display = 'block' - }, 150) - } - video.addEventListener('play', enterFullscreen); - video.addEventListener('fullscreenchange', event => { - if (document.fullscreenElement === null) { - continueTimecode = video.currentTime + function enterFullscreen(event) { + video.removeEventListener('play', enterFullscreen); + if (video.webkitRequestFullscreen) { + video.requestFullscreen(); + } else { + video.requestFullscreen().catch(err => { + console.log(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`); + video.remove() + video = null + }); + } + setTimeout(() => { + video.style.display = 'block' + }, 150) + } + video.addEventListener('play', enterFullscreen); + video.addEventListener('fullscreenchange', event => { + if (document.fullscreenElement === null) { + continueTimecode = video.currentTime + video.remove() + if (document.fullscreenElement) { + document.exitFullscreen(); + } + video = null + } + }); + video.addEventListener('pause', event => { + }) + video.addEventListener('ended', event => { + continueTimecode = 0 video.remove() if (document.fullscreenElement) { document.exitFullscreen(); } - } - }); - video.addEventListener('pause', event => { - }) - video.addEventListener('ended', event => { - continueTimecode = 0 - video.remove() - if (document.fullscreenElement) { - document.exitFullscreen(); - } - }); - video.play() + video = null + }); + video.play() + } })