From 984a19cc3076e2240fa78ae2755d76caaa274849 Mon Sep 17 00:00:00 2001 From: Jan Umbach Date: Wed, 29 May 2024 23:36:21 +0200 Subject: [PATCH] test --- assets/global.js | 15 +++++++++++++++ assets/media-gallery.js | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/global.js b/assets/global.js index 298a31b..39f2fdb 100644 --- a/assets/global.js +++ b/assets/global.js @@ -134,6 +134,21 @@ function pauseAllMedia() { }); } +function pauseAllMediaInGallery(gallery) { + console.log('Pausing all media in gallery'); + + gallery.querySelectorAll('.js-youtube').forEach((video) => { + video.contentWindow.postMessage('{"event":"command","func":"' + 'pauseVideo' + '","args":""}', '*'); + }); + gallery.querySelectorAll('.js-vimeo').forEach((video) => { + video.contentWindow.postMessage('{"method":"pause"}', '*'); + }); + gallery.querySelectorAll('video').forEach((video) => video.pause()); + gallery.querySelectorAll('product-model').forEach((model) => { + if (model.modelViewerUI) model.modelViewerUI.pause(); + }); +} + function removeTrapFocus(elementToFocus = null) { document.removeEventListener('focusin', trapFocusHandlers.focusin); document.removeEventListener('focusout', trapFocusHandlers.focusout); diff --git a/assets/media-gallery.js b/assets/media-gallery.js index 10adbbd..11718d7 100644 --- a/assets/media-gallery.js +++ b/assets/media-gallery.js @@ -99,7 +99,8 @@ if (!customElements.get('media-gallery')) { playActiveMedia(activeItem) { console.log('Playing active media:', activeItem); - window.pauseAllMedia(); + //window.pauseAllMedia(); + pauseAllMediaInGallery(this.elements.viewer); const deferredMedia = activeItem.querySelector('.deferred-media'); if (deferredMedia) deferredMedia.loadContent(false); }