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