PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.8.1
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.8.1
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / assets / js / front.js
embedpress / assets / js Last commit date
vendor 7 years ago admin.js 4 years ago documents-viewer-script.js 3 years ago front.js 3 years ago index.html 7 years ago initplyr.js 3 years ago pdfobject.min.js 3 years ago plyr.polyfilled.js 3 years ago preview.js 3 years ago settings.js 6 years ago
front.js
508 lines
1 /**
2 * @package EmbedPress
3 * @author EmbedPress <help@embedpress.com>
4 * @copyright Copyright (C) 2023 EmbedPress. All rights reserved.
5 * @license GPLv2 or later
6 * @since 1.7.0
7 */
8
9
10
11 let 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 // Run on initial load.
71 embedPressResponsiveEmbeds();
72
73 // Run on resize.
74 window.onresize = embedPressResponsiveEmbeds;
75
76
77 function hasClass(ele, cls) {
78 return !!ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)"));
79 }
80
81 function addClass(ele, cls) {
82 if (!hasClass(ele, cls)) ele.className += " " + cls;
83 }
84
85 function removeClass(ele, cls) {
86 if (hasClass(ele, cls)) {
87 var reg = new RegExp("(\\s|^)" + cls + "(\\s|$)");
88 ele.className = ele.className.replace(reg, " ");
89 }
90 }
91 if (!Element.prototype.matches) {
92 Element.prototype.matches =
93 Element.prototype.matchesSelector ||
94 Element.prototype.webkitMatchesSelector ||
95 Element.prototype.mozMatchesSelector ||
96 Element.prototype.msMatchesSelector ||
97 Element.prototype.oMatchesSelector ||
98 function (s) {
99 var matches = (this.document || this.ownerDocument).querySelectorAll(s),
100 i = matches.length;
101 while (--i >= 0 && matches.item(i) !== this) { }
102 return i > -1;
103 };
104 }
105 var delegate = function (el, evt, sel, handler) {
106 el.addEventListener(evt, function (event) {
107 var t = event.target;
108 while (t && t !== this) {
109 if (t.matches(sel)) {
110 handler.call(t, event);
111 }
112 t = t.parentNode;
113 }
114 });
115 };
116
117 function sendRequest(url, postData, callback) {
118 var req = createXMLHTTPObject();
119 if (!req) return;
120 var method = postData ? "POST" : "GET";
121 req.open(method, url, true);
122 if (postData) {
123 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
124 }
125 req.onreadystatechange = function () {
126 if (req.readyState != 4) return;
127 if (req.status != 200 && req.status != 304) {
128 return;
129 }
130 callback(req);
131 };
132 if (req.readyState == 4) return;
133 req.send(postData);
134 }
135
136 var XMLHttpFactories = [
137 function () {
138 return new XMLHttpRequest();
139 },
140 function () {
141 return new ActiveXObject("Msxml3.XMLHTTP");
142 },
143 function () {
144 return new ActiveXObject("Msxml2.XMLHTTP.6.0");
145 },
146 function () {
147 return new ActiveXObject("Msxml2.XMLHTTP.3.0");
148 },
149 function () {
150 return new ActiveXObject("Msxml2.XMLHTTP");
151 },
152 function () {
153 return new ActiveXObject("Microsoft.XMLHTTP");
154 },
155 ];
156
157 function createXMLHTTPObject() {
158 var xmlhttp = false;
159 for (var i = 0; i < XMLHttpFactories.length; i++) {
160 try {
161 xmlhttp = XMLHttpFactories[i]();
162 } catch (e) {
163 continue;
164 }
165 break;
166 }
167 return xmlhttp;
168 }
169
170 epGlobals.youtubeChannelGallery = function () {
171 var playerWraps = document.getElementsByClassName("ep-player-wrap");
172 if (playerWraps && playerWraps.length) {
173 for (var i = 0, im = playerWraps.length; im > i; i++) {
174 youtubeChannelEvents(playerWraps[i])
175 }
176 }
177 }
178
179 function youtubeChannelEvents(playerWrap) {
180
181 delegate(playerWrap, "click", ".item", function (event) {
182 var embed = "https://www.youtube.com/embed/";
183 var vid = this.getAttribute("data-vid");
184 var iframe = playerWrap.getElementsByTagName("iframe");
185 if (vid) {
186 if (iframe) {
187 var vidSrc = iframe[0].src.replace(/(.*\/embed\/)([^\?&"'>]+)(.+)?/, `\$1${vid}\$3`);
188 if (vidSrc.indexOf('autoplay') > 0) {
189 vidSrc = vidSrc.replace('autoplay=0', 'autoplay=1');
190 }
191 else {
192 vidSrc += '&autoplay=1';
193 }
194 iframe[0].src = vidSrc;
195 playerWrap.scrollIntoView();
196 }
197 }
198 });
199
200 var currentPage = 1;
201
202 let nearestEpContentId = playerWrap.querySelector('.ep-youtube__content__block').getAttribute('data-unique-id');
203
204 delegate(playerWrap, "click", ".ep-next, .ep-prev", function (event) {
205 const totalPages = event.target.closest('.ose-youtube').getAttribute('data-total-pages');
206 const closestClass = event.target.closest('.ose-youtube').classList;
207
208 const activePage = document.querySelector(`.${closestClass[1]} .embedpress-page-active`);
209 if (activePage) {
210 document.querySelector(`.${closestClass[1]} .embedpress-page-active`).classList.remove('embedpress-page-active');
211 }
212
213
214
215 var isNext = this.classList.contains("ep-next");
216
217 if (isNext) {
218 currentPage++;
219 } else {
220 currentPage--;
221 }
222
223 var data = {
224 action: "youtube_rest_api",
225 playlistid: this.getAttribute("data-playlistid"),
226 pagetoken: this.getAttribute("data-pagetoken"),
227 pagesize: this.getAttribute("data-pagesize"),
228 currentpage: currentPage
229 };
230
231 var formBody = [];
232 for (var property in data) {
233 var encodedKey = encodeURIComponent(property);
234 var encodedValue = encodeURIComponent(data[property]);
235 formBody.push(encodedKey + "=" + encodedValue);
236 }
237 formBody = formBody.join("&");
238
239 var galleryWrapper = playerWrap.getElementsByClassName(
240 "ep-youtube__content__block"
241 );
242
243 playerWrap.setAttribute('data-current-page', currentPage);
244
245
246 let x = 1;
247
248 sendRequest("/wp-admin/admin-ajax.php", formBody, function (request) {
249 if (galleryWrapper && galleryWrapper[0] && request.responseText) {
250 var response = JSON.parse(request.responseText);
251 galleryWrapper[0].outerHTML = response.html;
252
253 var currentPageNode =
254 galleryWrapper[0].getElementsByClassName("current-page");
255 if (currentPageNode && currentPageNode[0]) {
256 currentPageNode[0].textContent = currentPage;
257
258 }
259 }
260 });
261
262 const intervalID = setInterval(() => {
263 x++
264
265 if (playerWrap.querySelector('.ep-youtube__content__block')) {
266 const newNearestEpContentId = playerWrap
267 .querySelector('.ep-youtube__content__block')
268 .getAttribute('data-unique-id');
269
270 if (newNearestEpContentId !== nearestEpContentId && playerWrap.querySelector(`[data-page="${currentPage}"]`)) {
271 playerWrap.querySelector(`[data-page="${currentPage}"]`).classList.add('embedpress-page-active');
272 nearestEpContentId = newNearestEpContentId;
273 clearInterval(intervalID);
274 }
275 }
276
277 if (x > 100) {
278 clearInterval(intervalID);
279 }
280 }, 100);
281
282 });
283 }
284
285 //Load more for OpenaSea collection
286 const epLoadMore = () => {
287
288 $('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').each(function () {
289 let selctorEl = `[data-nftid='${$(this).data('nftid')}']`;
290
291 let loadmorelabel = $(selctorEl).data('loadmorelabel');
292 let iconcolor = $(selctorEl + " .nft-loadmore").data('iconcolor');
293
294 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>`;
295
296 $(selctorEl + ` .ep_nft_item`).slice(0, $(selctorEl).data('itemparpage')).show();
297 $('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper .ep-loadmore-wrapper button').css('display', 'flex');
298
299 $(selctorEl + " .nft-loadmore").click(function (e) {
300 //change the text of the button
301 $(this).html(loadmorelabel + spinicon);
302 //disable the button
303 $(this).prop("disabled", true);
304 //wait for 1 seconds
305 setTimeout(function () {
306 //change the text back
307 $(selctorEl + " .nft-loadmore").text(loadmorelabel);
308 //enable the button
309 $(selctorEl + " .nft-loadmore").prop("disabled", false);
310 $(selctorEl + " .ep_nft_item:hidden").slice(0, $(selctorEl).data('itemparpage')).fadeIn("slow");
311 if ($(selctorEl + " .ep_nft_item:hidden").length == 0) {
312 $(selctorEl + " .nft-loadmore").fadeOut("slow");
313 }
314 }, 500);
315 });
316 });
317 };
318
319 if ($('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').length > 0) {
320 epLoadMore();
321 }
322
323 // Content protection system function
324 const unlockSubmitHander = (perentSel, that) => {
325 var ep_client_id = jQuery(that).closest('form').find('input[name="ep_client_id"]').val();
326 var password = jQuery(`input[name="pass_${ep_client_id}"]`).val();
327 var epbase = jQuery(`input[name="ep_base_${ep_client_id}"]`).val();
328 var hash_key = jQuery(`input[name="hash_key_${ep_client_id}"]`).val();
329 const buttonText = jQuery(that).closest('.password-form-container').find('input[type="submit"]').val();
330 const unlokingText = jQuery(that).data('unlocking-text');
331
332
333 var data = {
334 'action': 'lock_content_form_handler',
335 'client_id': ep_client_id,
336 'password': password,
337 'hash_key': hash_key,
338 'epbase': epbase
339 };
340
341 jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(unlokingText);
342
343 jQuery.post(eplocalize.ajaxurl, data, function (response) {
344 if (response.success) {
345 if (!response.embedHtml) {
346
347 jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(buttonText);
348 jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="password"]').val('');
349 jQuery(that).closest('.password-form-container').find('.error-message').removeClass('hidden');
350 }
351 else {
352 jQuery('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper').html(response.embedHtml);
353
354 if (jQuery('#' + perentSel + '-' + ep_client_id + ' .ose-youtube').length > 0) {
355 epGlobals.youtubeChannelGallery();
356 }
357
358 if ($('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').length > 0) {
359 epLoadMore();
360 }
361
362 // Custom player initialization when content protection enabled
363 document.querySelector('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper').classList.remove('plyr-initialized');
364
365 initPlayer(document.querySelector('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper'));
366
367 }
368 } else {
369 jQuery('#password-error_' + ep_client_id).html(response.form);
370 jQuery('#password-error_' + ep_client_id).show();
371 }
372 }, 'json');
373 }
374
375 // unlockSubmitHander called for gutentberg
376 jQuery('.ep-gutenberg-content .password-form').submit(function (e) {
377 e.preventDefault(); // Prevent the default form submission
378 unlockSubmitHander('ep-gutenberg-content', this);
379 });
380
381 window.addEventListener('load', function (e) {
382 const urlParams = new URLSearchParams(window.location.search);
383 const hash = urlParams.get('hash');
384
385 // find the element with the matching id
386 const element = document.getElementById(hash);
387
388 if (element) {
389 element.scrollIntoView({ behavior: 'smooth' });
390 }
391
392 });
393
394
395 })(jQuery);
396
397
398 jQuery(window).on("elementor/frontend/init", function () {
399
400 var filterableGalleryHandler = function ($scope, $) {
401
402 // Get the Elementor unique selector for this widget
403 let classes = $scope[0].className;
404 let selectorEl = '.' + classes.split(' ').join('.');
405
406 const epElLoadMore = () => {
407
408 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>';
409
410 $('.elementor-widget-container .ep-nft-gallery-wrapper').each(function () {
411 let selctorEl = `.elementor-widget-container [data-nftid='${$(this).data('nftid')}']`;
412 let loadmorelabel = $(selctorEl).data('loadmorelabel');
413 $(selctorEl + ` .ep_nft_item`).slice(0, $(selctorEl).data('itemparpage')).show();
414 $('.elementor-widget-container .ep-nft-gallery-wrapper .ep-loadmore-wrapper button').css('display', 'flex');
415
416 $(selctorEl + " .nft-loadmore").click(function (e) {
417 //change the text of the button
418 $(this).html(loadmorelabel + spinicon);
419
420 //disable the button
421 $(this).prop("disabled", true);
422 //wait for 1 seconds
423 setTimeout(function () {
424 //change the text back
425 $(selctorEl + " .nft-loadmore").text(loadmorelabel);
426 //enable the button
427 $(selctorEl + " .nft-loadmore").prop("disabled", false);
428 $(selctorEl + " .ep_nft_item:hidden").slice(0, $(selctorEl).data('itemparpage')).fadeIn("slow");
429 if ($(selctorEl + " .ep_nft_item:hidden").length == 0) {
430 $(selctorEl + " .nft-loadmore").fadeOut("slow");
431 }
432 }, 500);
433 });
434 });
435 };
436
437 if ($('.elementor-widget-container .ep-nft-gallery-wrapper').length > 0) {
438 epElLoadMore();
439 }
440
441 // Content protection system function
442 const unlockElSubmitHander = (perentSel, that) => {
443 var ep_client_id = jQuery(that).closest('form').find('input[name="ep_client_id"]').val();
444 var password = jQuery(`input[name="pass_${ep_client_id}"]`).val();
445 var epbase = jQuery(`input[name="ep_base_${ep_client_id}"]`).val();
446 var hash_key = jQuery(`input[name="hash_key_${ep_client_id}"]`).val();
447 const buttonText = jQuery(that).closest('.password-form-container').find('input[type="submit"]').val();
448 const unlokingText = jQuery(that).data('unlocking-text');
449
450 var data = {
451 'action': 'lock_content_form_handler',
452 'client_id': ep_client_id,
453 'password': password,
454 'hash_key': hash_key,
455 'epbase': epbase
456 };
457
458 jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(unlokingText);
459
460 jQuery.post(eplocalize.ajaxurl, data, function (response) {
461 if (response.success) {
462 if (!response.embedHtml) {
463 jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(buttonText);
464 jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="password"]').val('');
465 jQuery(that).closest('.password-form-container').find('.error-message').removeClass('hidden');
466 }
467 else {
468 if ($('.ep-content-locked').has('#' + perentSel + '-' + ep_client_id).length) {
469 $('.ep-content-locked').removeClass('ep-content-locked');
470 }
471
472 jQuery('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper').html(response.embedHtml);
473
474 $('#' + perentSel + '-' + ep_client_id).removeClass('ep-content-protection-enabled');
475
476 if (jQuery('#' + perentSel + '-' + ep_client_id + ' .ose-youtube').length > 0) {
477 epGlobals.youtubeChannelGallery();
478 }
479
480 if ($('.elementor-widget-container .ep-nft-gallery-wrapper').length > 0) {
481 epElLoadMore();
482 }
483 }
484 } else {
485 jQuery('#password-error_' + ep_client_id).html(response.form);
486 jQuery('#password-error_' + ep_client_id).show();
487 }
488 }, 'json');
489 }
490
491 // unlockElSubmitHander called for Elementor
492 jQuery('.ep-elementor-content .password-form').submit(function (e) {
493 e.preventDefault(); // Prevent the default form submission
494 unlockElSubmitHander('ep-elementor-content', this);
495 });
496 };
497 elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_elementor.default", filterableGalleryHandler);
498 elementorFrontend.hooks.addAction("frontend/element_ready/embedpress_pdf.default", filterableGalleryHandler);
499 elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_document.default", filterableGalleryHandler);
500 });
501
502
503 // document.addEventListener('DOMContentLoaded', function () {
504 // testHellowWorld();
505 // });
506
507 // testHellowWorld();
508