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
342 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 | #mainContainer { |
| 217 | top: -40px!important; |
| 218 | } |
| 219 | `; |
| 220 | } |
| 221 | |
| 222 | style.textContent = ` |
| 223 | .toolbar{ |
| 224 | display: ${toolbar}!important; |
| 225 | position: absolute; |
| 226 | ${position} |
| 227 | } |
| 228 | #secondaryToolbar{ |
| 229 | display: ${toolbar}; |
| 230 | } |
| 231 | #secondaryPresentationMode, #toolbarViewerRight #presentationMode{ |
| 232 | display: ${presentation}!important; |
| 233 | } |
| 234 | #secondaryOpenFile, #toolbarViewerRight #openFile{ |
| 235 | display: none!important; |
| 236 | } |
| 237 | #secondaryDownload, #secondaryPrint, #print, #download{ |
| 238 | display: ${download}!important; |
| 239 | } |
| 240 | #pageRotateCw{ |
| 241 | display: ${doc_rotation}!important; |
| 242 | } |
| 243 | #editorStamp{ |
| 244 | display: ${add_image}!important; |
| 245 | } |
| 246 | #pageRotateCcw{ |
| 247 | display: ${doc_rotation}!important; |
| 248 | } |
| 249 | #documentProperties{ |
| 250 | display: ${doc_details}!important; |
| 251 | } |
| 252 | .textLayer{ |
| 253 | user-select: ${copy_text}!important; |
| 254 | -webkit-user-select: ${copy_text}!important; |
| 255 | -moz-user-select: ${copy_text}!important; |
| 256 | -ms-user-select: ${copy_text}!important; |
| 257 | } |
| 258 | button#cursorSelectTool{ |
| 259 | display: ${copy_text}!important; |
| 260 | } |
| 261 | |
| 262 | #editorFreeText{ |
| 263 | display: ${add_text}!important; |
| 264 | } |
| 265 | #editorInk{ |
| 266 | display: ${draw}!important; |
| 267 | } |
| 268 | |
| 269 | ${pdfCustomColor} |
| 270 | |
| 271 | ${settingsPos} |
| 272 | `; |
| 273 | |
| 274 | if (otherhead) { |
| 275 | if (document.getElementById("EBiframeStyleID")) { |
| 276 | document.getElementById("EBiframeStyleID").remove(); |
| 277 | } |
| 278 | otherhead.appendChild(style); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | const manupulatePDFIframe = (e) => { |
| 283 | let hashNewUrl = new URL(e.newURL); |
| 284 | let data = getParamObj(hashNewUrl.hash); |
| 285 | pdfIframeStyle(data); |
| 286 | setThemeMode(data.themeMode); |
| 287 | |
| 288 | } |
| 289 | |
| 290 | window.addEventListener('hashchange', (e) => { |
| 291 | manupulatePDFIframe(e); |
| 292 | }, false); |
| 293 | |
| 294 | |
| 295 | let data = getParamObj(location.hash); |
| 296 | |
| 297 | pdfIframeStyle(data); |
| 298 | setThemeMode(data.themeMode); |
| 299 | |
| 300 | |
| 301 | |
| 302 | document.querySelector(".presentationMode")?.addEventListener("click", function () { |
| 303 | |
| 304 | var mainContainer = document.getElementById("mainContainer"); |
| 305 | if (mainContainer && !document.fullscreenElement) { |
| 306 | mainContainer.requestFullscreen().catch(err => { |
| 307 | alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`); |
| 308 | }); |
| 309 | } else { |
| 310 | if (document.exitFullscreen) { |
| 311 | document.exitFullscreen(); |
| 312 | } |
| 313 | } |
| 314 | }); |
| 315 | |
| 316 | document.getElementById("viewBookmark")?.addEventListener('click', (e) => { |
| 317 | e.preventDefault(); |
| 318 | const url = e.target.getAttribute('href'); |
| 319 | if (url !== null) { |
| 320 | alert(`Current Page: ${url}`); |
| 321 | } |
| 322 | }); |
| 323 | |
| 324 | |
| 325 | if (data.lazyLoad === false || data.lazyLoad == 'false') { |
| 326 | document.querySelector('html').style.opacity = '1'; |
| 327 | } |
| 328 | else { |
| 329 | function updateOpacity() { |
| 330 | const pdfViewer = document.querySelector('.pdfViewer'); |
| 331 | |
| 332 | if (pdfViewer.innerHTML.trim()) { |
| 333 | document.querySelector('html').style.opacity = '1'; |
| 334 | document.querySelector('html').style.transition = '500ms'; |
| 335 | clearInterval(intervalId); // Clear the interval once opacity is set to 1 |
| 336 | } |
| 337 | } |
| 338 | const intervalId = setInterval(updateOpacity, 100); |
| 339 | updateOpacity(); |
| 340 | } |
| 341 | |
| 342 |