vendor
7 years ago
admin.js
2 years ago
ads.js
2 years ago
documents-viewer-script.js
3 years ago
front.js
2 years ago
index.html
7 years ago
initplyr.js
2 years ago
pdfobject.min.js
3 years ago
plyr.polyfilled.js
3 years ago
preview.js
3 years ago
settings.js
6 years ago
vimeo-player.js
2 years ago
ytiframeapi.js
2 years ago
documents-viewer-script.js
292 lines
| 1 | |
| 2 | const embedpressDocViewer = {}; |
| 3 | |
| 4 | document.addEventListener("fullscreenchange", () => { |
| 5 | if (!document.fullscreenElement) { |
| 6 | const viwerParentEl = document.querySelector('.ep-file-download-option-masked.fullscreen-enabled'); |
| 7 | if (viwerParentEl) { |
| 8 | viwerParentEl.classList.remove("fullscreen-enabled"); |
| 9 | viwerParentEl.querySelector(".ep-doc-minimize-icon").style.display = 'none'; |
| 10 | viwerParentEl.querySelector(".ep-doc-fullscreen-icon").style.display = 'flex'; |
| 11 | } |
| 12 | } |
| 13 | }); |
| 14 | |
| 15 | document.addEventListener("keydown", (event) => { |
| 16 | if (event.key === "Escape") { |
| 17 | const viwerParentEl = document.querySelector('.ep-file-download-option-masked.fullscreen-enabled'); |
| 18 | if (viwerParentEl) { |
| 19 | if (document.exitFullscreen) { |
| 20 | document.exitFullscreen(); |
| 21 | } else if (document.webkitExitFullscreen) { |
| 22 | document.webkitExitFullscreen(); |
| 23 | } else if (document.msExitFullscreen) { |
| 24 | document.msExitFullscreen(); |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | }); |
| 29 | |
| 30 | |
| 31 | embedpressDocViewer.getColorBrightness = (hexColor) => { |
| 32 | const r = parseInt(hexColor.slice(1, 3), 16); |
| 33 | const g = parseInt(hexColor.slice(3, 5), 16); |
| 34 | const b = parseInt(hexColor.slice(5, 7), 16); |
| 35 | |
| 36 | // Convert the RGB color to HSL |
| 37 | const max = Math.max(r, g, b); |
| 38 | const min = Math.min(r, g, b); |
| 39 | const l = (max + min) / 2; |
| 40 | |
| 41 | // Calculate the brightness position in percentage |
| 42 | const brightnessPercentage = Math.round(l / 255 * 100); |
| 43 | |
| 44 | return brightnessPercentage; |
| 45 | } |
| 46 | |
| 47 | embedpressDocViewer.adjustHexColor = (hexColor, percentage) => { |
| 48 | // Convert hex color to RGB values |
| 49 | const r = parseInt(hexColor.slice(1, 3), 16); |
| 50 | const g = parseInt(hexColor.slice(3, 5), 16); |
| 51 | const b = parseInt(hexColor.slice(5, 7), 16); |
| 52 | |
| 53 | // Calculate adjusted RGB values |
| 54 | const adjustment = Math.round((percentage / 100) * 255); |
| 55 | const newR = Math.max(Math.min(r + adjustment, 255), 0); |
| 56 | const newG = Math.max(Math.min(g + adjustment, 255), 0); |
| 57 | const newB = Math.max(Math.min(b + adjustment, 255), 0); |
| 58 | |
| 59 | // Convert adjusted RGB values back to hex color |
| 60 | const newHexColor = '#' + ((1 << 24) + (newR << 16) + (newG << 8) + newB).toString(16).slice(1); |
| 61 | |
| 62 | return newHexColor; |
| 63 | } |
| 64 | |
| 65 | embedpressDocViewer.viewerStyle = () => { |
| 66 | const viwerParentEls = document.querySelectorAll('.ep-file-download-option-masked'); |
| 67 | |
| 68 | let customStyle = document.getElementById('custom-styles') || document.createElement('style'); |
| 69 | customStyle.id = 'custom-styles'; |
| 70 | customStyle.type = 'text/css'; |
| 71 | customStyle.innerHTML = '' |
| 72 | |
| 73 | if (viwerParentEls !== null) { |
| 74 | viwerParentEls.forEach((el) => { |
| 75 | let customColor = el.getAttribute('data-custom-color'); |
| 76 | if (customColor == null) { |
| 77 | return false; |
| 78 | } |
| 79 | let colorBrightness = embedpressDocViewer.getColorBrightness(customColor); |
| 80 | let docId = el.getAttribute('data-id'); |
| 81 | |
| 82 | let iconsColor = '#f2f2f6'; |
| 83 | if (colorBrightness > 60) { |
| 84 | iconsColor = '#343434'; |
| 85 | } |
| 86 | |
| 87 | if (el.getAttribute('data-theme-mode') == 'custom') { |
| 88 | |
| 89 | viewerCustomColor = ` |
| 90 | [data-id='${docId}'][data-theme-mode='custom'] { |
| 91 | --viewer-primary-color: ${customColor}; |
| 92 | --viewer-icons-color: ${iconsColor}; |
| 93 | --viewer-icons-hover-bgcolor: ${embedpressDocViewer.adjustHexColor(customColor, -10)}; |
| 94 | |
| 95 | }`; |
| 96 | customStyle.innerHTML += viewerCustomColor; |
| 97 | } |
| 98 | }); |
| 99 | |
| 100 | document.head.appendChild(customStyle); |
| 101 | } |
| 102 | } |
| 103 | embedpressDocViewer.epDocumentsViewerController = () => { |
| 104 | const viwerParentEls = document.querySelectorAll('.ep-file-download-option-masked'); |
| 105 | |
| 106 | function handleFullscreenChange() { |
| 107 | if (!document.fullscreenElement) { |
| 108 | viwerParentEls.forEach((el) => { |
| 109 | el.classList.remove('fullscreen-enabled'); |
| 110 | el.querySelector('.ep-doc-minimize-icon').style.display = 'none'; |
| 111 | el.querySelector('.ep-doc-fullscreen-icon').style.display = 'flex'; |
| 112 | }); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | function handleClick(event) { |
| 117 | event.stopPropagation(); |
| 118 | |
| 119 | const viwerParentEl = event.target.closest('.ep-file-download-option-masked'); |
| 120 | |
| 121 | if (!viwerParentEl) return; |
| 122 | |
| 123 | const viewerIframeEl = viwerParentEl.querySelector('iframe'); |
| 124 | if (!viewerIframeEl) return; |
| 125 | |
| 126 | const iframeSrc = decodeURIComponent(viewerIframeEl.getAttribute('src')); |
| 127 | if (!iframeSrc) return; |
| 128 | |
| 129 | const regex = /(url|src)=([^&]+)/; |
| 130 | const match = iframeSrc.match(regex); |
| 131 | let fileUrl = match && match[2]; |
| 132 | |
| 133 | if (!fileUrl) { |
| 134 | fileUrl = iframeSrc; |
| 135 | } |
| 136 | |
| 137 | const popupIcon = event.target.closest('.ep-doc-popup-icon svg'); |
| 138 | const printIcon = event.target.closest('.ep-doc-print-icon svg'); |
| 139 | const downloadcIcon = event.target.closest('.ep-doc-download-icon svg'); |
| 140 | const minimizeIcon = event.target.closest('.ep-doc-minimize-icon svg'); |
| 141 | const fullscreenIcon = event.target.closest('.ep-doc-fullscreen-icon svg'); |
| 142 | |
| 143 | if (popupIcon instanceof SVGElement) { |
| 144 | window.open(fileUrl, '_blank'); |
| 145 | } else if (printIcon instanceof SVGElement) { |
| 146 | const newTab = window.open(`https://view.officeapps.live.com/op/view.aspx?src=${fileUrl}&wdOrigin=BROWSELINK`, '_blank'); |
| 147 | } else if (downloadcIcon instanceof SVGElement) { |
| 148 | fetch(fileUrl, { mode: 'no-cors' }) |
| 149 | .then(response => { |
| 150 | if (response.ok) { |
| 151 | response.blob().then(blob => { |
| 152 | const url = window.URL.createObjectURL(blob); |
| 153 | const a = document.createElement('a'); |
| 154 | a.href = url; |
| 155 | a.download = fileUrl.substring(fileUrl.lastIndexOf('/') + 1); |
| 156 | document.body.appendChild(a); |
| 157 | a.click(); |
| 158 | a.remove(); |
| 159 | }); |
| 160 | } else { |
| 161 | window.location.href = fileUrl; |
| 162 | } |
| 163 | }) |
| 164 | .catch(error => { |
| 165 | window.location.href = fileUrl; |
| 166 | }); |
| 167 | } else if (minimizeIcon instanceof SVGElement) { |
| 168 | if (document.exitFullscreen) { |
| 169 | document.exitFullscreen(); |
| 170 | } else if (document.webkitExitFullscreen) { |
| 171 | document.webkitExitFullscreen(); |
| 172 | } else if (document.msExitFullscreen) { |
| 173 | document.msExitFullscreen(); |
| 174 | } |
| 175 | } else if (fullscreenIcon instanceof SVGElement) { |
| 176 | if (viwerParentEl.requestFullscreen) { |
| 177 | viwerParentEl.requestFullscreen(); |
| 178 | } else if (viwerParentEl.webkitRequestFullscreen) { |
| 179 | viwerParentEl.webkitRequestFullscreen(); |
| 180 | } else if (viwerParentEl.msRequestFullscreen) { |
| 181 | viwerParentEl.msRequestFullscreen(); |
| 182 | } |
| 183 | |
| 184 | viwerParentEl.querySelector(".ep-doc-minimize-icon").style.display = 'flex'; |
| 185 | viwerParentEl.querySelector(".ep-doc-fullscreen-icon").style.display = 'none'; |
| 186 | viwerParentEl.classList.add("fullscreen-enabled"); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | function handleDrawIconClick(event) { |
| 191 | event.stopPropagation(); |
| 192 | |
| 193 | const drawIcon = event.target.closest('.ep-doc-draw-icon svg'); |
| 194 | if (!drawIcon) return; |
| 195 | |
| 196 | const viwerParentEl = drawIcon.closest('.ep-file-download-option-masked'); |
| 197 | if (!viwerParentEl) return; |
| 198 | |
| 199 | const canvas = viwerParentEl.querySelector(".ep-doc-canvas"); |
| 200 | const drawToggle = viwerParentEl.querySelector(".ep-doc-draw-icon svg"); |
| 201 | if (!canvas || !drawToggle) return; |
| 202 | |
| 203 | const ctx = canvas.getContext("2d"); |
| 204 | let isDrawing = false; |
| 205 | let canDraw = false; |
| 206 | |
| 207 | canvas.addEventListener("mousedown", function (e) { |
| 208 | if (canDraw) { |
| 209 | isDrawing = true; |
| 210 | const rect = canvas.getBoundingClientRect(); |
| 211 | const scrollX = window.pageXOffset || document.documentElement.scrollLeft; |
| 212 | const x = e.pageX - rect.left - scrollX; |
| 213 | const y = e.pageY - rect.top; |
| 214 | ctx.beginPath(); |
| 215 | ctx.moveTo(x, y); |
| 216 | } |
| 217 | }); |
| 218 | |
| 219 | canvas.addEventListener("mousemove", function (e) { |
| 220 | if (isDrawing && canDraw) { |
| 221 | const rect = canvas.getBoundingClientRect(); |
| 222 | const scrollX = window.pageXOffset || document.documentElement.scrollLeft; |
| 223 | const x = e.pageX - rect.left - scrollX; |
| 224 | const y = e.pageY - rect.top; |
| 225 | ctx.lineTo(x, y); |
| 226 | ctx.stroke(); |
| 227 | } |
| 228 | }); |
| 229 | |
| 230 | canvas.addEventListener("mouseup", function (e) { |
| 231 | isDrawing = false; |
| 232 | }); |
| 233 | |
| 234 | |
| 235 | drawToggle.parentNode.classList.toggle("active"); |
| 236 | canDraw = drawToggle.parentNode.classList.contains("active"); |
| 237 | canvas.style.display = canDraw ? "block" : "none"; |
| 238 | } |
| 239 | |
| 240 | document.addEventListener('click', handleClick); |
| 241 | document.addEventListener('click', handleDrawIconClick); |
| 242 | document.addEventListener('fullscreenchange', handleFullscreenChange); |
| 243 | }; |
| 244 | |
| 245 | |
| 246 | if (typeof embedpressDocViewer.epDocumentsViewerController === "function") { |
| 247 | if (jQuery('.wp-block-embedpress-document.embedpress-document-embed').length > 0) { |
| 248 | embedpressDocViewer.epDocumentsViewerController(); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | if (typeof wp !== 'undefined' && typeof wp.editor !== 'undefined') { |
| 253 | if (typeof embedpressDocViewer.viewerStyle === "function") { |
| 254 | embedpressDocViewer.epDocumentsViewerController(); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | |
| 259 | if (typeof embedpressDocViewer.viewerStyle === "function") { |
| 260 | if (jQuery('.wp-block-embedpress-document.embedpress-document-embed').length > 0) { |
| 261 | embedpressDocViewer.viewerStyle(); |
| 262 | } |
| 263 | } |
| 264 | jQuery(window).on("elementor/frontend/init", function () { |
| 265 | var filterableGalleryHandler = function ($scope, $) { |
| 266 | if (typeof embedpressDocViewer.epDocumentsViewerController === "function") { |
| 267 | embedpressDocViewer.epDocumentsViewerController(); |
| 268 | } |
| 269 | if (typeof embedpressDocViewer.epDocumentsViewerController === "function") { |
| 270 | embedpressDocViewer.viewerStyle(); |
| 271 | } |
| 272 | |
| 273 | }; |
| 274 | elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_document.default", filterableGalleryHandler); |
| 275 | }); |
| 276 | |
| 277 | |
| 278 | const myDivs = document.querySelectorAll('.ep-file-download-option-masked'); |
| 279 | const canDownloadDivs = document.querySelectorAll('.enabled-file-download'); |
| 280 | |
| 281 | |
| 282 | myDivs.forEach(function (div) { |
| 283 | div.addEventListener('contextmenu', preventRightClick); |
| 284 | }); |
| 285 | |
| 286 | function preventRightClick(event) { |
| 287 | event.preventDefault(); |
| 288 | } |
| 289 | |
| 290 | canDownloadDivs.forEach(function (div) { |
| 291 | div.removeEventListener('contextmenu', preventRightClick); |
| 292 | }); |