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 |