/** * @package EmbedPress * @author EmbedPress * @copyright Copyright (C) 2023 EmbedPress. All rights reserved. * @license GPLv2 or later * @since 1.7.0 */ let epGlobals = {}; (function ($) { 'use strict'; // function equivalent to jquery ready() function ready(fn) { if (document.readyState !== 'loading') { fn(); } else { document.addEventListener('DOMContentLoaded', fn); } } ready(function () { let option = { forceObject: true, }; let selector = document.querySelectorAll('.embedpress-embed-document-pdf'); if (selector.length) { selector.forEach((function (value, index, thisArg) { let id = value.dataset['emid']; let src = value.dataset['emsrc']; PDFObject?.embed(src, "." + id, option); })); } if (typeof epGlobals.youtubeChannelGallery === 'function') { epGlobals.youtubeChannelGallery(); } }); /** * * Make embeds responsive so they don't overflow their container. */ /** * Add max-width & max-height to
`; return $(videoPopupHtml).appendTo('body'); } function openVideoPopup(index) { const items = $('.layout-grid .item, .layout-list .item, .layout-carousel .item'); if (index >= 0 && index < items.length) { // Remove any existing video popup before creating a new one $('#videoPopup').remove(); currentIndex = index; const videoId = $(items[currentIndex]).data('vid'); const videoPopup = createVideoPopup(); const videoIframe = videoPopup.find('#videoIframe'); const videoDescriptionContainer = videoPopup.find('#videoDescription'); const closeBtn = videoPopup.find('.close'); const nextBtn = videoPopup.find('#nextVideo'); const prevBtn = videoPopup.find('#prevVideo'); if (videoId) { fetchVideoData(videoId, videoIframe, videoDescriptionContainer); videoPopup.show(); updateNavigationButtons(nextBtn, prevBtn, items); closeBtn.on('click', () => { closeVideoPopup(videoPopup); }); $(window).on('click', function (event) { if ($(event.target).is(videoPopup)) { closeVideoPopup(videoPopup); } }); nextBtn.on('click', function () { if (currentIndex >= 0 && currentIndex < items.length - 1) { openVideoPopup(currentIndex + 1); } }); prevBtn.on('click', function () { if (currentIndex > 0) { openVideoPopup(currentIndex - 1); } }); } } } function closeVideoPopup(videoPopup) { videoPopup.remove(); currentIndex = -1; // Reset the index } function updateNavigationButtons(nextBtn, prevBtn, items) { prevBtn.toggle(currentIndex > 0); nextBtn.toggle(currentIndex < items.length - 1); } function fetchVideoData(videoId, videoIframe, videoDescriptionContainer) { const data = { action: 'fetch_video_description', vid: videoId }; $.post(eplocalize.ajaxurl, data, function (response) { if (response.success) { videoIframe.attr('src', `https://www.youtube.com/embed/${videoId}?autoplay=1`); videoDescriptionContainer.html(response.data.description); } else { console.error('Error fetching video data:', response?.data?.error); } }); } $(document).on('click', '.layout-grid .item, .layout-list .item, .layout-carousel .item', function () { const items = $('.layout-grid .item, .layout-list .item, .layout-carousel .item'); const index = items.index(this); openVideoPopup(index); }); }); // pause audio/video jQuery(document).ready(function () { const players = jQuery('.enabled-auto-pause audio, .enabled-auto-pause video'); function pauseAllExcept(currentPlayer) { players.each(function () { if (this !== currentPlayer[0]) { this.pause(); } }); } players.on('play', function () { pauseAllExcept(jQuery(this)); }); });