PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.1.2
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.1.2
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 1 year 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 selection_tool: hashParams.get('selection_tool'),
45 scrolling: hashParams.get('scrolling'),
46 spreads: hashParams.get('spreads'),
47 is_pro_active: hashParams.get('is_pro_active'),
48 };
49
50
51 if (hashParams.get('download') !== 'true' && hashParams.get('download') !== 'yes') {
52 window.addEventListener('beforeunload', function (event) {
53 event.stopImmediatePropagation();
54 });
55 }
56 }
57
58 return paramsObj;
59 }
60
61 const isDisplay = (selectorName) => {
62 if (selectorName == 'false' || selectorName == false) {
63 selectorName = 'none';
64 }
65 else {
66 selectorName = 'block';
67 }
68 return selectorName;
69 }
70
71
72 const adjustHexColor = (hexColor, percentage) => {
73 // Convert hex color to RGB values
74 const r = parseInt(hexColor.slice(1, 3), 16);
75 const g = parseInt(hexColor.slice(3, 5), 16);
76 const b = parseInt(hexColor.slice(5, 7), 16);
77
78 // Calculate adjusted RGB values
79 const adjustment = Math.round((percentage / 100) * 255);
80 const newR = Math.max(Math.min(r + adjustment, 255), 0);
81 const newG = Math.max(Math.min(g + adjustment, 255), 0);
82 const newB = Math.max(Math.min(b + adjustment, 255), 0);
83
84 // Convert adjusted RGB values back to hex color
85 const newHexColor = '#' + ((1 << 24) + (newR << 16) + (newG << 8) + newB).toString(16).slice(1);
86
87 return newHexColor;
88 }
89
90
91 const getColorBrightness = (hexColor) => {
92 const r = parseInt(hexColor.slice(1, 3), 16);
93 const g = parseInt(hexColor.slice(3, 5), 16);
94 const b = parseInt(hexColor.slice(5, 7), 16);
95
96 // Convert the RGB color to HSL
97 const max = Math.max(r, g, b);
98 const min = Math.min(r, g, b);
99 const l = (max + min) / 2;
100
101 // Calculate the brightness position in percentage
102 const brightnessPercentage = Math.round(l / 255 * 100);
103
104 return brightnessPercentage;
105 }
106 const pdfIframeStyle = (data) => {
107
108 const isAllNull = Object.values(data).every(value => value === null);;
109
110 if (isAllNull) {
111 return false;
112 };
113
114 let settingsPos = '';
115
116 if (data.toolbar === false || data.toolbar == 'false') {
117 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;
118 }
119
120 let position = 'top';
121 let toolbar = isDisplay(data.toolbar);
122 let presentation = isDisplay(data.presentation);
123 let download = isDisplay(data.download);
124 let copy_text = isDisplay(data.copy_text);
125 let add_text = isDisplay(data.add_text);
126 let draw = isDisplay(data.draw);
127
128 if (copy_text === 'block' || copy_text == 'true' || copy_text == true) {
129 copy_text = 'text';
130 }
131
132
133 let doc_details = isDisplay(data.doc_details);
134 let doc_rotation = isDisplay(data.doc_rotation);
135 let add_image = isDisplay(data.add_image);
136
137 const otherhead = document.getElementsByTagName("head")[0];
138
139 const style = document.createElement("style");
140 style.setAttribute('id', 'EBiframeStyleID');
141
142 let pdfCustomColor = '';
143
144
145
146 if (data.themeMode == 'custom') {
147 if (!data.customColor) {
148 data.customColor = '#38383d';
149 }
150
151 let colorBrightness = getColorBrightness(data.customColor);
152
153 let iconsTextsColor = 'white';
154 if (colorBrightness > 60) {
155 iconsTextsColor = 'black';
156 }
157
158 pdfCustomColor = `
159 [ep-data-theme="custom"] {
160 --body-bg-color: ${data.customColor};
161 --toolbar-bg-color: ${adjustHexColor(data.customColor, 15)};
162 --doorhanger-bg-color: ${data.customColor};
163 --field-bg-color: ${data.customColor};
164 --dropdown-btn-bg-color: ${data.customColor};
165 --button-hover-color: ${adjustHexColor(data.customColor, 25)};
166 --toggled-btn-bg-color: ${adjustHexColor(data.customColor, 25)};
167 --doorhanger-hover-bg-color: ${adjustHexColor(data.customColor, 20)};
168 --toolbar-border-color: ${adjustHexColor(data.customColor, 10)};
169 --doorhanger-border-color: ${adjustHexColor(data.customColor, 10)};
170 --doorhanger-border-color-whcm: ${adjustHexColor(data.customColor, 10)};
171 --separator-color: ${adjustHexColor(data.customColor, 10)};
172 --doorhanger-separator-color: ${adjustHexColor(data.customColor, 15)};
173 --toolbar-icon-bg-color: ${iconsTextsColor};
174 --toolbar-icon-bg-color: ${iconsTextsColor};
175 --main-color: ${iconsTextsColor};
176 --field-color: ${iconsTextsColor};
177 --doorhanger-hover-color: ${iconsTextsColor};
178 --toolbar-icon-hover-bg-color: ${iconsTextsColor};
179 --toggled-btn-color: ${iconsTextsColor};
180
181 }`;
182 }
183
184 if (data.position === 'top') {
185 position = 'top:0;bottom:auto;'
186 settingsPos = '';
187 }
188 else {
189 position = 'bottom:0;top:auto;'
190 settingsPos = `
191 .findbar, .secondaryToolbar {
192 top: auto;bottom: 32px;
193 }
194 .doorHangerRight:after{
195 transform: rotate(180deg);
196 bottom: -16px;
197 }
198 .doorHangerRight:before {
199 transform: rotate(180deg);
200 bottom: -18px;
201 }
202
203 .findbar.doorHanger:before {
204 bottom: -18px;
205 transform: rotate(180deg);
206 }
207 .findbar.doorHanger:after {
208 bottom: -16px;
209 transform: rotate(180deg);
210 }
211
212 div#editorInkParamsToolbar, #editorFreeTextParamsToolbar {
213 bottom: 32px;
214 top: auto;
215 }
216 `;
217 }
218
219 style.textContent = `
220 .toolbar{
221 display: ${toolbar}!important;
222 position: absolute;
223 ${position}
224 }
225 #secondaryToolbar{
226 display: ${toolbar};
227 }
228 #secondaryPresentationMode, #toolbarViewerRight #presentationMode{
229 display: ${presentation}!important;
230 }
231 #secondaryOpenFile, #toolbarViewerRight #openFile{
232 display: none!important;
233 }
234 #secondaryDownload, #secondaryPrint, #print, #download{
235 display: ${download}!important;
236 }
237 #pageRotateCw{
238 display: ${doc_rotation}!important;
239 }
240 #editorStamp{
241 display: ${add_image}!important;
242 }
243 #pageRotateCcw{
244 display: ${doc_rotation}!important;
245 }
246 #documentProperties{
247 display: ${doc_details}!important;
248 }
249 .textLayer{
250 user-select: ${copy_text}!important;
251 }
252 button#cursorSelectTool{
253 display: ${copy_text}!important;
254 }
255
256 #editorFreeText{
257 display: ${add_text}!important;
258 }
259 #editorInk{
260 display: ${draw}!important;
261 }
262
263 ${pdfCustomColor}
264
265 ${settingsPos}
266 `;
267
268 if (otherhead) {
269 if (document.getElementById("EBiframeStyleID")) {
270 document.getElementById("EBiframeStyleID").remove();
271 }
272 otherhead.appendChild(style);
273 }
274 }
275
276 const manupulatePDFIframe = (e) => {
277 let hashNewUrl = new URL(e.newURL);
278 let data = getParamObj(hashNewUrl.hash);
279 pdfIframeStyle(data);
280 setThemeMode(data.themeMode);
281
282 }
283
284 window.addEventListener('hashchange', (e) => {
285 manupulatePDFIframe(e);
286 }, false);
287
288
289 let data = getParamObj(location.hash);
290
291 pdfIframeStyle(data);
292 setThemeMode(data.themeMode);
293
294
295
296 document.querySelector(".presentationMode")?.addEventListener("click", function () {
297
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