PluginProbe
Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades / trunk
Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades vtrunk
trunk 1.0 1.1 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 11.0 11.0.1 11.1 11.2 11.3 11.3.1 11.4 11.5 11.6 11.7 11.7.1 11.8 All 143 releases
youtube-embed-plus / scripts / ytprefs.js

ytprefs.js in Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades trunk, at scripts/ytprefs.js

935 lines 45.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function (window, $)
2 {
3 window._EPYT_ = window._EPYT_ || {
4 ajaxurl: "\/wp-admin\/admin-ajax.php",
5 security: "",
6 gallery_scrolloffset: 100,
7 eppathtoscripts: "\/wp-content\/plugins\/youtube-embed-plus\/scripts\/",
8 eppath: "\/wp-content\/plugins\/youtube-embed-plus\/",
9 epresponsiveselector: ["iframe.__youtube_prefs_widget__"],
10 epdovol: true,
11 evselector: 'iframe.__youtube_prefs__[src], iframe[src*="youtube.com/embed/"], iframe[src*="youtube-nocookie.com/embed/"]',
12 stopMobileBuffer: true,
13 ajax_compat: false,
14 usingdefault: true,
15 ytapi_load: 'light',
16 pause_others: false,
17 facade_mode: false,
18 not_live_on_channel: false,
19 maxres_facade: 'eager'
20 };
21
22 window._EPYT_.touchmoved = false;
23
24 window._EPYT_.apiVideos = window._EPYT_.apiVideos || {};
25
26 if (window.location.toString().indexOf('https://') === 0)
27 {
28 window._EPYT_.ajaxurl = window._EPYT_.ajaxurl.replace("http://", "https://");
29 }
30
31 window._EPYT_.pageLoaded = false;
32 $(window).on('load._EPYT_', function ()
33 {
34 window._EPYT_.pageLoaded = true;
35 });
36
37 if (!document.querySelectorAll)
38 {
39 document.querySelectorAll = function (selector)
40 {
41 var doc = document, head = doc.documentElement.firstChild, styleTag = doc.createElement('STYLE');
42 head.appendChild(styleTag);
43 doc.__qsaels = [];
44 styleTag.styleSheet.cssText = selector + "{x:expression(document.__qsaels.push(this))}";
45 window.scrollBy(0, 0);
46 return doc.__qsaels;
47 };
48 }
49
50 if (typeof window._EPADashboard_ === 'undefined')
51 {
52 window._EPADashboard_ =
53 {
54 initStarted: false,
55 checkCount: 0,
56 onPlayerReady: function (event)
57 {
58 try
59 {
60 if (typeof _EPYT_.epdovol !== "undefined" && _EPYT_.epdovol)
61 {
62 var vol = parseInt(event.target.getIframe().getAttribute("data-vol"));
63 if (!isNaN(vol))
64 {
65 if (vol === 0)
66 {
67 event.target.mute();
68 }
69 else
70 {
71 if (event.target.isMuted())
72 {
73 event.target.unMute();
74 }
75 event.target.setVolume(vol);
76 }
77 }
78 }
79
80 var epautoplay = parseInt(event.target.getIframe().getAttribute("data-epautoplay"));
81 if (!isNaN(epautoplay) && epautoplay === 1)
82 {
83 event.target.playVideo();
84 }
85
86 }
87 catch (err)
88 {
89 }
90
91 try
92 {
93 var apiVideoIframe = event.target.getIframe();
94 var apiVideoId = apiVideoIframe.getAttribute("id");
95 window._EPYT_.apiVideos[apiVideoId] = event.target;
96
97 if (window._EPYT_.not_live_on_channel && event.target.getVideoUrl().indexOf('live_stream') > 0)
98 {
99 window._EPADashboard_.doLiveFallback(apiVideoIframe);
100 }
101 }
102 catch (liveErr)
103 {
104 }
105 finally
106 {
107 $(event.target.getIframe()).css('opacity', 1);
108 }
109 },
110 onPlayerStateChange: function (event)
111 {
112 var ifm = event.target.getIframe();
113
114 if (window._EPYT_.pause_others && event.data === window.YT.PlayerState.PLAYING)
115 {
116 window._EPADashboard_.pauseOthers(event.target);
117 }
118
119 if (event.data === window.YT.PlayerState.PLAYING && event.target.ponce !== true && ifm.src.indexOf('autoplay=1') === -1)
120 {
121 event.target.ponce = true;
122 }
123
124 if (event.data === window.YT.PlayerState.ENDED && $(ifm).data('relstop') == '1')
125 {
126 if (typeof event.target.stopVideo === 'function')
127 {
128 event.target.stopVideo();
129 }
130 else
131 {
132 var $iframeTemp = $(ifm).clone(true).off();
133 $iframeTemp.attr('src', window._EPADashboard_.cleanSrc($iframeTemp.attr('src').replace('autoplay=1', 'autoplay=0')));
134 $(ifm).replaceWith($iframeTemp);
135 window._EPADashboard_.setupevents($iframeTemp.attr('id'));
136 ifm = $iframeTemp.get(0);
137 }
138 }
139
140 var $gallery = $(ifm).closest('.epyt-gallery');
141 if (!$gallery.length)
142 {
143 $gallery = $('#' + $(ifm).data('epytgalleryid'));
144 }
145 if ($gallery.length)
146 {
147 var autonext = $gallery.find('.epyt-pagebutton').first().data('autonext') == '1';
148 if (autonext && event.data === window.YT.PlayerState.ENDED)
149 {
150 var $currvid = $gallery.find('.epyt-current-video');
151 if (!$currvid.length)
152 {
153 $currvid = $gallery.find('.epyt-gallery-thumb').first();
154 }
155 var $nextvid = $currvid.find(' ~ .epyt-gallery-thumb').first();
156
157 if ($nextvid.length)
158 {
159 $nextvid.trigger('click');
160 }
161 else
162 {
163 $gallery.find('.epyt-pagebutton.epyt-next[data-pagetoken!=""][data-pagetoken]').first().trigger('click');
164
165 }
166 }
167 }
168
169 },
170 isMobile: function ()
171 {
172 return /Mobi|Android/i.test(navigator.userAgent);
173 },
174 base64DecodeUnicode: function (str)
175 {
176 str = str.replace(/\s/g, '');
177 return decodeURIComponent(Array.prototype.map.call(atob(str), function (c)
178 {
179 return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
180 }).join(''))
181 },
182 findSwapBlock: function (playerIframe)
183 {
184 var $swapBlock = $(playerIframe).closest('.wp-block-embed');
185 if (!$swapBlock.length)
186 {
187 $swapBlock = $(playerIframe).closest('.epyt-live-chat-wrapper');
188 }
189 if (!$swapBlock.length)
190 {
191 $swapBlock = $(playerIframe).closest('.epyt-video-wrapper');
192 }
193 if (!$swapBlock.length)
194 {
195 $swapBlock = $(playerIframe);
196 }
197 return $swapBlock;
198 },
199 doLiveFallback: function (playerIframe)
200 {
201 var $swapBlock = _EPADashboard_.findSwapBlock(playerIframe);
202
203 if ($swapBlock.length)
204 {
205 var $liveFallbackBlock = $('#epyt-live-fallback');
206 if ($liveFallbackBlock.length)
207 {
208 var fallbackHtml = '';
209 try
210 {
211 fallbackHtml = window._EPADashboard_.base64DecodeUnicode($liveFallbackBlock.get(0).innerHTML);
212 }
213 catch (fallbackErr)
214 {
215 }
216 if (fallbackHtml)
217 {
218 var $swapBlockParent = $swapBlock.parent();
219 window._EPADashboard_.loadYTAPI();
220 $swapBlock.replaceWith(fallbackHtml);
221 window._EPADashboard_.apiInit();
222 window._EPADashboard_.pageReady();
223 setTimeout(function ()
224 {
225 if (typeof $.fn.fitVidsEP !== 'undefined')
226 {
227 $swapBlockParent.fitVidsEP();
228 }
229 }, 1);
230 }
231 }
232 }
233 },
234 videoEqual: function (a, b)
235 {
236 if (a.getIframe && b.getIframe && a.getIframe().id === b.getIframe().id)
237 {
238 return true;
239 }
240 return false;
241 },
242 pauseOthers: function (currentVid)
243 {
244 if (!currentVid)
245 {
246 return;
247 }
248 for (var vidKey in window._EPYT_.apiVideos)
249 {
250 var vid = window._EPYT_.apiVideos[vidKey];
251 if (
252 vid &&
253 typeof vid.pauseVideo === 'function' &&
254 vid != currentVid &&
255 !_EPADashboard_.videoEqual(vid, currentVid) &&
256 typeof vid.getPlayerState === 'function' &&
257 [YT.PlayerState.BUFFERING, window.YT.PlayerState.PLAYING].indexOf(vid.getPlayerState()) >= 0
258 )
259 {
260 vid.pauseVideo();
261 }
262 }
263 },
264 justid: function (s)
265 {
266 return new RegExp("[\\?&]v=([^&#]*)").exec(s)[1];
267 },
268 setupevents: function (iframeid)
269 {
270 if (typeof (window.YT) !== 'undefined' && window.YT !== null && window.YT.loaded)
271 {
272 var thisvid = document.getElementById(iframeid);
273
274 if (!thisvid.epytsetupdone)
275 {
276 window._EPADashboard_.log('Setting up YT API events: ' + iframeid);
277 thisvid.epytsetupdone = true;
278 var ytOptions = {
279 events: {
280 "onReady": window._EPADashboard_.onPlayerReady,
281 "onStateChange": window._EPADashboard_.onPlayerStateChange
282 },
283 host: (thisvid.src || '').indexOf('nocookie') > 0 ? 'https://www.youtube-nocookie.com' : 'https://www.youtube.com'
284 };
285 return new window.YT.Player(iframeid, ytOptions);
286 }
287 }
288 },
289 apiInit: function ()
290 {
291 if (typeof (window.YT) !== 'undefined')
292 {
293 window._EPADashboard_.initStarted = true;
294 var __allytifr = document.querySelectorAll(_EPYT_.evselector);
295 for (var i = 0; i < __allytifr.length; i++)
296 {
297 if (!__allytifr[i].hasAttribute("id"))
298 {
299 __allytifr[i].id = "_dytid_" + Math.round(Math.random() * 8999 + 1000);
300 }
301 window._EPADashboard_.setupevents(__allytifr[i].id);
302 }
303 }
304 },
305 log: function (msg)
306 {
307 try
308 {
309 console.log(msg);
310 }
311 catch (err)
312 {
313 }
314 },
315 doubleCheck: function ()
316 {
317 window._EPADashboard_.checkInterval = setInterval(function ()
318 {
319 window._EPADashboard_.checkCount++;
320 if (window._EPADashboard_.checkCount >= 5 || window._EPADashboard_.initStarted)
321 {
322 clearInterval(window._EPADashboard_.checkInterval);
323 }
324 else
325 {
326 window._EPADashboard_.apiInit();
327 window._EPADashboard_.log('YT API init check');
328 }
329
330 }, 1000);
331 },
332 selectText: function (ele)
333 {
334 if (document.selection)
335 {
336 var range = document.body.createTextRange();
337 range.moveToElementText(ele);
338 range.select();
339 }
340 else if (window.getSelection)
341 {
342 var selection = window.getSelection();
343 var range = document.createRange();
344 range.selectNode(ele);
345 selection.removeAllRanges();
346 selection.addRange(range);
347 }
348 },
349 setVidSrc: function ($iframe, vidSrc)
350 {
351 if ($iframe.is('.epyt-facade'))
352 {
353 $iframe.attr('data-facadesrc', window._EPADashboard_.cleanSrc(vidSrc));
354 $iframe.trigger('click');
355 return;
356 }
357
358 var cleanSrcValue = window._EPADashboard_.cleanSrc(vidSrc);
359 var parsed = window._EPADashboard_.parseYouTubeEmbedUrl(cleanSrcValue);
360
361 var iframeId = $iframe.attr('id');
362 var player = iframeId ? window._EPYT_.apiVideos[iframeId] : null;
363
364 var ytReady = typeof window.YT !== 'undefined' && window.YT !== null && window.YT.loaded;
365
366 if (!parsed.videoId || parsed.videoId === 'live_stream' || !ytReady || !player || typeof player.loadVideoById !== 'function')
367 {
368 window._EPADashboard_.setVidSrcLegacy($iframe, cleanSrcValue);
369 return;
370 }
371
372 var loadOptions = window._EPADashboard_.mapUrlParamsToLoadOptions(parsed.params, parsed.videoId);
373 var shouldAutoplay = parsed.params.autoplay === '1';
374
375 try
376 {
377 if (shouldAutoplay)
378 {
379 player.loadVideoById(loadOptions);
380 }
381 else
382 {
383 player.cueVideoById(loadOptions);
384 }
385
386 $iframe.data('ep-current-src', cleanSrcValue);
387 }
388 catch (apiError)
389 {
390 window._EPADashboard_.setVidSrcLegacy($iframe, cleanSrcValue);
391 return;
392 }
393
394 $iframe.css('opacity', '1');
395 },
396 cleanSrc: function (srcInput)
397 {
398 var cleanedUrl = srcInput.replace('enablejsapi=1?enablejsapi=1', 'enablejsapi=1');
399 return cleanedUrl;
400 },
401 parseYouTubeEmbedUrl: function (embedUrl)
402 {
403 var result = {
404 videoId: null,
405 params: {}
406 };
407
408 if (!embedUrl || typeof embedUrl !== 'string')
409 {
410 return result;
411 }
412
413 var videoIdMatch = embedUrl.match(/\/embed\/([a-zA-Z0-9_-]{11})/);
414 if (videoIdMatch && videoIdMatch[1])
415 {
416 result.videoId = videoIdMatch[1];
417 }
418 else if (embedUrl.indexOf('/embed/live_stream') > -1)
419 {
420 result.videoId = 'live_stream';
421 }
422
423 var queryStart = embedUrl.indexOf('?');
424 if (queryStart > -1)
425 {
426 var queryString = embedUrl.substring(queryStart + 1).split('#')[0];
427 var pairs = queryString.split('&');
428 for (var i = 0; i < pairs.length; i++)
429 {
430 var pair = pairs[i].split('=');
431 if (pair.length === 2)
432 {
433 result.params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
434 }
435 }
436 }
437
438 return result;
439 },
440 mapUrlParamsToLoadOptions: function (urlParams, videoId)
441 {
442 var options = {
443 videoId: videoId
444 };
445
446 var startVal = urlParams.start || urlParams.t;
447 if (startVal)
448 {
449 var startSeconds = parseInt(startVal, 10);
450 if (!isNaN(startSeconds) && startSeconds > 0)
451 {
452 options.startSeconds = startSeconds;
453 }
454 }
455
456 if (urlParams.end)
457 {
458 var endSeconds = parseInt(urlParams.end, 10);
459 if (!isNaN(endSeconds) && endSeconds > 0)
460 {
461 options.endSeconds = endSeconds;
462 }
463 }
464
465 return options;
466 },
467 setVidSrcLegacy: function ($iframe, cleanSrcValue)
468 {
469 if ($iframe.get(0).src && $iframe.get(0).contentWindow && $iframe.get(0).contentWindow.location)
470 {
471 try
472 {
473 $iframe.get(0).contentWindow.location.replace(cleanSrcValue);
474 }
475 catch (err)
476 {
477 $iframe.attr('src', cleanSrcValue);
478 }
479 }
480 else
481 {
482 $iframe.attr('src', cleanSrcValue);
483 }
484 $iframe.get(0).epytsetupdone = false;
485 // Ensure the iframe has an ID before calling setupevents
486 if (!$iframe.attr('id'))
487 {
488 $iframe.attr('id', "_dytid_" + Math.round(Math.random() * 8999 + 1000));
489 }
490 window._EPADashboard_.setupevents($iframe.attr('id'));
491 $iframe.css('opacity', '1');
492 },
493 loadYTAPI: function ()
494 {
495 if (typeof window.YT === 'undefined')
496 {
497 if (window._EPYT_.ytapi_load !== 'never' && (window._EPYT_.ytapi_load === 'always' || $('iframe[src*="youtube.com/embed/"], iframe[data-src*="youtube.com/embed/"], .__youtube_prefs__').length))
498 {
499 var iapi = document.createElement('script');
500 iapi.src = "https://www.youtube.com/iframe_api";
501 iapi.type = "text/javascript";
502 document.getElementsByTagName('head')[0].appendChild(iapi);
503 }
504 }
505 else if (window.YT.loaded)
506 {
507 if (window._EPYT_.pageLoaded)
508 {
509 window._EPADashboard_.apiInit();
510 window._EPADashboard_.log('YT API available');
511 }
512 else
513 {
514 $(window).on('load._EPYT_', function ()
515 {
516 window._EPADashboard_.apiInit();
517 window._EPADashboard_.log('YT API available 2');
518 });
519 }
520 }
521 },
522 resolveFacadeQuality: function (img, isError)
523 {
524 img.epytFacadeCount = typeof (img.epytFacadeCount) === 'undefined' ? 0 : img.epytFacadeCount + 1;
525 if (isError || img.naturalHeight < 200)
526 {
527 var facadeOldSrc = $(img).attr("src");
528 if (facadeOldSrc)
529 {
530 $(img).attr("src", facadeOldSrc.replace('maxresdefault', 'hqdefault'));
531 $(img).off('load.epyt');
532 }
533 }
534 if (img.epytFacadeCount > 2)
535 {
536 $(img).off('load.epyt');
537 }
538 },
539 maximizeFacadeQuality: function (img)
540 {
541 var facadeOldSrc = $(img).attr("src");
542 if (facadeOldSrc && facadeOldSrc.indexOf('maxresdefault') < 0)
543 {
544 var maxResSrc = facadeOldSrc.replace('hqdefault', 'maxresdefault');
545 var maxRes = new Image();
546 maxRes.src = maxResSrc;
547 $(maxRes).on("load.epyt", function ()
548 {
549 $(maxRes).off('load.epyt');
550 if (maxRes.naturalHeight > 200)
551 {
552 $(img).off('load.epyt');
553 $(img).attr("src", maxRes.src);
554 }
555 }).on('error', function ()
556 {
557 $(maxRes).off('load.epyt');
558 }).each(function ()
559 {
560 if (maxRes.complete)
561 {
562 $(maxRes).trigger('load');
563 }
564 });
565 }
566 },
567 pageReady: function ()
568 {
569 if (window._EPYT_.not_live_on_channel && window._EPYT_.ytapi_load !== 'never')
570 {
571 $('.epyt-live-channel').each(function ()
572 {
573 var $ch = $(this);
574 if (!$ch.data('eypt-fallback'))
575 {
576 $ch.data('eypt-fallback', true);
577 $ch.css('opacity', 0);
578 setTimeout(function ()
579 {
580 $ch.css('opacity', 1);
581 }, 4000);
582 }
583 });
584 }
585 $('.epyt-gallery').each(function ()
586 {
587 var $container = $(this);
588 if (!$container.data('epytevents') || !$('body').hasClass('block-editor-page'))
589 {
590 $container.data('epytevents', '1');
591 var $iframe = $(this).find('iframe, div.__youtube_prefs_gdpr__, div.epyt-facade').first();
592
593 var initSrc = $iframe.data('src') || $iframe.data('facadesrc') || $iframe.attr('src');
594 if (!initSrc)
595 {
596 initSrc = $iframe.data('ep-src');
597 }
598 var firstId = $(this).find('.epyt-gallery-list .epyt-gallery-thumb').first().data('videoid');
599 if (typeof (initSrc) !== 'undefined')
600 {
601 initSrc = initSrc.replace(firstId, 'GALLERYVIDEOID');
602 $container.data('ep-gallerysrc', initSrc);
603 }
604 else if ($iframe.hasClass('__youtube_prefs_gdpr__'))
605 {
606 $container.data('ep-gallerysrc', '');
607 }
608 $container.on('click touchend', '.epyt-gallery-list .epyt-gallery-thumb', function (e)
609 {
610 $iframe = $container.find('iframe, div.__youtube_prefs_gdpr__, div.epyt-facade').first();
611 if (window._EPYT_.touchmoved)
612 {
613 return;
614 }
615 if (!$(this).hasClass('epyt-current-video'))
616 {
617 $container.find('.epyt-gallery-list .epyt-gallery-thumb').removeClass('epyt-current-video');
618 $(this).addClass('epyt-current-video');
619 var vid = $(this).data('videoid');
620 $container.data('currvid', vid);
621 var vidSrc = $container.data('ep-gallerysrc').replace('GALLERYVIDEOID', vid);
622
623 var thumbplay = $container.find('.epyt-pagebutton').first().data('thumbplay');
624 if (thumbplay !== '0' && thumbplay !== 0)
625 {
626 if (vidSrc.indexOf('autoplay') > 0)
627 {
628 vidSrc = vidSrc.replace('autoplay=0', 'autoplay=1');
629 }
630 else
631 {
632 vidSrc += '&autoplay=1';
633 }
634
635 $iframe.addClass('epyt-thumbplay');
636 }
637
638 // https://github.com/jquery/jquery-ui/blob/master/ui/scroll-parent.js
639 var bodyScrollTop = Math.max($('body').scrollTop(), $('html').scrollTop());
640 var scrollNext = $iframe.offset().top - parseInt(_EPYT_.gallery_scrolloffset);
641 if (bodyScrollTop > scrollNext)
642 {
643 $('html, body').animate({
644 scrollTop: scrollNext
645 }, 500, function ()
646 {
647 window._EPADashboard_.setVidSrc($iframe, vidSrc);
648 });
649 }
650 else
651 {
652 window._EPADashboard_.setVidSrc($iframe, vidSrc);
653 }
654 }
655
656 }).on('touchmove', function (e)
657 {
658 window._EPYT_.touchmoved = true;
659 }).on('touchstart', function ()
660 {
661 window._EPYT_.touchmoved = false;
662 }).on('keydown', '.epyt-gallery-list .epyt-gallery-thumb, .epyt-pagebutton', function (e)
663 {
664 var code = e.which;
665 if ((code === 13) || (code === 32))
666 {
667 e.preventDefault();
668 $(this).trigger('click');
669
670 }
671 });
672
673 $container.on('mouseenter', '.epyt-gallery-list .epyt-gallery-thumb', function ()
674 {
675 $(this).addClass('hover');
676 });
677
678 $container.on('mouseleave', '.epyt-gallery-list .epyt-gallery-thumb', function ()
679 {
680 $(this).removeClass('hover');
681 });
682
683 $container.on('click touchend', '.epyt-pagebutton', function (ev)
684 {
685 if (window._EPYT_.touchmoved)
686 {
687 return;
688 }
689 if (!$container.find('.epyt-gallery-list').hasClass('epyt-loading'))
690 {
691 $container.find('.epyt-gallery-list').addClass('epyt-loading');
692 var humanClick = typeof (ev.originalEvent) !== 'undefined';
693 var pageData = {
694 action: 'my_embedplus_gallery_page',
695 security: _EPYT_.security,
696 options: {
697 playlistId: $(this).data('playlistid'),
698 pageToken: $(this).data('pagetoken'),
699 pageSize: $(this).data('pagesize'),
700 columns: $(this).data('epcolumns'),
701 showTitle: $(this).data('showtitle'),
702 showPaging: $(this).data('showpaging'),
703 autonext: $(this).data('autonext'),
704 thumbplay: $(this).data('thumbplay')
705 }
706 };
707
708 var forward = $(this).hasClass('epyt-next');
709 var currpage = parseInt($container.data('currpage') + "");
710 currpage += forward ? 1 : -1;
711 $container.data('currpage', currpage);
712
713 $.post(_EPYT_.ajaxurl, pageData, function (response)
714 {
715 $container.find('.epyt-gallery-list').html(response);
716 $container.find('.epyt-current').each(function ()
717 {
718 $(this).text($container.data('currpage'));
719 });
720 $container.find('.epyt-gallery-thumb[data-videoid="' + $container.data('currvid') + '"]').addClass('epyt-current-video');
721
722 if ($container.find('.epyt-pagebutton').first().data('autonext') == '1' && !humanClick)
723 {
724 $container.find('.epyt-gallery-thumb').first().trigger('click');
725 }
726
727 })
728 .fail(function ()
729 {
730 alert('Sorry, there was an error loading the next page.');
731 })
732 .always(function ()
733 {
734 $container.find('.epyt-gallery-list').removeClass('epyt-loading');
735
736 if ($container.find('.epyt-pagebutton').first().data('autonext') != '1')
737 {
738 // https://github.com/jquery/jquery-ui/blob/master/ui/scroll-parent.js
739 var bodyScrollTop = Math.max($('body').scrollTop(), $('html').scrollTop());
740 var scrollNext = $container.find('.epyt-gallery-list').offset().top - parseInt(_EPYT_.gallery_scrolloffset);
741 if (bodyScrollTop > scrollNext)
742 {
743 $('html, body').animate({
744 scrollTop: scrollNext
745 }, 500);
746 }
747 }
748
749 });
750 }
751 }).on('touchmove', function (e)
752 {
753 window._EPYT_.touchmoved = true;
754 }).on('touchstart', function ()
755 {
756 window._EPYT_.touchmoved = false;
757 });
758 }
759 });
760
761 $('.__youtube_prefs_gdpr__.epyt-is-override').each(function ()
762 {
763 $(this).parent('.wp-block-embed__wrapper').addClass('epyt-is-override__wrapper');
764 });
765
766 $('button.__youtube_prefs_gdpr__').on('click', function (e)
767 {
768 e.preventDefault();
769 if ($.cookie)
770 {
771 $.cookie("ytprefs_gdpr_consent", '1', {expires: 30, path: '/'});
772 window.top.location.reload();
773 }
774 });
775
776 if (window._EPYT_.maxres_facade === 'eager')
777 {
778 $('img.epyt-facade-poster').on("load.epyt", function ()
779 {
780 window._EPADashboard_.resolveFacadeQuality(this, false);
781 }).on('error', function ()
782 {
783 window._EPADashboard_.resolveFacadeQuality(this, true);
784 }).each(function ()
785 {
786 if (this.complete)
787 {
788 $(this).trigger('load');
789 }
790 });
791 }
792 else if (window._EPYT_.maxres_facade === 'soft')
793 {
794
795 $('img.epyt-facade-poster').on("load.epyt", function ()
796 {
797 window._EPADashboard_.maximizeFacadeQuality(this);
798 }).each(function ()
799 {
800 if (this.complete)
801 {
802 $(this).trigger('load');
803 }
804 });
805 }
806
807 $('.epyt-facade-play').each(function ()
808 {
809 if (!$(this).find('svg').length)
810 {
811 $(this).append('<svg data-no-lazy="1" height="100%" version="1.1" viewBox="0 0 68 48" width="100%"><path class="ytp-large-play-button-bg" d="M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z" fill="#f00"></path><path d="M 45,24 27,14 27,34" fill="#fff"></path></svg>');
812 }
813 });
814
815 $('.epyt-facade-poster[data-facadeoembed]').each(function ()
816 {
817 var $facadePoster = $(this);
818 if (!$facadePoster.data('facadeoembedcomplete'))
819 {
820 $facadePoster.data('facadeoembedcomplete', '1');
821 var facadeOembedUrl = 'https://www.youtube.com/' + $facadePoster.data('facadeoembed');
822 $.get('https://youtube.com/oembed', {url: facadeOembedUrl, format: 'json'},
823 function (response)
824 {
825 var newSrc = window._EPYT_.maxres_facade === 'eager' ? response.thumbnail_url.replace('hqdefault', 'maxresdefault') : response.thumbnail_url;
826 $facadePoster.attr('src', newSrc);
827 }, 'json')
828 .fail(function ()
829 {
830 })
831 .always(function ()
832 {
833 });
834 }
835 });
836
837 $(document).on('click', '.epyt-facade', function (e)
838 {
839 var $facade = $(this);
840 var srcTemp = $facade.attr('data-facadesrc');
841 srcTemp = window._EPADashboard_.cleanSrc(srcTemp);
842 var iframe = document.createElement('iframe');
843 for (var i = 0; i < this.attributes.length; i++)
844 {
845 var attrib = this.attributes[i];
846 if (['allow', 'class', 'height', 'id', 'width'].indexOf(attrib.name.toLowerCase()) >= 0 || attrib.name.toLowerCase().indexOf('data-') == 0)
847 {
848 $(iframe).attr(attrib.name, attrib.value);
849 }
850 }
851 $(iframe).removeClass('epyt-facade');
852 $(iframe).attr('allowfullscreen', '')
853 .attr('title', $facade.find('img').attr('alt'))
854 .attr('allow', 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share')
855 .attr('referrerpolicy', 'strict-origin-when-cross-origin');
856
857 window._EPADashboard_.loadYTAPI();
858 $facade.replaceWith(iframe);
859 window._EPADashboard_.setVidSrc($(iframe), srcTemp);
860 setTimeout(function ()
861 {
862 if (typeof $.fn.fitVidsEP !== 'undefined')
863 {
864 $($(iframe).parent()).fitVidsEP();
865 }
866 }, 1);
867 });
868 }
869 };
870 }
871
872 window.onYouTubeIframeAPIReady = typeof window.onYouTubeIframeAPIReady !== 'undefined' ? window.onYouTubeIframeAPIReady : function ()
873 {
874 if (window._EPYT_.pageLoaded)
875 {
876 window._EPADashboard_.apiInit();
877 window._EPADashboard_.log('YT API ready');
878 }
879 else
880 {
881 $(window).on('load._EPYT_', function ()
882 {
883 window._EPADashboard_.apiInit();
884 window._EPADashboard_.log('YT API ready 2');
885 });
886 }
887 };
888
889 if (!window._EPYT_.facade_mode || (window._EPYT_.not_live_on_channel && $('iframe[src*="youtube.com/embed/live_stream"], iframe[data-src*="youtube.com/embed/live_stream"]').length))
890 {
891 window._EPADashboard_.loadYTAPI();
892 }
893
894 if (window._EPYT_.pageLoaded)
895 {
896 window._EPADashboard_.doubleCheck();
897 }
898 else
899 {
900 $(window).on('load._EPYT_', function ()
901 {
902 window._EPADashboard_.doubleCheck();
903 });
904 }
905
906
907 $(document).ready(function ()
908 {
909 window._EPADashboard_.pageReady();
910
911 if (!window._EPYT_.facade_mode || (window._EPYT_.not_live_on_channel && $('iframe[src*="youtube.com/embed/live_stream"], iframe[data-src*="youtube.com/embed/live_stream"]').length))
912 {
913 window._EPADashboard_.loadYTAPI();
914 }
915
916 if (window._EPYT_.ajax_compat)
917 {
918 $(window).on('load._EPYT_', function ()
919 {
920 $(document).ajaxSuccess(function (e, xhr, settings)
921 {
922 if (xhr && xhr.responseText && (xhr.responseText.indexOf('<iframe ') !== -1 || xhr.responseText.indexOf('enablejsapi') !== -1))
923 {
924 window._EPADashboard_.loadYTAPI();
925 window._EPADashboard_.apiInit();
926 window._EPADashboard_.log('YT API AJAX');
927 window._EPADashboard_.pageReady();
928 }
929 });
930 });
931 }
932
933 });
934 })(window, jQuery);
935