diff --git a/frontend/js/feed.js b/frontend/js/feed.js index 98dfca2..1234e8a 100644 --- a/frontend/js/feed.js +++ b/frontend/js/feed.js @@ -259,7 +259,11 @@ App.feed = App.feed || {}; pipBtn.hidden = !App.customPlayer.supportsPiP(); const onClick = async (event) => { event.stopPropagation(); - await App.customPlayer.togglePiP(video); + if (document.pictureInPictureElement) { + await document.exitPictureInPicture().catch(() => {}); + return; + } + await App.feed.openPip(pane); }; pipBtn.addEventListener('click', onClick); cleanups.push(() => pipBtn.removeEventListener('click', onClick)); @@ -752,6 +756,8 @@ App.feed = App.feed || {}; const removeSlide = function(index) { const slide = slidesByIndex.get(index); if (!slide) return; + // Removing the element in the picture-in-picture window closes it. + if (pipPinned(slide)) return; teardownSlide(slide); slide.remove(); slidesByIndex.delete(index); @@ -922,7 +928,7 @@ App.feed = App.feed || {}; // Recently-watched panes stay loaded but paused so scrolling // back resumes seamlessly from where it was paused. if (pane.classList.contains('is-loaded')) pauseSlide(pane); - } else if (pane.classList.contains('is-loaded')) { + } else if (pane.classList.contains('is-loaded') && pane !== pipPane) { destroySlidePlayback(pane); } }); @@ -994,6 +1000,172 @@ App.feed = App.feed || {}; }); }; + // ------------------------------------------------------------------ + // Picture-in-picture that can be moved through + // + // A picture-in-picture window shows one