PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.4.11
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.4.11
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 / documents-viewer-script.js
embedpress / assets / js Last commit date
chunks 3 months ago vendor 8 months ago admin.build.js 7 months ago admin.js 9 months ago analytics-tracker.js 9 months ago analytics.build.js 3 months ago blocks.build.js 3 months ago carousel.js 1 year ago documents-viewer-script.js 4 months ago feature-notices.js 7 months ago front.js 4 months ago frontend.build.js 9 months ago gallery-justify.js 9 months ago gutneberg-script.js 1 year ago index.html 7 years ago initCarousel.js 2 years ago initplyr.js 8 months ago instafeed.js 7 months ago lazy-load.js 6 months ago license.js 3 months ago meetup-timezone.js 6 months ago preview.js 8 months ago settings.js 6 months ago sponsored.js 9 months ago
documents-viewer-script.js
335 lines
1
2 const embedpressDocViewer = {};
3
4 document.addEventListener("fullscreenchange", () => {
5 if (!document.fullscreenElement) {
6 const viwerParentEl = document.querySelector('.ep-file-download-option-masked.fullscreen-enabled');
7 if (viwerParentEl) {
8 viwerParentEl.classList.remove("fullscreen-enabled");
9 viwerParentEl.querySelector(".ep-doc-minimize-icon").style.display = 'none';
10 viwerParentEl.querySelector(".ep-doc-fullscreen-icon").style.display = 'flex';
11 }
12 }
13 });
14
15 document.addEventListener("keydown", (event) => {
16 if (event.key === "Escape") {
17 const viwerParentEl = document.querySelector('.ep-file-download-option-masked.fullscreen-enabled');
18 if (viwerParentEl) {
19 if (document.exitFullscreen) {
20 document.exitFullscreen();
21 } else if (document.webkitExitFullscreen) {
22 document.webkitExitFullscreen();
23 } else if (document.msExitFullscreen) {
24 document.msExitFullscreen();
25 }
26 }
27 }
28 });
29
30
31 embedpressDocViewer.getColorBrightness = (hexColor) => {
32 const r = parseInt(hexColor.slice(1, 3), 16);
33 const g = parseInt(hexColor.slice(3, 5), 16);
34 const b = parseInt(hexColor.slice(5, 7), 16);
35
36 // Convert the RGB color to HSL
37 const max = Math.max(r, g, b);
38 const min = Math.min(r, g, b);
39 const l = (max + min) / 2;
40
41 // Calculate the brightness position in percentage
42 const brightnessPercentage = Math.round(l / 255 * 100);
43
44 return brightnessPercentage;
45 }
46
47 embedpressDocViewer.adjustHexColor = (hexColor, percentage) => {
48 // Convert hex color to RGB values
49 const r = parseInt(hexColor.slice(1, 3), 16);
50 const g = parseInt(hexColor.slice(3, 5), 16);
51 const b = parseInt(hexColor.slice(5, 7), 16);
52
53 // Calculate adjusted RGB values
54 const adjustment = Math.round((percentage / 100) * 255);
55 const newR = Math.max(Math.min(r + adjustment, 255), 0);
56 const newG = Math.max(Math.min(g + adjustment, 255), 0);
57 const newB = Math.max(Math.min(b + adjustment, 255), 0);
58
59 // Convert adjusted RGB values back to hex color
60 const newHexColor = '#' + ((1 << 24) + (newR << 16) + (newG << 8) + newB).toString(16).slice(1);
61
62 return newHexColor;
63 }
64
65 embedpressDocViewer.viewerStyle = () => {
66 const viwerParentEls = document.querySelectorAll('.ep-file-download-option-masked');
67
68 let customStyle = document.getElementById('custom-styles') || document.createElement('style');
69 customStyle.id = 'custom-styles';
70 customStyle.type = 'text/css';
71 customStyle.innerHTML = ''
72
73 if (viwerParentEls !== null) {
74 viwerParentEls.forEach((el) => {
75 let customColor = el.getAttribute('data-custom-color');
76 if (customColor == null) {
77 return false;
78 }
79 let colorBrightness = embedpressDocViewer.getColorBrightness(customColor);
80 let docId = el.getAttribute('data-id');
81
82 let iconsColor = '#f2f2f6';
83 if (colorBrightness > 60) {
84 iconsColor = '#343434';
85 }
86
87 if (el.getAttribute('data-theme-mode') == 'custom') {
88
89 viewerCustomColor = `
90 [data-id='${docId}'][data-theme-mode='custom'] {
91 --viewer-primary-color: ${customColor};
92 --viewer-icons-color: ${iconsColor};
93 --viewer-icons-hover-bgcolor: ${embedpressDocViewer.adjustHexColor(customColor, -10)};
94
95 }`;
96 customStyle.innerHTML += viewerCustomColor;
97 }
98 });
99
100 document.head.appendChild(customStyle);
101 }
102 }
103
104 console.log('embedpressDocViewer', embedpressDocViewer);
105 console.log('embedpressDocViewer', embedpressDocViewer);
106
107 embedpressDocViewer.epDocumentsViewerController = () => {
108 console.log('[EP Debug] epDocumentsViewerController called');
109 // Remove previous listeners to prevent duplicates when called multiple times
110 if (embedpressDocViewer._handleClick) {
111 document.removeEventListener('click', embedpressDocViewer._handleClick);
112 }
113 if (embedpressDocViewer._handleDrawIconClick) {
114 document.removeEventListener('click', embedpressDocViewer._handleDrawIconClick);
115 }
116 if (embedpressDocViewer._handleFullscreenChange) {
117 document.removeEventListener('fullscreenchange', embedpressDocViewer._handleFullscreenChange);
118 }
119
120 const viwerParentEls = document.querySelectorAll('.ep-file-download-option-masked');
121
122 function handleFullscreenChange() {
123 if (!document.fullscreenElement) {
124 viwerParentEls.forEach((el) => {
125 el.classList.remove('fullscreen-enabled');
126 el.querySelector('.ep-doc-minimize-icon').style.display = 'none';
127 el.querySelector('.ep-doc-fullscreen-icon').style.display = 'flex';
128 });
129 }
130 }
131
132 function handleClick(event) {
133 event.stopPropagation();
134
135 console.log('[EP Debug] handleClick fired, target:', event.target);
136
137 const viwerParentEl = event.target.closest('.ep-file-download-option-masked');
138
139 if (!viwerParentEl) { console.log('[EP Debug] No .ep-file-download-option-masked parent found'); return; }
140
141 const viewerIframeEl = viwerParentEl.querySelector('iframe');
142 if (!viewerIframeEl) return;
143
144 const iframeSrc = decodeURIComponent(viewerIframeEl.getAttribute('src'));
145 if (!iframeSrc) return;
146
147 const regex = /(url|src)=([^&]+)/;
148 const match = iframeSrc.match(regex);
149 let fileUrl = match && match[2];
150
151 if (!fileUrl) {
152 fileUrl = iframeSrc;
153 }
154
155 const popupIcon = event.target.closest('.ep-doc-popup-icon svg');
156 const printIcon = event.target.closest('.ep-doc-print-icon svg');
157 const downloadcIcon = event.target.closest('.ep-doc-download-icon svg');
158 const minimizeIcon = event.target.closest('.ep-doc-minimize-icon svg');
159 const fullscreenIcon = event.target.closest('.ep-doc-fullscreen-icon svg');
160
161 console.log('popupIcon', popupIcon);
162 console.log('printIcon', printIcon);
163 console.log('downloadcIcon', downloadcIcon);
164 console.log('minimizeIcon', minimizeIcon);
165 console.log('fullscreenIcon', fullscreenIcon);
166
167 if (popupIcon instanceof SVGElement) {
168 window.open(fileUrl, '_blank');
169 } else if (printIcon instanceof SVGElement) {
170 const newTab = window.open(`https://view.officeapps.live.com/op/view.aspx?src=${fileUrl}&wdOrigin=BROWSELINK`, '_blank');
171 } else if (downloadcIcon instanceof SVGElement) {
172 fetch(fileUrl, { mode: 'no-cors' })
173 .then(response => {
174 if (response.ok) {
175 response.blob().then(blob => {
176 const url = window.URL.createObjectURL(blob);
177 const a = document.createElement('a');
178 a.href = url;
179 a.download = fileUrl.substring(fileUrl.lastIndexOf('/') + 1);
180 document.body.appendChild(a);
181 a.click();
182 a.remove();
183 });
184 } else {
185 window.location.href = fileUrl;
186 }
187 })
188 .catch(error => {
189 window.location.href = fileUrl;
190 });
191 } else if (minimizeIcon instanceof SVGElement) {
192 if (document.exitFullscreen) {
193 document.exitFullscreen();
194 } else if (document.webkitExitFullscreen) {
195 document.webkitExitFullscreen();
196 } else if (document.msExitFullscreen) {
197 document.msExitFullscreen();
198 }
199 } else if (fullscreenIcon instanceof SVGElement) {
200 if (viwerParentEl.requestFullscreen) {
201 viwerParentEl.requestFullscreen();
202 } else if (viwerParentEl.webkitRequestFullscreen) {
203 viwerParentEl.webkitRequestFullscreen();
204 } else if (viwerParentEl.msRequestFullscreen) {
205 viwerParentEl.msRequestFullscreen();
206 }
207
208 viwerParentEl.querySelector(".ep-doc-minimize-icon").style.display = 'flex';
209 viwerParentEl.querySelector(".ep-doc-fullscreen-icon").style.display = 'none';
210 viwerParentEl.classList.add("fullscreen-enabled");
211 }
212 }
213
214 function handleDrawIconClick(event) {
215 event.stopPropagation();
216
217 const drawIcon = event.target.closest('.ep-doc-draw-icon svg');
218 if (!drawIcon) return;
219
220 const viwerParentEl = drawIcon.closest('.ep-file-download-option-masked');
221 if (!viwerParentEl) return;
222
223 const canvas = viwerParentEl.querySelector(".ep-doc-canvas");
224 const drawToggle = viwerParentEl.querySelector(".ep-doc-draw-icon svg");
225 if (!canvas || !drawToggle) return;
226
227 const ctx = canvas.getContext("2d");
228 let isDrawing = false;
229 let canDraw = false;
230
231 canvas.addEventListener("mousedown", function (e) {
232 if (canDraw) {
233 isDrawing = true;
234 const rect = canvas.getBoundingClientRect();
235 const scrollX = window.pageXOffset || document.documentElement.scrollLeft;
236 const x = e.pageX - rect.left - scrollX;
237 const y = e.pageY - rect.top;
238 ctx.beginPath();
239 ctx.moveTo(x, y);
240 }
241 });
242
243 canvas.addEventListener("mousemove", function (e) {
244 if (isDrawing && canDraw) {
245 const rect = canvas.getBoundingClientRect();
246 const scrollX = window.pageXOffset || document.documentElement.scrollLeft;
247 const x = e.pageX - rect.left - scrollX;
248 const y = e.pageY - rect.top;
249 ctx.lineTo(x, y);
250 ctx.stroke();
251 }
252 });
253
254 canvas.addEventListener("mouseup", function (e) {
255 isDrawing = false;
256 });
257
258
259 drawToggle.parentNode.classList.toggle("active");
260 canDraw = drawToggle.parentNode.classList.contains("active");
261 canvas.style.display = canDraw ? "block" : "none";
262 }
263
264 embedpressDocViewer._handleClick = handleClick;
265 embedpressDocViewer._handleDrawIconClick = handleDrawIconClick;
266 embedpressDocViewer._handleFullscreenChange = handleFullscreenChange;
267
268 document.addEventListener('click', handleClick);
269 document.addEventListener('click', handleDrawIconClick);
270 document.addEventListener('fullscreenchange', handleFullscreenChange);
271 };
272
273
274 console.log('[EP Debug] Gutenberg check:', jQuery('.wp-block-embedpress-document.embedpress-document-embed').length);
275 console.log('[EP Debug] Elementor doc check:', jQuery('.ep-file-download-option-masked').length);
276
277 if (typeof embedpressDocViewer.epDocumentsViewerController === "function") {
278 if (jQuery('.wp-block-embedpress-document.embedpress-document-embed').length > 0) {
279 console.log('[EP Debug] Init: Gutenberg document block found');
280 embedpressDocViewer.epDocumentsViewerController();
281 }
282 }
283
284 if (typeof wp !== 'undefined' && typeof wp.editor !== 'undefined') {
285 if (typeof embedpressDocViewer.viewerStyle === "function") {
286 console.log('[EP Debug] Init: WP editor detected');
287 embedpressDocViewer.epDocumentsViewerController();
288 }
289 }
290
291 // Initialize for Elementor frontend (non-editor) when document viewers exist on the page
292 if (typeof embedpressDocViewer.epDocumentsViewerController === "function") {
293 if (jQuery('.ep-file-download-option-masked').length > 0) {
294 console.log('[EP Debug] Init: Elementor/shortcode document viewer found on frontend');
295 embedpressDocViewer.epDocumentsViewerController();
296 embedpressDocViewer.viewerStyle();
297 }
298 }
299
300 if (typeof embedpressDocViewer.viewerStyle === "function") {
301 if (jQuery('.wp-block-embedpress-document.embedpress-document-embed').length > 0) {
302 embedpressDocViewer.viewerStyle();
303 }
304 }
305 jQuery(window).on("elementor/frontend/init", function () {
306 console.log('[EP Debug] Elementor frontend init fired');
307 var filterableGalleryHandler = function ($scope, $) {
308 console.log('[EP Debug] Elementor element_ready/embedpres_document fired');
309 if (typeof embedpressDocViewer.epDocumentsViewerController === "function") {
310 embedpressDocViewer.epDocumentsViewerController();
311 }
312 if (typeof embedpressDocViewer.epDocumentsViewerController === "function") {
313 embedpressDocViewer.viewerStyle();
314 }
315
316 };
317 elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_document.default", filterableGalleryHandler);
318 });
319
320
321 const myDivs = document.querySelectorAll('.ep-file-download-option-masked');
322 const canDownloadDivs = document.querySelectorAll('.enabled-file-download');
323
324
325 myDivs.forEach(function (div) {
326 div.addEventListener('contextmenu', preventRightClick);
327 });
328
329 function preventRightClick(event) {
330 event.preventDefault();
331 }
332
333 canDownloadDivs.forEach(function (div) {
334 div.removeEventListener('contextmenu', preventRightClick);
335 });