PageSourceSearch

http://gnrc.net/wp-content/plugins/embedpress/assets/js/front.js

js gnrc.net collected 2026-10-02 12:23:38 UTC 60,444 bytes, 1,420 lines download raw bytes

1/**
2 * @package     EmbedPress
3 * @author      EmbedPress <[email protected]>
4 * @copyright   Copyright (C) 2023 EmbedPress. All rights reserved.
5 * @license     GPLv2 or later
6 * @since       1.7.0
7 */
8
9
10
11let epGlobals = {};
12
13(function ($) {
14    'use strict';
15    // function equivalent to jquery ready()
16    function ready(fn) {
17        if (document.readyState !== 'loading') {
18            fn();
19        } else {
20            document.addEventListener('DOMContentLoaded', fn);
21        }
22    }
23
24    ready(function () {
25        let option = {
26            forceObject: true,
27        };
28        let selector = document.querySelectorAll('.embedpress-embed-document-pdf');
29        if (selector.length) {
30            selector.forEach((function (value, index, thisArg) {
31                let id = value.dataset['emid'];
32                let src = value.dataset['emsrc'];
33                PDFObject?.embed(src, "." + id, option);
34            }));
35        }
36        if (typeof epGlobals.youtubeChannelGallery === 'function') {
37            epGlobals.youtubeChannelGallery();
38        }
39    });
40
41    /**
42     *
43     * Make embeds responsive so they don't overflow their container.
44     */
45
46    /**
47     * Add max-width & max-height to <iframe> elements, depending on their width & height props.
48     *
49     *
50     * @return {void}
51     */
52    function embedPressResponsiveEmbeds() {
53        var proportion, parentWidth;
54
55        // Loop iframe elements.
56        document.querySelectorAll('iframe').forEach(function (iframe) {
57            // Only continue if the iframe has a width & height defined.
58            if (iframe.width && iframe.height) {
59                // Calculate the proportion/ratio based on the width & height.
60                proportion = parseFloat(iframe.width) / parseFloat(iframe.height);
61                // Get the parent element's width.
62                parentWidth = parseFloat(window.getComputedStyle(iframe.parentElement, null).width.replace('px', ''));
63                // Set the max-width & height.
64                iframe.style.maxWidth = '100%';
65                iframe.style.maxHeight = Math.round(parentWidth / proportion).toString() + 'px';
66            }
67        });
68    }
69
70    epGlobals.handlePosterImageLoad = function () {
71        var posterImages = document.querySelectorAll(".plyr__poster");
72        posterImages.forEach(function (posterImage) {
73            if (posterImage) {
74                var videoWrappers = document.querySelectorAll("[data-playerid]");
75                videoWrappers.forEach(function (videoWrapper) {
76                    var observer = new MutationObserver(function (mutationsList, observer) {
77                        var posterImageStyle = window.getComputedStyle(posterImage);
78                        if (posterImageStyle.getPropertyValue('background-image') !== 'none') {
79                            setTimeout(function () {
80                                videoWrapper.style.opacity = "1";
81                            }, 200);
82                            observer.disconnect();
83                        }
84                    });
85
86                    observer.observe(posterImage, { attributes: true, attributeFilter: ['style'] });
87                });
88            }
89        });
90    }
91
92    // Run on initial load.
93    embedPressResponsiveEmbeds();
94
95    // Run on resize.
96    window.onresize = embedPressResponsiveEmbeds;
97
98
99    function hasClass(ele, cls) {
100        return !!ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)"));
101    }
102
103    function addClass(ele, cls) {
104        if (!hasClass(ele, cls)) ele.className += " " + cls;
105    }
106
107    function removeClass(ele, cls) {
108        if (hasClass(ele, cls)) {
109            var reg = new RegExp("(\\s|^)" + cls + "(\\s|$)");
110            ele.className = ele.className.replace(reg, " ");
111        }
112    }
113    if (!Element.prototype.matches) {
114        Element.prototype.matches =
115            Element.prototype.matchesSelector ||
116            Element.prototype.webkitMatchesSelector ||
117            Element.prototype.mozMatchesSelector ||
118            Element.prototype.msMatchesSelector ||
119            Element.prototype.oMatchesSelector ||
120            function (s) {
121                var matches = (this.document || this.ownerDocument).querySelectorAll(s),
122                    i = matches.length;
123                while (--i >= 0 && matches.item(i) !== this) { }
124                return i > -1;
125            };
126    }
127    var delegate = function (el, evt, sel, handler) {
128        el.addEventListener(evt, function (event) {
129            var t = event.target;
130            while (t && t !== this) {
131                if (t.matches(sel)) {
132                    handler.call(t, event);
133                }
134                t = t.parentNode;
135            }
136        });
137    };
138
139    function sendRequest(url, postData, callback) {
140        var req = createXMLHTTPObject();
141        if (!req) return;
142        var method = postData ? "POST" : "GET";
143        req.open(method, url, true);
144        if (postData) {
145            req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
146        }
147        req.onreadystatechange = function () {
148            if (req.readyState != 4) return;
149            if (req.status != 200 && req.status != 304) {
150                return;
151            }
152            callback(req);
153        };
154        if (req.readyState == 4) return;
155        req.send(postData);
156    }
157
158    var XMLHttpFactories = [
159        function () {
160            return new XMLHttpRequest();
161        },
162        function () {
163            return new ActiveXObject("Msxml3.XMLHTTP");
164        },
165        function () {
166            return new ActiveXObject("Msxml2.XMLHTTP.6.0");
167        },
168        function () {
169            return new ActiveXObject("Msxml2.XMLHTTP.3.0");
170        },
171        function () {
172            return new ActiveXObject("Msxml2.XMLHTTP");
173        },
174        function () {
175            return new ActiveXObject("Microsoft.XMLHTTP");
176        },
177    ];
178
179    function createXMLHTTPObject() {
180        var xmlhttp = false;
181        for (var i = 0; i < XMLHttpFactories.length; i++) {
182            try {
183                xmlhttp = XMLHttpFactories[i]();
184            } catch (e) {
185                continue;
186            }
187            break;
188        }
189        return xmlhttp;
190    }
191
192    epGlobals.youtubeChannelGallery = function () {
193        var playerWraps = document.getElementsByClassName("ep-player-wrap");
194        if (playerWraps && playerWraps.length) {
195            for (var i = 0, im = playerWraps.length; im > i; i++) {
196                youtubeChannelEvents(playerWraps[i])
197            }
198        }
199    }
200
201    function youtubeChannelEvents(playerWrap) {
202
203        delegate(playerWrap, "click", ".item", function (event) {
204            var embed = "https://www.youtube.com/embed/";
205            var vid = this.getAttribute("data-vid");
206            var iframe = playerWrap.getElementsByTagName("iframe");
207
208            console.log
209            
210            if (vid) {
211                if (iframe) {
212                    var vidSrc = iframe[0]?.src.replace(/(.*\/embed\/)([^\?&"'>]+)(.+)?/, `\$1${vid}\$3`);
213                    if (vidSrc.indexOf('autoplay') > 0) {
214                        vidSrc = vidSrc.replace('autoplay=0', 'autoplay=1');
215                    }
216                    else {
217                        vidSrc += '&autoplay=1';
218                    }
219                    iframe[0].src = vidSrc;
220                    playerWrap.scrollIntoView();
221                }
222            }
223        });
224
225        var currentPage = 1;
226
227        let nearestEpContentId = playerWrap.querySelector('.ep-youtube__content__block').getAttribute('data-unique-id');
228
229        let epContentBlock = playerWrap.querySelector('.ep-youtube__content__block');
230        let parentElement = epContentBlock.parentElement;
231
232        // Get the value of data-channel-url attribute from a sibling
233        let channelUrl = parentElement.querySelector('[data-channel-url]').getAttribute('data-channel-url');
234
235
236        delegate(playerWrap, "click", ".ep-next, .ep-prev", function (event) {
237            const totalPages = event.target.closest('.ose-youtube').getAttribute('data-total-pages');
238            const closestClass = event.target.closest('.ose-youtube').classList;
239
240            const activePage = document.querySelector(`.${closestClass[1]} .embedpress-page-active`);
241            if (activePage) {
242                document.querySelector(`.${closestClass[1]} .embedpress-page-active`).classList.remove('embedpress-page-active');
243            }
244
245
246
247            var isNext = this.classList.contains("ep-next");
248
249            if (isNext) {
250                currentPage++;
251            } else {
252                currentPage--;
253            }
254
255            var data = {
256                action: "youtube_rest_api",
257                playlistid: this.getAttribute("data-playlistid"),
258                pagetoken: this.getAttribute("data-pagetoken"),
259                pagesize: this.getAttribute("data-pagesize"),
260                channelUrl: channelUrl,
261                currentpage: currentPage
262            };
263
264            var formBody = [];
265            for (var property in data) {
266                var encodedKey = encodeURIComponent(property);
267                var encodedValue = encodeURIComponent(data[property]);
268                formBody.push(encodedKey + "=" + encodedValue);
269            }
270            formBody = formBody.join("&");
271
272            var galleryWrapper = playerWrap.getElementsByClassName(
273                "ep-youtube__content__block"
274            );
275
276            playerWrap.setAttribute('data-current-page', currentPage);
277
278
279            let x = 1;
280
281            sendRequest(embedpressFrontendData.ajaxurl, formBody, function (request) {
282                if (galleryWrapper && galleryWrapper[0] && request.responseText) {
283                    var response = JSON.parse(request.responseText);
284                    galleryWrapper[0].outerHTML = response.html;
285
286                    var currentPageNode =
287                        galleryWrapper[0].getElementsByClassName("current-page");
288                    if (currentPageNode && currentPageNode[0]) {
289                        currentPageNode[0].textContent = currentPage;
290
291                    }
292                }
293            });
294
295            const intervalID = setInterval(() => {
296                x++
297
298                if (playerWrap.querySelector('.ep-youtube__content__block')) {
299                    const newNearestEpContentId = playerWrap
300                        .querySelector('.ep-youtube__content__block')
301                        .getAttribute('data-unique-id');
302
303                    if (newNearestEpContentId !== nearestEpContentId && playerWrap.querySelector(`[data-
303page="${currentPage}"]`)) {
304                        playerWrap.querySelector(`[data-page="${currentPage}"]`).classList.add('embedpress-page-active');
305                        nearestEpContentId = newNearestEpContentId;
306                        clearInterval(intervalID);
307                    }
308                }
309
310                if (x > 100) {
311                    clearInterval(intervalID);
312                }
313            }, 100);
314
315        });
316    }
317
318    //Load more for OpenaSea collection
319    const epLoadMore = () => {
320
321        $('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').each(function () {
322            let selctorEl = `[data-nftid='${$(this).data('nftid')}']`;
323
324            let loadmorelabel = $(selctorEl).data('loadmorelabel');
325            let iconcolor = $(selctorEl + " .nft-loadmore").data('iconcolor');
326
327            let spinicon = `<svg width="18" height="18" fill="${iconcolor || '#fff'}" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.spinner_GuJz{transform-origin:center;animation:spinner_STY6 1.5s linear infinite}@keyframes spinner_STY6{100%{transform:rotate(360deg)}}</style><g class="spinner_GuJz"><circle cx="3" cy="12" r="2"/><circle cx="21" cy="12" r="2"/><circle cx="12" cy="21" r="2"/><circle cx="12" cy="3" r="2"/><circle cx="5.64" cy="5.64" r="2"/><circle cx="18.36" cy="18.36" r="2"/><circle cx="5.64" cy="18.36" r="2"/><circle cx="18.36" cy="5.64" r="2"/></g></svg>`;
328
329            $(selctorEl + ` .ep_nft_item`).slice(0, $(selctorEl).data('itemparpage')).show();
330            $('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper .ep-loadmore-wrapper button').css('display', 'flex');
331
332            $(selctorEl + " .nft-loadmore").click(function (e) {
333                //change the text of the button
334                $(this).html(loadmorelabel + spinicon);
335                //disable the button
336                $(this).prop("disabled", true);
337                //wait for 1 seconds
338                setTimeout(function () {
339                    //change the text back
340                    $(selctorEl + " .nft-loadmore").text(loadmorelabel);
341                    //enable the button
342                    $(selctorEl + " .nft-loadmore").prop("disabled", false);
343                    $(selctorEl + " .ep_nft_item:hidden").slice(0, $(selctorEl).data('itemparpage')).fadeIn("slow");
344                    if ($(selctorEl + " .ep_nft_item:hidden").length == 0) {
345                        $(selctorEl + " .nft-loadmore").fadeOut("slow");
346                    }
347                }, 500);
348            });
349        });
350    };
351
352    if ($('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').length > 0) {
353        epLoadMore();
354    }
355
356    // Content protection system function 
357    const unlockSubmitHander = (perentSel, that) => {
358        var ep_client_id = jQuery(that).closest('form').find('input[name="ep_client_id"]').val();
359        var password = jQuery(`input[name="pass_${ep_client_id}"]`).val();
360        var post_id = jQuery(`input[name="post_id"]`).val();
361        const buttonText = jQuery(that).closest('.password-form-container').find('input[type="submit"]').val();
362        const unlokingText = jQuery(that).data('unlocking-text');
363
364
365        var data = {
366            'action': 'lock_content_form_handler',
367            'client_id': ep_client_id,
368            'password': password,
369            'post_id': post_id,
370        };
371
372        jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(unlokingText);
373
374        jQuery.post(embedpressFrontendData.ajaxurl, data, function (response) {
375            if (response.success) {
376                if (!response.embedHtml) {
377                    jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(buttonText);
378                    jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="password"]').val('');
379                    jQuery(that).closest('.password-form-container').find('.error-message').removeClass('hidden');
380                }
381                else {
382                    jQuery('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper').html(response.embedHtml);
383
384                    if (jQuery('#' + perentSel + '-' + ep_client_id + ' .ose-youtube').length > 0) {
385                        epGlobals.youtubeChannelGallery();
386                    }
387
388                    if ($('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').length > 0) {
389                        epLoadMore();
390                    }
391
392                    // Custom player initialization when content protection enabled
393                    document.querySelector('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper')?.classList?.remove('plyr-initialized');
394
395                    if (typeof initPlayer === 'function') {
396                        initPlayer(document.querySelector('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper'));
397                    }
398                    if (embedpressFrontendData.isProPluginActive) {
399                        const adIdEl = document.querySelector('#' + perentSel + '-' + ep_client_id + ' [data-sponsored-id]');
400                        if (typeof adInitialization === 'function') {
401                            adInitialization(adIdEl, adIdEl?.getAttribute('data-ad-index'));
402                        }
403                    }
404
405                }
406            } else {
407                jQuery('#password-error_' + ep_client_id).html(response.form);
408                jQuery('#password-error_' + ep_client_id).show();
409            }
410        }, 'json');
411    }
412
413    // unlockSubmitHander called for gutentberg
414    jQuery('.ep-gutenberg-content .password-form').submit(function (e) {
415        e.preventDefault(); // Prevent the default form submission
416        unlockSubmitHander('ep-gutenberg-content', this);
417    });
418
419    jQuery('.ep-shortcode-content .password-form').submit(function (e) {
420        e.preventDefault(); // Prevent the default form submission
421        unlockSubmitHander('ep-shortcode-content', this);
422    });
423
424    window.addEventListener('load', function (e) {
425        const urlParams = new URLSearchParams(window.location.search);
426        const hash = urlParams.get('hash');
427
428        // find the element with the matching id
429        const element = document.getElementById(hash);
430
431        if (element) {
432            element.scrollIntoView({ behavior: 'smooth' });
433        }
434
435    });
436
437    // Get the insta-gallery container element
438    const getPopupTemplate = (instPost, hashtag = '', accountType) => {
439
440        let instaPostData = JSON.parse(instPost);
441
442
443        let likeIcon = '<svg aria-label="Like" class="x1lliihq x1n2onr6" color="#262626" fill="#262626" height="24" viewBox="0 0 24 24" width="24"><path d="M16.792 3.904A4.989 4.989 0 0 1 21.5 9.122c0 3.072-2.652 4.959-5.197 7.222-2.512 2.243-3.865 3.469-4.303 3.752-.477-.309-2.143-1.823-4.303-3.752C5.141 14.072 2.5 12.167 2.5 9.122a4.989 4.989 0 0 1 4.708-5.218 4.21 4.21 0 0 1 3.675 1.941c.84 1.175.98 1.763 1.12 1.763s.278-.588 1.11-1.766a4.17 4.17 0 0 1 3.679-1.938m0-2a6.04 6.04 0 0 0-4.797 2.127 6.052 6.052 0 0 0-4.787-2.127A6.985 6.985 0 0 0 .5 9.122c0 3.61 2.55 5.827 5.015 7.97.283.246.569.494.853.747l1.027.918a44.998 44.998 0 0 0 3.518 3.018 2 2 0 0 0 2.174 0 45.263 45.263 0 0 0 3.626-3.115l.922-.824c.293-.26.59-.519.885-.774 2.334-2.025 4.98-4.32 4.98-7.94a6.985 6.985 0 0 0-6.708-7.218Z"/></svg>';
444
445        if (instaPostData.like_count > 0) {
446            likeIcon = '<svg aria-label="Unlike" class="x1lliihq x1n2onr6" color="#FF3040" fill="#FF3040" height="24" viewBox="0 0 48 48" width="24"><path d="M34.6 3.1c-4.5 0-7.9 1.8-10.6 5.6-2.7-3.7-6.1-5.5-10.6-5.5C6 3.1 0 9.6 0 17.6c0 7.3 5.4 12 10.6 16.5.6.5 1.3 1.1 1.9 1.7l2.3 2c4.4 3.9 6.6 5.9 7.6 6.5.5.3 1.1.5 1.6.5s1.1-.2 1.6-.5c1-.6 2.8-2.2 7.8-6.8l2-1.8c.7-.6 1.3-1.2 2-1.7C42.7 29.6 48 25 48 17.6c0-8-6-14.5-13.4-14.5z"/></svg>';
447        }
448
449        const commentsIcon = '<svg aria-label="Comment" class="x1lliihq x1n2onr6" color="#000" height="24" viewBox="0 0 24 24" width="24"><path d="M20.656 17.008a9.993 9.993 0 1 0-3.59 3.615L22 22Z" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="2"/></svg>';
450
451        const shareIcon = '<svg width="20" height="20" viewBox="0 0 0.6 0.6" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg"><path stroke-width="1" d="m.543.282-.2-.2A.025.025 0 0 0 .3.1v.089a.275.275 0 0 0-.25.274V.5a.025.025 0 0 0 .045.015.3.3 0 0 1 .197-.101L.3.413V.5a.025.025 0 0 0 .043.018l.2-.2a.025.025 0 0 0 0-.035M.35.44V.388A.025.025 0 0 0 .325.363L.286.365a.35.35 0 0 0-.185.074.225.225 0 0 1 .224-.201A.025.025 0 0 0 .35.213V.16L.49.3Z"/></svg>';
452
453        const instaIcon = '<svg width="18" height="18" viewBox="0 0 0.338 0.338" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M.248.079H.27M.102.012h.135a.09.09 0 0 1 .09.09v.135a.09.09 0 0 1-.09.09H.102a.09.09 0 0 1-.09-.09V.102a.09.09 0 0 1 .09-.09ZM.17.237a.068.068 0 1 1 0-.135.068.068 0 0 1 0 .135Z" stroke="#000" stroke-width=".032"/></svg>';
454
455
456
457        const instaUserInfo = instPost.user_info;
458
459        let getDate = new Date(instaPostData.timestamp);
460        getDate = getDate.toLocaleString('en-US', { day: 'numeric', month: 'short', year: 'numeric' });
461
462        let getTime = new Date(instaPostData.timestamp);
463        getTime = getTime.toLocaleString('en-US', { hour12: false, hour: 'numeric', minute: 'numeric', second: 'numeric' });
464
465        let captionText = instaPostData.caption ? instaPostData.caption : '';
466        const tagRegex = /(#\w+)/g;
467
468        const wrapTag = (match) => {
469            const tag = match.substring(1); // Remove the '#' character
470            const tagUrl = `https://www.instagram.com/explore/tags/${tag}`;
471            return `<span class="tag-wrapper"><a target="_blank" href="${tagUrl}">${match}</a></span>`;
472        };
473
474        captionText = captionText.replace(tagRegex, wrapTag);
475
476        let carouselTemplate = '';
477        if (instaPostData.media_type === 'CAROUSEL_ALBUM') {
478            carouselTemplate += `<div class="popup-carousel"><div class="cg-carousel__track js-carousel__track">`;
479
480            instaPostData.children.data?.map((item) => {
481                if (item.media_type?.toLowerCase() === 'video') {
482                    carouselTemplate += `<video width="630" class="popup-media-image cg-carou
482sel__slide js-carousel__slide" controls src="${item.media_url || ''}" alt="${item.caption || ''}" controlsList="nodownload"></video>`;
483                }
484                else {
485                    carouselTemplate += `<img width="630" class="popup-media-image cg-carousel__slide js-carousel__slide" src="${item.media_url || ''}" alt="${item.caption || ''}" />`;
486                }
487            });
488
489            carouselTemplate += `</div></div>`;
490
491            carouselTemplate += `<div class="cg-carousel__btns">
492                    <button class="cg-carousel__btn js-carousel__prev-1"><svg width="20" height="30" viewBox="-5 0 23 23" xmlns="http://www.w3.org/2000/svg"><path d="M11.24.29.361 10.742l-.06.054a.97.97 0 0 0-.301.642v.124a.97.97 0 0 0 .3.642l.054.044L11.239 22.71a1.061 1.061 0 0 0 1.459 0 .964.964 0 0 0 0-1.402l-10.15-9.746 10.15-9.87a.964.964 0 0 0 0-1.402 1.061 1.061 0 0 0-1.459 0Z" fill="#fff"/></svg></button>
493
494                    <button class="cg-carousel__btn js-carousel__next-1"><svg width="20" height="30" viewBox="-5 0 23 23" xmlns="http://www.w3.org/2000/svg"><path d="m1.76.29 10.879 10.452.06.054a.97.97 0 0 1 .301.642v.124a.97.97 0 0 1-.3.642l-.054.044L1.761 22.71a1.061 1.061 0 0 1-1.459 0 .964.964 0 0 1 0-1.402l10.15-9.746-10.15-9.87a.964.964 0 0 1 0-1.402 1.061 1.061 0 0 1 1.459 0Z" fill="#fff"/></svg></button>
495                </div>`
496        }
497        else {
498            if (instaPostData.media_type?.toLowerCase() === 'video') {
499                carouselTemplate += `<video width="630" class="popup-media-image" controls src="${instaPostData.media_url || ''}" alt="${instaPostData.caption || ''}"></video>`;
500            }
501            else {
502                carouselTemplate += `<img width="630" class="popup-media-image" src="${instaPostData.media_url || ''}" alt="${instaPostData.caption || ''}" />`;
503            }
504        }
505
506        let srcUrl = `https://www.instagram.com/${instaPostData.username}/`;
507
508        if (hashtag) {
509            instaPostData.username = '#' + hashtag;
510            srcUrl = `https://www.instagram.com/explore/tags/${hashtag}/`;
511        }
512
513
514        let likeComments = '';
515
516        if (embedpressFrontendData.isProPluginActive && accountType === 'business') {
517            if (instaPostData.show_likes_count == 'true') {
518                likeComments += `
519                    <div class="embedpress-inline popup-like-button"><a target="_blank" href="${instaPostData.permalink}">${likeIcon} ${instaPostData.like_count || 0}</a></div> 
520                `;
521            }
522            if (instaPostData.show_comments_count == 'true') {
523                likeComments += `
524                    <div class="embedpress-inline"><a target="_blank" href="${instaPostData.permalink}">${commentsIcon} ${instaPostData.comments_count || 0}</a></div>
525                `;
526            }
527        }
528
529
530        let followBtn = '';
531        if (instaPostData.popup_follow_button_text == 'false') {
532            instaPostData.popup_follow_button_text = '';
533        }
534        if (instaPostData.popup_follow_button == 'true' || instaPostData.popup_follow_button == 'yes') {
535            followBtn = `<div class="insta-followbtn">
536                <a target="_new" href="${srcUrl}" type="button" class="btn btn-primary">${instaPostData.popup_follow_button_text}</a>
537            </div>`;
538        }
539
540        let popupHtml = '';
541        popupHtml += `
542        <div class="popup-container">
543                <div class="popup-md-9 white">
544                    <div class="embedpress-popup-block embedpress-popup-img" id="post-${instaPostData.id}">
545                        ${carouselTemplate}
546                    </div>
547                </div>
548                <div class="popup-md-3 red">
549                    <div class="embedpress-popup-block embedpress-popup-info">
550                        <div class="embedpress-popup-header">
551                            <div class="embedpress-popup-header-img"> <a target="_blank" href="${srcUrl}"
552                                    target="_blank" class="embedpress-href">
553                                     <img decoding="async" loading="lazy" class="embedpress-popup-round" src="${instaPostData.profile_picture_url}" width="30" height="30"> <span class="embedpress-popup-username">${instaPostData.username}</span>
554                                </a>
555                            </div>
556                            ${followBtn}
557                        </div>
558                        <div class="embedpress-popup-text">${captionText}</div>
559                        <div class="embedpress-popup-stats">
560                            ${likeComments}
561                                <div class="embedpress-inline">
562                                <div class="embedpress-popup-share-buttons"> <a
563                                        href="https://www.facebook.com/sharer/sharer.php?u=${instaPostData.permalink}" target="_blank">
564                                        <span class="dashicons dashicons-facebook"></span></a> <a
565                                        href="https://twitter.com/intent/tweet?url=${instaPostData.permalink}"
566                                        target="_blank"><span>
567                                        <svg viewBox="0 0 18 18" aria-hidden="true" class="r-4qtqp9 r-yyyyoo r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-lrsllp r-18jsvk2 r-16y2uox r-8kz0gk" width="18" height="18"><path d="M13.683 1.688h2.481l-5.42 6.195 6.377 8.43h-4.993L8.217 11.2l-4.474 5.113H1.26l5.798-6.626L.941 1.688H6.06l3.535 4.673zm-.871 13.14h1.375L5.313 3.095H3.838z"/></svg>
568                                        </span></a>                                       
569                                        <a href="https://www.linkedin.com/shareArticle?mini=true&amp;url=${instaPostData.permalink}"
570                                        target="_blank"><span class="dashicons dashicons-linkedin"></span></a> <a
571                                        href="https://pinterest.com/pin/create/button/?url=${instaPostData.permalink}"
572                                        target="_blank"><span class="dashicons dashicons-pinterest"></span></a></div>
573                                <div class="embedpress-href embedpress-popup-share">${shareIcon}</div>
574                            </div><div class="embedpress-inline embedpress-popup-instagram-buttons"><a
575                                    href="${instaPostData.permalink}" target="_blank"
576                                    class="embedpress-href">${instaIcon}</a></div>
577                        </div>
578                        
579                    </div>
580                </div>
581            </div>
582        `;
583
584        // INIT CAROUSEL
585
586
587        return popupHtml;
588    }
589
590    // Add a click event listener to the insta-gallery container
591    epGlobals.instaPopup = (container) => {
592        container?.addEventListener('click', function (event) {
593            // Check if the clicked element has the class insta-gallery-item
594            const instaItem = event.target.closest('.insta-gallery-item');
595
596            if (instaItem) {
597
598                const postData = instaItem.dataset.postdata;
599
600                const postid = instaItem.getAttribute('data-insta-postid');
601                const accountType = container?.closest('.instagram-container')?.getAttribute('data-connected-acc-type');
602
603                let hashtag = '';
604
605                if (instaItem.closest('.instagram-container').getAttribute('data-hashtag')) {
606                    hashtag = instaItem?.closest('.instagram-container')?.getAttribute('data-hashtag');
607                }
608
609                const closestPopup = event.target.closest('.ose-instagram-feed')?.querySelector('.insta-popup');
610
611                if (closestPopup) {
612                    closestPopup.style.display = 'block';
613                }
614
615
616                var feedElement = event.target.closest('.ose-instagram-feed');
617                if (feedElement) {
618                    var popupElement = feedElement.querySelector('.popup-is-initialized');
619                    if (popupElement) {
620                        popupElement.innerHTML = getPopupTemplate(postData, hashtag, accountType);
621                    }
622                }
623
624                if (!document.querySelector(`#post-${postid}`)?.classList.contains('carousel-is-initialized')) {
625                    const carousel = new CgCarousel(`#post-${postid}`, { slidesPerView: 1, loop: true }, {});
626
627                    const next = document.querySelector(`#post-${postid} .js-carousel__next-1`);
628                    next?.addEventListener('click', () => carousel.next());
629
630                    const prev = document.querySelector(`#post-${postid} .js-carousel__prev-1`);
631                    prev?.addEventListener('click', () => carousel.prev());
632
633                    document.querySelector(`#post-${postid}`)?.classList.add('carousel-is-initialized');
634                }
635
636            }
637        });
638    }
639
640
641    const instaContainers = document.querySelectorAll('.embedpress-gutenberg-wrapper .insta-gallery');
642    if (instaContainers.length > 0) {
643        instaContainers.forEach((container) => {
644            epGlobals.instaPopup(container);
645        });
646    }
647
648    $('.popup-close').click(function (e) {
649        // Hide the popup by setting display to none
650        $('.insta-popup').hide();
651        $('.popup-container').remove();
652    });
653
654    $(document).on('click', function (e) {
655        if (e.target.classList.contains('popup-wrapper')) {
656            $('.insta-popup').hide();
657            $('.popup-container').remove();
658        }
659    });
660
661
662    const instafeeds = document.querySelectorAll('.ose-instagram-feed');
663
664    epGlobals.initializeTabs = (containerEl) => {
665
666        // Initial tab selection
667        showItems('ALL');
668
669        containerEl.addEventListener('click', function (event) {
670            const clickedElement = event.target;
671            if (!clickedElement) {
672                return; // No element clicked, ignore the event
673            }
674
675            if (containerEl.querySelector('.load-more-button-container') && (clickedElement.getAttribute('data-media-type') === 'VIDEO' || clickedElement.getAttribute('data-media-type') === 'CAROUSEL_ALBUM')) {
676                containerEl.querySelector('.load-more-button-container').style.display = 'none';
677            }
678            else if (containerEl.querySelector('.load-more-button-container') && (clickedElement.getAttribute('data-media-type') === 'ALL')) {
679                containerEl.querySelector('.load-more-button-container').style.display = 'flex';
680            }
681
682            // Handle tab click
683            if (clickedElement.matches('.tabs li')) {
684                if (clickedElement.classList.contains('active')) {
685                    return;
686                } else {
687                    const mediaType = clickedElement.getAttribute('data-media-type');
688                    showItems(mediaType);
689
690                    const tabs = containerEl.querySelectorAll('.tabs li');
691                    tabs.forEach(t => t.classList.remove('active'));
692                    clickedElement.classList.add('active');
693                }
694            }
695
696        });
697
698        function showItems(mediaType) {
699            const items = containerEl.getElementsByClassName('insta-gallery-item');
700            for (let i = 0; i < items.length; i++) {
701                const item = items[i];
702                if (mediaType === 'ALL' || item.getAttribute('data-media-type') === mediaType) {
703                    item.style.display = 'block';
704                } else {
705                    item.style.display = 'none';
706                }
707            }
708        }
709    }
710
711    epGlobals.instaLoadMore = () => {
712        // Unbind any previously bound click event to avoid multiple bindings
713        $('.insta-load-more-button').off('click').on('click', function (e) {
714            const that = $(this);
715            const loadmoreBtn = that.closest('.load-more-button-container');
716            const loadmoreKey = loadmoreBtn.data('loadmorekey');
717            const connectedAccount = that.closest('.instagram-container').data('connected-acc-type');
718            const feedType = that.closest('.instagram-container').data('feed-type');
719            const hashtagId = that.closest('.instagram-container').data('hashtag-id');
720            const userId = that.closest('.instagram-container').data('uid');
721            let loadedPosts = loadmoreBtn.data('loaded-posts') || 0;
722            let postsPerPage = loadmoreBtn.data('posts-per-page') || 0;
723            const params = JSON.stringify(that.closest('.instagram-container').data('params'));
724
725
726            const instaContainer = that.closest('.instagram-container');
727
728            const spinicon = `<svg class="insta-loadmore-spinicon" width="18" height="18" fill="${'#fff'}" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.spinner_GuJz{transform-origin:center;animation:spinner_STY6 1.5s linear infinite}@keyframes spinner_STY6{100%{transform:rotate(360deg)}}</style><g class="spinner_GuJz"><circle cx="3" cy="12" r="2"/><circle cx="21" cy="12" r="2"/><circle cx="12" cy="21" r="2"/><circle cx="12" cy="3" r="2"/><circle cx="5.64" cy="5.64" r="2"/><circle cx="18.36" cy="18.36" r="2"/><circle cx="5.64" cy="18.36" r="2"/><circle cx="18.36" cy="5.64" r="2"/></g></svg>`;
729
730            // Check if no spinicon exists
731            if (instaContainer.find('.insta-loadmore-spinicon').length === 0) {
732                that.append(spinicon);
733            }
734
735            that.attr('disabled', true);
736
737            var data = {
738                'action': 'loadmore_data_handler',
739                'user_id': userId,
740                'loaded_posts': loadedPosts,
741                'posts_per_page': postsPerPage,
742                'feed_type': feedType,
743                'connected_account_type': connectedAccount,
744                'loadmore_key': loadmoreKey,
745                'params': params,
746                '_nonce': embedpressFrontendData.nonce
747            };
748
749            if (feedType === 'hashtag_type') {
750                data.hashtag_id = hashtagId;
751            }
752
753            jQuery.post(embedpressFrontendData.ajaxurl, data, function (response) {
754                if (response.total_feed_posts >= response.next_post_index) {
755                    var $responseHtml = $(response.html);
756
757                    instaContainer.find('.insta-gallery').append($responseHtml);
758                    that.removeAttr('disabled');
759
760                    instaContainer.find('.insta-loadmore-spinicon').remove();
761
762                    loadedPosts = response.next_post_index;
763
764                    loadmoreBtn.data('loaded-posts', loadedPosts);
765
766                    // After loading more items, reinitialize the tabs for the specific container
767                    const containerEl = loadmoreBtn.closest('.ose-instagram-feed')[0];
768                    epGlobals.initializeTabs(containerEl);
769
770                    if (response.total_feed_posts === response.next_post_index) {
771                        loadmoreBtn.remove();
772                    }
773                } else {
774                    loadmoreBtn.remove();
775                }
776            });
777        });
778    }
779
780
781    if (instafeeds.length > 0) {
782        instafeeds.forEach(function (feed) {
783            epGlobals.initializeTabs(feed);
784        });
785    }
786
787    if ($('.embedpress-gutenberg-wrapper .ose-instagram-feed').length > 0) {
788        epGlobals.instaLoadMore();
789    }
790
791    $(document).on({
792        mouseenter: function () {
793            $('.embedpress-popup-share-buttons').addClass('show');
794        },
795        mouseleave: function () {
796            var buttons = $('.embedpress-popup-share-buttons');
797            setTimeout(function () {
798                if (!buttons.is(':hover')) buttons.removeClass('show');
799            }, 200);
800        }
801    }, '.embedpress-href.embedpress-popup-share, .embedpress-popup-share-buttons');
802
803    $(document).on({
804        mouseenter: function () {
805            $(this).addClass('show');
806        },
807        mouseleave: function () {
808            $(this).removeClass('show');
809        }
810    }, '.embedpress-popup-share-buttons');
811
812
813
814
815
816})(jQuery);
817
818
819
820document.addEventListener('DOMContentLoaded', function () {
821
822    epGlobals.initCarousel = (carouselSelector, options, carouselId) => {
823
824        const carouselOptions = {
825            slidesPerView: options.slideshow,
826            spacing: options.spacing,
827            loop: options.loop,
828            autoplay: options.autoplay,
829            transitionSpeed: options.transitionspeed,
830            autoplaySpeed: options.autoplayspeed,
831            arrows: options.arrows,
832            breakpoints: {
833                768: {
834                    slidesPerView: parseInt(options.slideshow) - 1
835                },
836                1024: {
837                    slidesPerView: parseInt(options.slideshow)
838                }
839            }
840        };
841
842        // INIT CAROUSEL
843        const carousel = new CgCarousel(carouselSelector, carouselOptions, {});
844
845        // Navigation
846        const next = document.querySelector(`[data-carouselid="${carouselId}"] #js-carousel__next-1`);
847        next?.addEventListener('click', () => carousel.next());
848
849        const prev = document.querySelector(`[data-carouselid="${carouselId}"] #js-carousel__prev-1`);
850        prev?.addEventListener('click', () => carousel.prev());
851    }
852
853    const instaWrappers = document.querySelectorAll('.ep-embed-content-wraper');
854
855    if (instaWrappers.length > 0) {
856        instaWrappers.forEach((wrapper) => {
857            const carouselId = wrapper.getAttribute('data-carouselid');
858
859            if (!carouselId) return;
860
861            let options = wrapper.getAttribute(`data-carousel-options`);
862
863            options = JSON.parse(options);
864            const carouselSelector = `[data-carouselid="${carouselId}"] .embedpress-insta-container`;
865
866            if (options.arrows) {
867                document.querySelector(`[data-carouselid="${carouselId}
867"] .cg-carousel__btns`).classList.remove('hidden');
868            }
869
870            epGlobals.initCarousel(carouselSelector, options, carouselId);
871
872        });
873    }
874
875    // Youtube Channel Carousel
876
877    const youtubeCarouselWraper = document.querySelectorAll('[data-youtube-channel-carousel]');
878
879    if (youtubeCarouselWraper.length > 0) {
880        youtubeCarouselWraper.forEach((wrapper) => {
881            const carouselId = wrapper.getAttribute('data-youtube-channel-carousel');
882            if (!carouselId) return;
883
884            // let options = wrapper.getAttribute(`data-carousel-options`);
885
886            // options = JSON.parse(options);
887
888            const carouselSelector = `[data-youtube-channel-carousel="${carouselId}"] .youtube__content__body`;
889
890            // if (options.arrows) {
891            //     document.querySelector(`[data-youtube-channel-carousel="${carouselId}"] .cg-carousel__btns`).classList.remove('hidden');
892            // }
893
894            const options = {
895                slidesPerView: 2,
896                autoplay: true,
897                loop: true,
898                breakpoints: {
899                    768: {
900                        slidesPerView: 2
901                    },
902                    1024: {
903                        slidesPerView: 4
904                    }
905                }
906            }
907
908            // epGlobals.initCarousel(carouselSelector, options, {});
909
910        });
911    }
912
913
914
915});
916
917document.addEventListener('DOMContentLoaded', () => {
918    const carousel = document.querySelector('.youtube-carousel');
919
920    if (!carousel) {
921        return;
922    }
923
924    const items = document.querySelectorAll('.item');
925    const prevButton = document.querySelector('.preview');
926    const nextButton = document.querySelector('.next');
927
928    let itemsToShow = getItemsToShow(); // Determine items to show based on screen width
929
930    const totalItems = items.length;
931    let currentIndex = 0;
932
933    function updateCarousel() {
934        const offset = -currentIndex * (100 / itemsToShow);
935        carousel.style.transform = `translateX(${offset}%)`;
936    }
937
938    function nextSlide() {
939        const remainingItems = totalItems - (currentIndex + itemsToShow);
940        if (remainingItems >= itemsToShow) {
941            currentIndex += itemsToShow;
942        } else if (remainingItems > 0) {
943            currentIndex += remainingItems;
944        } else {
945            currentIndex = 0;
946        }
947        updateCarousel();
948    }
949
950    function prevSlide() {
951        if (currentIndex > 0) {
952            currentIndex -= itemsToShow;
953            if (currentIndex < 0) {
954                currentIndex = 0;
955            }
956        } else {
957            currentIndex = totalItems - itemsToShow;
958        }
959        updateCarousel();
960    }
961
962    nextButton?.addEventListener('click', nextSlide);
963    prevButton?.addEventListener('click', prevSlide);
964
965    // Optional: Autoplay
966    let autoplay = false;
967    const autoplayInterval = 3000; // Change the time as needed
968    let autoplayId;
969
970    function startAutoplay() {
971        autoplayId = setInterval(nextSlide, autoplayInterval);
972    }
973
974    function stopAutoplay() {
975        clearInterval(autoplayId);
976    }
977
978    if (autoplay) {
979        startAutoplay();
980
981        // Stop autoplay on mouseover, resume on mouseout
982        carousel.addEventListener('mouseover', stopAutoplay);
983        carousel.addEventListener('mouseout', startAutoplay);
984    }
985
986    // Handle responsive behavior
987    window.addEventListener('resize', () => {
988        itemsToShow = getItemsToShow();
989        updateCarousel();
990
991    });
992
993    function getItemsToShow() {
994        const width = window.innerWidth;
995        if (width >= 1024) {
996            return 3;
997        } else if (width >= 768) {
998            return 2;
999        } else {
1000            return 1;
1001        }
1002    }
1003});
1004
1005
1006
1007
1008jQuery(window).on("elementor/frontend/init", function () {
1009
1010    var filterableGalleryHandler = function ($scope, $) {
1011
1012        // Get the Elementor unique selector for this widget
1013        let classes = $scope[0].className;
1014        let selectorEl = '.' + classes.split(' ').join('.');
1015
1016        const epElLoadMore = () => {
1017
1018            const spinicon = '<svg width="18" height="18" fill="#fff" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.spinner_GuJz{transform-origin:center;animation:spinner_STY6 1.5s linear infinite}@keyframes spinner_STY6{100%{transform:rotate(360deg)}}</style><g class="spinner_GuJz"><circle cx="3" cy="12" r="2"/><circle cx="21" cy="12" r="2"/><circle cx="12" cy="21" r="2"/><circle cx="12" cy="3" r="2"/><circle cx="5.64" cy="5.64" r="2"/><circle cx="18.36" cy="18.36" r="2"/><circle cx="5.64" cy="18.36" r="2"/><circle cx="18.36" cy="5.64" r="2"/></g></svg>';
1019
1020            $('.elementor-widget-embedpres_elementor .ep-nft-gallery-wrapper').each(function () {
1021                let selctorEl = `.elementor-widget-embedpres_elementor [data-nftid='${$(this).data('nftid')}
1021']`;
1022                let loadmorelabel = $(selctorEl).data('loadmorelabel');
1023                $(selctorEl + ` .ep_nft_item`).slice(0, $(selctorEl).data('itemparpage')).show();
1024                $('.elementor-widget-embedpres_elementor .ep-nft-gallery-wrapper .ep-loadmore-wrapper button').css('display', 'flex');
1025
1026                $(selctorEl + " .nft-loadmore").click(function (e) {
1027                    //change the text of the button
1028                    $(this).html(loadmorelabel + spinicon);
1029
1030                    //disable the button
1031                    $(this).prop("disabled", true);
1032                    //wait for 1 seconds
1033                    setTimeout(function () {
1034                        //change the text back
1035                        $(selctorEl + " .nft-loadmore").text(loadmorelabel);
1036                        //enable the button
1037                        $(selctorEl + " .nft-loadmore").prop("disabled", false);
1038                        $(selctorEl + " .ep_nft_item:hidden").slice(0, $(selctorEl).data('itemparpage')).fadeIn("slow");
1039                        if ($(selctorEl + " .ep_nft_item:hidden").length == 0) {
1040                            $(selctorEl + " .nft-loadmore").fadeOut("slow");
1041                        }
1042                    }, 500);
1043                });
1044            });
1045        };
1046
1047        if ($('.elementor-widget-embedpres_elementor .ep-nft-gallery-wrapper').length > 0) {
1048            epElLoadMore();
1049        }
1050
1051        // Content protection system function 
1052        const unlockElSubmitHander = (perentSel, that) => {
1053            var ep_client_id = jQuery(that).closest('form').find('input[name="ep_client_id"]').val();
1054            var password = jQuery(`input[name="pass_${ep_client_id}"]`).val();
1055            var post_id = jQuery(`input[name="post_id"]`).val();
1056            const buttonText = jQuery(that).closest('.password-form-container').find('input[type="submit"]').val();
1057            const unlokingText = jQuery(that).data('unlocking-text');
1058
1059            var data = {
1060                'action': 'lock_content_form_handler',
1061                'client_id': ep_client_id,
1062                'password': password,
1063                'post_id': post_id,
1064            };
1065
1066            jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(unlokingText);
1067
1068            jQuery.post(embedpressFrontendData.ajaxurl, data, function (response) {
1069                if (response.success) {
1070                    if (!response.embedHtml) {
1071                        jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(buttonText);
1072                        jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="password"]').val('');
1073                        jQuery(that).closest('.password-form-container').find('.error-message').removeClass('hidden');
1074                    }
1075                    else {
1076                        if ($('.ep-content-locked').has('#' + perentSel + '-' + ep_client_id).length) {
1077                            $('.ep-content-locked').removeClass('ep-content-locked');
1078                        }
1079
1080                        jQuery('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper').html(response.embedHtml);
1081
1082                        $('#' + perentSel + '-' + ep_client_id).removeClass('ep-content-protection-enabled');
1083
1084                        if (jQuery('#' + perentSel + '-' + ep_client_id + ' .ose-youtube').length > 0) {
1085                            epGlobals.youtubeChannelGallery();
1086                        }
1087
1088                        if ($('.elementor-widget-embedpres_elementor .ep-nft-gallery-wrapper').length > 0) {
1089                            epElLoadMore();
1090                        }
1091                    }
1092                } else {
1093                    jQuery('#password-error_' + ep_client_id).html(response.form);
1094                    jQuery('#password-error_' + ep_client_id).show();
1095                }
1096            }, 'json');
1097        }
1098
1099        // unlockElSubmitHander called for Elementor
1100        jQuery('.ep-elementor-content .password-form').submit(function (e) {
1101            e.preventDefault(); // Prevent the default form submission
1102            unlockElSubmitHander('ep-elementor-content', this);
1103        });
1104
1105
1106        const instaWrappers = document.querySelectorAll('.ep-embed-content-wrapper');
1107
1108        if (instaWrappers.length > 0) {
1109
1110            instaWrappers.forEach((wrapper) => {
1111                wrapper.classList.add('class-content-wrapper');
1112                const carouselId = wrapper.getAttribute('data-carouselid');
1113
1114                if (!carouselId) return;
1115
1116                let options = wrapper.getAttribute(`data-carousel-options`);
1117
1118                options = JSON.parse(options);
1119                const carouselSelector = `[data-carouselid="${carouselId}"] .embedpress-insta-container`;
1120
1121
1122                if (options.arrows) {
1123                    document.querySelector(`[data-carouselid="${carouselId}"] .cg-carousel__btns`).classList.remove('hidden');
1124                }
1125
1126                epGlobals.initCarousel(carouselSelector, options, carouselId);
1127
1128            });
1129        }
1130
1131
1132        const instaFeed = document.querySelector(`${selectorEl} .ose-instagram-feed`);
1133        const instaGallery = document.querySelector(`${selectorEl} .insta-gallery`);
1134        if (instaFeed) {
1135            epGlobals.initializeTabs(instaFeed);
1136        }
1137        if (instaGallery) {
1138            epGlobals.instaPopup(instaGallery);
1139
1140            $('.popup-close').click(function (e) {
1141                // Hide the popup by setting display to none
1142                $('.insta-popup').hide();
1143                $('.popup-container').remove();
1144            });
1145
1146        }
1147
1148        if ($('.elementor-widget-embedpres_elementor .ose-instagram-feed').length > 0) {
1149            epGlobals.instaLoadMore();
1150        }
1151
1152    };
1153
1154    const adsHandler = function ($scope, $) {
1155        window.epAdIndex = typeof (window.epAdIndex) === 'undefined' ? 0 : window.epAdIndex + 1;
1156        let classes = $scope[0].className;
1157        let classJoint = '.' + classes.split(' ').join('.');
1158        const selectorEl = document.querySelector(classJoint + ' [data-sponsored-id]');
1159
1160        if (jQuery('body').hasClass('elementor-editor-active') && embedpressFrontendData.isProPluginActive) {
1161            adInitialization(selectorEl, window.epAdIndex);
1162        }
1163 
1164    }
1165
1166    elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_elementor.default", filterableGalleryHandler);
1167    elementorFrontend.hooks.addAction("frontend/element_ready/embedpress_pdf.default", filterableGalleryHandler);
1168    elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_document.default", filterableGalleryHandler);
1169    elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_elementor.default", adsHandler);
1170    elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_elementor.default", epGlobals.handlePosterImageLoad);
1171});
1172
1173
1174function presentationModeForIOS(iframes) {
1175    iframes?.forEach(function (iframe) {
1176        iframe.onload = function () {
1177            var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
1178            var button = iframeDoc?.querySelector('#presentationMode.presentationMode');
1179            button?.addEventListener('click', function () {
1180                iframe.classList.toggle('presentationModeEnabledIosDevice');
1181            });
1182            iframeDoc?.addEventListener('keydown', function (event) {
1183                if (event.keyCode === 27) {
1184                    iframe.classList.remove('presentationModeEnabledIosDevice');
1185                }
1186            });
1187        };
1188    });
1189}
1190
1191function isIOSDevice() {
1192    return /iPhone|iPad|iPod/i.test(navigator.userAgent);
1193}
1194
1195if (isIOSDevice()) {
1196    var iframes = document.querySelectorAll('.embedpress-embed-document-pdf');
1197    presentationModeForIOS(iframes)
1198}
1199
1200document.addEventListener("DOMContentLoaded", epGlobals.handlePosterImageLoad);
1201
1202
1203jQuery(document).ready(function ($) {
1204
1205    let currentIndex = -1;
1206
1207    function createVideoPopup() {
1208        const videoPopupHtml = `
1209            <div id="videoPopup" class="video-popup">
1210                <div class="video-popup-content">
1211                    <span class="close">&times;</span>
1212                    <div class="video-popup-inner-content">
1213                        <iframe id="videoIframe" frameborder="0" allowfullscreen allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"></iframe>
1214                        <div id="videoDescription"></div>
1215                    </div>
1216                    <div class="popup-controls">
1217                        <span id="prevVideo" class="nav-icon prev-icon">&#10094;</span>
1218                        <span id="nextVideo" class="nav-icon next-icon">&#10095;</span>
1219                    </div>
1220                </div>
1221            </div>`;
1222        return $(videoPopupHtml).appendTo('body');
1223    }
1224
1225    function openVideoPopup(index) {
1226        const items = $('.layout-grid .item, .layout-list .item, .layout-carousel .item');
1227        if (index >= 0 && index < items.length) {
1228            // Remove any existing video popup before creating a new one
1229            $('#videoPopup').remove();
1230
1231            currentIndex = index;
1232            const videoId = $(items[currentIndex]).data('vid');
1233            const videoPopup = createVideoPopup();
1234            const videoIframe = videoPopup.find('#videoIframe');
1235            const videoDescriptionContainer = videoPopup.find('#videoDescription');
1236            const closeBtn = videoPopup.find('.close');
1237            const nextBtn = videoPopup.find('#nextVideo');
1238            const prevBtn = videoPopup.find('#prevVideo');
1239
1240            if (videoId) {
1241                fetchVideoData(videoId, videoIframe, videoDescriptionContainer);
1242                videoPopup.show();
1243                updateNavigationButtons(nextBtn, prevBtn, items);
1244
1245                closeBtn.on('click', () => {
1246                    closeVideoPopup(videoPopup);
1247                });
1248
1249                $(window).on('click', function (event) {
1250                    if ($(event.target).is(videoPopup)) {
1251                        closeVideoPopup(videoPopup);
1252                    }
1253                });
1254
1255                nextBtn.on('click', function () {
1256                    if (currentIndex >= 0 && currentIndex < items.length - 1) {
1257                        openVideoPopup(currentIndex + 1);
1258                    }
1259                });
1260
1261                prevBtn.on('click', function () {
1262                    if (currentIndex > 0) {
1263                        openVideoPopup(currentIndex - 1);
1264                    }
1265                });
1266            }
1267        }
1268    }
1269
1270
1271    function closeVideoPopup(videoPopup) {
1272        videoPopup.remove();
1273        currentIndex = -1; // Reset the index
1274    }
1275
1276    function updateNavigationButtons(nextBtn, prevBtn, items) {
1277        prevBtn.toggle(currentIndex > 0);
1278        nextBtn.toggle(currentIndex < items.length - 1);
1279    }
1280
1281    function fetchVideoData(videoId, videoIframe, videoDescriptionContainer) {
1282        const data = {
1283            action: 'fetch_video_description',
1284            vid: videoId
1285        }; 
1286
1287        $.post(embedpressFrontendData.ajaxurl, data, function (response) {
1288            if (response.success) {
1289                videoIframe.attr('src', `https://www.youtube.com/embed/${videoId}?autoplay=1`);
1290                videoDescriptionContainer.html(response.data.description);
1291            } else {
1292                console.error('Error fetching video data:', response?.data?.error);
1293            }
1294        });
1295    }
1296
1297    $(document).on('click', '.layout-grid .item, .layout-list .item, .layout-carousel .item', function () {
1298        const items = $('.layout-grid .item, .layout-list .item, .layout-carousel .item');
1299        const index = items.index(this);
1300        openVideoPopup(index);
1301    });
1302});
1303jQuery(document).ready(function ($) {
1304    let currentIndex = 0;
1305    const $photos = $('.photo-item');
1306
1307    function createPopupGooglePhotos() {
1308        if ($('#ep-popup-overlay').length === 0) {
1309            const photoPopup = `
1310            <div class="popup-overlay" id="ep-popup-overlay" style="display: none!important">
1311               
1312                <div class="popup">
1313                    <span class="close-btn" id="close-btn">
1314                        <svg width="20" height="20" viewBox="0 0 0.6 0.6" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M.132.132a.025.025 0 0 1 .035 0L.3.265.432.133a.025.025 0 1 1 .035.035L.335.3l.132.132a.025.025 0 0 1-.035.035L.3.335.168.467A.025.025 0 0 1 .133.432L.265.3.132.168a.025.025 0 0 1 0-.035" fill="#fff"/></svg>
1315                    </span>
1316                    <button class="prev-btn" id="prev-btn">
1317                        <svg width="20" height="20" viewBox="0 0 0.6 0.6" data-name="Flat Color" xmlns="http://www.w3.org/2000/svg" class="icon flat-color"><path d="M.525.275h-.39L.268.143A.025.025 0 1 0 .233.108L.058.283a.025.025 0 0 0 0 .035l.175.175a.025.025 0 0 0 .035 0 .025.025 0 0 0 0-.035L.135.325h.39a.025.025 0 0 0 0-.05" style="fill:#fff"/></svg>
1318                    </button>
1319                    <div id="popup-content" class="loading">
1320                        <div class="photo-loader"></div>
1321                        <img id="popup-image" src="" style="display:none;" loading="lazy" />
1322                    </div>
1323                    <button class="next-btn" id="next-btn">
1324                        <svg width="20" height="20" viewBox="0 0 0.6 0.6" data-name="Flat Color" xmlns="http://www.w3.org/2000/svg" class="icon flat-color"><path d="M.543.282.368.107a.025.025 0 0 0-.035.035l.133.132H.075a.025.025 0 0 0 0 .05h.39L.332.456a.025.025 0 0 0 0 .035.025.025 0 0 0 .035 0L.542.316a.025.025 0 0 0 0-.035" style="fill:#fff"/></svg>
1325                    </button>
1326                </div>
1327            </div>`;
1328            $('body').append(photoPopup);
1329
1330            // Loader spinner CSS (can be moved to your CSS file)
1331            const spinnerStyles = `
1332            <style>
1333                .popup #popup-content .photo-loader {
1334                    display: none;
1335                }
1336                .popup #popup-content.loading .photo-loader {
1337                    width: 40px;
1338                    height: 40px;
1339                    border: 4px solid #fff;
1340                    border-top: 4px solid transparent;
1341                    border-radius: 50%;
1342                    animation: spin 1s linear infinite;
1343                    margin: 40px auto;
1344                    display: block;
1345                }
1346                @keyframes spin {
1347                    0% { transform: rotate(0deg); }
1348                    100% { transform: rotate(360deg); }
1349                }
1350            </style>`;
1351            $('head').append(spinnerStyles);
1352
1353            // Events
1354            $('#ep-popup-overlay').on('click', function (e) {
1355                if ($(e.target).is('#ep-popup-overlay') || $(e.target).is('.popup')) {
1356                    $('#ep-popup-overlay').hide();
1357                }
1358            });
1359
1360            $('#close-btn').on('click', function () {
1361                $('#ep-popup-overlay').hide();
1362            });
1363
1364            $('#prev-btn').on('click', function () {
1365                currentIndex = (currentIndex - 1 + $photos.length) % $photos.length;
1366                updatePopupImage();
1367            });
1368
1369            $('#next-btn').on('click', function () {
1370                currentIndex = (currentIndex + 1) % $photos.length;
1371                updatePopupImage();
1372            });
1373        }
1374    }
1375
1376    function updatePopupImage() {
1377        const imgSrc = $photos.eq(currentIndex).find('img').attr('data-photo-src');
1378        const $popupImage = $('#popup-image');
1379        const $popupContent = $('#popup-content');
1380
1381        $popupContent.addClass('loading');
1382        $popupImage.hide();
1383
1384        const preload = new Image();
1385        preload.src = imgSrc;
1386
1387        preload.onload = function () {
1388            $popupImage.attr('src', imgSrc);
1389            $popupContent.removeClass('loading');
1390            $popupImage.fadeIn();
1391        };
1392    }
1393
1394    $('.photo-item').on('click', function () {
1395        currentIndex = $photos.index(this);
1396        createPopupGooglePhotos();
1397        updatePopupImage();
1398        $('#ep-popup-overlay').show();
1399    });
1400});
1401
1402
1403// pause audio/video
1404
1405jQuery(document).ready(function () {
1406    const players = jQuery('.enabled-auto-pause audio, .enabled-auto-pause video');
1407
1408    function pauseAllExcept(currentPlayer) {
1409        players.each(function () {
1410            if (this !== currentPlayer[0]) {
1411                this.pause();
1412            }
1413        });
1414    }
1415
1416    players.on('play', function () {
1417        pauseAllExcept(jQuery(this));
1418    });
1419});
1420

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.