From 7290975873b033f93f5cf10ee3c1a42e28055678 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Sun, 2 Aug 2020 17:52:25 +0200 Subject: [PATCH] disable download button on blocked files --- res/include/script/file_viewer/Viewer.js | 35 +++++++++++-------- .../file_viewer/viewer_scripts/AbuseViewer.js | 10 +++++- res/include/style/layout.css | 10 ++++++ 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/res/include/script/file_viewer/Viewer.js b/res/include/script/file_viewer/Viewer.js index d161904..d1fbe20 100644 --- a/res/include/script/file_viewer/Viewer.js +++ b/res/include/script/file_viewer/Viewer.js @@ -7,12 +7,12 @@ function Viewer(type, viewToken, data) { this.file = null this.title = "" // Contains either the file name or list title this.listId = "" - this.viewToken = "" + this.viewToken = viewToken this.isList = false this.isFile = false this.initialized = false + this.viewerScript = null - this.viewToken = viewToken this.toolbar = new Toolbar(this) this.detailsWindow = new DetailsWindow(this) this.editWindow = new EditWindow() @@ -92,48 +92,53 @@ Viewer.prototype.setFile = function(file) { ) } + // Clean up the previous viewer if possible + if (this.viewerScript !== null && typeof this.viewerScript.destroy === "function") { + this.viewerScript.destroy() + } + // Clear the canvas this.divFilepreview.innerHTML = "" + // This function can be used by the viewer scripts to navigate to the next + // file when a songs has ended for example let nextItem = () => { if (this.listNavigator !== null) { this.listNavigator.nextItem() } } - if ( - file.abuse_type !== "" - ) { - new AbuseViewer(this,file).render(this.divFilepreview) - }else if ( - file.mime_type.startsWith("image") - ) { - new ImageViewer(this, file).render(this.divFilepreview) + if (file.abuse_type !== "") { + this.viewerScript = new AbuseViewer(this,file) + }else if (file.mime_type.startsWith("image")) { + this.viewerScript = new ImageViewer(this, file) } else if ( file.mime_type.startsWith("video") || file.mime_type === "application/matroska" || file.mime_type === "application/x-matroska" ) { - new VideoViewer(this, file, nextItem).render(this.divFilepreview) + this.viewerScript = new VideoViewer(this, file, nextItem) } else if ( file.mime_type.startsWith("audio") || file.mime_type === "application/ogg" || file.name.endsWith(".mp3") ) { - new AudioViewer(this, file, nextItem).render(this.divFilepreview) + this.viewerScript = new AudioViewer(this, file, nextItem) } else if ( file.mime_type === "application/pdf" || file.mime_type === "application/x-pdf" ) { - new PDFViewer(this, file).render(this.divFilepreview) + this.viewerScript = new PDFViewer(this, file) } else if ( file.mime_type.startsWith("text") || file.id === "demo" ) { - new TextViewer(this, file).render(this.divFilepreview) + this.viewerScript = new TextViewer(this, file) } else { - new FileViewer(this, file).render(this.divFilepreview) + this.viewerScript = new FileViewer(this, file) } + + this.viewerScript.render(this.divFilepreview) } Viewer.prototype.renderSponsors = function() { diff --git a/res/include/script/file_viewer/viewer_scripts/AbuseViewer.js b/res/include/script/file_viewer/viewer_scripts/AbuseViewer.js index 4d371cb..bcfde20 100644 --- a/res/include/script/file_viewer/viewer_scripts/AbuseViewer.js +++ b/res/include/script/file_viewer/viewer_scripts/AbuseViewer.js @@ -12,7 +12,6 @@ function AbuseViewer(viewer, file, next) { this.container.appendChild(this.title) this.description = document.createElement("p") - // this.description.style.maxWidth = "500px" this.description.innerText = "This file has received an abuse report and "+ "was taken down." this.container.appendChild(this.description) @@ -25,4 +24,13 @@ function AbuseViewer(viewer, file, next) { AbuseViewer.prototype.render = function(parent) { parent.appendChild(this.container) + + // Disable the download button + this.btnDownloadDisplay = this.viewer.toolbar.btnDownload.style.display + this.viewer.toolbar.btnDownload.style.display = "none" +} + +AbuseViewer.prototype.destroy = function(parent) { + // Restore the download button + this.viewer.toolbar.btnDownload.style.display = this.btnDownloadDisplay } diff --git a/res/include/style/layout.css b/res/include/style/layout.css index 239ed8f..c903216 100644 --- a/res/include/style/layout.css +++ b/res/include/style/layout.css @@ -458,6 +458,16 @@ select:active{ .button_red {background: linear-gradient(var(--danger_color), var(--danger_color_dark)) !important; color: var(--highlight_text_color) !important;} .button_red:active {background: linear-gradient(var(--danger_color_dark), var(--danger_color)) !important; color: var(--highlight_text_color) !important;} +button:disabled, button.disabled, +.button:disabled, .button.disabled, +input[type="submit"]:disabled, input[type="submit"].disabled, +input[type="button"]:disabled, input[type="button"].disabled, +input[type="color"]:disabled, input[type="color"].disabled, +select:disabled , select.disabled { + background: var(--input_color_dark); + box-shadow: none; +} + /* Dropdown list of the select tag */ option{ background-color: var(--input_color_dark);