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