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