/** * @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(embedpressFrontendData.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); }); }); jQuery(document).ready(function ($) { let currentIndex = 0; const $photos = $('.photo-item'); function createPopupGooglePhotos() { if ($('#ep-popup-overlay').length === 0) { const photoPopup = ` `; $('body').append(photoPopup); // Loader spinner CSS (can be moved to your CSS file) const spinnerStyles = ` `; $('head').append(spinnerStyles); // Events $('#ep-popup-overlay').on('click', function (e) { if ($(e.target).is('#ep-popup-overlay') || $(e.target).is('.popup')) { $('#ep-popup-overlay').hide(); } }); $('#close-btn').on('click', function () { $('#ep-popup-overlay').hide(); }); $('#prev-btn').on('click', function () { currentIndex = (currentIndex - 1 + $photos.length) % $photos.length; updatePopupImage(); }); $('#next-btn').on('click', function () { currentIndex = (currentIndex + 1) % $photos.length; updatePopupImage(); }); } } function updatePopupImage() { const imgSrc = $photos.eq(currentIndex).find('img').attr('data-photo-src'); const $popupImage = $('#popup-image'); const $popupContent = $('#popup-content'); $popupContent.addClass('loading'); $popupImage.hide(); const preload = new Image(); preload.src = imgSrc; preload.onload = function () { $popupImage.attr('src', imgSrc); $popupContent.removeClass('loading'); $popupImage.fadeIn(); }; } $('.photo-item').on('click', function () { currentIndex = $photos.index(this); createPopupGooglePhotos(); updatePopupImage(); $('#ep-popup-overlay').show(); }); }); // 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)); }); }); // Meetup Events Load More jQuery(document).on('click', '.ep-load-more-button', function(e) { e.preventDefault(); const button = jQuery(this); const container = button.closest('.embedpress-meetup-events'); const eventsContainer = container.find('.embedpress-meetup-events-list'); // Get data attributes const embedId = button.data('embed-id'); const currentPage = parseInt(container.data('page')) || 1; const perPage = parseInt(container.data('per-page')) || 10; const nextPage = currentPage + 1; // Show loading state const loadingText = button.find('.ep-load-more-text'); const spinner = button.find('.ep-load-more-spinner'); loadingText.hide(); spinner.show(); button.prop('disabled', true); // Make AJAX request jQuery.ajax({ url: embedpressFrontendData.ajaxurl, type: 'POST', data: { action: 'embedpress_meetup_load_more', nonce: embedpressFrontendData.nonce, embed_id: embedId, page: nextPage, per_page: perPage }, success: function(response) { if (response.success) { // Append new events eventsContainer.append(response.data.html); // Update page number container.data('page', nextPage); // Hide button if no more events if (!response.data.has_more) { button.closest('.ep-events-load-more').fadeOut(); } else { loadingText.show(); spinner.hide(); button.prop('disabled', false); } } else { alert(response.data.message || 'Error loading more events'); loadingText.show(); spinner.hide(); button.prop('disabled', false); } }, error: function() { alert('Error loading more events'); loadingText.show(); spinner.hide(); button.prop('disabled', false); } }); });