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); }