PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.6.1
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.6.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 front.js 3 years ago index.html 7 years ago pdfobject.min.js 4 years ago preview.js 3 years ago settings.js 6 years ago
front.js
279 lines
1 /**
2 * @package EmbedPress
3 * @author EmbedPress <help@embedpress.com>
4 * @copyright Copyright (C) 2022 EmbedPress. All rights reserved.
5 * @license GPLv2 or later
6 * @since 1.7.0
7 */
8 (function () {
9 'use strict';
10 // function equivalent to jquery ready()
11 function ready(fn) {
12 if (document.readyState !== 'loading') {
13 fn();
14 } else {
15 document.addEventListener('DOMContentLoaded', fn);
16 }
17 }
18
19 ready(function () {
20 let option = {
21 forceObject: true,
22 };
23 let selector = document.querySelectorAll('.embedpress-embed-document-pdf');
24 if (selector.length) {
25 selector.forEach((function (value, index, thisArg) {
26 let id = value.dataset['emid'];
27 let src = value.dataset['emsrc'];
28 PDFObject.embed(src, "." + id, option);
29 }));
30 }
31 youtubeChannelGallery();
32 });
33
34 /**
35 *
36 * Make embeds responsive so they don't overflow their container.
37 */
38
39 /**
40 * Add max-width & max-height to <iframe> elements, depending on their width & height props.
41 *
42 *
43 * @return {void}
44 */
45 function embedPressResponsiveEmbeds() {
46 var proportion, parentWidth;
47
48 // Loop iframe elements.
49 document.querySelectorAll('iframe').forEach(function (iframe) {
50 // Only continue if the iframe has a width & height defined.
51 if (iframe.width && iframe.height) {
52 // Calculate the proportion/ratio based on the width & height.
53 proportion = parseFloat(iframe.width) / parseFloat(iframe.height);
54 // Get the parent element's width.
55 parentWidth = parseFloat(window.getComputedStyle(iframe.parentElement, null).width.replace('px', ''));
56 // Set the max-width & height.
57 iframe.style.maxWidth = '100%';
58 iframe.style.maxHeight = Math.round(parentWidth / proportion).toString() + 'px';
59 }
60 });
61 }
62
63 // Run on initial load.
64 embedPressResponsiveEmbeds();
65
66 // Run on resize.
67 window.onresize = embedPressResponsiveEmbeds;
68
69
70 function hasClass(ele, cls) {
71 return !!ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)"));
72 }
73
74 function addClass(ele, cls) {
75 if (!hasClass(ele, cls)) ele.className += " " + cls;
76 }
77
78 function removeClass(ele, cls) {
79 if (hasClass(ele, cls)) {
80 var reg = new RegExp("(\\s|^)" + cls + "(\\s|$)");
81 ele.className = ele.className.replace(reg, " ");
82 }
83 }
84 if (!Element.prototype.matches) {
85 Element.prototype.matches =
86 Element.prototype.matchesSelector ||
87 Element.prototype.webkitMatchesSelector ||
88 Element.prototype.mozMatchesSelector ||
89 Element.prototype.msMatchesSelector ||
90 Element.prototype.oMatchesSelector ||
91 function (s) {
92 var matches = (this.document || this.ownerDocument).querySelectorAll(s),
93 i = matches.length;
94 while (--i >= 0 && matches.item(i) !== this) { }
95 return i > -1;
96 };
97 }
98 var delegate = function (el, evt, sel, handler) {
99 el.addEventListener(evt, function (event) {
100 var t = event.target;
101 while (t && t !== this) {
102 if (t.matches(sel)) {
103 handler.call(t, event);
104 }
105 t = t.parentNode;
106 }
107 });
108 };
109
110 function sendRequest(url, postData, callback) {
111 var req = createXMLHTTPObject();
112 if (!req) return;
113 var method = postData ? "POST" : "GET";
114 req.open(method, url, true);
115 if (postData) {
116 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
117 }
118 req.onreadystatechange = function () {
119 if (req.readyState != 4) return;
120 if (req.status != 200 && req.status != 304) {
121 return;
122 }
123 callback(req);
124 };
125 if (req.readyState == 4) return;
126 req.send(postData);
127 }
128
129 var XMLHttpFactories = [
130 function () {
131 return new XMLHttpRequest();
132 },
133 function () {
134 return new ActiveXObject("Msxml3.XMLHTTP");
135 },
136 function () {
137 return new ActiveXObject("Msxml2.XMLHTTP.6.0");
138 },
139 function () {
140 return new ActiveXObject("Msxml2.XMLHTTP.3.0");
141 },
142 function () {
143 return new ActiveXObject("Msxml2.XMLHTTP");
144 },
145 function () {
146 return new ActiveXObject("Microsoft.XMLHTTP");
147 },
148 ];
149
150 function createXMLHTTPObject() {
151 var xmlhttp = false;
152 for (var i = 0; i < XMLHttpFactories.length; i++) {
153 try {
154 xmlhttp = XMLHttpFactories[i]();
155 } catch (e) {
156 continue;
157 }
158 break;
159 }
160 return xmlhttp;
161 }
162 function youtubeChannelGallery() {
163 var playerWraps = document.getElementsByClassName("ep-player-wrap");
164 if (playerWraps && playerWraps.length) {
165 for (var i = 0, im = playerWraps.length; im > i; i++) {
166 youtubeChannelEvents(playerWraps[i])
167 }
168 }
169 }
170 function youtubeChannelEvents(playerWrap) {
171
172
173
174 delegate(playerWrap, "click", ".item", function (event) {
175 var embed = "https://www.youtube.com/embed/";
176 var vid = this.getAttribute("data-vid");
177 var iframe = playerWrap.getElementsByTagName("iframe");
178 if (vid) {
179 if (iframe) {
180 var vidSrc = iframe[0].src.replace(/(.*\/embed\/)([^\?&"'>]+)(.+)?/, `\$1${vid}\$3`);
181 if (vidSrc.indexOf('autoplay') > 0) {
182 vidSrc = vidSrc.replace('autoplay=0', 'autoplay=1');
183 }
184 else {
185 vidSrc += '&autoplay=1';
186 }
187 iframe[0].src = vidSrc;
188 playerWrap.scrollIntoView();
189 }
190 }
191 });
192
193
194 var currentPage = 1;
195
196 let nearestEpContentId = playerWrap.querySelector('.ep-youtube__content__block').getAttribute('data-unique-id');
197
198 delegate(playerWrap, "click", ".ep-next, .ep-prev", function (event) {
199 const totalPages = event.target.closest('.ose-youtube').getAttribute('data-total-pages');
200 const closestClass = event.target.closest('.ose-youtube').classList;
201
202 const activePage = document.querySelector(`.${closestClass[1]} .embedpress-page-active`);
203 if (activePage) {
204 document.querySelector(`.${closestClass[1]} .embedpress-page-active`).classList.remove('embedpress-page-active');
205 }
206
207
208
209 var isNext = this.classList.contains("ep-next");
210
211 if (isNext) {
212 currentPage++;
213 } else {
214 currentPage--;
215 }
216
217 var data = {
218 action: "youtube_rest_api",
219 playlistid: this.getAttribute("data-playlistid"),
220 pagetoken: this.getAttribute("data-pagetoken"),
221 pagesize: this.getAttribute("data-pagesize"),
222 currentpage: currentPage
223 };
224
225 var formBody = [];
226 for (var property in data) {
227 var encodedKey = encodeURIComponent(property);
228 var encodedValue = encodeURIComponent(data[property]);
229 formBody.push(encodedKey + "=" + encodedValue);
230 }
231 formBody = formBody.join("&");
232
233 var galleryWrapper = playerWrap.getElementsByClassName(
234 "ep-youtube__content__block"
235 );
236
237 playerWrap.setAttribute('data-current-page', currentPage);
238
239
240 let x = 1;
241
242 sendRequest("/wp-admin/admin-ajax.php", formBody, function (request) {
243 if (galleryWrapper && galleryWrapper[0] && request.responseText) {
244 var response = JSON.parse(request.responseText);
245 galleryWrapper[0].outerHTML = response.html;
246
247 var currentPageNode =
248 galleryWrapper[0].getElementsByClassName("current-page");
249 if (currentPageNode && currentPageNode[0]) {
250 currentPageNode[0].textContent = currentPage;
251
252 }
253 }
254 });
255
256 const intervalID = setInterval(() => {
257 x++
258
259 if (playerWrap.querySelector('.ep-youtube__content__block')) {
260 const newNearestEpContentId = playerWrap
261 .querySelector('.ep-youtube__content__block')
262 .getAttribute('data-unique-id');
263
264 if (newNearestEpContentId !== nearestEpContentId && playerWrap.querySelector(`[data-page="${currentPage}"]`)) {
265 playerWrap.querySelector(`[data-page="${currentPage}"]`).classList.add('embedpress-page-active');
266 nearestEpContentId = newNearestEpContentId;
267 clearInterval(intervalID);
268 }
269 }
270
271 if (x > 100) {
272 clearInterval(intervalID);
273 }
274 }, 100);
275
276 });
277 }
278 })();
279