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