PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.0.13
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.0.13
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 / pdf / web / ep-scripts.js
embedpress / assets / pdf / web Last commit date
images 2 years ago locale 2 years ago ep-scripts.js 1 year ago ep-styles.css 1 year ago viewer.css 2 years ago viewer.html 1 year ago viewer.js 2 years ago
ep-scripts.js
336 lines
1 "use strict";
2
3 //Create theme mode function
4 const setThemeMode = (themeMode) => {
5 const htmlEL = document.getElementsByTagName("html")[0];
6 if (htmlEL) {
7 htmlEL.setAttribute('ep-data-theme', themeMode);
8 }
9 }
10
11
12 const getParamObj = (hash) => {
13
14 let paramsObj = {};
15 let colorsObj = {};
16
17 if (location.hash) {
18 let hashParams = new URLSearchParams(hash.substring(1));
19
20 if (hashParams.get('key') !== null) {
21 hashParams = '#' + atob(hashParams.get('key'));
22 hashParams = new URLSearchParams(hashParams.substring(1));
23 }
24
25 if (hashParams.get('themeMode') == 'custom') {
26 colorsObj = {
27 customColor: hashParams.get('customColor'),
28 };
29 }
30 paramsObj = {
31 themeMode: hashParams.get('themeMode'),
32 ...colorsObj,
33 presentation: hashParams.get('presentation'),
34 lazyLoad: hashParams.get('lazyLoad'),
35 copy_text: hashParams.get('copy_text'),
36 add_text: hashParams.get('add_text'),
37 draw: hashParams.get('draw'),
38 add_image: hashParams.get('add_image'),
39 position: hashParams.get('position'),
40 download: hashParams.get('download'),
41 toolbar: hashParams.get('toolbar'),
42 doc_details: hashParams.get('pdf_details'),
43 doc_rotation: hashParams.get('pdf_rotation'),
44 };
45
46
47
48 if (hashParams.get('download') !== 'true' && hashParams.get('download') !== 'yes') {
49 window.addEventListener('beforeunload', function (event) {
50 event.stopImmediatePropagation();
51 });
52 }
53 }
54
55 return paramsObj;
56 }
57
58 const isDisplay = (selectorName) => {
59 if (selectorName == 'false' || selectorName == false) {
60 selectorName = 'none';
61 }
62 else {
63 selectorName = 'block';
64 }
65 return selectorName;
66 }
67
68
69 const adjustHexColor = (hexColor, percentage) => {
70 // Convert hex color to RGB values
71 const r = parseInt(hexColor.slice(1, 3), 16);
72 const g = parseInt(hexColor.slice(3, 5), 16);
73 const b = parseInt(hexColor.slice(5, 7), 16);
74
75 // Calculate adjusted RGB values
76 const adjustment = Math.round((percentage / 100) * 255);
77 const newR = Math.max(Math.min(r + adjustment, 255), 0);
78 const newG = Math.max(Math.min(g + adjustment, 255), 0);
79 const newB = Math.max(Math.min(b + adjustment, 255), 0);
80
81 // Convert adjusted RGB values back to hex color
82 const newHexColor = '#' + ((1 << 24) + (newR << 16) + (newG << 8) + newB).toString(16).slice(1);
83
84 return newHexColor;
85 }
86
87
88 const getColorBrightness = (hexColor) => {
89 const r = parseInt(hexColor.slice(1, 3), 16);
90 const g = parseInt(hexColor.slice(3, 5), 16);
91 const b = parseInt(hexColor.slice(5, 7), 16);
92
93 // Convert the RGB color to HSL
94 const max = Math.max(r, g, b);
95 const min = Math.min(r, g, b);
96 const l = (max + min) / 2;
97
98 // Calculate the brightness position in percentage
99 const brightnessPercentage = Math.round(l / 255 * 100);
100
101 return brightnessPercentage;
102 }
103 const pdfIframeStyle = (data) => {
104
105 const isAllNull = Object.values(data).every(value => value === null);;
106
107 if (isAllNull) {
108 return false;
109 };
110
111 let settingsPos = '';
112
113 if (data.toolbar === false || data.toolbar == 'false') {
114 data.presentation = false; data.download = true; data.copy_text = true; data.add_text = true; data.draw = true, data.doc_details = false; data.doc_rotation = false, data.add_image = false;
115 }
116
117 let position = 'top';
118 let toolbar = isDisplay(data.toolbar);
119 let presentation = isDisplay(data.presentation);
120 let download = isDisplay(data.download);
121 let copy_text = isDisplay(data.copy_text);
122 let add_text = isDisplay(data.add_text);
123 let draw = isDisplay(data.draw);
124
125 if (copy_text === 'block' || copy_text == 'true' || copy_text == true) {
126 copy_text = 'text';
127 }
128
129
130 let doc_details = isDisplay(data.doc_details);
131 let doc_rotation = isDisplay(data.doc_rotation);
132 let add_image = isDisplay(data.add_image);
133
134 const otherhead = document.getElementsByTagName("head")[0];
135
136 const style = document.createElement("style");
137 style.setAttribute('id', 'EBiframeStyleID');
138
139 let pdfCustomColor = '';
140
141
142
143 console.log(data);
144
145 if (data.themeMode == 'custom') {
146 if (!data.customColor) {
147 data.customColor = '#38383d';
148 }
149
150 let colorBrightness = getColorBrightness(data.customColor);
151
152 let iconsTextsColor = 'white';
153 if (colorBrightness > 60) {
154 iconsTextsColor = 'black';
155 }
156
157 pdfCustomColor = `
158 [ep-data-theme="custom"] {
159 --body-bg-color: ${data.customColor};
160 --toolbar-bg-color: ${adjustHexColor(data.customColor, 15)};
161 --doorhanger-bg-color: ${data.customColor};
162 --field-bg-color: ${data.customColor};
163 --dropdown-btn-bg-color: ${data.customColor};
164 --button-hover-color: ${adjustHexColor(data.customColor, 25)};
165 --toggled-btn-bg-color: ${adjustHexColor(data.customColor, 25)};
166 --doorhanger-hover-bg-color: ${adjustHexColor(data.customColor, 20)};
167 --toolbar-border-color: ${adjustHexColor(data.customColor, 10)};
168 --doorhanger-border-color: ${adjustHexColor(data.customColor, 10)};
169 --doorhanger-border-color-whcm: ${adjustHexColor(data.customColor, 10)};
170 --separator-color: ${adjustHexColor(data.customColor, 10)};
171 --doorhanger-separator-color: ${adjustHexColor(data.customColor, 15)};
172 --toolbar-icon-bg-color: ${iconsTextsColor};
173 --toolbar-icon-bg-color: ${iconsTextsColor};
174 --main-color: ${iconsTextsColor};
175 --field-color: ${iconsTextsColor};
176 --doorhanger-hover-color: ${iconsTextsColor};
177 --toolbar-icon-hover-bg-color: ${iconsTextsColor};
178 --toggled-btn-color: ${iconsTextsColor};
179
180 }`;
181 }
182
183 if (data.position === 'top') {
184 position = 'top:0;bottom:auto;'
185 settingsPos = '';
186 }
187 else {
188 position = 'bottom:0;top:auto;'
189 settingsPos = `
190 .findbar, .secondaryToolbar {
191 top: auto;bottom: 32px;
192 }
193 .doorHangerRight:after{
194 transform: rotate(180deg);
195 bottom: -16px;
196 }
197 .doorHangerRight:before {
198 transform: rotate(180deg);
199 bottom: -18px;
200 }
201
202 .findbar.doorHanger:before {
203 bottom: -18px;
204 transform: rotate(180deg);
205 }
206 .findbar.doorHanger:after {
207 bottom: -16px;
208 transform: rotate(180deg);
209 }
210
211 div#editorInkParamsToolbar, #editorFreeTextParamsToolbar {
212 bottom: 32px;
213 top: auto;
214 }
215 `;
216 }
217
218 style.textContent = `
219 .toolbar{
220 display: ${toolbar}!important;
221 position: absolute;
222 ${position}
223 }
224 #secondaryToolbar{
225 display: ${toolbar};
226 }
227 #secondaryPresentationMode, #toolbarViewerRight #presentationMode{
228 display: ${presentation}!important;
229 }
230 #secondaryOpenFile, #toolbarViewerRight #openFile{
231 display: none!important;
232 }
233 #secondaryDownload, #secondaryPrint, #print, #download{
234 display: ${download}!important;
235 }
236 #pageRotateCw{
237 display: ${doc_rotation}!important;
238 }
239 #editorStamp{
240 display: ${add_image}!important;
241 }
242 #pageRotateCcw{
243 display: ${doc_rotation}!important;
244 }
245 #documentProperties{
246 display: ${doc_details}!important;
247 }
248 .textLayer{
249 user-select: ${copy_text}!important;
250 }
251 button#cursorSelectTool{
252 display: ${copy_text}!important;
253 }
254
255 #editorFreeText{
256 display: ${add_text}!important;
257 }
258 #editorInk{
259 display: ${draw}!important;
260 }
261
262 ${pdfCustomColor}
263
264 ${settingsPos}
265 `;
266
267 if (otherhead) {
268 if (document.getElementById("EBiframeStyleID")) {
269 document.getElementById("EBiframeStyleID").remove();
270 }
271 otherhead.appendChild(style);
272 }
273 }
274
275 const manupulatePDFIframe = (e) => {
276 let hashNewUrl = new URL(e.newURL);
277 let data = getParamObj(hashNewUrl.hash);
278 pdfIframeStyle(data);
279 setThemeMode(data.themeMode);
280
281 }
282
283 window.addEventListener('hashchange', (e) => {
284 manupulatePDFIframe(e);
285 }, false);
286
287
288 let data = getParamObj(location.hash);
289
290 pdfIframeStyle(data);
291 setThemeMode(data.themeMode);
292
293
294
295 document.querySelector(".presentationMode")?.addEventListener("click", function () {
296
297 console.log("presentation mode clicked");
298 var mainContainer = document.getElementById("mainContainer");
299 if (mainContainer && !document.fullscreenElement) {
300 mainContainer.requestFullscreen().catch(err => {
301 alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
302 });
303 } else {
304 if (document.exitFullscreen) {
305 document.exitFullscreen();
306 }
307 }
308 });
309
310 document.getElementById("viewBookmark")?.addEventListener('click', (e) => {
311 e.preventDefault();
312 const url = e.target.getAttribute('href');
313 if (url !== null) {
314 alert(`Current Page: ${url}`);
315 }
316 });
317
318
319 if (data.lazyLoad === false || data.lazyLoad == 'false') {
320 document.querySelector('html').style.opacity = '1';
321 }
322 else {
323 function updateOpacity() {
324 const pdfViewer = document.querySelector('.pdfViewer');
325
326 if (pdfViewer.innerHTML.trim()) {
327 document.querySelector('html').style.opacity = '1';
328 document.querySelector('html').style.transition = '500ms';
329 clearInterval(intervalId); // Clear the interval once opacity is set to 1
330 }
331 }
332 const intervalId = setInterval(updateOpacity, 100);
333 updateOpacity();
334 }
335
336