images
4 years ago
locale
4 years ago
ep-scripts.js
3 years ago
viewer.css
3 years ago
viewer.html
3 years ago
viewer.js
4 years ago
ep-scripts.js
158 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 | const getParamObj = (hash) => { |
| 12 | let paramsObj = {}; |
| 13 | |
| 14 | if (location.hash) { |
| 15 | let hashParams = new URLSearchParams(hash.substring(1)); |
| 16 | |
| 17 | paramsObj = { |
| 18 | themeMode: hashParams.get('themeMode'), |
| 19 | presentation: hashParams.get('presentation'), |
| 20 | copy_text: hashParams.get('copy_text'), |
| 21 | position: hashParams.get('position'), |
| 22 | download: hashParams.get('download'), |
| 23 | toolbar: hashParams.get('toolbar'), |
| 24 | doc_details: hashParams.get('doc_details'), |
| 25 | doc_rotation: hashParams.get('doc_rotation') |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | return paramsObj; |
| 30 | } |
| 31 | |
| 32 | const isDisplay = (selectorName) => { |
| 33 | if (selectorName == 'false' || selectorName == false) { |
| 34 | selectorName = 'none'; |
| 35 | } |
| 36 | else { |
| 37 | selectorName = 'block'; |
| 38 | } |
| 39 | return selectorName; |
| 40 | } |
| 41 | |
| 42 | |
| 43 | const pdfIframeStyle = (data) => { |
| 44 | let settingsPos = ''; |
| 45 | |
| 46 | if (data.toolbar === false || data.toolbar == 'false') { |
| 47 | data.presentation = false; data.download = true; data.copy_text = true; data.doc_details = false; data.doc_rotation = false; |
| 48 | } |
| 49 | |
| 50 | let position = 'top'; |
| 51 | let toolbar = isDisplay(data.toolbar); |
| 52 | let presentation = isDisplay(data.presentation); |
| 53 | let download = isDisplay(data.download); |
| 54 | let copy_text = isDisplay(data.copy_text); |
| 55 | |
| 56 | if (copy_text === 'block' || copy_text == 'true' || copy_text == true) { |
| 57 | copy_text = 'all'; |
| 58 | } |
| 59 | |
| 60 | let doc_details = isDisplay(data.doc_details); |
| 61 | let doc_rotation = isDisplay(data.doc_rotation); |
| 62 | |
| 63 | // console.log(position, toolbar, presentation, download, copy_text, doc_details, doc_rotation); |
| 64 | |
| 65 | const otherhead = document.getElementsByTagName("head")[0]; |
| 66 | |
| 67 | // console.log(document.getElementsByTagName("head")[0]); |
| 68 | |
| 69 | const style = document.createElement("style"); |
| 70 | style.setAttribute('id', 'EBiframeStyleID'); |
| 71 | |
| 72 | if (data.position === 'top') { |
| 73 | position = 'top:0;bottom:auto;' |
| 74 | settingsPos = ''; |
| 75 | } |
| 76 | else { |
| 77 | position = 'bottom:0;top:auto;' |
| 78 | settingsPos = ` |
| 79 | .findbar, .secondaryToolbar { |
| 80 | top: auto;bottom: 32px; |
| 81 | } |
| 82 | .doorHangerRight:after{ |
| 83 | transform: rotate(180deg); |
| 84 | bottom: -16px; |
| 85 | } |
| 86 | .doorHangerRight:before { |
| 87 | transform: rotate(180deg); |
| 88 | bottom: -18px; |
| 89 | } |
| 90 | |
| 91 | .findbar.doorHanger:before { |
| 92 | bottom: -18px; |
| 93 | transform: rotate(180deg); |
| 94 | } |
| 95 | .findbar.doorHanger:after { |
| 96 | bottom: -16px; |
| 97 | transform: rotate(180deg); |
| 98 | } |
| 99 | `; |
| 100 | } |
| 101 | |
| 102 | style.textContent = ` |
| 103 | .toolbar{ |
| 104 | display: ${toolbar}!important; |
| 105 | position: absolute; |
| 106 | ${position} |
| 107 | } |
| 108 | #secondaryToolbar{ |
| 109 | display: ${toolbar}; |
| 110 | } |
| 111 | #secondaryPresentationMode, #toolbarViewerRight #presentationMode{ |
| 112 | display: ${presentation}!important; |
| 113 | } |
| 114 | #secondaryOpenFile, #toolbarViewerRight #openFile{ |
| 115 | display: none!important; |
| 116 | } |
| 117 | #secondaryDownload, #secondaryPrint, #toolbarViewerRight #print, #toolbarViewerRight #download{ |
| 118 | display: ${download}!important; |
| 119 | } |
| 120 | #pageRotateCw{ |
| 121 | display: ${doc_rotation}!important; |
| 122 | } |
| 123 | #pageRotateCcw{ |
| 124 | display: ${doc_rotation}!important; |
| 125 | } |
| 126 | #documentProperties{ |
| 127 | display: ${doc_details}!important; |
| 128 | } |
| 129 | .textLayer{ |
| 130 | user-select: ${copy_text}!important; |
| 131 | } |
| 132 | ${settingsPos} |
| 133 | `; |
| 134 | |
| 135 | if (otherhead) { |
| 136 | if (document.getElementById("EBiframeStyleID")) { |
| 137 | document.getElementById("EBiframeStyleID").remove(); |
| 138 | } |
| 139 | otherhead.appendChild(style); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | const manupulatePDFIframe = (e) => { |
| 144 | let hashNewUrl = new URL(e.newURL); |
| 145 | let data = getParamObj(hashNewUrl.hash); |
| 146 | pdfIframeStyle(data); |
| 147 | setThemeMode(data.themeMode); |
| 148 | } |
| 149 | |
| 150 | window.addEventListener('hashchange', (e) => { |
| 151 | manupulatePDFIframe(e); |
| 152 | }, false); |
| 153 | |
| 154 | |
| 155 | let data = getParamObj(location.hash); |
| 156 | pdfIframeStyle(data); |
| 157 | setThemeMode(data.themeMode); |
| 158 |